summaryrefslogtreecommitdiff
path: root/java/src/com
diff options
context:
space:
mode:
author Joshua Trask <joshtrask@google.com> 2022-11-09 11:28:07 -0500
committer Joshua Trask <joshtrask@google.com> 2022-11-09 17:40:58 +0000
commit5ff8942a8e160269c98deefbfb16e53b812b74e9 (patch)
tree7f1718313adb8367a667351c8d3e4496bbdd2771 /java/src/com
parent9c8893a5983988c9127f3ae846ea212593777466 (diff)
Extract ChooserActivity.RoundedRectImageView
This is a trivial code move (diffs show only minor formatting changes [EDIT: a later snapshot also gets rid of the `<view>` tags in our layouts, which were only necessary to reference this as an inner class, in favor of the more common practice of using an XML element with the same fully-qualified name). As an inner class, it had already been marked `static`, so there's no correctness concern (EDIT: on the Java side...) The only "client" is the (soon-to-be-extracted) preview UI, but instead of moving this to an inner class of the extracted component, it seems reasonable for this class to stand alone -- it has a simple design that's plausibly reusable in other applications, since it doesn't really encapsulate any requirements that are specific to Sharesheet. Bug: 202167050 Test: atest IntentResolverUnitTests Change-Id: I63833626925896a0baaa06d729233cd7037ac730
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/android/intentresolver/ChooserActivity.java110
-rw-r--r--java/src/com/android/intentresolver/widget/RoundedRectImageView.java131
2 files changed, 132 insertions, 109 deletions
diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java
index 938fbb0d..080ff41f 100644
--- a/java/src/com/android/intentresolver/ChooserActivity.java
+++ b/java/src/com/android/intentresolver/ChooserActivity.java
@@ -58,11 +58,7 @@ import android.content.res.Resources;
import android.database.Cursor;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Color;
import android.graphics.Insets;
-import android.graphics.Paint;
-import android.graphics.Path;
import android.graphics.drawable.Drawable;
import android.metrics.LogMaker;
import android.net.Uri;
@@ -85,7 +81,6 @@ import android.provider.OpenableColumns;
import android.provider.Settings;
import android.service.chooser.ChooserTarget;
import android.text.TextUtils;
-import android.util.AttributeSet;
import android.util.HashedStringCache;
import android.util.Log;
import android.util.PluralsMessageFormatter;
@@ -122,6 +117,7 @@ import com.android.intentresolver.chooser.SelectableTargetInfo.SelectableTargetI
import com.android.intentresolver.chooser.TargetInfo;
import com.android.intentresolver.shortcuts.AppPredictorFactory;
import com.android.intentresolver.widget.ResolverDrawerLayout;
+import com.android.intentresolver.widget.RoundedRectImageView;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.internal.content.PackageMonitor;
@@ -3677,110 +3673,6 @@ public class ChooserActivity extends ResolverActivity implements
}
/**
- * Used internally to round image corners while obeying view padding.
- */
- public static class RoundedRectImageView extends ImageView {
- private int mRadius = 0;
- private Path mPath = new Path();
- private Paint mOverlayPaint = new Paint(0);
- private Paint mRoundRectPaint = new Paint(0);
- private Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
- private String mExtraImageCount = null;
-
- public RoundedRectImageView(Context context) {
- super(context);
- }
-
- public RoundedRectImageView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public RoundedRectImageView(Context context, AttributeSet attrs, int defStyleAttr) {
- this(context, attrs, defStyleAttr, 0);
- }
-
- public RoundedRectImageView(Context context, AttributeSet attrs, int defStyleAttr,
- int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- mRadius = context.getResources().getDimensionPixelSize(R.dimen.chooser_corner_radius);
-
- mOverlayPaint.setColor(0x99000000);
- mOverlayPaint.setStyle(Paint.Style.FILL);
-
- mRoundRectPaint.setColor(context.getResources().getColor(R.color.chooser_row_divider));
- mRoundRectPaint.setStyle(Paint.Style.STROKE);
- mRoundRectPaint.setStrokeWidth(context.getResources()
- .getDimensionPixelSize(R.dimen.chooser_preview_image_border));
-
- mTextPaint.setColor(Color.WHITE);
- mTextPaint.setTextSize(context.getResources()
- .getDimensionPixelSize(R.dimen.chooser_preview_image_font_size));
- mTextPaint.setTextAlign(Paint.Align.CENTER);
- }
-
- private void updatePath(int width, int height) {
- mPath.reset();
-
- int imageWidth = width - getPaddingRight() - getPaddingLeft();
- int imageHeight = height - getPaddingBottom() - getPaddingTop();
- mPath.addRoundRect(getPaddingLeft(), getPaddingTop(), imageWidth, imageHeight, mRadius,
- mRadius, Path.Direction.CW);
- }
-
- /**
- * Sets the corner radius on all corners
- *
- * param radius 0 for no radius, &gt; 0 for a visible corner radius
- */
- public void setRadius(int radius) {
- mRadius = radius;
- updatePath(getWidth(), getHeight());
- }
-
- /**
- * Display an overlay with extra image count on 3rd image
- */
- public void setExtraImageCount(int count) {
- if (count > 0) {
- this.mExtraImageCount = "+" + count;
- } else {
- this.mExtraImageCount = null;
- }
- }
-
- @Override
- protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
- super.onSizeChanged(width, height, oldWidth, oldHeight);
- updatePath(width, height);
- }
-
- @Override
- protected void onDraw(Canvas canvas) {
- if (mRadius != 0) {
- canvas.clipPath(mPath);
- }
-
- super.onDraw(canvas);
-
- int x = getPaddingLeft();
- int y = getPaddingRight();
- int width = getWidth() - getPaddingRight() - getPaddingLeft();
- int height = getHeight() - getPaddingBottom() - getPaddingTop();
- if (mExtraImageCount != null) {
- canvas.drawRect(x, y, width, height, mOverlayPaint);
-
- int xPos = canvas.getWidth() / 2;
- int yPos = (int) ((canvas.getHeight() / 2.0f)
- - ((mTextPaint.descent() + mTextPaint.ascent()) / 2.0f));
-
- canvas.drawText(mExtraImageCount, xPos, yPos, mTextPaint);
- }
-
- canvas.drawRoundRect(x, y, width, height, mRadius, mRadius, mRoundRectPaint);
- }
- }
-
- /**
* A helper class to track app's readiness for the scene transition animation.
* The app is ready when both the image is laid out and the drawer offset is calculated.
*/
diff --git a/java/src/com/android/intentresolver/widget/RoundedRectImageView.java b/java/src/com/android/intentresolver/widget/RoundedRectImageView.java
new file mode 100644
index 00000000..cf7bd543
--- /dev/null
+++ b/java/src/com/android/intentresolver/widget/RoundedRectImageView.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2008 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.
+ */
+
+package com.android.intentresolver.widget;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+
+import com.android.intentresolver.R;
+
+/**
+ * {@link ImageView} that rounds the corners around the presented image while obeying view padding.
+ */
+public class RoundedRectImageView extends ImageView {
+ private int mRadius = 0;
+ private Path mPath = new Path();
+ private Paint mOverlayPaint = new Paint(0);
+ private Paint mRoundRectPaint = new Paint(0);
+ private Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ private String mExtraImageCount = null;
+
+ public RoundedRectImageView(Context context) {
+ super(context);
+ }
+
+ public RoundedRectImageView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public RoundedRectImageView(Context context, AttributeSet attrs, int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public RoundedRectImageView(
+ Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ mRadius = context.getResources().getDimensionPixelSize(R.dimen.chooser_corner_radius);
+
+ mOverlayPaint.setColor(0x99000000);
+ mOverlayPaint.setStyle(Paint.Style.FILL);
+
+ mRoundRectPaint.setColor(context.getResources().getColor(R.color.chooser_row_divider));
+ mRoundRectPaint.setStyle(Paint.Style.STROKE);
+ mRoundRectPaint.setStrokeWidth(context.getResources()
+ .getDimensionPixelSize(R.dimen.chooser_preview_image_border));
+
+ mTextPaint.setColor(Color.WHITE);
+ mTextPaint.setTextSize(context.getResources()
+ .getDimensionPixelSize(R.dimen.chooser_preview_image_font_size));
+ mTextPaint.setTextAlign(Paint.Align.CENTER);
+ }
+
+ private void updatePath(int width, int height) {
+ mPath.reset();
+
+ int imageWidth = width - getPaddingRight() - getPaddingLeft();
+ int imageHeight = height - getPaddingBottom() - getPaddingTop();
+ mPath.addRoundRect(getPaddingLeft(), getPaddingTop(), imageWidth, imageHeight, mRadius,
+ mRadius, Path.Direction.CW);
+ }
+
+ /**
+ * Sets the corner radius on all corners
+ *
+ * param radius 0 for no radius, &gt; 0 for a visible corner radius
+ */
+ public void setRadius(int radius) {
+ mRadius = radius;
+ updatePath(getWidth(), getHeight());
+ }
+
+ /**
+ * Display an overlay with extra image count on 3rd image
+ */
+ public void setExtraImageCount(int count) {
+ if (count > 0) {
+ this.mExtraImageCount = "+" + count;
+ } else {
+ this.mExtraImageCount = null;
+ }
+ }
+
+ @Override
+ protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
+ super.onSizeChanged(width, height, oldWidth, oldHeight);
+ updatePath(width, height);
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (mRadius != 0) {
+ canvas.clipPath(mPath);
+ }
+
+ super.onDraw(canvas);
+
+ int x = getPaddingLeft();
+ int y = getPaddingRight();
+ int width = getWidth() - getPaddingRight() - getPaddingLeft();
+ int height = getHeight() - getPaddingBottom() - getPaddingTop();
+ if (mExtraImageCount != null) {
+ canvas.drawRect(x, y, width, height, mOverlayPaint);
+
+ int xPos = canvas.getWidth() / 2;
+ int yPos = (int) ((canvas.getHeight() / 2.0f)
+ - ((mTextPaint.descent() + mTextPaint.ascent()) / 2.0f));
+
+ canvas.drawText(mExtraImageCount, xPos, yPos, mTextPaint);
+ }
+
+ canvas.drawRoundRect(x, y, width, height, mRadius, mRadius, mRoundRectPaint);
+ }
+}