use of androidx.appcompat.view.ContextThemeWrapper in project MTweaks-KernelAdiutorMOD by morogoku.
the class SettingsFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.settings);
SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
getPreferenceScreen().removePreference(forceEnglish);
} else {
forceEnglish.setOnPreferenceChangeListener(this);
}
/*
if (Utils.hideStartActivity()) {
((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
.removePreference(findPreference(KEY_MATERIAL_ICON));
} else {
findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
}
*/
findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this);
findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this);
findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this);
findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
findPreference(KEY_PRIMARY_COLOR).setOnPreferenceClickListener(this);
findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);
if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
} else {
((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(findPreference(KEY_LAST_KMSG));
}
findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference(findPreference(KEY_FINGERPRINT));
} else {
mFingerprint = findPreference(KEY_FINGERPRINT);
mFingerprint.setEnabled(!AppSettings.getPassword(getActivity()).isEmpty());
}
NavigationActivity activity = (NavigationActivity) getActivity();
PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
for (NavigationActivity.NavigationFragment navigationFragment : activity.getFragments()) {
Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
int id = navigationFragment.mId;
if (fragmentClass != null && fragmentClass != SettingsFragment.class) {
SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
switchPreference.setSummary(getString(id));
switchPreference.setKey(fragmentClass.getSimpleName() + "_enabled");
switchPreference.setChecked(AppSettings.isFragmentEnabled(fragmentClass, getActivity()));
switchPreference.setOnPreferenceChangeListener(this);
switchPreference.setPersistent(true);
sectionsCategory.addPreference(switchPreference);
}
}
}
use of androidx.appcompat.view.ContextThemeWrapper in project MTweaks-KernelAdiutorMOD by morogoku.
the class SecurityActivity method loadFingerprint.
@RequiresApi(api = Build.VERSION_CODES.M)
private void loadFingerprint() {
try {
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
KeyGenerator keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
mCipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7);
keyStore.load(null);
keyGenerator.init(new KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT).setBlockModes(KeyProperties.BLOCK_MODE_CBC).setUserAuthenticationRequired(true).setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7).build());
keyGenerator.generateKey();
SecretKey key = (SecretKey) keyStore.getKey(KEY_NAME, null);
mCipher.init(Cipher.ENCRYPT_MODE, key);
} catch (KeyStoreException | NoSuchProviderException | NoSuchAlgorithmException | NoSuchPaddingException | UnrecoverableKeyException | InvalidKeyException | CertificateException | InvalidAlgorithmParameterException | IOException e) {
return;
}
mCryptoObject = new FingerprintManagerCompat.CryptoObject(mCipher);
FrameLayout fingerprintParent = findViewById(R.id.fingerprint_parent);
final SwirlView swirlView = new SwirlView(new ContextThemeWrapper(this, R.style.Swirl));
swirlView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
fingerprintParent.addView(swirlView);
fingerprintParent.setVisibility(View.VISIBLE);
mFingerprintUiHelper = new FingerprintUiHelper.FingerprintUiHelperBuilder(mFingerprintManagerCompat).build(swirlView, new FingerprintUiHelper.Callback() {
@Override
public void onAuthenticated() {
try {
mCipher.doFinal(SECRET_MESSAGE.getBytes());
mPasswordWrong.setVisibility(View.GONE);
setResult(1);
finish();
} catch (IllegalBlockSizeException | BadPaddingException e) {
e.printStackTrace();
swirlView.setState(SwirlView.State.ERROR);
}
}
@Override
public void onError() {
}
});
mFingerprintUiHelper.startListening(mCryptoObject);
}
use of androidx.appcompat.view.ContextThemeWrapper in project apps-android-commons by commons-app.
the class AchievementsFragment method inflateAchievements.
/**
* Used the inflate the fetched statistics of the images uploaded by user
* and assign badge and level
* @param achievements
*/
private void inflateAchievements(Achievements achievements) {
imagesUsedByWikiProgressBar.setVisibility(View.VISIBLE);
thanksReceived.setText(String.valueOf(achievements.getThanksReceived()));
imagesUsedByWikiProgressBar.setProgress(100 * achievements.getUniqueUsedImages() / levelInfo.getMaxUniqueImages());
imagesUsedByWikiProgressBar.setProgressTextFormatPattern(achievements.getUniqueUsedImages() + "/" + levelInfo.getMaxUniqueImages());
imagesFeatured.setText(String.valueOf(achievements.getFeaturedImages()));
tvQualityImages.setText(String.valueOf(achievements.getQualityImages()));
String levelUpInfoString = getString(R.string.level).toUpperCase();
levelUpInfoString += " " + levelInfo.getLevelNumber();
levelNumber.setText(levelUpInfoString);
imageView.setImageDrawable(VectorDrawableCompat.create(getResources(), R.drawable.badge, new ContextThemeWrapper(getActivity(), levelInfo.getLevelStyle()).getTheme()));
badgeText.setText(Integer.toString(levelInfo.getLevelNumber()));
}
use of androidx.appcompat.view.ContextThemeWrapper in project Android-skin-support by ximsfei.
the class SkinAppCompatViewInflater method themifyContext.
/**
* Allows us to emulate the {@code android:theme} attribute for devices before L.
*/
private static Context themifyContext(Context context, AttributeSet attrs, boolean useAndroidTheme, boolean useAppTheme) {
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.View, 0, 0);
int themeId = 0;
if (useAndroidTheme) {
// First try reading android:theme if enabled
themeId = a.getResourceId(R.styleable.View_android_theme, 0);
}
if (useAppTheme && themeId == 0) {
// ...if that didn't work, try reading app:theme (for legacy reasons) if enabled
themeId = a.getResourceId(R.styleable.View_theme, 0);
if (themeId != 0) {
Slog.i(LOG_TAG, "app:theme is now deprecated. " + "Please move to using android:theme instead.");
}
}
a.recycle();
if (themeId != 0 && (!(context instanceof ContextThemeWrapper) || ((ContextThemeWrapper) context).getThemeResId() != themeId)) {
// If the context isn't a ContextThemeWrapper, or it is but does not have
// the same theme as we need, wrap it in a new wrapper
context = new ContextThemeWrapper(context, themeId);
}
return context;
}
use of androidx.appcompat.view.ContextThemeWrapper in project Douya by DreaminginCodeZH.
the class WebViewActivity method onConfigurationChanged.
@Override
public void onConfigurationChanged(Configuration newConfig) {
// Need to do this before calling super to avoid activity recreation by AppCompat.
NightModeHelper.onConfigurationChanged(this, this::onApplyThemeResource, R.style.Theme_Douya);
super.onConfigurationChanged(newConfig);
Context themedContext = new ContextThemeWrapper(this, ViewUtils.getResIdFromAttrRes(R.attr.actionBarTheme, 0, this));
Toolbar newToolbar = (Toolbar) LayoutInflater.from(themedContext).inflate(R.layout.webview_acitivity_toolbar, mAppbarWrapperLayout, false);
ViewUtils.replaceChild(mAppbarWrapperLayout, mToolbar, newToolbar);
ButterKnife.bind(this);
setupToolbar();
ViewUtils.setVisibleOrGone(mProgress, mProgressVisible);
ViewUtils.setMarginTop(mWebView, mToolbarHeight);
mWebView.requestLayout();
}
Aggregations