From a6585b12bf3b37a530eae38a6b31cf0e1c2eb978 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Tue, 3 Jan 2017 21:22:20 +0800 Subject: [PATCH] improved transparent theme --- twidere/build.gradle | 2 +- .../org/mariotaku/twidere/util/ThemeUtils.java | 10 ---------- .../mariotaku/twidere/activity/BaseActivity.kt | 5 +++++ .../mariotaku/twidere/app/TwidereApplication.kt | 6 ------ .../mariotaku/twidere/constant/PreferenceKeys.kt | 15 ++++++++++++++- .../mariotaku/twidere/fragment/UserFragment.kt | 5 +++-- .../src/main/res/layout/activity_home_content.xml | 1 + 7 files changed, 24 insertions(+), 20 deletions(-) diff --git a/twidere/build.gradle b/twidere/build.gradle index 7dd47212b..16a5c12ef 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -171,7 +171,7 @@ dependencies { compile "com.github.mariotaku.CommonsLibrary:text:$mariotaku_commons_library_version" compile "com.github.mariotaku.CommonsLibrary:text-kotlin:$mariotaku_commons_library_version" compile 'com.github.mariotaku:KPreferences:0.9.5' - compile 'com.github.mariotaku:Chameleon:0.9.6' + compile 'com.github.mariotaku:Chameleon:0.9.7-SNAPSHOT' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile 'nl.komponents.kovenant:kovenant:3.3.0' compile 'nl.komponents.kovenant:kovenant-android:3.3.0' diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java index 862050cd2..03c1c5566 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ThemeUtils.java @@ -20,7 +20,6 @@ package org.mariotaku.twidere.util; import android.content.Context; -import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Color; @@ -540,15 +539,6 @@ public class ThemeUtils implements Constants { } } - public static void fixNightMode(Resources resources, Configuration newConfig) { - int currentNightMode = resources.getConfiguration().uiMode - & Configuration.UI_MODE_NIGHT_MASK; - - if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) - newConfig.uiMode = (newConfig.uiMode & ~Configuration.UI_MODE_NIGHT_MASK) - | Configuration.UI_MODE_NIGHT_YES; - } - public static int getColorDependent(int color) { return ChameleonUtils.getColorDependent(color); } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt index fea6cffb8..9ff364e6f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt @@ -29,6 +29,7 @@ import android.graphics.Rect import android.nfc.NfcAdapter import android.os.Bundle import android.support.annotation.StyleRes +import android.support.v4.graphics.ColorUtils import android.support.v7.preference.Preference import android.support.v7.preference.PreferenceFragmentCompat import android.support.v7.preference.PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback @@ -102,6 +103,10 @@ open class BaseActivity : ChameleonActivity(), IExtendedActivity, IThemedActivit if (theme.isToolbarColored) { theme.colorToolbar = theme.colorPrimary } + if (ThemeUtils.isTransparentBackground(themeBackgroundOption)) { + theme.colorToolbar = ColorUtils.setAlphaComponent(theme.colorToolbar, + ThemeUtils.getActionBarAlpha(ThemeUtils.getUserThemeBackgroundAlpha(this))) + } theme.statusBarColor = ChameleonUtils.darkenColor(theme.colorToolbar) theme.lightStatusBarMode = LightStatusBarMode.AUTO theme.textColorLink = ThemeUtils.getOptimalAccentColor(theme.colorAccent, theme.colorForeground) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt index 42dd58519..58cde45ac 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/app/TwidereApplication.kt @@ -27,7 +27,6 @@ import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper import android.os.AsyncTask import android.support.multidex.MultiDex -import android.support.v7.app.AppCompatDelegate import android.util.Log import nl.komponents.kovenant.android.startKovenant import nl.komponents.kovenant.android.stopKovenant @@ -48,7 +47,6 @@ import org.mariotaku.twidere.activity.MainHondaJOJOActivity import org.mariotaku.twidere.constant.apiLastChangeKey import org.mariotaku.twidere.constant.bugReportsKey import org.mariotaku.twidere.constant.defaultFeatureLastUpdated -import org.mariotaku.twidere.constant.nightModeKey import org.mariotaku.twidere.model.DefaultFeatures import org.mariotaku.twidere.util.* import org.mariotaku.twidere.util.content.TwidereSQLiteOpenHelper @@ -99,7 +97,6 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis StrictModeUtils.detectAllVmPolicy() } super.onCreate() - AppCompatDelegate.setDefaultNightMode(sharedPreferences[nightModeKey]) startKovenant() initializeAsyncTask() initDebugMode() @@ -234,9 +231,6 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis KEY_SAME_OAUTH_SIGNING_URL, KEY_THUMBOR_ENABLED, KEY_THUMBOR_ADDRESS, KEY_THUMBOR_SECURITY_KEY -> { preferences[apiLastChangeKey] = System.currentTimeMillis() } - KEY_THEME -> { - AppCompatDelegate.setDefaultNightMode(preferences[nightModeKey]) - } KEY_EMOJI_SUPPORT -> { externalThemeManager.reloadEmojiPreferences() } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt index c11404120..9700392c4 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt @@ -10,11 +10,11 @@ import org.mariotaku.twidere.BuildConfig import org.mariotaku.twidere.Constants.KEY_DISPLAY_PROFILE_IMAGE import org.mariotaku.twidere.Constants.KEY_NO_CLOSE_AFTER_TWEET_SENT import org.mariotaku.twidere.TwidereConstants.* -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_THEME import org.mariotaku.twidere.extension.getNonEmptyString import org.mariotaku.twidere.model.CustomAPIConfig import org.mariotaku.twidere.model.account.cred.Credentials import org.mariotaku.twidere.model.sync.SyncProviderInfo +import org.mariotaku.twidere.preference.ThemeBackgroundPreference import org.mariotaku.twidere.util.sync.SyncProviderInfoFactory import org.mariotaku.twidere.view.ProfileImageView @@ -77,6 +77,19 @@ object nightModeKey : KSimpleKey(KEY_THEME, AppCompatDelegate.MODE_NIGHT_NO } } +object themeBackgroundAlphaKey : KSimpleKey(KEY_THEME_BACKGROUND_ALPHA, 0xFF) { + override fun read(preferences: SharedPreferences): Int { + return preferences.getInt(KEY_THEME_BACKGROUND_ALPHA, DEFAULT_THEME_BACKGROUND_ALPHA) + .coerceIn(ThemeBackgroundPreference.MIN_ALPHA, ThemeBackgroundPreference.MAX_ALPHA) + } + + override fun write(editor: SharedPreferences.Editor, value: Int): Boolean { + editor.putInt(key, value.coerceIn(ThemeBackgroundPreference.MIN_ALPHA, + ThemeBackgroundPreference.MAX_ALPHA)) + return true + } +} + object profileImageStyleKey : KSimpleKey(KEY_PROFILE_IMAGE_STYLE, ProfileImageView.SHAPE_CIRCLE) { override fun read(preferences: SharedPreferences): Int { if (preferences.getString(key, null) == VALUE_PROFILE_IMAGE_STYLE_SQUARE) return ProfileImageView.SHAPE_RECTANGLE diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt index 19dc0e0b1..00cec2092 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt @@ -48,6 +48,7 @@ import android.support.v4.app.LoaderManager.LoaderCallbacks import android.support.v4.content.AsyncTaskLoader import android.support.v4.content.Loader import android.support.v4.content.res.ResourcesCompat +import android.support.v4.graphics.ColorUtils import android.support.v4.view.ViewCompat import android.support.v4.view.ViewPager.OnPageChangeListener import android.support.v4.view.WindowCompat @@ -1292,9 +1293,9 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener } val taskColor: Int if (theme.isToolbarColored) { - taskColor = color + taskColor = ColorUtils.setAlphaComponent(color, 0xFF) } else { - taskColor = theme.colorToolbar + taskColor = ColorUtils.setAlphaComponent(theme.colorToolbar, 0xFF) } if (user != null) { val name = userColorNameManager.getDisplayName(user, nameFirst) diff --git a/twidere/src/main/res/layout/activity_home_content.xml b/twidere/src/main/res/layout/activity_home_content.xml index d99a29d59..8fc23c1b1 100644 --- a/twidere/src/main/res/layout/activity_home_content.xml +++ b/twidere/src/main/res/layout/activity_home_content.xml @@ -38,6 +38,7 @@ android:layout_width="match_parent" android:layout_height="?actionBarSize" android:layout_alignParentTop="true" + android:background="?colorToolbar" android:elevation="@dimen/toolbar_elevation" app:contentInsetEnd="0dp" app:contentInsetStart="0dp">