migrating to new theme engine
This commit is contained in:
parent
8398953ec8
commit
049f9f65b1
|
@ -0,0 +1,58 @@
|
||||||
|
package org.mariotaku.chameleon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mariotaku on 2016/12/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Chameleon {
|
||||||
|
/**
|
||||||
|
* Created by mariotaku on 2016/12/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static class Theme {
|
||||||
|
int primaryColor;
|
||||||
|
int accentColor;
|
||||||
|
int toolbarColor;
|
||||||
|
boolean toolbarColored;
|
||||||
|
|
||||||
|
public int getAccentColor() {
|
||||||
|
return accentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccentColor(int accentColor) {
|
||||||
|
this.accentColor = accentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPrimaryColor() {
|
||||||
|
return primaryColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrimaryColor(int primaryColor) {
|
||||||
|
this.primaryColor = primaryColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getToolbarColor() {
|
||||||
|
return toolbarColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToolbarColor(int toolbarColor) {
|
||||||
|
this.toolbarColor = toolbarColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isToolbarColored() {
|
||||||
|
return toolbarColored;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToolbarColored(boolean toolbarColored) {
|
||||||
|
this.toolbarColored = toolbarColored;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mariotaku on 2016/12/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface Themeable {
|
||||||
|
Theme getOverrideTheme();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.mariotaku.ktextension
|
||||||
|
|
||||||
|
import android.annotation.TargetApi
|
||||||
|
import android.os.Build
|
||||||
|
import android.webkit.CookieManager
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mariotaku on 2016/12/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
fun CookieManager.removeAllCookiesSupport(callback: ((Boolean) -> Unit)? = null) {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
removeAllCookie()
|
||||||
|
callback?.invoke(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
CookieManagerSupportL.removeAllCookiesL(this, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal object CookieManagerSupportL {
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
fun removeAllCookiesL(manager: CookieManager, callback: ((Boolean) -> Unit)?) {
|
||||||
|
if (callback != null) {
|
||||||
|
manager.removeAllCookies { callback(it) }
|
||||||
|
} else {
|
||||||
|
manager.removeAllCookies(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,22 +28,18 @@ import android.content.res.Resources
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.nfc.NfcAdapter
|
import android.nfc.NfcAdapter
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.support.v7.preference.Preference
|
import android.support.v7.preference.Preference
|
||||||
import android.support.v7.preference.PreferenceFragmentCompat
|
import android.support.v7.preference.PreferenceFragmentCompat
|
||||||
import android.support.v7.preference.PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback
|
import android.support.v7.preference.PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback
|
||||||
import android.support.v7.view.menu.ActionMenuItemView
|
import android.support.v7.view.menu.ActionMenuItemView
|
||||||
import android.support.v7.widget.Toolbar
|
|
||||||
import android.support.v7.widget.TwidereActionMenuView
|
import android.support.v7.widget.TwidereActionMenuView
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.afollestad.appthemeengine.ATE
|
|
||||||
import com.afollestad.appthemeengine.ATEActivity
|
|
||||||
import com.afollestad.appthemeengine.Config
|
|
||||||
import com.afollestad.appthemeengine.customizers.ATEStatusBarCustomizer
|
|
||||||
import com.afollestad.appthemeengine.customizers.ATEToolbarCustomizer
|
|
||||||
import com.squareup.otto.Bus
|
import com.squareup.otto.Bus
|
||||||
|
import org.mariotaku.chameleon.Chameleon
|
||||||
import org.mariotaku.kpreferences.KPreferences
|
import org.mariotaku.kpreferences.KPreferences
|
||||||
import org.mariotaku.twidere.BuildConfig
|
import org.mariotaku.twidere.BuildConfig
|
||||||
import org.mariotaku.twidere.Constants
|
import org.mariotaku.twidere.Constants
|
||||||
|
@ -62,10 +58,9 @@ import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@SuppressLint("Registered")
|
@SuppressLint("Registered")
|
||||||
open class BaseActivity : ATEActivity(), Constants, IExtendedActivity, IThemedActivity,
|
open class BaseActivity : AppCompatActivity(), Constants, IExtendedActivity, IThemedActivity,
|
||||||
IControlBarActivity, OnFitSystemWindowsListener, SystemWindowsInsetsCallback,
|
IControlBarActivity, OnFitSystemWindowsListener, SystemWindowsInsetsCallback,
|
||||||
KeyboardShortcutCallback, OnPreferenceDisplayDialogCallback, ATEToolbarCustomizer,
|
KeyboardShortcutCallback, OnPreferenceDisplayDialogCallback, Chameleon.Themeable {
|
||||||
ATEStatusBarCustomizer {
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var keyboardShortcutsHandler: KeyboardShortcutsHandler
|
lateinit var keyboardShortcutsHandler: KeyboardShortcutsHandler
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -260,11 +255,6 @@ open class BaseActivity : ATEActivity(), Constants, IExtendedActivity, IThemedAc
|
||||||
override val themeBackgroundOption: String
|
override val themeBackgroundOption: String
|
||||||
get() = ThemeUtils.getThemeBackgroundOption(this)
|
get() = ThemeUtils.getThemeBackgroundOption(this)
|
||||||
|
|
||||||
|
|
||||||
override fun getATEKey(): String? {
|
|
||||||
return ThemeUtils.getATEKey(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onApplyThemeResource(theme: Resources.Theme, resId: Int, first: Boolean) {
|
override fun onApplyThemeResource(theme: Resources.Theme, resId: Int, first: Boolean) {
|
||||||
super.onApplyThemeResource(theme, resId, first)
|
super.onApplyThemeResource(theme, resId, first)
|
||||||
if (window != null && shouldApplyWindowBackground) {
|
if (window != null && shouldApplyWindowBackground) {
|
||||||
|
@ -350,22 +340,8 @@ open class BaseActivity : ATEActivity(), Constants, IExtendedActivity, IThemedAc
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getStatusBarColor(): Int {
|
override fun getOverrideTheme(): Chameleon.Theme {
|
||||||
return ATE.USE_DEFAULT
|
return Chameleon.Theme()
|
||||||
}
|
|
||||||
|
|
||||||
override fun getToolbarColor(toolbar: Toolbar?): Int {
|
|
||||||
return ATE.USE_DEFAULT
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getLightStatusBarMode(): Int {
|
|
||||||
//noinspection WrongConstant
|
|
||||||
return ThemeUtils.getLightStatusBarMode(Config.statusBarColor(this, ateKey))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getLightToolbarMode(toolbar: Toolbar?): Int {
|
|
||||||
//noinspection WrongConstant
|
|
||||||
return ThemeUtils.getLightToolbarMode(Config.toolbarColor(this, ateKey, toolbar))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.TextUtils.isEmpty
|
import android.text.TextUtils.isEmpty
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -37,6 +36,7 @@ import android.webkit.WebView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import kotlinx.android.synthetic.main.activity_browser_sign_in.*
|
import kotlinx.android.synthetic.main.activity_browser_sign_in.*
|
||||||
import org.attoparser.ParseException
|
import org.attoparser.ParseException
|
||||||
|
import org.mariotaku.ktextension.removeAllCookiesSupport
|
||||||
import org.mariotaku.microblog.library.MicroBlogException
|
import org.mariotaku.microblog.library.MicroBlogException
|
||||||
import org.mariotaku.microblog.library.twitter.TwitterOAuth
|
import org.mariotaku.microblog.library.twitter.TwitterOAuth
|
||||||
import org.mariotaku.restfu.oauth.OAuthAuthorization
|
import org.mariotaku.restfu.oauth.OAuthAuthorization
|
||||||
|
@ -77,11 +77,7 @@ class BrowserSignInActivity : BaseActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_browser_sign_in)
|
setContentView(R.layout.activity_browser_sign_in)
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
CookieManager.getInstance().removeAllCookiesSupport()
|
||||||
CookieManager.getInstance().removeAllCookie()
|
|
||||||
} else {
|
|
||||||
CookieManager.getInstance().removeAllCookies(null)
|
|
||||||
}
|
|
||||||
webView.setWebViewClient(AuthorizationWebViewClient(this))
|
webView.setWebViewClient(AuthorizationWebViewClient(this))
|
||||||
webView.isVerticalScrollBarEnabled = false
|
webView.isVerticalScrollBarEnabled = false
|
||||||
webView.addJavascriptInterface(InjectorJavaScriptInterface(this), "injector")
|
webView.addJavascriptInterface(InjectorJavaScriptInterface(this), "injector")
|
||||||
|
|
|
@ -197,10 +197,6 @@ class MediaViewerActivity : BaseActivity(), IExtendedActivity, ATEToolbarCustomi
|
||||||
setBarVisibility(!isBarShowing)
|
setBarVisibility(!isBarShowing)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getATEKey(): String? {
|
|
||||||
return VALUE_THEME_NAME_DARK
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getInitialPosition(): Int {
|
override fun getInitialPosition(): Int {
|
||||||
return media.indexOf(initialMedia)
|
return media.indexOf(initialMedia)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1277,21 +1277,24 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
||||||
setupBaseActionBar()
|
setupBaseActionBar()
|
||||||
}
|
}
|
||||||
val activity = activity as BaseActivity
|
val activity = activity as BaseActivity
|
||||||
if (Config.coloredActionBar(activity, activity.ateKey)) {
|
val theme = activity.overrideTheme
|
||||||
|
primaryColor = theme.primaryColor
|
||||||
|
primaryColorDark = ThemeUtils.computeDarkColor(primaryColor)
|
||||||
|
if (theme.isToolbarColored) {
|
||||||
primaryColor = color
|
primaryColor = color
|
||||||
primaryColorDark = ThemeUtils.computeDarkColor(color)
|
primaryColorDark = ThemeUtils.computeDarkColor(color)
|
||||||
} else {
|
} else {
|
||||||
primaryColor = Config.primaryColor(activity, activity.ateKey)
|
primaryColor = theme.primaryColor
|
||||||
primaryColorDark = Color.BLACK
|
primaryColorDark = Color.BLACK
|
||||||
}
|
}
|
||||||
if (actionBarBackground != null) {
|
if (actionBarBackground != null) {
|
||||||
actionBarBackground!!.color = primaryColor
|
actionBarBackground!!.color = primaryColor
|
||||||
}
|
}
|
||||||
val taskColor: Int
|
val taskColor: Int
|
||||||
if (Config.coloredActionBar(activity, activity.ateKey)) {
|
if (theme.isToolbarColored) {
|
||||||
taskColor = color
|
taskColor = color
|
||||||
} else {
|
} else {
|
||||||
taskColor = Config.toolbarColor(activity, activity.ateKey, toolbar)
|
taskColor = theme.toolbarColor
|
||||||
}
|
}
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
val name = userColorNameManager.getDisplayName(user, nameFirst)
|
val name = userColorNameManager.getDisplayName(user, nameFirst)
|
||||||
|
@ -1399,11 +1402,11 @@ class UserFragment : BaseSupportFragment(), OnClickListener, OnLinkClickListener
|
||||||
val tabContrastColor = ThemeUtils.getColorDependent(currentTabColor)
|
val tabContrastColor = ThemeUtils.getColorDependent(currentTabColor)
|
||||||
toolbarTabs.setIconColor(tabContrastColor)
|
toolbarTabs.setIconColor(tabContrastColor)
|
||||||
toolbarTabs.setLabelColor(tabContrastColor)
|
toolbarTabs.setLabelColor(tabContrastColor)
|
||||||
if (Config.coloredActionBar(activity, activity.ateKey)) {
|
val theme = activity.overrideTheme
|
||||||
|
if (theme.isToolbarColored) {
|
||||||
toolbarTabs.setStripColor(tabContrastColor)
|
toolbarTabs.setStripColor(tabContrastColor)
|
||||||
} else {
|
} else {
|
||||||
toolbarTabs.setStripColor(ThemeUtils.getOptimalAccentColor(uiColor,
|
toolbarTabs.setStripColor(ThemeUtils.getOptimalAccentColor(uiColor, tabContrastColor))
|
||||||
tabContrastColor))
|
|
||||||
}
|
}
|
||||||
toolbarTabs.updateAppearance()
|
toolbarTabs.updateAppearance()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue