You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.8 KiB
92 lines
2.8 KiB
package org.purplei2p.lightning.browser.activity; |
|
|
|
import android.content.Intent; |
|
import android.content.res.Configuration; |
|
import android.graphics.Color; |
|
import android.os.Build; |
|
import android.os.Bundle; |
|
import android.support.v7.app.AppCompatActivity; |
|
|
|
import javax.inject.Inject; |
|
|
|
import org.purplei2p.lightning.R; |
|
import org.purplei2p.lightning.BrowserApp; |
|
import org.purplei2p.lightning.preference.PreferenceManager; |
|
import org.purplei2p.lightning.utils.ThemeUtils; |
|
|
|
public abstract class ThemableBrowserActivity extends AppCompatActivity { |
|
|
|
// TODO: 6/26/17 get rid fo protected reference |
|
@Inject protected PreferenceManager mPreferences; |
|
|
|
private int mTheme; |
|
private boolean mShowTabsInDrawer; |
|
private boolean mShouldRunOnResumeActions = false; |
|
|
|
@Override |
|
protected void onCreate(Bundle savedInstanceState) { |
|
BrowserApp.getAppComponent().inject(this); |
|
mTheme = mPreferences.getUseTheme(); |
|
mShowTabsInDrawer = mPreferences.getShowTabsInDrawer(!isTablet()); |
|
|
|
// set the theme |
|
if (mTheme == 1) { |
|
setTheme(R.style.Theme_DarkTheme); |
|
} else if (mTheme == 2) { |
|
setTheme(R.style.Theme_BlackTheme); |
|
} |
|
super.onCreate(savedInstanceState); |
|
|
|
resetPreferences(); |
|
} |
|
|
|
private void resetPreferences() { |
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
|
if (mPreferences.getUseBlackStatusBar()) { |
|
getWindow().setStatusBarColor(Color.BLACK); |
|
} else { |
|
getWindow().setStatusBarColor(ThemeUtils.getStatusBarColor(this)); |
|
} |
|
} |
|
} |
|
|
|
@Override |
|
public void onWindowFocusChanged(boolean hasFocus) { |
|
super.onWindowFocusChanged(hasFocus); |
|
if (hasFocus && mShouldRunOnResumeActions) { |
|
mShouldRunOnResumeActions = false; |
|
onWindowVisibleToUserAfterResume(); |
|
} |
|
} |
|
|
|
/** |
|
* Called after the activity is resumed |
|
* and the UI becomes visible to the user. |
|
* Called by onWindowFocusChanged only if |
|
* onResume has been called. |
|
*/ |
|
void onWindowVisibleToUserAfterResume() { |
|
|
|
} |
|
|
|
@Override |
|
protected void onResume() { |
|
super.onResume(); |
|
resetPreferences(); |
|
mShouldRunOnResumeActions = true; |
|
int theme = mPreferences.getUseTheme(); |
|
boolean drawerTabs = mPreferences.getShowTabsInDrawer(!isTablet()); |
|
if (theme != mTheme || mShowTabsInDrawer != drawerTabs) { |
|
restart(); |
|
} |
|
} |
|
|
|
boolean isTablet() { |
|
return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE; |
|
} |
|
|
|
void restart() { |
|
finish(); |
|
startActivity(new Intent(this, getClass())); |
|
} |
|
}
|
|
|