Search in sources :

Example 11 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project MTweaks-KernelAdiutorMOD by morogoku.

the class SecurityActivity method loadFingerprint.

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 = (FrameLayout) 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(android.support.v4.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(android.support.v7.view.ContextThemeWrapper) FrameLayout(android.widget.FrameLayout) NoSuchProviderException(java.security.NoSuchProviderException)

Example 12 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project fdroidclient by f-droid.

the class InstallExtensionDialogActivity method askBeforeInstall.

private void askBeforeInstall() {
    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());
    // not support on Android >= 5.1
    if (android.os.Build.VERSION.SDK_INT >= 22) {
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme);
        alertBuilder.setMessage(R.string.system_install_not_supported);
        alertBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
                InstallExtensionDialogActivity.this.finish();
            }
        });
        alertBuilder.create().show();
        return;
    }
    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(theme);
    alertBuilder.setTitle(R.string.system_install_question);
    String message = InstallExtension.create(getApplicationContext()).getWarningString();
    alertBuilder.setMessage(Html.fromHtml(message));
    alertBuilder.setPositiveButton(R.string.system_install_button_install, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            checkRootTask.execute();
        }
    });
    alertBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            InstallExtensionDialogActivity.this.setResult(Activity.RESULT_CANCELED);
            InstallExtensionDialogActivity.this.finish();
        }
    });
    alertBuilder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ContextThemeWrapper(android.view.ContextThemeWrapper) DialogInterface(android.content.DialogInterface)

Example 13 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project fdroidclient by f-droid.

the class InstallExtensionDialogActivity method postInstall.

/**
 * 3. Verify that install worked
 */
private void postInstall() {
    int isInstalledCorrectly = PrivilegedInstaller.isExtensionInstalledCorrectly(this);
    String title;
    String message;
    final int result;
    switch(isInstalledCorrectly) {
        case PrivilegedInstaller.IS_EXTENSION_INSTALLED_YES:
            title = getString(R.string.system_install_post_success);
            message = getString(R.string.system_install_post_success_message);
            result = Activity.RESULT_OK;
            break;
        case PrivilegedInstaller.IS_EXTENSION_INSTALLED_NO:
            title = getString(R.string.system_install_post_fail);
            message = getString(R.string.system_install_post_fail_message);
            result = Activity.RESULT_CANCELED;
            break;
        case PrivilegedInstaller.IS_EXTENSION_INSTALLED_SIGNATURE_PROBLEM:
            title = getString(R.string.system_install_post_fail);
            message = getString(R.string.system_install_post_fail_message) + "\n\n" + getString(R.string.system_install_denied_signature);
            result = Activity.RESULT_CANCELED;
            break;
        default:
            throw new RuntimeException("unhandled return");
    }
    // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay
    ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId());
    AlertDialog.Builder builder = new AlertDialog.Builder(theme).setTitle(title).setMessage(message).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            InstallExtensionDialogActivity.this.setResult(result);
            InstallExtensionDialogActivity.this.finish();
            startActivity(new Intent(InstallExtensionDialogActivity.this, MainActivity.class));
        }
    }).setCancelable(false);
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ContextThemeWrapper(android.view.ContextThemeWrapper) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) MainActivity(org.fdroid.fdroid.views.main.MainActivity)

Example 14 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project xDrip-plus by jamorham.

the class JoH method show_ok_dialog.

public static void show_ok_dialog(final Activity activity, String title, String message, final Runnable runnable) {
    try {
        AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme));
        builder.setTitle(title);
        builder.setMessage(message);
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                // 
                }
                if (runnable != null) {
                    runOnUiThreadDelayed(runnable, 10);
                }
            }
        });
        builder.create().show();
    } catch (Exception e) {
        Log.wtf(TAG, "show_dialog exception: " + e);
        static_toast_long(message);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) DialogInterface(android.content.DialogInterface) GsonBuilder(com.google.gson.GsonBuilder) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ActivityNotFoundException(android.content.ActivityNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 15 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project openhab-android by openhab.

the class WidgetAdapterTest method testColorMappingDarkTheme.

@Test
public void testColorMappingDarkTheme() {
    ColorMapper colorMapper = new ColorMapper(new ContextThemeWrapper(context, R.style.HABDroid_Basic_ui_dark));
    assertEquals("Map #ffffff", Integer.valueOf(0xffffffff), colorMapper.mapColor("#ffffff"));
    assertEquals("Must return \"null\" for invalid colors", null, colorMapper.mapColor("#fffzzz"));
    assertEquals("Map white => #ffffff in dark themes", Integer.valueOf(0xffffffff), colorMapper.mapColor("white"));
    assertEquals("Map red => #ff0000 in dark themes", Integer.valueOf(0xffff0000), colorMapper.mapColor("red"));
    assertEquals("Map yellow => #ffff00 in dark themes", Integer.valueOf(0xffffff00), colorMapper.mapColor("yellow"));
}
Also used : ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) ColorMapper(org.openhab.habdroid.ui.OpenHABWidgetAdapter.ColorMapper) Test(org.junit.Test)

Aggregations

View (android.view.View)40 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)38 ContextThemeWrapper (android.view.ContextThemeWrapper)31 Context (android.content.Context)25 DialogInterface (android.content.DialogInterface)24 TextView (android.widget.TextView)22 RecyclerView (android.support.v7.widget.RecyclerView)21 ImageView (android.widget.ImageView)21 AlertDialog (android.support.v7.app.AlertDialog)20 LayoutInflater (android.view.LayoutInflater)18 Intent (android.content.Intent)13 Nullable (android.support.annotation.Nullable)10 ColorPreferences (me.ccrama.redditslide.ColorPreferences)10 Drawable (android.graphics.drawable.Drawable)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9 EditText (android.widget.EditText)8 Bundle (android.os.Bundle)7 ArrayList (java.util.ArrayList)7 SuppressLint (android.annotation.SuppressLint)6 Dialog (android.app.Dialog)6