fix: 首次提交
This commit is contained in:
29
SettingsLib/AdaptiveIcon/Android.bp
Normal file
29
SettingsLib/AdaptiveIcon/Android.bp
Normal file
@@ -0,0 +1,29 @@
|
||||
package {
|
||||
// See: http://go/android-license-faq
|
||||
// A large-scale-change added 'default_applicable_licenses' to import
|
||||
// all of the 'license_kinds' from "frameworks_base_license"
|
||||
// to get the below license kinds:
|
||||
// SPDX-license-identifier-Apache-2.0
|
||||
default_applicable_licenses: ["frameworks_base_license"],
|
||||
}
|
||||
|
||||
android_library {
|
||||
name: "SettingsLibAdaptiveIcon",
|
||||
use_resource_processor: true,
|
||||
defaults: [
|
||||
"SettingsLintDefaults",
|
||||
],
|
||||
|
||||
srcs: ["src/**/*.java"],
|
||||
resource_dirs: ["res"],
|
||||
|
||||
static_libs: [
|
||||
"androidx.annotation_annotation",
|
||||
"SettingsLibTile",
|
||||
],
|
||||
|
||||
min_sdk_version: "21",
|
||||
lint: {
|
||||
baseline_filename: "lint-baseline.xml",
|
||||
},
|
||||
}
|
||||
23
SettingsLib/AdaptiveIcon/AndroidManifest.xml
Normal file
23
SettingsLib/AdaptiveIcon/AndroidManifest.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.settingslib.widget.adaptiveicon">
|
||||
|
||||
<uses-sdk android:minSdkVersion="21" />
|
||||
|
||||
</manifest>
|
||||
52
SettingsLib/AdaptiveIcon/build.gradle
Normal file
52
SettingsLib/AdaptiveIcon/build.gradle
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Include this gradle file if you are building against this as a standalone gradle library project,
|
||||
* as opposed to building it as part of the git-tree. This is typically the file you want to include
|
||||
* if you create a new project in Android Studio.
|
||||
*
|
||||
* For example, you can include the following in your settings.gradle file:
|
||||
* include ':setupcompat'
|
||||
* project(':setupcompat').projectDir = new File(PATH_TO_THIS_DIRECTORY)
|
||||
*
|
||||
* And then you can include the :setupcompat project as one of your dependencies
|
||||
* dependencies {
|
||||
* implementation project(path: ':setupcompat')
|
||||
* }
|
||||
*/
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.android.library)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
}
|
||||
|
||||
android {
|
||||
// Not specifying compileSdkVersion here so clients can specify it; must be at least Q
|
||||
namespace = "com.android.settingslib.widget.adaptiveicon"
|
||||
compileSdk 34
|
||||
defaultConfig {
|
||||
minSdkVersion 31
|
||||
targetSdkVersion 34
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.flags'
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
manifest.srcFile 'AndroidManifest.xml'
|
||||
java.srcDirs = ['src']
|
||||
res.srcDirs = ['res']
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation libs.androidx.annotation.annotation
|
||||
implementation project(':SettingsLib:Tile')
|
||||
}
|
||||
81
SettingsLib/AdaptiveIcon/lint-baseline.xml
Normal file
81
SettingsLib/AdaptiveIcon/lint-baseline.xml
Normal file
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<issues format="6" by="lint 8.4.0-alpha01" type="baseline" client="" dependencies="true" name="" variant="all" version="8.4.0-alpha01">
|
||||
|
||||
<issue
|
||||
id="NewApi"
|
||||
message="Call requires API level 23 (current min is 21): `android.content.res.Resources#getColor`"
|
||||
errorLine1=" .getColor(colorRes, null /* theme */);"
|
||||
errorLine2=" ~~~~~~~~">
|
||||
<location
|
||||
file="frameworks/base/packages/SettingsLib/AdaptiveIcon/src/com/android/settingslib/widget/AdaptiveIcon.java"
|
||||
line="79"
|
||||
column="34"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="NewApi"
|
||||
message="Call requires API level 23 (current min is 21): `android.content.Context#getColor`"
|
||||
errorLine1=" setBackgroundColor(context.getColor(R.color.homepage_generic_icon_background));"
|
||||
errorLine2=" ~~~~~~~~">
|
||||
<location
|
||||
file="frameworks/base/packages/SettingsLib/AdaptiveIcon/src/com/android/settingslib/widget/AdaptiveIcon.java"
|
||||
line="91"
|
||||
column="36"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="NewApi"
|
||||
message="Class requires API level 23 (current min is 21): `android.graphics.drawable.DrawableWrapper`"
|
||||
errorLine1="public class AdaptiveOutlineDrawable extends DrawableWrapper {"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="frameworks/base/packages/SettingsLib/AdaptiveIcon/src/com/android/settingslib/widget/AdaptiveOutlineDrawable.java"
|
||||
line="45"
|
||||
column="46"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="NewApi"
|
||||
message="Call requires API level 23 (current min is 21): `new android.graphics.drawable.DrawableWrapper`"
|
||||
errorLine1=" super(new AdaptiveIconShapeDrawable(resources));"
|
||||
errorLine2=" ~~~~~">
|
||||
<location
|
||||
file="frameworks/base/packages/SettingsLib/AdaptiveIcon/src/com/android/settingslib/widget/AdaptiveOutlineDrawable.java"
|
||||
line="67"
|
||||
column="9"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="NewApi"
|
||||
message="Call requires API level 23 (current min is 21): `new android.graphics.drawable.DrawableWrapper`"
|
||||
errorLine1=" super(new AdaptiveIconShapeDrawable(resources));"
|
||||
errorLine2=" ~~~~~">
|
||||
<location
|
||||
file="frameworks/base/packages/SettingsLib/AdaptiveIcon/src/com/android/settingslib/widget/AdaptiveOutlineDrawable.java"
|
||||
line="74"
|
||||
column="9"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="NewApi"
|
||||
message="Call requires API level 23 (current min is 21): `android.graphics.drawable.DrawableWrapper#getDrawable`"
|
||||
errorLine1=" getDrawable().setTint(Color.WHITE);"
|
||||
errorLine2=" ~~~~~~~~~~~">
|
||||
<location
|
||||
file="frameworks/base/packages/SettingsLib/AdaptiveIcon/src/com/android/settingslib/widget/AdaptiveOutlineDrawable.java"
|
||||
line="82"
|
||||
column="9"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="NewApi"
|
||||
message="Call requires API level 23 (current min is 21): `android.content.res.Resources#getColor`"
|
||||
errorLine1=" return resources.getColor(resId, /* theme */ null);"
|
||||
errorLine2=" ~~~~~~~~">
|
||||
<location
|
||||
file="frameworks/base/packages/SettingsLib/AdaptiveIcon/src/com/android/settingslib/widget/AdaptiveOutlineDrawable.java"
|
||||
line="107"
|
||||
column="26"/>
|
||||
</issue>
|
||||
|
||||
</issues>
|
||||
19
SettingsLib/AdaptiveIcon/res/values-night/colors.xml
Normal file
19
SettingsLib/AdaptiveIcon/res/values-night/colors.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2020 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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<color name="advanced_outline_color">#FFFFFFFF</color> <!-- icon outline color -->
|
||||
</resources>
|
||||
25
SettingsLib/AdaptiveIcon/res/values/colors.xml
Normal file
25
SettingsLib/AdaptiveIcon/res/values/colors.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<color name="homepage_generic_icon_background">#1A73E8</color>
|
||||
|
||||
<color name="bt_outline_color">#1f000000</color> <!-- icon outline color -->
|
||||
|
||||
<color name="advanced_outline_color">#BDC1C6</color> <!-- icon outline color -->
|
||||
|
||||
<color name="advanced_icon_color">#3C4043</color>
|
||||
</resources>
|
||||
26
SettingsLib/AdaptiveIcon/res/values/dimens.xml
Normal file
26
SettingsLib/AdaptiveIcon/res/values/dimens.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<!-- Dashboard foreground image inset (from background edge to foreground edge) -->
|
||||
<dimen name="dashboard_tile_foreground_image_inset">6dp</dimen>
|
||||
<!-- Advanced dashboard foreground image inset (from background edge to foreground edge) -->
|
||||
<dimen name="advanced_dashboard_tile_foreground_image_inset">9dp</dimen>
|
||||
|
||||
<!-- Stroke size of adaptive outline -->
|
||||
<dimen name="adaptive_outline_stroke">1dp</dimen>
|
||||
</resources>
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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.settingslib.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.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.widget.adaptiveicon.R;
|
||||
|
||||
/**
|
||||
* Adaptive icon that can set background color
|
||||
*/
|
||||
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) {
|
||||
this(context, foreground, R.dimen.dashboard_tile_foreground_image_inset);
|
||||
}
|
||||
|
||||
public AdaptiveIcon(Context context, Drawable foreground, int insetResId) {
|
||||
super(new Drawable[]{
|
||||
new AdaptiveIconShapeDrawable(context.getResources()),
|
||||
foreground
|
||||
});
|
||||
final int insetPx = context.getResources().getDimensionPixelSize(insetResId);
|
||||
setLayerInset(1 /* index */, insetPx, insetPx, insetPx, insetPx);
|
||||
mAdaptiveConstantState = new AdaptiveConstantState(context, foreground);
|
||||
}
|
||||
|
||||
/**
|
||||
* According {@code tile} metaData to set background color
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set background color by {@code color}
|
||||
*/
|
||||
public void setBackgroundColor(int color) {
|
||||
mBackgroundColor = color;
|
||||
getDrawable(0).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||
Log.d(TAG, "Setting background color " + mBackgroundColor);
|
||||
mAdaptiveConstantState.mColor = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstantState getConstantState() {
|
||||
return mAdaptiveConstantState;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static class AdaptiveConstantState extends ConstantState {
|
||||
Context mContext;
|
||||
Drawable mDrawable;
|
||||
int mColor;
|
||||
|
||||
AdaptiveConstantState(Context context, Drawable drawable) {
|
||||
this.mContext = context;
|
||||
this.mDrawable = drawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable newDrawable() {
|
||||
final AdaptiveIcon
|
||||
icon = new AdaptiveIcon(mContext, mDrawable);
|
||||
icon.setBackgroundColor(mColor);
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChangingConfigurations() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.settingslib.widget;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.PathShape;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.PathParser;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Draws a filled {@link ShapeDrawable} using the path from {@link AdaptiveIconDrawable}.
|
||||
*/
|
||||
public class AdaptiveIconShapeDrawable extends ShapeDrawable {
|
||||
public AdaptiveIconShapeDrawable() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AdaptiveIconShapeDrawable(Resources resources) {
|
||||
super();
|
||||
init(resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
|
||||
throws XmlPullParserException, IOException {
|
||||
super.inflate(r, parser, attrs, theme);
|
||||
init(r);
|
||||
}
|
||||
|
||||
private void init(Resources resources) {
|
||||
final float pathSize = AdaptiveIconDrawable.MASK_SIZE;
|
||||
final Path path = new Path(PathParser.createPathFromPathData(
|
||||
resources.getString(com.android.internal.R.string.config_icon_mask)));
|
||||
setShape(new PathShape(path, pathSize, pathSize));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.settingslib.widget;
|
||||
|
||||
import android.annotation.ColorInt;
|
||||
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.os.RemoteException;
|
||||
import android.util.PathParser;
|
||||
import android.view.IWindowManager;
|
||||
import android.view.WindowManagerGlobal;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settingslib.widget.adaptiveicon.R;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* Adaptive outline drawable with white plain background color and black outline
|
||||
*/
|
||||
public class AdaptiveOutlineDrawable extends DrawableWrapper {
|
||||
|
||||
private static final float ADVANCED_ICON_CENTER = 50f;
|
||||
private static final float ADVANCED_ICON_RADIUS = 48f;
|
||||
|
||||
public static final int ICON_TYPE_DEFAULT = 0;
|
||||
public static final int ICON_TYPE_ADVANCED = 1;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({ICON_TYPE_DEFAULT, ICON_TYPE_ADVANCED})
|
||||
public @interface AdaptiveOutlineIconType {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Paint mOutlinePaint;
|
||||
private Path mPath;
|
||||
private int mInsetPx;
|
||||
private int mStrokeWidth;
|
||||
private Bitmap mBitmap;
|
||||
private int mType;
|
||||
|
||||
public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap) {
|
||||
super(new AdaptiveIconShapeDrawable(resources));
|
||||
|
||||
init(resources, bitmap, ICON_TYPE_DEFAULT);
|
||||
}
|
||||
|
||||
public AdaptiveOutlineDrawable(Resources resources, Bitmap bitmap,
|
||||
@AdaptiveOutlineIconType int type) {
|
||||
super(new AdaptiveIconShapeDrawable(resources));
|
||||
|
||||
init(resources, bitmap, type);
|
||||
}
|
||||
|
||||
private void init(Resources resources, Bitmap bitmap,
|
||||
@AdaptiveOutlineIconType int type) {
|
||||
mType = type;
|
||||
getDrawable().setTint(Color.WHITE);
|
||||
mPath = new Path(PathParser.createPathFromPathData(
|
||||
resources.getString(com.android.internal.R.string.config_icon_mask)));
|
||||
mStrokeWidth = resources.getDimensionPixelSize(R.dimen.adaptive_outline_stroke);
|
||||
mOutlinePaint = new Paint();
|
||||
mOutlinePaint.setColor(getColor(resources, type));
|
||||
mOutlinePaint.setStyle(Paint.Style.STROKE);
|
||||
mOutlinePaint.setStrokeWidth(mStrokeWidth);
|
||||
mOutlinePaint.setAntiAlias(true);
|
||||
|
||||
mInsetPx = getDimensionPixelSize(resources, type);
|
||||
mBitmap = bitmap;
|
||||
}
|
||||
|
||||
private @ColorInt int getColor(Resources resources, @AdaptiveOutlineIconType int type) {
|
||||
int resId;
|
||||
switch (type) {
|
||||
case ICON_TYPE_ADVANCED:
|
||||
resId = R.color.advanced_outline_color;
|
||||
break;
|
||||
case ICON_TYPE_DEFAULT:
|
||||
default:
|
||||
resId = R.color.bt_outline_color;
|
||||
break;
|
||||
}
|
||||
return resources.getColor(resId, /* theme */ null);
|
||||
}
|
||||
|
||||
private int getDimensionPixelSize(Resources resources, @AdaptiveOutlineIconType int type) {
|
||||
int resId;
|
||||
switch (type) {
|
||||
case ICON_TYPE_ADVANCED:
|
||||
resId = R.dimen.advanced_dashboard_tile_foreground_image_inset;
|
||||
break;
|
||||
case ICON_TYPE_DEFAULT:
|
||||
default:
|
||||
resId = R.dimen.dashboard_tile_foreground_image_inset;
|
||||
break;
|
||||
}
|
||||
return resources.getDimensionPixelSize(resId);
|
||||
}
|
||||
|
||||
@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
|
||||
if (mType == ICON_TYPE_DEFAULT) {
|
||||
canvas.drawPath(mPath, mOutlinePaint);
|
||||
} else {
|
||||
canvas.drawCircle(ADVANCED_ICON_CENTER, ADVANCED_ICON_CENTER, ADVANCED_ICON_RADIUS,
|
||||
mOutlinePaint);
|
||||
}
|
||||
canvas.restoreToCount(count);
|
||||
|
||||
// Draw the foreground icon
|
||||
canvas.drawBitmap(mBitmap, bounds.left + mInsetPx, bounds.top + mInsetPx, null);
|
||||
}
|
||||
|
||||
private static int getDefaultDisplayDensity(int displayId) {
|
||||
try {
|
||||
final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
|
||||
return wm.getInitialDisplayDensity(displayId);
|
||||
} catch (RemoteException exc) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return mBitmap.getHeight() + 2 * mInsetPx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return mBitmap.getWidth() + 2 * mInsetPx;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user