diff --git a/app/build.gradle b/app/build.gradle index ecf0dfc..ea1a0b1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,13 +7,13 @@ apply from: '../dependencies.gradle' android { compileSdkVersion 28 - //buildToolsVersion '28.0.2' + defaultConfig { applicationId "com.wt.apkinfo" minSdkVersion 15 targetSdkVersion 28 - versionCode 8 - versionName "1.1.5" + versionCode 9 + versionName "1.1.6" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" resConfigs "en", "pl" diff --git a/app/src/main/java/com/wt/apkinfo/activity/ApplicationDetailsActivity.java b/app/src/main/java/com/wt/apkinfo/activity/ApplicationDetailsActivity.java index c8794e7..6a0ceb6 100644 --- a/app/src/main/java/com/wt/apkinfo/activity/ApplicationDetailsActivity.java +++ b/app/src/main/java/com/wt/apkinfo/activity/ApplicationDetailsActivity.java @@ -9,7 +9,9 @@ import android.content.Context; import android.content.Intent; import android.content.res.Resources; +import android.graphics.Bitmap; import android.graphics.drawable.AdaptiveIconDrawable; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -38,11 +40,15 @@ import com.google.firebase.perf.metrics.AddTrace; import com.hivedi.console.Console; import com.hivedi.era.ERA; +import com.squareup.picasso.Picasso; +import com.squareup.picasso.Target; import com.wt.apkinfo.R; import com.wt.apkinfo.dialog.InfoListDialog; import com.wt.apkinfo.entity.ApplicationDetailsEntity; import com.wt.apkinfo.entity.ComponentInfo; +import com.wt.apkinfo.util.BitmapUtil; import com.wt.apkinfo.util.DateTime; +import com.wt.apkinfo.util.ImageLoader; import com.wt.apkinfo.util.ViewUtil; import com.wt.apkinfo.viewmodel.ApplicationDetailsViewModel; @@ -59,7 +65,7 @@ * */ -public class ApplicationDetailsActivity extends AppCompatActivity implements InfoListDialog.OnGetData { +public class ApplicationDetailsActivity extends AppCompatActivity implements InfoListDialog.OnGetData, Target { public static final String KEY_APP_ID = "application_id"; public static final String KEY_APP_NAME = "application_name"; @@ -71,24 +77,24 @@ public static void start(@NonNull Activity ctx, @NonNull String appId, @NonNull // Bug in activity transitions, fixed in android 6.x // https://issuetracker.google.com/issues/37121916 - //if (Build.VERSION.SDK_INT >= 23 && Build.VERSION.SDK_INT < 27) { - // View decorView = ctx.getWindow().getDecorView(); - // View statusBar = decorView.findViewById(android.R.id.statusBarBackground); - // View navigationBar = decorView.findViewById(android.R.id.navigationBarBackground); - // List> el = new ArrayList<>(); - // el.add(Pair.create(holderImage, "transition_" + appId)); - // if (statusBar != null) { - // el.add(Pair.create(statusBar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME)); - // } - // if (navigationBar != null) { - // el.add(Pair.create(navigationBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME)); - // } - // //noinspection unchecked - // ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(ctx, el.toArray(new Pair[0])); - // ctx.startActivity(it, options.toBundle()); - //} else { + if (Build.VERSION.SDK_INT >= 23) { + View decorView = ctx.getWindow().getDecorView(); + View statusBar = decorView.findViewById(android.R.id.statusBarBackground); + View navigationBar = decorView.findViewById(android.R.id.navigationBarBackground); + List> el = new ArrayList<>(); + el.add(Pair.create(holderImage, "transition_" + appId)); + if (statusBar != null) { + el.add(Pair.create(statusBar, Window.STATUS_BAR_BACKGROUND_TRANSITION_NAME)); + } + if (navigationBar != null) { + el.add(Pair.create(navigationBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME)); + } + //noinspection unchecked + ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(ctx, el.toArray(new Pair[0])); + ctx.startActivity(it, options.toBundle()); + } else { ctx.startActivity(it); - //} + } } @BindView(R.id.toolbar) Toolbar toolbar; @@ -126,10 +132,9 @@ public void onChanged(final @Nullable ApplicationDetailsEntity productEntity) { if (productEntity != null) { toolbar.setTitle(productEntity.getName()); toolbar.setSubtitle(productEntity.getId()); - //toolbar.setNavigationIcon(productEntity.getIcon36dp(ApplicationDetailsActivity.this)); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); - //Console.loge("R=" + productEntity.icon.mutate()); - //AdaptiveIconDrawable a; + + ImageLoader.get().load(productEntity.getIconUri(), ApplicationDetailsActivity.this); mAppInfoAdapter.setData(productEntity); supportStartPostponedEnterTransition(); @@ -220,18 +225,18 @@ public void onClick(View view) { } }); toolbar.setNavigationContentDescription(appId); - //if (Build.VERSION.SDK_INT >= 23) { - // supportPostponeEnterTransition(); - // View navIcon = ViewUtil.findViewWithContentDescription(toolbar, appId); - // if (navIcon != null) { - // navIcon.setTransitionName("transition_" + appId); - // } - // Transition fade = new Fade(); - // fade.excludeTarget(android.R.id.statusBarBackground, true); - // fade.excludeTarget(android.R.id.navigationBarBackground, true); - // getWindow().setExitTransition(fade); - // getWindow().setEnterTransition(fade); - //} + if (Build.VERSION.SDK_INT >= 23) { + supportPostponeEnterTransition(); + View navIcon = ViewUtil.findViewWithContentDescription(toolbar, appId); + if (navIcon != null) { + navIcon.setTransitionName("transition_" + appId); + } + Transition fade = new Fade(); + fade.excludeTarget(android.R.id.statusBarBackground, true); + fade.excludeTarget(android.R.id.navigationBarBackground, true); + getWindow().setExitTransition(fade); + getWindow().setEnterTransition(fade); + } mAppInfoAdapter = new AppInfoAdapter(getResources(), new OnHeaderClick() { @Override @@ -280,6 +285,21 @@ public List onGetData() { return null; } + @Override + public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { + toolbar.setNavigationIcon(BitmapUtil.bitmapToDrawable(this, bitmap)); + } + + @Override + public void onBitmapFailed(Drawable errorDrawable) { + toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); + } + + @Override + public void onPrepareLoad(Drawable placeHolderDrawable) { + toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp); + } + private static class ItemHeader { public String title; public ComponentInfo[] data; diff --git a/app/src/main/java/com/wt/apkinfo/db/AppInfoTask.java b/app/src/main/java/com/wt/apkinfo/db/AppInfoTask.java index c5117e0..49b1399 100644 --- a/app/src/main/java/com/wt/apkinfo/db/AppInfoTask.java +++ b/app/src/main/java/com/wt/apkinfo/db/AppInfoTask.java @@ -72,12 +72,6 @@ protected ApplicationDetailsEntity doInBackground(Context... contexts) { */ result.id = appId; result.name = pi.applicationInfo.loadLabel(pm).toString(); - //result.icon = pi.applicationInfo.loadIcon(pm); - - //Bitmap src = BitmapUtil.drawableToBitmap(result.icon); - //int dp36 = (int) (context.getResources().getDisplayMetrics().density * 36f); - //result.icon36dp = result.icon; - //result.icon36dp = BitmapUtil.bitmapToDrawable(context, Bitmap.createScaledBitmap(src, dp36, dp36, true)); int counter; diff --git a/app/src/main/java/com/wt/apkinfo/db/AppListTask.java b/app/src/main/java/com/wt/apkinfo/db/AppListTask.java index 12de518..abde66d 100644 --- a/app/src/main/java/com/wt/apkinfo/db/AppListTask.java +++ b/app/src/main/java/com/wt/apkinfo/db/AppListTask.java @@ -60,18 +60,7 @@ protected List doInBackground(Context... params) { } e.iconUri = "app://" + ri.activityInfo.packageName; - //Console.logi("SRC=" + ri.activityInfo.applicationInfo.publicSourceDir); - //if (ri.activityInfo.icon == 0) { - // e.iconUri = ri.activityInfo.packageName + "/" + ri.activityInfo.applicationInfo.; - //} else { - // e.iconUri = ri.activityInfo.packageName + "/" + ri.activityInfo.targetActivity; - //} - - //if (ri.activityInfo.icon == 0) { - //e.icon = ri.activityInfo.applicationInfo.loadIcon(pm); - //} else { - // e.icon = ri.activityInfo.loadIcon(pm); - //} + list.add(e); } diff --git a/app/src/main/java/com/wt/apkinfo/entity/ApplicationDetailsEntity.java b/app/src/main/java/com/wt/apkinfo/entity/ApplicationDetailsEntity.java index b8e50d1..9dd6974 100644 --- a/app/src/main/java/com/wt/apkinfo/entity/ApplicationDetailsEntity.java +++ b/app/src/main/java/com/wt/apkinfo/entity/ApplicationDetailsEntity.java @@ -18,8 +18,6 @@ public class ApplicationDetailsEntity implements ApplicationDetailsModel { public String id; public String name; - //public Drawable icon; - //public Drawable icon36dp; public ComponentInfo[] activities; public ComponentInfo[] services; public ComponentInfo[] permissions; @@ -46,28 +44,9 @@ public String getName() { } @Override - public Drawable getIcon() { - return null; // icon; + public String getIconUri() { + return "app://" + id; } - @Override - public Drawable getIcon36dp(Context ctx) { - //if (icon != null && icon36dp == null) { - // int dp36 = (int) (ctx.getResources().getDisplayMetrics().density * 36f); - // Bitmap src = BitmapUtil.drawableToBitmap(icon); - // icon36dp = BitmapUtil.bitmapToDrawable(ctx, Bitmap.createScaledBitmap(src, dp36, dp36, true)); - //} - //if (icon36dp == null) { - // PackageManager pm = ctx.getPackageManager(); - // try { - // PackageInfo pi = pm.getPackageInfo(id, PackageManager.GET_ACTIVITIES); - // icon36dp = pi.applicationInfo.loadIcon(pm); - // } catch (Exception e) { - // // ignore - // } - //} - //return icon36dp; - return null; - } } diff --git a/app/src/main/java/com/wt/apkinfo/entity/ApplicationEntity.java b/app/src/main/java/com/wt/apkinfo/entity/ApplicationEntity.java index 70d72e8..87a0bd2 100644 --- a/app/src/main/java/com/wt/apkinfo/entity/ApplicationEntity.java +++ b/app/src/main/java/com/wt/apkinfo/entity/ApplicationEntity.java @@ -14,7 +14,6 @@ public class ApplicationEntity implements ApplicationModel, Comparable mData; private OnItemClick mOnItemClick; + private ImageLoader mImageLoader; ApplicationsListAdapter(OnItemClick click) { mOnItemClick = click; + mImageLoader = ImageLoader.get(); } public void setData(List d) { @@ -226,7 +228,6 @@ public void onBindViewHolder(@NonNull final ApplicationsItemHolder holder, int p final ApplicationEntity entry = mData.get(position); holder.text1.setText(entry.getName()); holder.text2.setText(entry.getId()); - //holder.icon1.setImageDrawable(entry.getIcon()); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -236,7 +237,7 @@ public void onClick(View view) { } }); - ImageLoader.get().load(entry.getIconUri(), holder.icon1); + mImageLoader.load(entry.getIconUri(), holder.icon1); holder.update(entry); } diff --git a/app/src/main/java/com/wt/apkinfo/model/ApplicationDetailsModel.java b/app/src/main/java/com/wt/apkinfo/model/ApplicationDetailsModel.java index b7ab0b6..d267e9e 100644 --- a/app/src/main/java/com/wt/apkinfo/model/ApplicationDetailsModel.java +++ b/app/src/main/java/com/wt/apkinfo/model/ApplicationDetailsModel.java @@ -12,7 +12,6 @@ public interface ApplicationDetailsModel { String getId(); String getName(); - Drawable getIcon(); - Drawable getIcon36dp(Context ctx); + String getIconUri(); } diff --git a/app/src/main/java/com/wt/apkinfo/model/ApplicationModel.java b/app/src/main/java/com/wt/apkinfo/model/ApplicationModel.java index 1d320e4..cbf327d 100644 --- a/app/src/main/java/com/wt/apkinfo/model/ApplicationModel.java +++ b/app/src/main/java/com/wt/apkinfo/model/ApplicationModel.java @@ -11,7 +11,6 @@ public interface ApplicationModel { String getId(); String getName(); - Drawable getIcon(); String getIconUri(); } diff --git a/app/src/main/java/com/wt/apkinfo/util/ImageLoader.java b/app/src/main/java/com/wt/apkinfo/util/ImageLoader.java index 4232142..29c01c2 100644 --- a/app/src/main/java/com/wt/apkinfo/util/ImageLoader.java +++ b/app/src/main/java/com/wt/apkinfo/util/ImageLoader.java @@ -13,7 +13,9 @@ import com.squareup.picasso.Picasso; import com.squareup.picasso.Request; import com.squareup.picasso.RequestHandler; +import com.squareup.picasso.Target; import com.wt.apkinfo.BuildConfig; +import com.wt.apkinfo.R; import java.io.IOException; @@ -49,18 +51,19 @@ private ImageLoader(Context ctx) { .addRequestHandler(new RequestHandler() { @Override public boolean canHandleRequest(Request data) { - return data.uri.getScheme().equals("app"); + String scheme = data.uri.getScheme(); + return "app".equals(scheme); } @Override public Result load(Request request, int networkPolicy) throws IOException { try { return new Result( - drawableToBitmap(pm.getApplicationIcon(request.uri.getHost())), + BitmapUtil.drawableToBitmap(pm.getApplicationIcon(request.uri.getHost())), Picasso.LoadedFrom.DISK ); } catch (Exception e) { if (BuildConfig.DEBUG) { - Console.loge("" + e, e); + Console.loge("ImageLoader.load: " + e, e); } } return null; @@ -69,32 +72,19 @@ public Result load(Request request, int networkPolicy) throws IOException { .build(); } - private static Bitmap drawableToBitmap (Drawable drawable) { - Bitmap bitmap = null; - - if (drawable instanceof BitmapDrawable) { - BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; - if(bitmapDrawable.getBitmap() != null) { - return bitmapDrawable.getBitmap(); - } - } - - if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { - bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel - } else { - bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - } - - Canvas canvas = new Canvas(bitmap); - drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - drawable.draw(canvas); - return bitmap; - } - public void load(String url, ImageView img) { + mPicasso.cancelRequest(img); mPicasso.load(url) .fit() .centerInside() .into(img); } + + public void load(String url, Target img) { + mPicasso.load(url) + //.fit() + .resizeDimen(R.dimen.app_icon_size, R.dimen.app_icon_size) + .centerInside() + .into(img); + } } diff --git a/app/src/main/res/layout/item_application.xml b/app/src/main/res/layout/item_application.xml index 284e12d..d84a99e 100644 --- a/app/src/main/res/layout/item_application.xml +++ b/app/src/main/res/layout/item_application.xml @@ -7,12 +7,13 @@ android:layout_height="wrap_content" android:padding="16dp" android:background="?attr/selectableItemBackground" - android:clickable="true"> + android:clickable="true" + android:focusable="true"> - + 40dp