updated
This commit is contained in:
parent
a3a4618769
commit
7a42723b9e
103 changed files with 1879 additions and 1195 deletions
|
@ -0,0 +1,202 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Hemanth Savarala.
|
||||
*
|
||||
* Licensed under the GNU General Public License v3
|
||||
*
|
||||
* This is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
package code.name.monkey.retromusic.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.media.ExifInterface;
|
||||
import android.net.Uri;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.List;
|
||||
|
||||
import code.name.monkey.retromusic.App;
|
||||
|
||||
/**
|
||||
* Author: Mario Velasco Casquero
|
||||
* Date: 08/09/2015
|
||||
* Email: m3ario@gmail.com
|
||||
*/
|
||||
public class ImagePicker {
|
||||
private static final int DEFAULT_MIN_WIDTH_QUALITY = 400; // min pixels
|
||||
private static final String TAG = "ImagePicker";
|
||||
private static final String TEMP_IMAGE_NAME = "tempImage";
|
||||
public static int minWidthQuality = DEFAULT_MIN_WIDTH_QUALITY;
|
||||
|
||||
|
||||
|
||||
private static List<Intent> addIntentsToList(Context context, List<Intent> list, Intent intent) {
|
||||
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(intent, 0);
|
||||
for (ResolveInfo resolveInfo : resInfo) {
|
||||
String packageName = resolveInfo.activityInfo.packageName;
|
||||
Intent targetedIntent = new Intent(intent);
|
||||
targetedIntent.setPackage(packageName);
|
||||
list.add(targetedIntent);
|
||||
Log.d(TAG, "Intent: " + intent.getAction() + " package: " + packageName);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static Bitmap getImageFromResult(Context context, int resultCode,
|
||||
Intent imageReturnedIntent) {
|
||||
Log.d(TAG, "getImageFromResult, resultCode: " + resultCode);
|
||||
Bitmap bm = null;
|
||||
File imageFile = getTempFile(context);
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
Uri selectedImage;
|
||||
boolean isCamera = (imageReturnedIntent == null ||
|
||||
imageReturnedIntent.getData() == null ||
|
||||
imageReturnedIntent.getData().toString().contains(imageFile.toString()));
|
||||
if (isCamera) { /** CAMERA **/
|
||||
selectedImage = Uri.fromFile(imageFile);
|
||||
} else { /** ALBUM **/
|
||||
selectedImage = imageReturnedIntent.getData();
|
||||
}
|
||||
Log.d(TAG, "selectedImage: " + selectedImage);
|
||||
|
||||
bm = getImageResized(context, selectedImage);
|
||||
int rotation = getRotation(context, selectedImage, isCamera);
|
||||
bm = rotate(bm, rotation);
|
||||
}
|
||||
return bm;
|
||||
}
|
||||
|
||||
|
||||
private static File getTempFile(Context context) {
|
||||
File imageFile = new File(context.getExternalCacheDir(), TEMP_IMAGE_NAME);
|
||||
imageFile.getParentFile().mkdirs();
|
||||
return imageFile;
|
||||
}
|
||||
|
||||
private static Bitmap decodeBitmap(Context context, Uri theUri, int sampleSize) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inSampleSize = sampleSize;
|
||||
|
||||
AssetFileDescriptor fileDescriptor = null;
|
||||
try {
|
||||
fileDescriptor = context.getContentResolver().openAssetFileDescriptor(theUri, "r");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Bitmap actuallyUsableBitmap = BitmapFactory.decodeFileDescriptor(
|
||||
fileDescriptor.getFileDescriptor(), null, options);
|
||||
|
||||
Log.d(TAG, options.inSampleSize + " sample method bitmap ... " +
|
||||
actuallyUsableBitmap.getWidth() + " " + actuallyUsableBitmap.getHeight());
|
||||
|
||||
return actuallyUsableBitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize to avoid using too much memory loading big images (e.g.: 2560*1920)
|
||||
**/
|
||||
private static Bitmap getImageResized(Context context, Uri selectedImage) {
|
||||
Bitmap bm = null;
|
||||
int[] sampleSizes = new int[]{5, 3, 2, 1};
|
||||
int i = 0;
|
||||
do {
|
||||
bm = decodeBitmap(context, selectedImage, sampleSizes[i]);
|
||||
Log.d(TAG, "resizer: new bitmap width = " + bm.getWidth());
|
||||
i++;
|
||||
} while (bm.getWidth() < minWidthQuality && i < sampleSizes.length);
|
||||
return bm;
|
||||
}
|
||||
|
||||
|
||||
private static int getRotation(Context context, Uri imageUri, boolean isCamera) {
|
||||
int rotation;
|
||||
if (isCamera) {
|
||||
rotation = getRotationFromCamera(context, imageUri);
|
||||
} else {
|
||||
rotation = getRotationFromGallery(context, imageUri);
|
||||
}
|
||||
Log.d(TAG, "Image rotation: " + rotation);
|
||||
return rotation;
|
||||
}
|
||||
|
||||
private static int getRotationFromCamera(Context context, Uri imageFile) {
|
||||
int rotate = 0;
|
||||
try {
|
||||
|
||||
context.getContentResolver().notifyChange(imageFile, null);
|
||||
ExifInterface exif = new ExifInterface(imageFile.getPath());
|
||||
int orientation = exif.getAttributeInt(
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.ORIENTATION_NORMAL);
|
||||
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
rotate = 270;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
rotate = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
rotate = 90;
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return rotate;
|
||||
}
|
||||
|
||||
public static int getRotationFromGallery(Context context, Uri imageUri) {
|
||||
int result = 0;
|
||||
String[] columns = {MediaStore.Images.Media.ORIENTATION};
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = context.getContentResolver().query(imageUri, columns, null, null, null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
int orientationColumnIndex = cursor.getColumnIndex(columns[0]);
|
||||
result = cursor.getInt(orientationColumnIndex);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//Do nothing
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}//End of try-catch block
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static Bitmap rotate(Bitmap bm, int rotation) {
|
||||
if (rotation != 0) {
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(rotation);
|
||||
Bitmap bmOut = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
|
||||
return bmOut;
|
||||
}
|
||||
return bm;
|
||||
}
|
||||
}
|
|
@ -21,15 +21,16 @@ import android.content.SharedPreferences.Editor;
|
|||
import android.content.res.TypedArray;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.google.android.material.bottomnavigation.LabelVisibilityMode;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StyleRes;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import code.name.monkey.retromusic.App;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.helper.SortOrder;
|
||||
|
@ -38,8 +39,8 @@ import code.name.monkey.retromusic.transform.DepthTransformation;
|
|||
import code.name.monkey.retromusic.transform.HingeTransformation;
|
||||
import code.name.monkey.retromusic.transform.HorizontalFlipTransformation;
|
||||
import code.name.monkey.retromusic.transform.NormalPageTransformer;
|
||||
import code.name.monkey.retromusic.transform.VerticalStackTransformer;
|
||||
import code.name.monkey.retromusic.transform.VerticalFlipTransformation;
|
||||
import code.name.monkey.retromusic.transform.VerticalStackTransformer;
|
||||
import code.name.monkey.retromusic.ui.activities.MainActivity;
|
||||
import code.name.monkey.retromusic.ui.fragments.AlbumCoverStyle;
|
||||
import code.name.monkey.retromusic.ui.fragments.NowPlayingScreen;
|
||||
|
@ -61,6 +62,7 @@ public final class PreferenceUtil {
|
|||
public static final String GENERAL_THEME = "general_theme";
|
||||
public static final String CIRCULAR_ALBUM_ART = "circular_album_art";
|
||||
public static final String USER_NAME = "user_name";
|
||||
public static final String USER_BIO = "user_bio";
|
||||
public static final String TOGGLE_FULL_SCREEN = "toggle_full_screen";
|
||||
public static final String TOGGLE_VOLUME = "toggle_volume";
|
||||
public static final String TOGGLE_TAB_TITLES = "toggle_tab_titles";
|
||||
|
@ -154,6 +156,14 @@ public final class PreferenceUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public String getUserBio() {
|
||||
return mPreferences.getString(USER_BIO, "");
|
||||
}
|
||||
|
||||
public void setUserBio(String bio) {
|
||||
mPreferences.edit().putString(USER_BIO, bio).apply();
|
||||
}
|
||||
|
||||
public int getFilterLength() {
|
||||
return mPreferences.getInt(FILTER_SONG, 20);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue