List of usage examples for android.content Intent putStringArrayListExtra
public @NonNull Intent putStringArrayListExtra(String name, ArrayList<String> value)
From source file:csms19.inapp.msg.customgallery.VideoFragment.java
private void setAdapter() { int count = mCursor.getCount(); if (count > 0) { mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA); // move position to first element mCursor.moveToFirst();//from w w w . j av a 2 s .com mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < count; i++) { mCursor.moveToPosition(i); String url = mCursor.getString(mDataColumnIndex); mGalleryModelList.add(new MediaModel(url, false)); } mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true); mVideoAdapter.videoFragment = this; mVideoGridView.setAdapter(mVideoAdapter); mVideoGridView.setOnScrollListener(this); } else { Toast.makeText(getActivity(), "no media file available", Toast.LENGTH_SHORT).show(); } mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "video/*"); startActivity(intent); return false; } }); mVideoGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), true); // comment start 14Jan /*if (size != 0) { Toast.makeText( getActivity(), "The file size exceeds the maximum limit of" + " " + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " " + "MB", Toast.LENGTH_SHORT) .show(); return; }*/ // comment end if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) { if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), "Max limit" + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + "file", Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), "Max limit" + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + "file", Toast.LENGTH_SHORT).show(); return; } } } // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); MediaChooserConstants.SELECTED_MEDIA_COUNT++; } else { mSelectedItems.remove(galleryModel.url.toString().trim()); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } if (mCallback != null) { mCallback.onVideoSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.dazone.crewchat.libGallery.fragment.ImageFragment.java
private void setAdapter(Cursor imagecursor) { if (imagecursor.getCount() > 0) { mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false); mGalleryModelList.add(galleryModel); }/*from ww w. j ava2 s.c om*/ mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false); mImageGridView.setAdapter(mImageAdapter); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mImageGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); return true; } }); mImageGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), false); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) { if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } } // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); MediaChooserConstants.SELECTED_MEDIA_COUNT++; } else { mSelectedItems.remove(galleryModel.url.toString().trim()); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } if (mCallback != null) { mCallback.onImageSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.media.LuYinFragment.java
private void setAdapter(Cursor imagecursor) { if (imagecursor.getCount() > 0) { mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Audio.Media.DATA); MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false); mGalleryModelList.add(galleryModel); }//from ww w. ja v a 2 s . c o m mImageAdapter = new AudioListViewAdapter(getActivity(), 0, mGalleryModelList, false); audioListView.setAdapter(mImageAdapter); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } audioListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { AudioListViewAdapter adapter = (AudioListViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "audio/*"); startActivity(intent); return true; } }); audioListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter AudioListViewAdapter adapter = (AudioListViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), false); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) { if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } } // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); MediaChooserConstants.SELECTED_MEDIA_COUNT++; } else { mSelectedItems.remove(galleryModel.url.toString().trim()); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } if (mCallback != null) { mCallback.onLuYinSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.nicolls.ablum.fragment.ImageFragment.java
private void setAdapter(Cursor imagecursor) { // Toast.makeText(getActivity(),pathList.size()+"###",Toast.LENGTH_SHORT).show(); if (imagecursor.getCount() > 0) { mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false); for (String path : pathList) { if (TextUtils.equals(path, galleryModel.url)) { galleryModel.status = true; mSelectedItems.add(galleryModel.url.toString()); break; }/*w w w. j a v a 2 s. co m*/ } mGalleryModelList.add(galleryModel); } mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false); mImageGridView.setAdapter(mImageAdapter); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mImageGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); return true; } }); mImageGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), false); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) { if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } } // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); MediaChooserConstants.SELECTED_MEDIA_COUNT++; } else { mSelectedItems.remove(galleryModel.url.toString().trim()); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } if (mCallback != null) { mCallback.onImageSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.media.VideoFragment.java
private void setAdapter() { int count = mCursor.getCount(); if (count > 0) { mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA); // move position to first element mCursor.moveToFirst();//from w ww. j a va 2 s . com mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < count; i++) { mCursor.moveToPosition(i); String url = mCursor.getString(mDataColumnIndex); mGalleryModelList.add(new MediaModel(url, false)); } mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true); mVideoAdapter.videoFragment = this; mVideoGridView.setAdapter(mVideoAdapter); mVideoGridView.setOnScrollListener(this); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "video/*"); startActivity(intent); return false; } }); mVideoGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), true); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) { if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } } // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); MediaChooserConstants.SELECTED_MEDIA_COUNT++; } else { mSelectedItems.remove(galleryModel.url.toString().trim()); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } if (mCallback != null) { mCallback.onVideoSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.dazone.crewchat.libGallery.fragment.VideoFragment.java
private void setAdapter() { int count = mCursor.getCount(); if (count > 0) { mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA); //move position to first element mCursor.moveToFirst();//from w w w .j ava 2 s . co m mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < count; i++) { mCursor.moveToPosition(i); String url = mCursor.getString(mDataColumnIndex); mGalleryModelList.add(new MediaModel(url, false)); } mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true); mVideoAdapter.videoFragment = this; mVideoGridView.setAdapter(mVideoAdapter); mVideoGridView.setOnScrollListener(this); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "video/*"); startActivity(intent); return false; } }); mVideoGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), true); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) { if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } } // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); MediaChooserConstants.SELECTED_MEDIA_COUNT++; } else { mSelectedItems.remove(galleryModel.url.toString().trim()); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } if (mCallback != null) { mCallback.onVideoSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.nicolls.ablum.fragment.VideoFragment.java
private void setAdapter() { int count = mCursor.getCount(); // Toast.makeText(getActivity(),pathList.size()+"###",Toast.LENGTH_SHORT).show(); if (count > 0) { mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA); //move position to first element mCursor.moveToFirst();//w w w .java 2 s . co m mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < count; i++) { mCursor.moveToPosition(i); String url = mCursor.getString(mDataColumnIndex); MediaModel galleryModel = new MediaModel(url, false); for (String path : pathList) { if (TextUtils.equals(path, galleryModel.url)) { galleryModel.status = true; mSelectedItems.add(galleryModel.url.toString()); break; } } mGalleryModelList.add(galleryModel); } mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true); mVideoAdapter.videoFragment = this; mVideoGridView.setAdapter(mVideoAdapter); mVideoGridView.setOnScrollListener(this); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "video/*"); startActivity(intent); return false; } }); mVideoGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), true); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) { if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } } // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); MediaChooserConstants.SELECTED_MEDIA_COUNT++; } else { mSelectedItems.remove(galleryModel.url.toString().trim()); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } if (mCallback != null) { mCallback.onVideoSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.example.de.taomi2.mediachooser.fragment.ImageFragment.java
private void setAdapter(Cursor imagecursor) { if (imagecursor.getCount() > 0) { mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false); mGalleryModelList.add(galleryModel); }/*from w ww . ja v a2 s . co m*/ mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false); mImageGridView.setAdapter(mImageAdapter); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mImageGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); return true; } }); mImageGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), false); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } /* if((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)){ if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } */ } /* // inverse the status galleryModel.status = ! galleryModel.status; adapter.notifyDataSetChanged(); */ int i = 0; for (; i < adapter.getCount(); i++) { if (i != position) { adapter.getItem(i).status = false; } } galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); mSelectedItems.clear(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); //MediaChooserConstants.SELECTED_MEDIA_COUNT ++; } else { //mSelectedItems.remove(galleryModel.url.toString().trim()); //MediaChooserConstants.SELECTED_MEDIA_COUNT --; } if (mCallback != null) { mCallback.onImageSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.example.de.taomi2.mediachooser.fragment.VideoFragment.java
private void setAdapter() { int count = mCursor.getCount(); if (count > 0) { mDataColumnIndex = mCursor.getColumnIndex(MEDIA_DATA); //move position to first element mCursor.moveToFirst();/* ww w . j a v a2 s . co m*/ mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < count; i++) { mCursor.moveToPosition(i); String url = mCursor.getString(mDataColumnIndex); mGalleryModelList.add(new MediaModel(url, false)); } mVideoAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, true); mVideoAdapter.videoFragment = this; mVideoGridView.setAdapter(mVideoAdapter); mVideoGridView.setOnScrollListener(this); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mVideoGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "video/*"); startActivity(intent); return false; } }); mVideoGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), true); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_VIDEO_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } /* if((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)){ if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } */ } /* // inverse the status galleryModel.status = ! galleryModel.status; adapter.notifyDataSetChanged(); */ int i = 0; for (; i < adapter.getCount(); i++) { if (i != position) { adapter.getItem(i).status = false; } } galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); mSelectedItems.clear(); if (galleryModel.status) { mSelectedItems.add(galleryModel.url.toString()); //MediaChooserConstants.SELECTED_MEDIA_COUNT ++; } else { /* mSelectedItems.remove(galleryModel.url.toString().trim()); MediaChooserConstants.SELECTED_MEDIA_COUNT --; */ } if (mCallback != null) { mCallback.onVideoSelected(mSelectedItems.size()); Intent intent = new Intent(); intent.putStringArrayListExtra("list", mSelectedItems); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:org.de.jmg.learn.MainActivity.java
@SuppressLint("InlinedApi") public void SaveVokAs(boolean blnUniCode, boolean blnNew) throws Exception { boolean blnActionCreateDocument = false; try {//from ww w . ja v a 2 s . com if (fPA.fragMain != null && fPA.fragMain.mainView != null) fPA.fragMain.EndEdit(false); if (!libString.IsNullOrEmpty(vok.getFileName()) || vok.getURI() == null || Build.VERSION.SDK_INT < 19) { boolean blnSuccess; for (int i = 0; i < 2; i++) { try { String key = "AlwaysStartExternalProgram"; int AlwaysStartExternalProgram = prefs.getInt(key, 999); lib.YesNoCheckResult res; if (AlwaysStartExternalProgram == 999 && !(vok.getURI() != null && i == 1)) { res = lib.ShowMessageYesNoWithCheckbox(this, "", getString(R.string.msgStartExternalProgram), getString(R.string.msgRememberChoice), false); if (res != null) { if (res.res == yesnoundefined.undefined) return; if (res.checked) prefs.edit().putInt(key, res.res == yesnoundefined.yes ? -1 : 0).commit(); } else { yesnoundefined par = yesnoundefined.undefined; res = new lib.YesNoCheckResult(par, true); } } else { yesnoundefined par = yesnoundefined.undefined; if (AlwaysStartExternalProgram == -1) par = yesnoundefined.yes; if (AlwaysStartExternalProgram == 0) par = yesnoundefined.no; res = new lib.YesNoCheckResult(par, true); } if ((vok.getURI() != null && i == 1) || res.res == yesnoundefined.no) { Intent intent = new Intent(this, AdvFileChooser.class); ArrayList<String> extensions = new ArrayList<>(); extensions.add(".k??"); extensions.add(".v??"); extensions.add(".K??"); extensions.add(".V??"); extensions.add(".KAR"); extensions.add(".VOK"); extensions.add(".kar"); extensions.add(".vok"); extensions.add(".dic"); extensions.add(".DIC"); if (libString.IsNullOrEmpty(vok.getFileName())) { if (vok.getURI() != null) { intent.setData(vok.getURI()); } } else { File F = new File(vok.getFileName()); Uri uri = Uri.fromFile(F); intent.setData(uri); } intent.putExtra("URIName", vok.getURIName()); intent.putStringArrayListExtra("filterFileExtension", extensions); intent.putExtra("blnUniCode", blnUniCode); intent.putExtra("DefaultDir", new File(JMGDataDirectory).exists() ? JMGDataDirectory : Environment.getExternalStorageDirectory().getPath()); intent.putExtra("selectFolder", false); intent.putExtra("blnNew", blnNew); if (_blnUniCode) _oldUniCode = yesnoundefined.yes; else _oldUniCode = yesnoundefined.no; _blnUniCode = blnUniCode; this.startActivityForResult(intent, FILE_CHOOSERADV); blnSuccess = true; } else if (Build.VERSION.SDK_INT < 19) { //org.openintents.filemanager Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setData(vok.getURI()); intent.putExtra("org.openintents.extra.WRITEABLE_ONLY", true); intent.putExtra("org.openintents.extra.TITLE", getString(R.string.SaveAs)); intent.putExtra("org.openintents.extra.BUTTON_TEXT", getString(R.string.btnSave)); intent.setType("*/*"); Intent chooser = Intent.createChooser(intent, getString(R.string.SaveAs)); if (intent.resolveActivity(context.getPackageManager()) != null) { startActivityForResult(chooser, FILE_OPENINTENT); blnSuccess = true; } else { lib.ShowToast(this, getString(R.string.InstallFilemanager)); intent.setData(null); intent.removeExtra("org.openintents.extra.WRITEABLE_ONLY"); intent.removeExtra("org.openintents.extra.TITLE"); intent.removeExtra("org.openintents.extra.BUTTON_TEXT"); startActivityForResult(chooser, FILE_OPENINTENT); blnSuccess = true; } } else { blnActionCreateDocument = true; blnSuccess = true; } } catch (Exception ex) { blnSuccess = false; Log.e("SaveAs", ex.getMessage(), ex); if (i == 1) { lib.ShowException(this, ex); } } if (blnSuccess) break; } } else if (Build.VERSION.SDK_INT >= 19) { blnActionCreateDocument = true; } if (blnActionCreateDocument) { /** * Open a file for writing and append some text to it. */ // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's // file browser. Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); // Create a file with the requested MIME type. String defaultURI = prefs.getString("defaultURI", ""); if (!libString.IsNullOrEmpty(defaultURI)) { String FName = ""; if (vok.getURI() != null) { String path2 = lib.dumpUriMetaData(this, vok.getURI()); if (path2.contains(":")) path2 = path2.split(":")[0]; FName = path2.substring(path2.lastIndexOf("/") + 1); } else if (!libString.IsNullOrEmpty(vok.getFileName())) { FName = new File(vok.getFileName()).getName(); } intent.putExtra(Intent.EXTRA_TITLE, FName); //defaultURI = (!defaultURI.endsWith("/")?defaultURI.substring(0,defaultURI.lastIndexOf("/")+1):defaultURI); Uri def = Uri.parse(defaultURI); intent.setData(def); } else { Log.d("empty", "empty"); //intent.setType("file/*"); } // Filter to only show results that can be "opened", such as a // file (as opposed to a list of contacts or timezones). intent.addCategory(Intent.CATEGORY_OPENABLE); // Filter to show only text files. intent.setType("*/*"); startActivityForResult(intent, EDIT_REQUEST_CODE); } } catch (Exception ex) { libLearn.gStatus = "SaveVokAs"; lib.ShowException(this, ex); } }