Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/romannurik/muzei
Browse files Browse the repository at this point in the history
  • Loading branch information
romannurik committed Apr 11, 2016
2 parents 7d2e00b + c7bfcb8 commit 4df9f33
Show file tree
Hide file tree
Showing 39 changed files with 87 additions and 212 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -14,7 +14,7 @@ gen/
out/
build/
.gradle/

.ART
# Project files
*.iml
.idea
Expand Down
1 change: 1 addition & 0 deletions android-client-common/build.gradle
Expand Up @@ -27,6 +27,7 @@ apply plugin: 'com.android.library'

dependencies {
compile project(':api')
compile 'com.android.support:support-annotations:23.1.1'
}

android {
Expand Down
Expand Up @@ -31,6 +31,7 @@
import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.support.annotation.NonNull;
import android.util.Log;

import com.google.android.apps.muzei.api.MuzeiContract;
Expand Down Expand Up @@ -128,12 +129,12 @@ private static UriMatcher buildUriMatcher() {
}

@Override
public int delete(final Uri uri, final String where, final String[] whereArgs) {
public int delete(@NonNull final Uri uri, final String where, final String[] whereArgs) {
throw new UnsupportedOperationException("Deletes are not supported");
}

@Override
public String getType(final Uri uri) {
public String getType(@NonNull final Uri uri) {
/**
* Chooses the MIME type based on the incoming URI pattern
*/
Expand All @@ -147,7 +148,7 @@ public String getType(final Uri uri) {
}

@Override
public Uri insert(final Uri uri, final ContentValues values) {
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
// Validates the incoming URI. Only the full provider URI is allowed for inserts.
if (MuzeiProvider.uriMatcher.match(uri) != MuzeiProvider.ARTWORK)
throw new IllegalArgumentException("Unknown URI " + uri);
Expand Down Expand Up @@ -181,8 +182,8 @@ public boolean onCreate() {
}

@Override
public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs,
final String sortOrder) {
public Cursor query(@NonNull final Uri uri, final String[] projection, final String selection,
final String[] selectionArgs, final String sortOrder) {
// Validates the incoming URI. Only the full provider URI is allowed for queries.
if (MuzeiProvider.uriMatcher.match(uri) != MuzeiProvider.ARTWORK)
throw new IllegalArgumentException("Unknown URI " + uri);
Expand All @@ -196,7 +197,7 @@ public Cursor query(final Uri uri, final String[] projection, final String selec
}

@Override
public ParcelFileDescriptor openFile(final Uri uri, final String mode) throws FileNotFoundException {
public ParcelFileDescriptor openFile(@NonNull final Uri uri, @NonNull final String mode) throws FileNotFoundException {
// Validates the incoming URI. Only the full provider URI is allowed for openFile
if (MuzeiProvider.uriMatcher.match(uri) != MuzeiProvider.ARTWORK) {
throw new IllegalArgumentException("Unknown URI " + uri);
Expand All @@ -217,7 +218,7 @@ public ParcelFileDescriptor openFile(final Uri uri, final String mode) throws Fi
}

@Override
public int update(final Uri uri, final ContentValues values, final String selection, final String[] selectionArgs) {
public int update(@NonNull final Uri uri, final ContentValues values, final String selection, final String[] selectionArgs) {
throw new UnsupportedOperationException("Updates are not allowed: insert does an insert or update operation");
}

Expand Down
Expand Up @@ -21,7 +21,6 @@
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
import android.support.v8.renderscript.Matrix3f;
import android.support.v8.renderscript.RSInvalidStateException;
import android.support.v8.renderscript.RenderScript;
import android.support.v8.renderscript.ScriptIntrinsicBlur;
import android.support.v8.renderscript.ScriptIntrinsicColorMatrix;
Expand All @@ -32,8 +31,8 @@ public class ImageBlurrer {

private ScriptIntrinsicBlur mSIBlur;
private ScriptIntrinsicColorMatrix mSIGrey;
private Allocation mTmp1;
private Allocation mTmp2;
private Allocation mAllocationSrc;
private Allocation mAllocationDest;

public ImageBlurrer(Context context) {
mRS = RenderScript.create(context);
Expand All @@ -51,30 +50,27 @@ public Bitmap blurBitmap(Bitmap src, float radius, float desaturateAmount) {
return dest;
}

if (mTmp1 != null) {
mTmp1.destroy();
if (mAllocationSrc == null) {
mAllocationSrc = Allocation.createFromBitmap(mRS, src);
} else {
mAllocationSrc.copyFrom(src);
}
if (mTmp2 != null) {
try {
mTmp2.destroy();
} catch (RSInvalidStateException e) {
// Ignore 'Object already destroyed' exceptions
}
if (mAllocationDest == null) {
mAllocationDest = Allocation.createFromBitmap(mRS, dest);
} else {
mAllocationDest.copyFrom(dest);
}

mTmp1 = Allocation.createFromBitmap(mRS, src);
mTmp2 = Allocation.createFromBitmap(mRS, dest);

if (radius > 0f && desaturateAmount > 0f) {
doBlur(radius, mTmp1, mTmp2);
doDesaturate(MathUtil.constrain(0, 1, desaturateAmount), mTmp2, mTmp1);
mTmp1.copyTo(dest);
doBlur(radius, mAllocationSrc, mAllocationDest);
doDesaturate(MathUtil.constrain(0, 1, desaturateAmount), mAllocationDest, mAllocationSrc);
mAllocationSrc.copyTo(dest);
} else if (radius > 0f) {
doBlur(radius, mTmp1, mTmp2);
mTmp2.copyTo(dest);
doBlur(radius, mAllocationSrc, mAllocationDest);
mAllocationDest.copyTo(dest);
} else {
doDesaturate(MathUtil.constrain(0, 1, desaturateAmount), mTmp1, mTmp2);
mTmp2.copyTo(dest);
doDesaturate(MathUtil.constrain(0, 1, desaturateAmount), mAllocationSrc, mAllocationDest);
mAllocationDest.copyTo(dest);
}
return dest;
}
Expand Down Expand Up @@ -105,11 +101,11 @@ private void doDesaturate(float normalizedAmount, Allocation input, Allocation o

public void destroy() {
mSIBlur.destroy();
if (mTmp1 != null) {
mTmp1.destroy();
if (mAllocationSrc != null) {
mAllocationSrc.destroy();
}
if (mTmp2 != null) {
mTmp2.destroy();
if (mAllocationDest != null) {
mAllocationDest.destroy();
}
mRS.destroy();
}
Expand Down
Expand Up @@ -40,10 +40,6 @@ public static int roundMult4(int num) {
return (num + 2) & ~0x03;
}

public static boolean isEven(int num) {
return num % 2 == 0;
}

// divide two integers but round up
// see http://stackoverflow.com/a/7446742/102703
public static int intDivideRoundUp(int num, int divisor) {
Expand Down
Expand Up @@ -49,6 +49,7 @@ private void init(Context context, AttributeSet attrs, int defStyle) {
if (shadowColor != 0) {
setShadowLayer(shadowRadius, shadowDx, shadowDy, shadowColor);
}
a.recycle();
}
}

Expand Up @@ -36,7 +36,7 @@ public class SourceState {
private Artwork mCurrentArtwork;
private String mDescription;
private boolean mWantsNetworkAvailable;
private List<UserCommand> mUserCommands = new ArrayList<>();
private final ArrayList<UserCommand> mUserCommands = new ArrayList<>();

public Artwork getCurrentArtwork() {
return mCurrentArtwork;
Expand Down Expand Up @@ -71,27 +71,27 @@ public void setWantsNetworkAvailable(boolean wantsNetworkAvailable) {
}

public void setUserCommands(int... userCommands) {
mUserCommands = new ArrayList<>();
mUserCommands.clear();
if (userCommands != null) {
mUserCommands.ensureCapacity(userCommands.length);
for (int command : userCommands) {
mUserCommands.add(new UserCommand(command));
}
}
}

public void setUserCommands(UserCommand... userCommands) {
mUserCommands = new ArrayList<>();
mUserCommands.clear();
if (userCommands != null) {
mUserCommands.ensureCapacity(userCommands.length);
Collections.addAll(mUserCommands, userCommands);
}
}

public void setUserCommands(List<UserCommand> userCommands) {
mUserCommands = new ArrayList<>();
mUserCommands.clear();
if (userCommands != null) {
for (UserCommand command : userCommands) {
mUserCommands.add(command);
}
mUserCommands.addAll(userCommands);
}
}

Expand Down Expand Up @@ -120,6 +120,7 @@ public static SourceState fromBundle(Bundle bundle) {
state.mWantsNetworkAvailable = bundle.getBoolean("wantsNetworkAvailable");
String[] commandsSerialized = bundle.getStringArray("userCommands");
if (commandsSerialized != null && commandsSerialized.length > 0) {
state.mUserCommands.ensureCapacity(commandsSerialized.length);
for (String s : commandsSerialized) {
state.mUserCommands.add(UserCommand.deserialize(s));
}
Expand Down Expand Up @@ -149,10 +150,11 @@ public void readJson(JSONObject jsonObject) throws JSONException {
}
mDescription = jsonObject.optString("description");
mWantsNetworkAvailable = jsonObject.optBoolean("wantsNetworkAvailable");
mUserCommands.clear();
JSONArray commandsSerialized = jsonObject.optJSONArray("userCommands");
mUserCommands.clear();
if (commandsSerialized != null && commandsSerialized.length() > 0) {
int length = commandsSerialized.length();
mUserCommands.ensureCapacity(length);
for (int i = 0; i < length; i++) {
mUserCommands.add(UserCommand.deserialize(commandsSerialized.optString(i)));
}
Expand Down
Expand Up @@ -52,7 +52,6 @@ public class ArtworkCache {
private static final String TAG = LogUtil.makeLogTag(ArtworkCache.class);

private Context mApplicationContext;
private File mAppCacheRoot;
private File mArtCacheRoot;

private static final int MAX_CACHE_SIZE = 3; // 3 items per source
Expand All @@ -74,8 +73,7 @@ private ArtworkCache(Context context) {

// TODO: instead of best available, optimize for stable location since these aren't
// meant to be too temporary
mAppCacheRoot = IOUtil.getBestAvailableCacheRoot(mApplicationContext);
mArtCacheRoot = new File(mAppCacheRoot, "artcache");
mArtCacheRoot = new File(IOUtil.getBestAvailableCacheRoot(mApplicationContext), "artcache");
}

public synchronized void maybeDownloadCurrentArtworkSync() {
Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.google.android.apps.muzei;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
Expand All @@ -30,13 +29,11 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.SparseIntArray;
Expand Down
Expand Up @@ -31,6 +31,7 @@
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;

import com.google.android.apps.muzei.api.Artwork;
Expand Down Expand Up @@ -171,7 +172,7 @@ public static void maybeShowNewArtworkNotification(Context context, Artwork artw
: artwork.getTitle();
NotificationCompat.Builder nb = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_stat_muzei)
.setColor(context.getResources().getColor(R.color.notification))
.setColor(ContextCompat.getColor(context, R.color.notification))
.setPriority(Notification.PRIORITY_MIN)
.setAutoCancel(true)
.setContentTitle(title)
Expand Down Expand Up @@ -260,7 +261,7 @@ public static void maybeShowNewArtworkNotification(Context context, Artwork artw
// Hide the image and artwork title for the public version
NotificationCompat.Builder publicBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_stat_muzei)
.setColor(context.getResources().getColor(R.color.notification))
.setColor(ContextCompat.getColor(context, R.color.notification))
.setPriority(Notification.PRIORITY_MIN)
.setAutoCancel(true)
.setContentTitle(context.getString(R.string.app_name))
Expand Down
Expand Up @@ -23,7 +23,6 @@
import android.text.TextUtils;

import com.google.android.apps.muzei.api.internal.SourceState;
import com.google.android.apps.muzei.event.SelectedSourceChangedEvent;
import com.google.android.apps.muzei.event.SelectedSourceStateChangedEvent;
import com.google.android.apps.muzei.featuredart.FeaturedArtSource;
import com.google.android.apps.muzei.util.LogUtil;
Expand Down Expand Up @@ -150,7 +149,6 @@ public void selectSource(ComponentName source) {
subscribeToSelectedSource();
}

EventBus.getDefault().post(new SelectedSourceChangedEvent());
EventBus.getDefault().post(new SelectedSourceStateChangedEvent());
}

Expand Down
Expand Up @@ -28,8 +28,6 @@
import static com.google.android.apps.muzei.api.internal.ProtocolConstants.EXTRA_TOKEN;

public class SourceSubscriberService extends IntentService {
private static final String TAG = LogUtil.makeLogTag(SourceSubscriberService.class);

public SourceSubscriberService() {
super("SourceSubscriberService");
}
Expand Down

This file was deleted.

Expand Up @@ -427,7 +427,7 @@ private GalleryStore.Metadata getOrCreateMetadata(Uri imageUri) {
}

private interface ImagesQuery {
static String[] PROJECTION = {
String[] PROJECTION = {
MediaStore.MediaColumns._ID,
MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
};
Expand Down
Expand Up @@ -22,6 +22,8 @@
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
Expand Down Expand Up @@ -80,9 +82,9 @@ public GalleryEmptyStateGraphicView(Context context, AttributeSet attrs, int def

final Resources res = getResources();
mOffPaint.setAntiAlias(true);
mOffPaint.setColor(res.getColor(R.color.gallery_settings_empty_state_dark));
mOffPaint.setColor(ContextCompat.getColor(context, R.color.gallery_settings_empty_state_dark));
mOnPaint.setAntiAlias(true);
mOnPaint.setColor(res.getColor(R.color.gallery_settings_empty_state_light));
mOnPaint.setColor(ContextCompat.getColor(context, R.color.gallery_settings_empty_state_light));

mCellSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
CELL_SPACING_DIP, res.getDisplayMetrics());
Expand All @@ -100,7 +102,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
}

@Override
protected void onVisibilityChanged(View changedView, int visibility) {
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
super.onVisibilityChanged(changedView, visibility);
if (isShown()) {
postInvalidateOnAnimation();
Expand Down

0 comments on commit 4df9f33

Please sign in to comment.