Browse Source

VideoView Fragment and pop up working

bk_master_copy
Bastian Kohler 1 year ago
parent
commit
0082602bea

+ 0
- 1
app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java View File

passToServiceListener(stringBufferWifi); passToServiceListener(stringBufferWifi);
checkState(data); checkState(data);
checkTyp(data); checkTyp(data);

} }
}); });



+ 0
- 53
app/src/main/java/com/example/ueberwachungssystem/Fragments/VideoFileFragment.java View File

package com.example.ueberwachungssystem.Fragments;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.example.ueberwachungssystem.R;

import java.util.ArrayList;
import java.util.List;

public class VideoFileFragment extends Fragment {

private ListView listView;
private ArrayAdapter<String> adapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.video_file_fragment, container, false);

listView = rootView.findViewById(R.id.listView);
adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, getData());
listView.setAdapter(adapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Handle item click event here
String selectedItem = adapter.getItem(position);
Toast.makeText(requireContext(), selectedItem, Toast.LENGTH_SHORT).show();
}
});

return rootView;
}

private List<String> getData() {
// Add your data source here, e.g., an array or a list
List<String> data = new ArrayList<>();
data.add("Item 1");
data.add("Item 2");
data.add("Item 3");
return data;
}
}

+ 87
- 0
app/src/main/java/com/example/ueberwachungssystem/Fragments/VideoListFragment.java View File

package com.example.ueberwachungssystem.Fragments;

import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Toast;
import android.widget.VideoView;

import androidx.fragment.app.Fragment;

import com.example.ueberwachungssystem.R;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class VideoListFragment extends Fragment {

private ListView listView;
private ArrayAdapter<String> adapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.videolist_fragment, container, false);

listView = rootView.findViewById(R.id.listView);
adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, getFileNames());
listView.setAdapter(adapter);

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Handle item click event here
String selectedItem = getContext().getFilesDir().toString() + "/" + adapter.getItem(position);
//Toast.makeText(requireContext(), selectedItem, Toast.LENGTH_SHORT).show();

openVideoPopup(selectedItem);
}
});
return rootView;
}

private List<String> getFileNames() {
// Add your data source here, e.g., an array or a list
File dir = getContext().getFilesDir();
File[] files = dir.listFiles();
Log.d("files", getContext().getFilesDir().toString());


List<String> fileNamesList = new ArrayList<>();
assert files != null;
for (File file : files) {
fileNamesList.add(file.getName());
}
return fileNamesList;
}


private void openVideoPopup(String videoPath) {
LayoutInflater inflater = LayoutInflater.from(requireContext());
View popupView = inflater.inflate(R.layout.videolist_popup, null);

VideoView videoView = popupView.findViewById(R.id.videoView);
videoView.setVideoPath(videoPath);
videoView.start();

PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);

popupView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//Close the window when clicked
popupWindow.dismiss();
return true;
}
});
popupWindow.showAtLocation(listView, Gravity.CENTER, 0, 0);
}
}

+ 3
- 9
app/src/main/java/com/example/ueberwachungssystem/MainActivity.java View File



import androidx.camera.core.ExperimentalGetImage; import androidx.camera.core.ExperimentalGetImage;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.ToggleButton; import android.widget.ToggleButton;
import com.example.ueberwachungssystem.Fragments.Fragment2; import com.example.ueberwachungssystem.Fragments.Fragment2;
import com.example.ueberwachungssystem.Detection.DetectorService; import com.example.ueberwachungssystem.Detection.DetectorService;
import com.example.ueberwachungssystem.Fragments.Fragment3; import com.example.ueberwachungssystem.Fragments.Fragment3;
import com.example.ueberwachungssystem.Fragments.VideoFileFragment;

import java.util.ArrayList;
import com.example.ueberwachungssystem.Fragments.VideoListFragment;


@ExperimentalGetImage @ExperimentalGetImage
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private Fragment1 fragment1; private Fragment1 fragment1;
private Fragment2 fragment2; private Fragment2 fragment2;
private Fragment3 fragment3; private Fragment3 fragment3;
private VideoFileFragment videoFileFragment = new VideoFileFragment();
private VideoListFragment videoListFragment = new VideoListFragment();
private DetectorService detectorService = new DetectorService(); private DetectorService detectorService = new DetectorService();
int num = 0; int num = 0;
//Textviews //Textviews
public void onClickZeigeFragment2(View view) { public void onClickZeigeFragment2(View view) {
Button button = (Button) view; Button button = (Button) view;
//zeigeFragment(fragment2.erstellen("Hier stehen dann die Videos")); //zeigeFragment(fragment2.erstellen("Hier stehen dann die Videos"));
zeigeFragment(videoFileFragment);
zeigeFragment(videoListFragment);
} }
public void onClickZeigeFragment3(View view) { public void onClickZeigeFragment3(View view) {
Button button = (Button) view; Button button = (Button) view;

+ 0
- 53
app/src/main/java/com/example/ueberwachungssystem/VideoAdapter.java View File

package com.example.ueberwachungssystem;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;

import java.util.List;

public class VideoAdapter extends ArrayAdapter<String> {

private List<String> fileList;
private OnFileClickListener listener;

public VideoAdapter (Context context, List<String> fileList, OnFileClickListener listener) {
super(context, 0, fileList);
this.fileList = fileList;
this.listener = listener;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_file, parent, false);
}

TextView fileNameText = convertView.findViewById(R.id.file_name_text);
final String fileName = fileList.get(position);
fileNameText.setText(fileName);

convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onFileClick(fileName);
listener.onFileClick(fileName);
}
});

return convertView;
}

public interface OnFileClickListener {
View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState);

void onFileClick(String fileName);
}
}

+ 0
- 17
app/src/main/res/layout/list_item_file.xml View File

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- list_item_file.xml -->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/file_name_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:padding="8dp"
tools:ignore="MissingConstraints" />

</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/video_file_fragment.xml → app/src/main/res/layout/videolist_fragment.xml View File


+ 13
- 0
app/src/main/res/layout/videolist_popup.xml View File

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingVertical="100dp">

<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"/>

</FrameLayout>

Loading…
Cancel
Save