Remove method that used to get rainbow bt icon

Move get rainbow bt icon method to settingsLib

Bug: 128570540
Test: RunSettingsRoboTests
Change-Id: Iee022bd1471f1da057b1852bb648e9c7ce334727
This commit is contained in:
hughchen
2019-03-25 18:06:21 +08:00
parent bab3bf6f22
commit 9d4b634535
29 changed files with 24 additions and 587 deletions

View File

@@ -1,122 +0,0 @@
/*
* Copyright (C) 2018 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.settings.widget;
import static androidx.annotation.VisibleForTesting.NONE;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB;
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
import com.android.settingslib.drawer.Tile;
public class AdaptiveIcon extends LayerDrawable {
private static final String TAG = "AdaptiveHomepageIcon";
@VisibleForTesting(otherwise = NONE)
int mBackgroundColor = -1;
private AdaptiveConstantState mAdaptiveConstantState;
public AdaptiveIcon(Context context, Drawable foreground) {
super(new Drawable[]{
new AdaptiveIconShapeDrawable(context.getResources()),
foreground
});
final int insetPx = context.getResources()
.getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
setLayerInset(1 /* index */, insetPx, insetPx, insetPx, insetPx);
mAdaptiveConstantState = new AdaptiveConstantState(context, foreground);
}
public void setBackgroundColor(Context context, Tile tile) {
final Bundle metaData = tile.getMetaData();
try {
if (metaData != null) {
// Load from bg.argb first
int bgColor = metaData.getInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
0 /* default */);
// Not found, load from bg.hint
if (bgColor == 0) {
final int colorRes = metaData.getInt(META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
0 /* default */);
if (colorRes != 0) {
bgColor = context.getPackageManager()
.getResourcesForApplication(tile.getPackageName())
.getColor(colorRes, null /* theme */);
}
}
// If found anything, use it.
if (bgColor != 0) {
setBackgroundColor(bgColor);
return;
}
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Failed to set background color for " + tile.getPackageName());
}
setBackgroundColor(context.getColor(R.color.homepage_generic_icon_background));
}
public void setBackgroundColor(int color) {
mBackgroundColor = color;
getDrawable(0).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
Log.d(TAG, "Setting background color " + mBackgroundColor);
mAdaptiveConstantState.color = color;
}
@Override
public ConstantState getConstantState() {
return mAdaptiveConstantState;
}
@VisibleForTesting
static class AdaptiveConstantState extends ConstantState {
Context context;
Drawable drawable;
int color;
public AdaptiveConstantState(Context context, Drawable drawable) {
this.context = context;
this.drawable = drawable;
}
@Override
public Drawable newDrawable() {
final AdaptiveIcon icon = new AdaptiveIcon(context, drawable);
icon.setBackgroundColor(color);
return icon;
}
@Override
public int getChangingConfigurations() {
return 0;
}
}
}

View File

@@ -1,90 +0,0 @@
/*
* Copyright (C) 2019 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.settings.widget;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.DrawableWrapper;
import android.util.PathParser;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.homepage.AdaptiveIconShapeDrawable;
/**
* Adaptive outline drawable with white plain background color and black outline
*/
public class AdaptiveOutlineDrawable extends DrawableWrapper {
@VisibleForTesting
final Paint mOutlinePaint;
private Path mPath;
private final int mInsetPx;
private final Bitmap mBitmap;
public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap) {
super(new AdaptiveIconShapeDrawable(resources));
getDrawable().setTint(Color.WHITE);
mPath = new Path(PathParser.createPathFromPathData(
resources.getString(com.android.internal.R.string.config_icon_mask)));
mOutlinePaint = new Paint();
mOutlinePaint.setColor(resources.getColor(R.color.bt_outline_color, null));
mOutlinePaint.setStyle(Paint.Style.STROKE);
mOutlinePaint.setStrokeWidth(resources.getDimension(R.dimen.adaptive_outline_stroke));
mOutlinePaint.setAntiAlias(true);
mInsetPx = resources
.getDimensionPixelSize(R.dimen.dashboard_tile_foreground_image_inset);
mBitmap = bitmap;
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
final Rect bounds = getBounds();
final float pathSize = AdaptiveIconDrawable.MASK_SIZE;
final float scaleX = (bounds.right - bounds.left) / pathSize;
final float scaleY = (bounds.bottom - bounds.top) / pathSize;
final int count = canvas.save();
canvas.scale(scaleX, scaleY);
// Draw outline
canvas.drawPath(mPath, mOutlinePaint);
canvas.restoreToCount(count);
// Draw the foreground icon
canvas.drawBitmap(mBitmap, bounds.left + mInsetPx, bounds.top + mInsetPx, null);
}
@Override
public int getIntrinsicHeight() {
return mBitmap.getHeight() + 2 * mInsetPx;
}
@Override
public int getIntrinsicWidth() {
return mBitmap.getWidth() + 2 * mInsetPx;
}
}