Search in sources :

Example 6 with AutofillManager

use of android.view.autofill.AutofillManager in project android_packages_apps_Settings by omnirom.

the class AutofillPreferenceCategory method isAutofillEnabled.

// PreferenceCategory.isEnabled() always return false, so we rather not change that logic
// decide whether the children should be shown using isAutofillEnabled() instead.
private boolean isAutofillEnabled() {
    final AutofillManager afm = getContext().getSystemService(AutofillManager.class);
    final boolean enabled = afm != null && afm.isEnabled();
    Log.v(TAG, "isAutofillEnabled(): " + enabled);
    return enabled;
}
Also used : AutofillManager(android.view.autofill.AutofillManager)

Example 7 with AutofillManager

use of android.view.autofill.AutofillManager in project android_packages_apps_Settings by DirtyUnicorns.

the class AutofillPickerTrampolineActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // First check if the current user's service already belongs to the app...
    final Intent intent = getIntent();
    final String packageName = intent.getData().getSchemeSpecificPart();
    final String currentService = DefaultAutofillPicker.getDefaultKey(this);
    if (currentService != null && currentService.startsWith(packageName)) {
        // ...and succeed right away if it does.
        setResult(RESULT_OK);
        finish();
        return;
    }
    // Then check if the Autofill is available for the current user...
    final AutofillManager afm = getSystemService(AutofillManager.class);
    if (afm == null || !afm.hasAutofillFeature() || !afm.isAutofillSupported()) {
        // ... and fail right away if it is not.
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    // Otherwise, go ahead and show the real UI...
    final Intent newIntent = new Intent(this, AutofillPickerActivity.class).setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).setData(intent.getData());
    startActivity(newIntent);
    finish();
}
Also used : Intent(android.content.Intent) AutofillManager(android.view.autofill.AutofillManager)

Example 8 with AutofillManager

use of android.view.autofill.AutofillManager in project android_packages_apps_Settings by crdroidandroid.

the class AutofillPickerTrampolineActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // First check if the current user's service already belongs to the app...
    final Intent intent = getIntent();
    final String packageName = intent.getData().getSchemeSpecificPart();
    final String currentService = DefaultAutofillPicker.getDefaultKey(this);
    if (currentService != null && currentService.startsWith(packageName)) {
        // ...and succeed right away if it does.
        setResult(RESULT_OK);
        finish();
        return;
    }
    // Then check if the Autofill is available for the current user...
    final AutofillManager afm = getSystemService(AutofillManager.class);
    if (afm == null || !afm.hasAutofillFeature() || !afm.isAutofillSupported()) {
        // ... and fail right away if it is not.
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    // Otherwise, go ahead and show the real UI...
    final Intent newIntent = new Intent(this, AutofillPickerActivity.class).setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).setData(intent.getData());
    startActivity(newIntent);
    finish();
}
Also used : Intent(android.content.Intent) AutofillManager(android.view.autofill.AutofillManager)

Example 9 with AutofillManager

use of android.view.autofill.AutofillManager in project KeePassDX by Kunzisoft.

the class NestedSettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    int key = getArguments().getInt(TAG_KEY);
    // Load the preferences from an XML resource
    switch(key) {
        case NESTED_SCREEN_APP_KEY:
            setPreferencesFromResource(R.xml.app_preferences, rootKey);
            Preference keyFile = findPreference(getString(R.string.keyfile_key));
            keyFile.setOnPreferenceChangeListener((preference, newValue) -> {
                Boolean value = (Boolean) newValue;
                if (!value) {
                    App.getFileHistory().deleteAllKeys();
                }
                return true;
            });
            Preference recentHistory = findPreference(getString(R.string.recentfile_key));
            recentHistory.setOnPreferenceChangeListener((preference, newValue) -> {
                Boolean value = (Boolean) newValue;
                if (value == null) {
                    value = true;
                }
                if (!value) {
                    App.getFileHistory().deleteAll();
                }
                return true;
            });
            Preference stylePreference = findPreference(getString(R.string.setting_style_key));
            stylePreference.setOnPreferenceChangeListener((preference, newValue) -> {
                String styleString = (String) newValue;
                Stylish.assignStyle(getActivity(), styleString);
                getActivity().recreate();
                return true;
            });
            SwitchPreference fingerprintEnablePreference = (SwitchPreference) findPreference(getString(R.string.fingerprint_enable_key));
            // < M solve verifyError exception
            boolean fingerprintSupported = false;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
                fingerprintSupported = FingerPrintHelper.isFingerprintSupported(FingerprintManagerCompat.from(getContext()));
            if (!fingerprintSupported) {
                // False if under Marshmallow
                fingerprintEnablePreference.setChecked(false);
                fingerprintEnablePreference.setOnPreferenceClickListener(preference -> {
                    FragmentManager fragmentManager = getFragmentManager();
                    assert fragmentManager != null;
                    ((SwitchPreference) preference).setChecked(false);
                    UnavailableFeatureDialogFragment.getInstance(Build.VERSION_CODES.M).show(getFragmentManager(), "unavailableFeatureDialog");
                    return false;
                });
            }
            Preference deleteKeysFingerprints = findPreference(getString(R.string.fingerprint_delete_all_key));
            if (!fingerprintSupported) {
                deleteKeysFingerprints.setEnabled(false);
            } else {
                deleteKeysFingerprints.setOnPreferenceClickListener(preference -> {
                    new AlertDialog.Builder(getContext()).setMessage(getResources().getString(R.string.fingerprint_delete_all_warning)).setIcon(getResources().getDrawable(android.R.drawable.ic_dialog_alert)).setPositiveButton(getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() {

                        @RequiresApi(api = Build.VERSION_CODES.M)
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            FingerPrintHelper.deleteEntryKeyInKeystoreForFingerprints(getContext(), new FingerPrintHelper.FingerPrintErrorCallback() {

                                @Override
                                public void onInvalidKeyException(Exception e) {
                                }

                                @Override
                                public void onFingerPrintException(Exception e) {
                                    Toast.makeText(getContext(), getString(R.string.fingerprint_error, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show();
                                }
                            });
                            PreferencesUtil.deleteAllValuesFromNoBackupPreferences(getContext());
                        }
                    }).setNegativeButton(getResources().getString(android.R.string.no), (dialog, which) -> {
                    }).show();
                    return false;
                });
            }
            break;
        case NESTED_SCREEN_FORM_FILLING_KEY:
            setPreferencesFromResource(R.xml.form_filling_preferences, rootKey);
            SwitchPreference autoFillEnablePreference = (SwitchPreference) findPreference(getString(R.string.settings_autofill_enable_key));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                AutofillManager autofillManager = getActivity().getSystemService(AutofillManager.class);
                if (autofillManager != null && autofillManager.hasEnabledAutofillServices())
                    autoFillEnablePreference.setChecked(autofillManager.hasEnabledAutofillServices());
                autoFillEnablePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                    @RequiresApi(api = Build.VERSION_CODES.O)
                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        if (((SwitchPreference) preference).isChecked()) {
                            try {
                                startEnableService();
                            } catch (ActivityNotFoundException e) {
                                String error = getString(R.string.error_autofill_enable_service);
                                ((SwitchPreference) preference).setChecked(false);
                                Log.d(getClass().getName(), error, e);
                                Toast.makeText(getContext(), error, Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            disableService();
                        }
                        return false;
                    }

                    @RequiresApi(api = Build.VERSION_CODES.O)
                    private void disableService() {
                        if (autofillManager != null && autofillManager.hasEnabledAutofillServices()) {
                            autofillManager.disableAutofillServices();
                        } else {
                            Log.d(getClass().getName(), "Sample service already disabled.");
                        }
                    }

                    @RequiresApi(api = Build.VERSION_CODES.O)
                    private void startEnableService() throws ActivityNotFoundException {
                        if (autofillManager != null && !autofillManager.hasEnabledAutofillServices()) {
                            Intent intent = new Intent(Settings.ACTION_REQUEST_SET_AUTOFILL_SERVICE);
                            intent.setData(Uri.parse("package:com.example.android.autofill.service"));
                            Log.d(getClass().getName(), "enableService(): intent=" + intent);
                            startActivityForResult(intent, REQUEST_CODE_AUTOFILL);
                        } else {
                            Log.d(getClass().getName(), "Sample service already enabled.");
                        }
                    }
                });
            } else {
                autoFillEnablePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
                            ((SwitchPreference) preference).setChecked(false);
                            FragmentManager fragmentManager = getFragmentManager();
                            assert fragmentManager != null;
                            UnavailableFeatureDialogFragment.getInstance(Build.VERSION_CODES.O).show(fragmentManager, "unavailableFeatureDialog");
                        }
                        return false;
                    }
                });
            }
            break;
        case NESTED_SCREEN_DB_KEY:
            setPreferencesFromResource(R.xml.db_preferences, rootKey);
            Database db = App.getDB();
            if (db.Loaded()) {
                if (db.pm.algorithmSettingsEnabled()) {
                    Preference roundPref = findPreference(getString(R.string.rounds_key));
                    roundPref.setEnabled(true);
                    roundPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

                        public boolean onPreferenceChange(Preference preference, Object newValue) {
                            setRounds(App.getDB(), preference);
                            return true;
                        }
                    });
                    setRounds(db, roundPref);
                    // TODO Algo
                    Preference algorithmPref = findPreference(getString(R.string.algorithm_key));
                    // algorithmPref.setEnabled(true);
                    setAlgorithm(db, algorithmPref);
                }
                if (db.pm.isRecycleBinAvailable()) {
                    SwitchPreference recycleBinPref = (SwitchPreference) findPreference(getString(R.string.recycle_bin_key));
                    // TODO Recycle
                    // recycleBinPref.setEnabled(true);
                    recycleBinPref.setChecked(db.pm.isRecycleBinEnable());
                }
            } else {
                Log.e(getClass().getName(), "Database isn't ready");
            }
            break;
        default:
            break;
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) R(com.kunzisoft.keepass.R) Bundle(android.os.Bundle) PreferenceFragmentCompat(android.support.v7.preference.PreferenceFragmentCompat) Uri(android.net.Uri) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi) DialogFragment(android.support.v4.app.DialogFragment) AutofillManager(android.view.autofill.AutofillManager) FingerprintManagerCompat(android.support.v4.hardware.fingerprint.FingerprintManagerCompat) PwEncryptionAlgorithm(com.keepassdroid.database.PwEncryptionAlgorithm) Toast(android.widget.Toast) Settings(android.provider.Settings) Build(android.os.Build) Log(android.util.Log) DialogInterface(android.content.DialogInterface) UnavailableFeatureDialogFragment(com.keepassdroid.dialogs.UnavailableFeatureDialogFragment) Database(com.keepassdroid.database.Database) Stylish(com.keepassdroid.stylish.Stylish) App(com.keepassdroid.app.App) Preference(android.support.v7.preference.Preference) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) ActivityNotFoundException(android.content.ActivityNotFoundException) SwitchPreference(android.support.v14.preference.SwitchPreference) Resources(android.content.res.Resources) FingerPrintHelper(com.keepassdroid.fingerprint.FingerPrintHelper) SwitchPreference(android.support.v14.preference.SwitchPreference) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) AutofillManager(android.view.autofill.AutofillManager) ActivityNotFoundException(android.content.ActivityNotFoundException) FragmentManager(android.support.v4.app.FragmentManager) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) ActivityNotFoundException(android.content.ActivityNotFoundException) RequiresApi(android.support.annotation.RequiresApi) Database(com.keepassdroid.database.Database)

