Skip to content

Commit

Permalink
adds basic files for functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
MehdiNosrati committed Aug 10, 2019
1 parent 86df374 commit 2a3e28c
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "io.mns.android_media_adapter"
minSdkVersion 9
applicationId "io.mns.mediaadapter"
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionCode 19081010
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -26,4 +26,5 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.amirarcane.recent-images:recentimages:2.0.1'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.mns.android_media_adapter;
package io.mns.mediaadapter;

import android.content.Context;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

Expand Down
8 changes: 5 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.mns.android_media_adapter" >
xmlns:tools="http://schemas.android.com/tools"
package="io.mns.mediaadapter">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="io.mns.mediaadapter.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.mns.android_media_adapter;
package io.mns.mediaadapter;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
Expand Down
69 changes: 69 additions & 0 deletions app/src/main/java/io/mns/mediaadapter/media/MediaAdapter.java
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 app/src/main/java/io/mns/mediaadapter/media/RecentMedia.java
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;
}
}
12 changes: 6 additions & 6 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
Expand All @@ -29,6 +29,6 @@
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
Loading

0 comments on commit 2a3e28c

Please sign in to comment.