I've created a custom video gallery which populates all your video from the phone and shows it to you. I've succeeded in making the gallery, and yes it shows the thumbnails of the videos not the video. Now the next thing is that to select those videos either or multiple.
I've followed this link but couldn't find the appropriate answer my code is here :
to select multiple images from the gridview
I've set the choice mode of my grid view to ListView.CHOICE_MODE_MULTIPLE but couldn't find whether it is working or not. I need some border in order to find out whether I've implemented the correct code or not whether it has a deselection mode or not if the user want to deselect the video thumbnail.
Second thing I need to populate my selections in another activity in a listview which is horizontally scrollable.
This is my code so far. Everything is working except the two problems which I have just mentioned. I do not want to make checkboxes just the border thing but struggling to find my solution. I know here I can best people with best results.
public class AddFragment extends Fragment {
private ImageButton imageButton;
private GridView gridView;
ArrayList<File> list = new ArrayList<>();
public AddFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_add, container, false);
imageButton = (ImageButton) view.findViewById(R.id.gotoButton);
gridView = (GridView) view.findViewById(R.id.grid_view);
videoReader(Environment.getExternalStorageDirectory());
gridView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
gridView.setAdapter(new ImageAdapter(getContext()));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
//for making the button visible as ssonas the item gets selected
imageButton.setVisibility(view.VISIBLE);
}
});
return view;
}
void videoReader(File root) {
File[] file = root.listFiles();
for (File aFile : file) {
if (!aFile.isDirectory()) {
if (aFile.getName().endsWith(".mp4")) {
Log.e("VIDEO_FILE=====", aFile.getName());
list.add(aFile);
}
} else {
videoReader(aFile);
}
}
}
public class ImageAdapter extends BaseAdapter {
private Bitmap bitmap;
private final Context context;
private ImageAdapter(Context c) {
context = c;
}
//for the video numbers
@Override
public int getCount() {
return list.size();
}
//for getting the video items position vise
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
ImageView picturesView;
if (convertView == null) {
picturesView = new ImageView(context);
if (list.get(position).toString().contains(".jpg")) {
bitmap = BitmapFactory.decodeFile(list.get(position).toString()); //Creation of Thumbnail of image
} else {
if (list.get(position).toString().contains(".mp4")) {
bitmap = ThumbnailUtils.createVideoThumbnail(list.get(position).toString(), 1); //Creation of Thumbnail of video
}
}
picturesView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//picturesView.setPadding(8, 8, 8, 8);
picturesView.setLayoutParams(new GridView.LayoutParams(200,200));
picturesView.setImageBitmap(bitmap);
} else {
picturesView = (ImageView) convertView;
}
return picturesView;
}
} }
I've followed one more link but it is picking the photos from the gallery itself. I need to pick those thumbnails of the videos and get the videos in the next activity as a thumbnails but when we select the videos will be there in the VideoView.
Android selecting multiple images from the gallery and then populating in the gridview
**EDITS : **
OUTPUTS ON WHICH I'M WORKING
1. Here the thumbnails of the video comes up and you can see the checked video which is of red colored border, the page is multiple selectable and you can deselect it too.
2. Now here comes the activity which contains the selected video you chose from the previous video thumbnails. P.S. You are going from a fragment to activity which is Edit Section so we need to take the selected ones to the activity. In below you can see that the video's thumbnail is there at the bottom which is selected in the previous page.