Example 10 with AutofillManager

use of android.view.autofill.AutofillManager in project android_packages_apps_Settings by SudaMod.

the class AutofillPickerTrampolineActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // First check if the current user's service already belongs to the app...
    final Intent intent = getIntent();
    final String packageName = intent.getData().getSchemeSpecificPart();
    final String currentService = DefaultAutofillPicker.getDefaultKey(this);
    if (currentService != null && currentService.startsWith(packageName)) {
        // ...and succeed right away if it does.
        setResult(RESULT_OK);
        finish();
        return;
    }
    // Then check if the Autofill is available for the current user...
    final AutofillManager afm = getSystemService(AutofillManager.class);
    if (afm == null || !afm.hasAutofillFeature() || !afm.isAutofillSupported()) {
        // ... and fail right away if it is not.
        setResult(RESULT_CANCELED);
        finish();
        return;
    }
    // Otherwise, go ahead and show the real UI...
    final Intent newIntent = new Intent(this, AutofillPickerActivity.class).setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT).setData(intent.getData());
    startActivity(newIntent);
    finish();
}
Also used : Intent(android.content.Intent) AutofillManager(android.view.autofill.AutofillManager)

Aggregations

AutofillManager (android.view.autofill.AutofillManager)12 Intent (android.content.Intent)8 ComponentName (android.content.ComponentName)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 Resources (android.content.res.Resources)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Settings (android.provider.Settings)1 RequiresApi (android.support.annotation.RequiresApi)1 SwitchPreference (android.support.v14.preference.SwitchPreference)1 DialogFragment (android.support.v4.app.DialogFragment)1 FragmentManager (android.support.v4.app.FragmentManager)1 FingerprintManagerCompat (android.support.v4.hardware.fingerprint.FingerprintManagerCompat)1 AlertDialog (android.support.v7.app.AlertDialog)1 Preference (android.support.v7.preference.Preference)1 PreferenceFragmentCompat (android.support.v7.preference.PreferenceFragmentCompat)1 Log (android.util.Log)1 Toast (android.widget.Toast)1