diff options
| author | 2022-11-09 19:45:38 +0000 | |
|---|---|---|
| committer | 2022-11-09 19:45:38 +0000 | |
| commit | 4aae5d5a320e63b8cbecc82e904eaff238319b7f (patch) | |
| tree | 2b023752098871ad4f2f1ded58ec7e9ec57097c1 /java | |
| parent | 0baefe00a50f22191a932849da2daab50747f3d5 (diff) | |
| parent | 5ff8942a8e160269c98deefbfb16e53b812b74e9 (diff) | |
Merge "Extract ChooserActivity.RoundedRectImageView" into tm-qpr-dev
Diffstat (limited to 'java')
5 files changed, 138 insertions, 115 deletions
diff --git a/java/res/layout/chooser_grid_preview_file.xml b/java/res/layout/chooser_grid_preview_file.xml index 6d2e76a0..c3392704 100644 --- a/java/res/layout/chooser_grid_preview_file.xml +++ b/java/res/layout/chooser_grid_preview_file.xml @@ -37,7 +37,7 @@ android:layout_marginBottom="@dimen/chooser_view_spacing" android:id="@androidprv:id/content_preview_file_layout"> - <view class="com.android.intentresolver.ChooserActivity$RoundedRectImageView" + <com.android.intentresolver.widget.RoundedRectImageView android:id="@androidprv:id/content_preview_file_thumbnail" android:layout_width="75dp" android:layout_height="75dp" diff --git a/java/res/layout/chooser_grid_preview_image.xml b/java/res/layout/chooser_grid_preview_image.xml index 96054eb5..4d15bf75 100644 --- a/java/res/layout/chooser_grid_preview_image.xml +++ b/java/res/layout/chooser_grid_preview_image.xml @@ -32,7 +32,7 @@ android:paddingBottom="@dimen/chooser_view_spacing" android:background="?android:attr/colorBackground"> - <view class="com.android.intentresolver.ChooserActivity$RoundedRectImageView" + <com.android.intentresolver.widget.RoundedRectImageView android:id="@androidprv:id/content_preview_image_1_large" android:layout_width="120dp" android:layout_height="104dp" @@ -41,7 +41,7 @@ android:gravity="center" android:scaleType="centerCrop"/> - <view class="com.android.intentresolver.ChooserActivity$RoundedRectImageView" + <com.android.intentresolver.widget.RoundedRectImageView android:id="@androidprv:id/content_preview_image_2_large" android:visibility="gone" android:layout_width="120dp" @@ -53,7 +53,7 @@ android:gravity="center" android:scaleType="centerCrop"/> - <view class="com.android.intentresolver.ChooserActivity$RoundedRectImageView" + <com.android.intentresolver.widget.RoundedRectImageView android:id="@androidprv:id/content_preview_image_2_small" android:visibility="gone" android:layout_width="120dp" @@ -65,7 +65,7 @@ android:gravity="center" android:scaleType="centerCrop"/> - <view class="com.android.intentresolver.ChooserActivity$RoundedRectImageView" + <com.android.intentresolver.widget.RoundedRectImageView android:id="@androidprv:id/content_preview_image_3_small" android:visibility="gone" android:layout_width="120dp" diff --git a/java/res/layout/chooser_grid_preview_text.xml b/java/res/layout/chooser_grid_preview_text.xml index a9ed71b7..81fdbd08 100644 --- a/java/res/layout/chooser_grid_preview_text.xml +++ b/java/res/layout/chooser_grid_preview_text.xml @@ -75,7 +75,7 @@ android:background="@androidprv:drawable/chooser_content_preview_rounded" android:id="@androidprv:id/content_preview_title_layout"> - <view class="com.android.intentresolver.ChooserActivity$RoundedRectImageView" + <com.android.intentresolver.widget.RoundedRectImageView android:id="@androidprv:id/content_preview_thumbnail" android:layout_width="75dp" android:layout_height="75dp" diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index 6354de69..3eb30f57 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; @@ -124,6 +119,7 @@ import com.android.intentresolver.model.AppPredictionServiceResolverComparator; import com.android.intentresolver.model.ResolverRankerServiceResolverComparator; 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; @@ -3671,110 +3667,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, > 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, > 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); + } +} |