diff options
author | 2024-08-02 12:10:27 -0700 | |
---|---|---|
committer | 2024-08-08 10:20:53 -0700 | |
commit | 1a429e9038a47d30470df7e278fd1beabe2bc387 (patch) | |
tree | dfa71777661b2b5783e2409d905c29848208383e /java | |
parent | dd8b67226177c51bf5bb1019aff66fb7f138a03c (diff) |
Add disabled state to chooser targets
The new functinality is not used yet as this is a preparation step.
Allows chooser targets to be disabled: unclickable with grey-scale
icons.
Bug: 349468879
Test: presubmits
Flag: EXEMPT refactoring
Change-Id: I202a496954c08da27b7cc7c0f9df8d04d9916350
Diffstat (limited to 'java')
4 files changed, 73 insertions, 29 deletions
diff --git a/java/src/com/android/intentresolver/ChooserListAdapter.java b/java/src/com/android/intentresolver/ChooserListAdapter.java index 07a615a5..548cd6ac 100644 --- a/java/src/com/android/intentresolver/ChooserListAdapter.java +++ b/java/src/com/android/intentresolver/ChooserListAdapter.java @@ -18,6 +18,7 @@ package com.android.intentresolver; import static com.android.intentresolver.ChooserActivity.TARGET_TYPE_SHORTCUTS_FROM_PREDICTION_SERVICE; import static com.android.intentresolver.ChooserActivity.TARGET_TYPE_SHORTCUTS_FROM_SHORTCUT_MANAGER; +import static com.android.intentresolver.util.graphics.SuspendedMatrixColorFilter.getSuspendedColorMatrix; import android.app.ActivityManager; import android.app.prediction.AppTarget; @@ -153,6 +154,7 @@ public class ChooserListAdapter extends ResolverListAdapter { }; private boolean mAnimateItems = true; + private boolean mTargetsEnabled = true; public ChooserListAdapter( Context context, @@ -306,6 +308,16 @@ public class ChooserListAdapter extends ResolverListAdapter { } } + /** + * Set the enabled state for all targets. + */ + public void setTargetsEnabled(boolean isEnabled) { + if (mTargetsEnabled != isEnabled) { + mTargetsEnabled = isEnabled; + notifyDataSetChanged(); + } + } + public void setAnimateItems(boolean animateItems) { mAnimateItems = animateItems; } @@ -353,7 +365,7 @@ public class ChooserListAdapter extends ResolverListAdapter { @VisibleForTesting @Override public void onBindView(View view, TargetInfo info, int position) { - view.setEnabled(!isDestroyed()); + view.setEnabled(!isDestroyed() && mTargetsEnabled); final ViewHolder holder = (ViewHolder) view.getTag(); resetViewHolder(holder); @@ -413,6 +425,9 @@ public class ChooserListAdapter extends ResolverListAdapter { } holder.bindIcon(info); + if (info.hasDisplayIcon() && !mTargetsEnabled) { + holder.icon.setColorFilter(getSuspendedColorMatrix()); + } if (mAnimateItems && info.hasDisplayIcon()) { mAnimationTracker.animateIcon(holder.icon, info); } diff --git a/java/src/com/android/intentresolver/ResolverListAdapter.java b/java/src/com/android/intentresolver/ResolverListAdapter.java index 5fd37d43..7ca1c724 100644 --- a/java/src/com/android/intentresolver/ResolverListAdapter.java +++ b/java/src/com/android/intentresolver/ResolverListAdapter.java @@ -16,14 +16,14 @@ package com.android.intentresolver; +import static com.android.intentresolver.util.graphics.SuspendedMatrixColorFilter.getSuspendedColorMatrix; + import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.LabeledIntent; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.graphics.ColorMatrix; -import android.graphics.ColorMatrixColorFilter; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.RemoteException; @@ -63,9 +63,6 @@ import java.util.concurrent.atomic.AtomicBoolean; public class ResolverListAdapter extends BaseAdapter { private static final String TAG = "ResolverListAdapter"; - @Nullable // TODO: other model for lazy computation? Or just precompute? - private static ColorMatrixColorFilter sSuspendedMatrixColorFilter; - protected final Context mContext; protected final LayoutInflater mInflater; protected final ResolverListCommunicator mResolverListCommunicator; @@ -797,29 +794,6 @@ public class ResolverListAdapter extends BaseAdapter { return mDestroyed.get(); } - private static ColorMatrixColorFilter getSuspendedColorMatrix() { - if (sSuspendedMatrixColorFilter == null) { - - int grayValue = 127; - float scale = 0.5f; // half bright - - ColorMatrix tempBrightnessMatrix = new ColorMatrix(); - float[] mat = tempBrightnessMatrix.getArray(); - mat[0] = scale; - mat[6] = scale; - mat[12] = scale; - mat[4] = grayValue; - mat[9] = grayValue; - mat[14] = grayValue; - - ColorMatrix matrix = new ColorMatrix(); - matrix.setSaturation(0.0f); - matrix.preConcat(tempBrightnessMatrix); - sSuspendedMatrixColorFilter = new ColorMatrixColorFilter(matrix); - } - return sSuspendedMatrixColorFilter; - } - protected final Drawable loadIconPlaceholder() { return mContext.getDrawable(R.drawable.resolver_icon_placeholder); } diff --git a/java/src/com/android/intentresolver/profiles/ChooserMultiProfilePagerAdapter.java b/java/src/com/android/intentresolver/profiles/ChooserMultiProfilePagerAdapter.java index 8aee0da1..9176cd35 100644 --- a/java/src/com/android/intentresolver/profiles/ChooserMultiProfilePagerAdapter.java +++ b/java/src/com/android/intentresolver/profiles/ChooserMultiProfilePagerAdapter.java @@ -112,6 +112,15 @@ public class ChooserMultiProfilePagerAdapter extends MultiProfilePagerAdapter< } } + /** + * Set enabled status for all targets in all profiles. + */ + public void setTargetsEnabled(boolean isEnabled) { + for (int i = 0, size = getItemCount(); i < size; i++) { + getPageAdapterForIndex(i).getListAdapter().setTargetsEnabled(isEnabled); + } + } + private static ViewGroup makeProfileView(Context context) { LayoutInflater inflater = LayoutInflater.from(context); ViewGroup rootView = diff --git a/java/src/com/android/intentresolver/util/graphics/SuspendedMatrixColorFilter.kt b/java/src/com/android/intentresolver/util/graphics/SuspendedMatrixColorFilter.kt new file mode 100644 index 00000000..3e2d8e2a --- /dev/null +++ b/java/src/com/android/intentresolver/util/graphics/SuspendedMatrixColorFilter.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:JvmName("SuspendedMatrixColorFilter") + +package com.android.intentresolver.util.graphics + +import android.graphics.ColorMatrix +import android.graphics.ColorMatrixColorFilter + +val suspendedColorMatrix by lazy { + val grayValue = 127f + val scale = 0.5f // half bright + + val tempBrightnessMatrix = + ColorMatrix().apply { + array.let { m -> + m[0] = scale + m[6] = scale + m[12] = scale + m[4] = grayValue + m[9] = grayValue + m[14] = grayValue + } + } + + val matrix = + ColorMatrix().apply { + setSaturation(0.0f) + preConcat(tempBrightnessMatrix) + } + ColorMatrixColorFilter(matrix) +} |