Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 26
buildToolsVersion '26.0.0'
compileSdkVersion 34
buildToolsVersion '34.0.0'
namespace "uk.co.nickbutcher.adaptiveiconplayground"
defaultConfig {
applicationId "uk.co.nickbutcher.adaptiveiconplayground"
minSdkVersion 26
targetSdkVersion 26
targetSdkVersion 34
versionCode 1
versionName "1.0"
archivesBaseName = "adaptive-icon-playground"
Expand All @@ -32,14 +33,19 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
}

ext.supportLibVersion = '26.0.0-beta2'

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
implementation "com.android.support:design:${supportLibVersion}"
implementation "com.android.support:support-dynamic-animation:${supportLibVersion}"
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
}
13 changes: 10 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2017 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
Expand All @@ -14,15 +13,23 @@
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="uk.co.nickbutcher.adaptiveiconplayground">

<!--To get list of installed application for OS 11 and higher-->
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import android.graphics.Paint
import android.graphics.Shader.TileMode.CLAMP
import android.graphics.drawable.AdaptiveIconDrawable
import android.graphics.drawable.Drawable
import android.support.annotation.FloatRange
import android.support.annotation.Keep
import androidx.annotation.FloatRange
import androidx.annotation.Keep
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
Expand All @@ -41,8 +41,8 @@ import kotlin.reflect.KProperty
* allows animation of the corner radius.
*/
class AdaptiveIconView(
context: Context,
attrs: AttributeSet?
context: Context,
attrs: AttributeSet?
) : View(context, attrs, R.attr.adaptiveIconViewStyle) {

private val foregroundPaint = Paint(Paint.ANTI_ALIAS_FLAG)
Expand All @@ -65,6 +65,7 @@ class AdaptiveIconView(
private var foregroundScale by InvalidateDelegate(0f)

var cornerRadius by InvalidateDelegate(0f)

// scale & translate factors [0,1]
var foregroundTranslateFactor by FloatRangeDelegate(0f)
var backgroundTranslateFactor by FloatRangeDelegate(0f)
Expand All @@ -82,6 +83,7 @@ class AdaptiveIconView(
backgroundDy = backgroundTranslateFactor * displacementY
foregroundDy = foregroundTranslateFactor * displacementY
}

@Keep // called by @animator/scale
var scale = 0f
set(@FloatRange(from = 0.0, to = 1.0) value) {
Expand All @@ -94,7 +96,8 @@ class AdaptiveIconView(

init {
val a = context.obtainStyledAttributes(
attrs, R.styleable.AdaptiveIconView, R.attr.adaptiveIconViewStyle, 0)
attrs, R.styleable.AdaptiveIconView, R.attr.adaptiveIconViewStyle, 0
)
val shadowColor = a.getColor(R.styleable.AdaptiveIconView_shadowColor, Color.TRANSPARENT)
shadowDY = a.getDimension(R.styleable.AdaptiveIconView_shadowDy, 0f)
a.recycle()
Expand All @@ -103,8 +106,11 @@ class AdaptiveIconView(
color = shadowColor
}
}
layerSize = Math.round(TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 108f, context.resources.displayMetrics))
layerSize = Math.round(
TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 108f, context.resources.displayMetrics
)
)
layerCenter = (layerSize / 2).toFloat()
iconSize = (layerSize / (1 + 2 * AdaptiveIconDrawable.getExtraInsetFraction())).toInt()
viewportOffset = (layerSize - iconSize) / 2
Expand Down Expand Up @@ -140,14 +146,20 @@ class AdaptiveIconView(
translate(left, top)
if (shadowPaint != null) {
translate(0f, shadowDY)
drawRoundRect(0f, 0f, iconSize.toFloat(), iconSize.toFloat(),
cornerRadius, cornerRadius, shadowPaint)
drawRoundRect(
0f, 0f, iconSize.toFloat(), iconSize.toFloat(),
cornerRadius, cornerRadius, shadowPaint!!
)
translate(0f, -shadowDY)
}
drawRoundRect(0f, 0f, iconSize.toFloat(), iconSize.toFloat(),
cornerRadius, cornerRadius, backgroundPaint)
drawRoundRect(0f, 0f, iconSize.toFloat(), iconSize.toFloat(),
cornerRadius, cornerRadius, foregroundPaint)
drawRoundRect(
0f, 0f, iconSize.toFloat(), iconSize.toFloat(),
cornerRadius, cornerRadius, backgroundPaint
)
drawRoundRect(
0f, 0f, iconSize.toFloat(), iconSize.toFloat(),
cornerRadius, cornerRadius, foregroundPaint
)
restoreToCount(saveCount)
}
}
Expand Down Expand Up @@ -192,9 +204,10 @@ private class InvalidateDelegate<T : Any>(var value: T) {
* A [Float] Delegate which constrains its value between a minimum and maximum.
*/
private class FloatRangeDelegate(
var value: Float,
val min: Float = 0f,
val max: Float = 1f) {
var value: Float,
val min: Float = 0f,
val max: Float = 1f
) {
operator fun getValue(thisRef: Any?, property: KProperty<*>) = value
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Float) {
this.value = value.coerceIn(min, max)
Expand Down
Loading