Search in sources :

Example 6 with ContextThemeWrapper

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);
        }
    }
}
Also used : ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) SwitchPreferenceCompat(androidx.preference.SwitchPreferenceCompat) PreferenceCategory(androidx.preference.PreferenceCategory) NavigationActivity(com.moro.mtweaks.activities.NavigationActivity) SuppressLint(android.annotation.SuppressLint)

Example 7 with ContextThemeWrapper

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);
}
Also used : FingerprintManagerCompat(androidx.core.hardware.fingerprint.FingerprintManagerCompat) SwirlView(com.mattprecious.swirl.SwirlView) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) KeyGenerator(javax.crypto.KeyGenerator) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) KeyGenParameterSpec(android.security.keystore.KeyGenParameterSpec) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) KeyStore(java.security.KeyStore) SecretKey(javax.crypto.SecretKey) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) FrameLayout(android.widget.FrameLayout) NoSuchProviderException(java.security.NoSuchProviderException) RequiresApi(androidx.annotation.RequiresApi)

Example 8 with ContextThemeWrapper

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()));
}
Also used : ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper)

Example 9 with ContextThemeWrapper

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;
}
Also used : ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) TypedArray(android.content.res.TypedArray)

Example 10 with ContextThemeWrapper

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();
}
Also used : Context(android.content.Context) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

ContextThemeWrapper (androidx.appcompat.view.ContextThemeWrapper)21 Context (android.content.Context)14 View (android.view.View)12 ColorPreferences (me.ccrama.redditslide.Visuals.ColorPreferences)10 TextView (android.widget.TextView)9 LayoutInflater (android.view.LayoutInflater)7 Intent (android.content.Intent)6 ImageView (android.widget.ImageView)6 ArrayList (java.util.ArrayList)6 DialogInterface (android.content.DialogInterface)5 AlertDialog (androidx.appcompat.app.AlertDialog)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 Snackbar (com.google.android.material.snackbar.Snackbar)5 SpoilerRobotoTextView (me.ccrama.redditslide.SpoilerRobotoTextView)5 Activity (android.app.Activity)4 ContextWrapper (android.content.ContextWrapper)4 TypedArray (android.content.res.TypedArray)4 HorizontalScrollView (android.widget.HorizontalScrollView)4 NonNull (androidx.annotation.NonNull)4 DialogAction (com.afollestad.materialdialogs.DialogAction)4