Twidere-App-Android-Twitter.../twidere/src/main/java/org/mariotaku/twidere/activity/support/ThemedAppCompatActivity.java

123 lines
3.9 KiB
Java
Raw Normal View History

2015-01-18 17:15:38 +01:00
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity.support;
import android.os.Bundle;
2015-04-22 10:36:56 +02:00
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.app.ThemedAppCompatDelegate;
2015-01-18 17:15:38 +01:00
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.activity.iface.IThemedActivity;
import org.mariotaku.twidere.util.StrictModeUtils;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.Utils;
import org.mariotaku.twidere.view.ShapedImageView.ShapeStyle;
2015-04-22 10:36:56 +02:00
public abstract class ThemedAppCompatActivity extends AppCompatActivity implements Constants, IThemedActivity {
2015-01-18 17:15:38 +01:00
private int mCurrentThemeResource, mCurrentThemeColor, mCurrentThemeBackgroundAlpha;
@ShapeStyle
private int mProfileImageStyle;
2015-04-14 17:38:50 +02:00
private String mCurrentThemeBackgroundOption;
2015-01-18 17:15:38 +01:00
private AppCompatDelegate mDelegate;
2015-01-18 17:15:38 +01:00
@Override
2015-04-14 17:38:50 +02:00
public int getCurrentThemeBackgroundAlpha() {
return mCurrentThemeBackgroundAlpha;
}
@Override
public String getCurrentThemeBackgroundOption() {
return mCurrentThemeBackgroundOption;
}
@Override
public int getCurrentThemeColor() {
return mCurrentThemeColor;
2015-01-18 17:15:38 +01:00
}
@Override
public final int getCurrentThemeResourceId() {
return mCurrentThemeResource;
}
@Override
2015-04-14 17:38:50 +02:00
public int getThemeBackgroundAlpha() {
return ThemeUtils.getUserThemeBackgroundAlpha(this);
2015-01-18 17:15:38 +01:00
}
@Override
2015-04-14 17:38:50 +02:00
public String getThemeBackgroundOption() {
return ThemeUtils.getThemeBackgroundOption(this);
2015-01-18 17:15:38 +01:00
}
@Override
public String getThemeFontFamily() {
return ThemeUtils.getThemeFontFamily(this);
}
@Override
public int getCurrentProfileImageStyle() {
return mProfileImageStyle;
2015-01-18 17:15:38 +01:00
}
2015-04-16 21:38:02 +02:00
@Override
public final void restart() {
Utils.restartActivity(this);
2015-04-16 21:38:02 +02:00
}
2015-01-18 17:15:38 +01:00
@Override
protected void onCreate(final Bundle savedInstanceState) {
if (Utils.isDebugBuild()) {
StrictModeUtils.detectAllVmPolicy();
StrictModeUtils.detectAllThreadPolicy();
}
2015-04-14 17:38:50 +02:00
setupTheme();
2015-01-18 17:15:38 +01:00
super.onCreate(savedInstanceState);
}
@Override
public void onSupportActionModeStarted(android.support.v7.view.ActionMode mode) {
super.onSupportActionModeStarted(mode);
ThemeUtils.applySupportActionModeColor(mode, this, getCurrentThemeResourceId(),
getCurrentThemeColor(), getThemeBackgroundOption(), true);
2015-01-18 17:15:38 +01:00
}
2015-04-14 17:38:50 +02:00
@Override
public AppCompatDelegate getDelegate() {
if (mDelegate != null) return mDelegate;
return mDelegate = ThemedAppCompatDelegate.create(this, this);
2015-01-18 17:15:38 +01:00
}
2015-04-14 17:38:50 +02:00
private void setupTheme() {
2015-01-18 17:15:38 +01:00
mCurrentThemeResource = getThemeResourceId();
mCurrentThemeColor = getThemeColor();
mCurrentThemeBackgroundAlpha = getThemeBackgroundAlpha();
mProfileImageStyle = Utils.getProfileImageStyle(this);
2015-04-14 17:38:50 +02:00
mCurrentThemeBackgroundOption = getThemeBackgroundOption();
2015-01-18 17:15:38 +01:00
setTheme(mCurrentThemeResource);
ThemeUtils.applyWindowBackground(this, getWindow(), mCurrentThemeResource,
mCurrentThemeBackgroundOption, mCurrentThemeBackgroundAlpha);
2015-01-18 17:15:38 +01:00
}
2015-04-14 17:38:50 +02:00
2015-01-18 17:15:38 +01:00
}