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.content.Context;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.NonNull;
|
2015-04-22 10:36:56 +02:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
2015-01-18 17:15:38 +01:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
|
|
|
@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 final void restart() {
|
2015-04-22 10:36:56 +02:00
|
|
|
Utils.restartActivity(this);
|
2015-01-18 17:15:38 +01:00
|
|
|
}
|
2015-04-16 21:38:02 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSupportActionModeStarted(android.support.v7.view.ActionMode mode) {
|
|
|
|
super.onSupportActionModeStarted(mode);
|
2015-04-17 04:54:48 +02:00
|
|
|
ThemeUtils.applySupportActionModeColor(mode, this, getCurrentThemeResourceId(),
|
2015-04-16 22:29:36 +02:00
|
|
|
getCurrentThemeColor(), getThemeBackgroundOption(), true);
|
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 View onCreateView(String name, @NonNull Context context, @NonNull AttributeSet attrs) {
|
|
|
|
final View view = ThemeUtils.createView(name, context, attrs, mCurrentThemeColor);
|
|
|
|
if (view instanceof ShapedImageView) {
|
|
|
|
final ShapedImageView shapedImageView = (ShapedImageView) view;
|
|
|
|
shapedImageView.setStyle(mProfileImageStyle);
|
|
|
|
}
|
|
|
|
if (view != null) return view;
|
|
|
|
return super.onCreateView(name, context, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
}
|
|
|
|
|
2015-04-14 17:38:50 +02:00
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
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);
|
2015-04-14 17:38:50 +02:00
|
|
|
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
|
|
|
}
|