improved transparent theme

This commit is contained in:
Mariotaku Lee 2017-01-03 21:22:20 +08:00
parent cb7c69caae
commit a6585b12bf
7 changed files with 24 additions and 20 deletions

View File

@ -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'

View File

@ -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);
}

View File

@ -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)

View File

@ -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()
}

View File

@ -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<Int>(KEY_THEME, AppCompatDelegate.MODE_NIGHT_NO
}
}
object themeBackgroundAlphaKey : KSimpleKey<Int>(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<Int>(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

View File

@ -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)

View File

@ -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">