-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86df374
commit 2a3e28c
Showing
18 changed files
with
332 additions
and
98 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...edia_adapter/ExampleInstrumentedTest.java → ...mediaadapter/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...s/android_media_adapter/MainActivity.java → ...ava/io/mns/mediaadapter/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
app/src/main/java/io/mns/mediaadapter/media/MediaAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.mns.mediaadapter.media; | ||
|
||
import android.content.ContentResolver; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.provider.MediaStore; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.CursorAdapter; | ||
import android.widget.FrameLayout; | ||
import android.widget.ImageView; | ||
import com.jess.ui.TwoWayAbsListView; | ||
|
||
import io.mns.mediaadapter.R; | ||
|
||
public class MediaAdapter extends CursorAdapter { | ||
|
||
private static BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); | ||
static int IMAGE_WIDTH = 86; | ||
static int IMAGE_HEIGHT = 86; | ||
private ContentResolver contentResolver; | ||
private static final int MEDIA_ID_COLUMN = 0; | ||
private FrameLayout.LayoutParams videoIconLayoutParams; | ||
private TwoWayAbsListView.LayoutParams thumbnailLayoutParams; | ||
|
||
|
||
MediaAdapter(Context context, Cursor c, boolean autoReQuery) { | ||
super(context, c, autoReQuery); | ||
float scale = context.getResources().getDisplayMetrics().density; | ||
int mImageWidth = (int) (IMAGE_WIDTH * scale); | ||
int mImageHeight = (int) (IMAGE_HEIGHT * scale); | ||
bitmapOptions.inSampleSize = 2; | ||
contentResolver = context.getContentResolver(); | ||
int videoIconSize = context.getResources().getDimensionPixelSize(R.dimen.video_thumbnail_icon_size); | ||
videoIconLayoutParams = new FrameLayout.LayoutParams(videoIconSize, videoIconSize); | ||
videoIconLayoutParams.setMargins(8, 4, 4, 4); | ||
thumbnailLayoutParams = new TwoWayAbsListView.LayoutParams(mImageWidth, mImageHeight); | ||
} | ||
|
||
@Override | ||
public View newView(Context context, Cursor cursor, ViewGroup parent) { | ||
FrameLayout frameLayout = new FrameLayout(context); | ||
ImageView imageView = new ImageView(context); | ||
ImageView videoIcon = new ImageView(context); | ||
frameLayout.setLayoutParams(thumbnailLayoutParams); | ||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); | ||
videoIcon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_video_camera_white)); | ||
frameLayout.addView(imageView); | ||
frameLayout.addView(videoIcon, videoIconLayoutParams); | ||
return frameLayout; | ||
} | ||
|
||
@Override | ||
public void bindView(View view, Context context, Cursor cursor) { | ||
int id = cursor.getInt(MEDIA_ID_COLUMN); | ||
Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(contentResolver, id, MediaStore.Images.Thumbnails.MICRO_KIND, null); | ||
if (bitmap == null) { | ||
bitmap = MediaStore.Video.Thumbnails.getThumbnail(contentResolver, id, MediaStore.Images.Thumbnails.MICRO_KIND, null); | ||
((FrameLayout) view).getChildAt(1).setVisibility(View.VISIBLE); | ||
} else { | ||
((FrameLayout) view).getChildAt(1).setVisibility(View.GONE); | ||
} | ||
((ImageView) ((FrameLayout) view).getChildAt(0)).setImageBitmap(bitmap); | ||
|
||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
app/src/main/java/io/mns/mediaadapter/media/RecentMedia.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.mns.mediaadapter.media; | ||
|
||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.provider.MediaStore; | ||
|
||
import androidx.loader.content.CursorLoader; | ||
|
||
public class RecentMedia { | ||
public static final String DATE_TAKEN = "datetaken"; | ||
public static final String DESCENDING = " DESC"; | ||
public MediaAdapter getAdapter(Context context) { | ||
String[] projection = { | ||
MediaStore.Files.FileColumns._ID, | ||
MediaStore.Files.FileColumns.DATA, | ||
MediaStore.Files.FileColumns.DATE_ADDED, | ||
MediaStore.Files.FileColumns.MEDIA_TYPE, | ||
MediaStore.Files.FileColumns.MIME_TYPE, | ||
MediaStore.Files.FileColumns.TITLE | ||
}; | ||
|
||
// Return only video and image metadata. | ||
String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "=" | ||
+ MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE | ||
+ " OR " | ||
+ MediaStore.Files.FileColumns.MEDIA_TYPE + "=" | ||
+ MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO; | ||
|
||
Uri queryUri = MediaStore.Files.getContentUri("external"); | ||
|
||
CursorLoader cursorLoader = new CursorLoader( | ||
context, | ||
queryUri, | ||
projection, | ||
selection, | ||
null, // Selection args (none). | ||
MediaStore.Files.FileColumns.DATE_ADDED + DESCENDING // Sort order. | ||
); | ||
|
||
Cursor cursor = cursorLoader.loadInBackground(); | ||
|
||
return new MediaAdapter(context, cursor, true); | ||
} | ||
|
||
public void setHeight(int height) { | ||
MediaAdapter.IMAGE_HEIGHT = height; | ||
} | ||
|
||
public void setWidth(int width) { | ||
MediaAdapter.IMAGE_WIDTH = width; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.