Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
胡晟昊 committed Dec 5, 2021
2 parents 9abef50 + 776eb31 commit 5a5139d
Show file tree
Hide file tree
Showing 33 changed files with 455 additions and 153 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# AndroidEasterEggs

[![wakatime](https://wakatime.com/badge/user/5dcaf7c9-f166-4fc1-b818-5a6761bb52b6.svg)](https://wakatime.com/@5dcaf7c9-f166-4fc1-b818-5a6761bb52b6)

整理了Android系统各正式版内置彩蛋

![icon](./app/src/main/ic_launcher-playstore.png)
Expand Down
5 changes: 2 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ android {
applicationId = "com.dede.android_eggs"
minSdk = Versions.MIN_SDK
targetSdk = Versions.TARGET_SDK
versionCode = 11
versionName = "1.5.1"
versionCode = 12
versionName = "1.6.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
resourceConfigurations.addAll(listOf("zh", "en"))
Expand Down Expand Up @@ -75,7 +75,6 @@ dependencies {
implementation(deps.androidx.preference.ktx)
implementation(deps.androidx.constraintlayout)
implementation(deps.androidx.browser)
implementation(deps.google.browserhelper)
implementation(deps.google.material)
implementation(deps.free.reflection)
debugImplementation(deps.leakcanary)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
tools:replace="android:icon,android:label">
<activity
android:name=".EasterEggsActivity"
android:exported="true"
android:label="@string/title_activity_settings">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/com/dede/android_eggs/ChromeTabPreference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import android.content.Intent
import android.net.Uri
import android.text.TextUtils
import android.util.AttributeSet
import androidx.browser.trusted.TrustedWebActivityIntentBuilder
import androidx.preference.Preference
import com.google.androidbrowserhelper.trusted.TwaLauncher

/**
* Chrome Custom Tabs Preference
Expand All @@ -18,7 +16,11 @@ import com.google.androidbrowserhelper.trusted.TwaLauncher
open class ChromeTabPreference : Preference, Preference.OnPreferenceClickListener {

private var uri: Uri? = null
private val useTwa: Boolean
private val useChromeTab: Boolean

init {
ChromeTabsBrowser.warmup(context)
}

constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
Expand All @@ -27,7 +29,7 @@ open class ChromeTabPreference : Preference, Preference.OnPreferenceClickListene
if (!TextUtils.isEmpty(uriString)) {
uri = Uri.parse(uriString)
}
useTwa = arrays.getBoolean(R.styleable.ChromeTabPreference_useTwa, true)
useChromeTab = arrays.getBoolean(R.styleable.ChromeTabPreference_useChromeTab, true)
arrays.recycle()

if (uri != null) {
Expand All @@ -42,8 +44,8 @@ open class ChromeTabPreference : Preference, Preference.OnPreferenceClickListene
override fun onPreferenceClick(preference: Preference?): Boolean {
val uri = this.uri
if (uri != null) {
if (useTwa) {
openTwaWeb(uri)
if (useChromeTab) {
openChromeTabs(uri)
} else {
openBrowser(uri)
}
Expand All @@ -58,10 +60,8 @@ open class ChromeTabPreference : Preference, Preference.OnPreferenceClickListene
context.startActivity(intent)
}

private fun openTwaWeb(uri: Uri) {
val twaLauncher = TwaLauncher(context)
val builder = TrustedWebActivityIntentBuilder(uri)
twaLauncher.launch(builder, null, null, null)
private fun openChromeTabs(uri: Uri) {
ChromeTabsBrowser.launchUrl(context, uri)
}

}
83 changes: 83 additions & 0 deletions app/src/main/java/com/dede/android_eggs/ChromeTabsBrowser.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.dede.android_eggs

import android.content.ComponentName
import android.content.Context
import android.graphics.Color
import android.net.Uri
import androidx.appcompat.app.AppCompatDelegate
import androidx.browser.customtabs.*
import com.google.android.material.color.MaterialColors

/**
* CustomTabs Help
*
* @author hsh
* @since 2021/11/19 2:14 下午
*/
object ChromeTabsBrowser {

// Package name for the Chrome channel the client wants to connect to. This depends on the channel name.
// Stable = com.android.chrome
// Beta = com.chrome.beta
// Dev = com.chrome.dev
private const val CUSTOM_TAB_PACKAGE_NAME = "com.android.chrome"
private const val CUSTOM_SESSION_ID = 10

private var mayLaunchUrl: Uri? = null
private val customTabsCallback = CustomTabsCallback()
private var customTabsSession: CustomTabsSession? = null

private val customTabsServiceConnection = object : CustomTabsServiceConnection() {
override fun onServiceDisconnected(name: ComponentName?) {
customTabsSession = null
}

override fun onCustomTabsServiceConnected(name: ComponentName, client: CustomTabsClient) {
val result = client.warmup(0)
if (result) {
val session = client.newSession(customTabsCallback, CUSTOM_SESSION_ID)
if (session != null) {
customTabsSession = session
if (mayLaunchUrl != null) {
session.mayLaunchUrl(mayLaunchUrl, null, null)
}
}
}
}
}

/**
* 预热并预加载
*/
fun warmup(context: Context, mayLaunchUrl: Uri? = null) {
if (customTabsSession != null) return
this.mayLaunchUrl = mayLaunchUrl
val appContext = context.applicationContext
CustomTabsClient.bindCustomTabsService(
appContext,
CUSTOM_TAB_PACKAGE_NAME,
customTabsServiceConnection
)
}

fun launchUrl(context: Context, uri: Uri) {
val colorScheme =
if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_YES)
CustomTabsIntent.COLOR_SCHEME_DARK else CustomTabsIntent.COLOR_SCHEME_LIGHT

val color = MaterialColors.getColor(context, android.R.attr.colorPrimary, Color.WHITE)
val params = CustomTabColorSchemeParams.Builder()
.setToolbarColor(color)
.build()

val builder = CustomTabsIntent.Builder()
.setColorScheme(colorScheme)
.setDefaultColorSchemeParams(params)
val session = customTabsSession
if (session != null) {
builder.setSession(session)
}
val customTabsIntent = builder.build()
customTabsIntent.launchUrl(context, uri)
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/dede/android_eggs/EasterEggsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ class EasterEggsActivity : AppCompatActivity(), Runnable {
.start()
}

override fun onDestroy() {
binding.content.removeCallbacks(this)
super.onDestroy()
}

}
8 changes: 0 additions & 8 deletions app/src/main/java/com/dede/android_eggs/EggPreference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ class EggPreference : Preference {
super.performClick()
}

private class OvalOutlineProvider : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setOval(view.paddingLeft, view.paddingTop,
view.width - view.paddingRight,
view.height - view.paddingBottom)
}
}

private class CornersOutlineProvider(val radius: Float) : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(view.paddingLeft, view.paddingTop,
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/dede/android_eggs/OvalOutlineProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.dede.android_eggs

import android.graphics.Outline
import android.view.View
import android.view.ViewOutlineProvider

/**
* View 圆角
* @author hsh
* @since 2021/10/21 5:03 下午
*/
class OvalOutlineProvider : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setOval(
view.paddingLeft, view.paddingTop,
view.width - view.paddingRight,
view.height - view.paddingBottom
)
}
}
6 changes: 3 additions & 3 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<style name="Theme.EasterEggs" parent="Base.EasterEggs">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_700</item>
<item name="colorPrimaryVariant">@color/black</item>
<item name="colorOnPrimary">@color/white</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@android:color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<item name="colorOnSecondary">@android:color/black</item>
<!-- Customize your theme here. -->
</style>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/attrs_preference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<declare-styleable name="ChromeTabPreference">
<attr name="customUrl" format="string" />
<attr name="useTwa" format="boolean"/>
<attr name="useChromeTab" format="boolean"/>
</declare-styleable>

<declare-styleable name="EggPreference">
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
<color name="purple_700">#7b1fa2</color>
<color name="teal_200">#80cbc4</color>
<color name="teal_700">#00796b</color>
<color name="black">#000000</color>
<color name="white">#FFFFFF</color>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_500</item>
<item name="colorOnPrimary">@color/white</item>
<item name="colorOnPrimary">@android:color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<item name="colorOnSecondary">@android:color/black</item>
<!-- Customize your theme here. -->
</style>
</resources>
3 changes: 1 addition & 2 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@
<com.dede.android_eggs.VersionPreference
app:customUrl="@string/url_beta"
app:iconSpaceReserved="false"
app:title="@string/title_version"
app:useTwa="false" />
app:title="@string/title_version" />

</PreferenceCategory>

Expand Down
17 changes: 7 additions & 10 deletions basic/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dede.basic">

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

<application>
<!-- FileProvider for sending pictures -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
</application>

</manifest>
Loading

0 comments on commit 5a5139d

Please sign in to comment.