List of usage examples for android.hardware.fingerprint FingerprintManager hasEnrolledFingerprints
@Deprecated @RequiresPermission(USE_FINGERPRINT) public boolean hasEnrolledFingerprints()
From source file:com.tozny.e3db.android.KeyAuthentication.java
/** * Indicates if the device and SDK support the given type of key authentication. * @param ctx Application context./*w w w . j a va 2 s. c om*/ * @param authentication Authentication type. * @return {@code true} if the authencation type is supported; {@code false} otherwise. */ @SuppressLint("MissingPermission") public static boolean protectionTypeSupported(Context ctx, KeyAuthenticationType authentication) { switch (authentication) { case NONE: case PASSWORD: return true; case LOCK_SCREEN: return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; case FINGERPRINT: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Some devices support fingerprint but the support library doesn't recognize it, so // we use the actual FingerprintManager here. (https://stackoverflow.com/a/45181416/169359) FingerprintManager mgr = ctx.getSystemService(FingerprintManager.class); if (mgr != null) { return PermissionChecker.checkSelfPermission(ctx, Manifest.permission.USE_FINGERPRINT) == PermissionChecker.PERMISSION_GRANTED && mgr.isHardwareDetected() && mgr.hasEnrolledFingerprints(); } } return false; default: throw new IllegalStateException("Unhandled authentication type: " + authentication); } }
From source file:io.digibyte.tools.util.Utils.java
public static boolean isFingerprintEnrolled(Context app) { FingerprintManager fingerprintManager = (FingerprintManager) app.getSystemService(FINGERPRINT_SERVICE); // Device doesn't support fingerprint authentication return ActivityCompat.checkSelfPermission(app, Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED && fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints(); }
From source file:com.owncloud.android.ui.activity.FingerprintActivity.java
final static public boolean isFingerprintReady(Context context) { try {/* w ww. j a v a 2 s. c om*/ FingerprintManager fingerprintManager = (FingerprintManager) context .getSystemService(Context.FINGERPRINT_SERVICE); if (ActivityCompat.checkSelfPermission(context, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints(); } } catch (Exception e) { return false; } return false; }
From source file:com.breadwallet.presenter.fragments.FragmentSettings.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The last two arguments ensure LayoutParams are inflated // properly./*from ww w . j a v a 2 s. co m*/ View rootView = inflater.inflate(R.layout.fragment_settings, container, false); app = MainActivity.app; fragmentSettings = this; initList(); RelativeLayout about = (RelativeLayout) rootView.findViewById(R.id.about); TextView currencyName = (TextView) rootView.findViewById(R.id.three_letters_currency); RelativeLayout changePassword = (RelativeLayout) rootView.findViewById(R.id.change_password); final String tmp = SharedPreferencesManager.getIso(getActivity()); currencyName.setText(tmp); RelativeLayout localCurrency = (RelativeLayout) rootView.findViewById(R.id.local_currency); RelativeLayout recoveryPhrase = (RelativeLayout) rootView.findViewById(R.id.recovery_phrase); RelativeLayout startRecoveryWallet = (RelativeLayout) rootView.findViewById(R.id.start_recovery_wallet); RelativeLayout fingerprintLimit = (RelativeLayout) rootView.findViewById(R.id.fingerprint_limit); RelativeLayout earlyAccess = (RelativeLayout) rootView.findViewById(R.id.early_access); RelativeLayout line5 = (RelativeLayout) rootView.findViewById(R.id.settings_line_5); TextView theLimit = (TextView) rootView.findViewById(R.id.fingerprint_limit_text); RelativeLayout rescan = (RelativeLayout) rootView.findViewById(R.id.rescan_blockchain); theLimit.setText(BRStringFormatter.getFormattedCurrencyString("BTC", PassCodeManager.getInstance().getLimit(getActivity()))); FingerprintManager mFingerprintManager; mFingerprintManager = (FingerprintManager) getActivity().getSystemService(Context.FINGERPRINT_SERVICE); boolean useFingerPrint; useFingerPrint = ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED && mFingerprintManager.isHardwareDetected() && mFingerprintManager.hasEnrolledFingerprints(); if (!useFingerPrint) { fingerprintLimit.setVisibility(View.GONE); line5.setVisibility(View.GONE); } fingerprintLimit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { ((BreadWalletApp) getActivity().getApplicationContext()).promptForAuthentication(getActivity(), BRConstants.AUTH_FOR_LIMIT, null, null, null, null, false); } } }); startRecoveryWallet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { BRAnimator.pressWipeWallet(app, new FragmentWipeWallet()); app.activityButtonsEnable(false); } } }); recoveryPhrase.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BRWalletManager.getInstance(getActivity()).animateSavePhraseFlow(); } }); about.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { BRAnimator.animateSlideToLeft(app, new FragmentAbout(), fragmentSettings); } } }); localCurrency.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { BRAnimator.animateSlideToLeft(app, new FragmentCurrency(), fragmentSettings); } } }); changePassword.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { final android.app.FragmentManager fm = getActivity().getFragmentManager(); new PasswordDialogFragment().show(fm, PasswordDialogFragment.class.getName()); } } } ); rescan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { new Thread(new Runnable() { @Override public void run() { BRAnimator.goToMainActivity(fragmentSettings); BRPeerManager.getInstance(getActivity()).rescan(); SharedPreferencesManager.putStartHeight(getActivity(), 0); } }).start(); } } } ); //keep it hidden until finished if (!PLATFORM_ON) { earlyAccess.setVisibility(View.GONE); rootView.findViewById(R.id.early_access_separator).setVisibility(View.GONE); rootView.findViewById(R.id.early_access_separator2).setVisibility(View.GONE); } else { earlyAccess.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (BRAnimator.checkTheMultipressingAvailability()) { BRAnimator.animateSlideToLeft(app, new FragmentWebView(), fragmentSettings); } } }); } return rootView; }
From source file:de.j4velin.encrypter.MainActivity.java
private Requirement getMissingRequirement() { FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] { Manifest.permission.USE_FINGERPRINT }, REQUEST_PERMISSION); return Requirement.FINGERPRINT_PERMISSION; } else if (!fingerprintManager.isHardwareDetected()) { return Requirement.FINGERPRINT_SENSOR; } else if (!fingerprintManager.hasEnrolledFingerprints()) { return Requirement.FINGERPRINT_SETUP; } else if (!((KeyguardManager) getSystemService(KEYGUARD_SERVICE)).isDeviceSecure()) { return Requirement.DEVICE_SECURE; } else {/* w ww. j a va 2 s .com*/ return null; } }
From source file:com.rnd.snapsplit.view.OwedFragment.java
@Nullable @Override//from w ww .j a v a2 s . c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //super.onCreate(savedInstanceState); view = inflater.inflate(R.layout.activity_owed, container, false); activity = getActivity(); profile = new Profile(getContext()); ((Toolbar) getActivity().findViewById(R.id.tool_bar_hamburger)).setVisibility(View.VISIBLE); mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar); mMessageRecyclerView = (RecyclerView) view.findViewById(R.id.messageRecyclerView); mLinearLayoutManager = new LinearLayoutManager(getContext()); //mLinearLayoutManager.setStackFromEnd(true); mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference().child("requests"); mFirebaseAdapter = new FirebaseRecyclerAdapter<PaymentRequest, MessageViewHolder>(PaymentRequest.class, R.layout.list_owed, MessageViewHolder.class, mFirebaseDatabaseReference.orderByChild("requestEpochDate")) { @Override protected PaymentRequest parseSnapshot(DataSnapshot snapshot) { PaymentRequest pr = super.parseSnapshot(snapshot); if (pr != null) { pr.setId(snapshot.getKey()); return pr; } return null; } @Override protected void populateViewHolder(final MessageViewHolder viewHolder, PaymentRequest pr, int position) { mProgressBar.setVisibility(ProgressBar.INVISIBLE); if (pr != null && pr.getReceipientPhoneNo().equals(profile.getPhoneNumber())) { if (pr.getStrReceiptPic() != null && !pr.getStrReceiptPic().equals("")) { String encodedReceipt = pr.getStrReceiptPic(); byte[] encodeByte = Base64.decode(encodedReceipt, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length); viewHolder.receiptIcon.setImageBitmap(bitmap); } viewHolder.pr = pr; viewHolder.id = pr.getId(); viewHolder.description.setText(pr.getDescription()); viewHolder.from.setText( "Request sent by: " + pr.getRequestorName() + " - " + pr.getRequestorPhoneNumber()); viewHolder.share.setText("Your Share: HKD" + String.format("%.2f", pr.getShareAmount())); viewHolder.splitAmount .setText("Total Amount: HKD" + String.format("%.2f", pr.getTotalAmount())); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy' 'HH:mm:ss"); String date = null; Date temp = new Date(Long.parseLong(pr.getRequestEpochDate()) * (-1)); date = simpleDateFormat.format(temp); viewHolder.date.setText(date); } else { ViewGroup.LayoutParams params = viewHolder.item.getLayoutParams(); params.height = 0; viewHolder.item.setLayoutParams(params); } // log a view action on it //FirebaseUserActions.getInstance().end(getMessageViewAction(fd)); } @Override public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { MessageViewHolder viewHolder = super.onCreateViewHolder(parent, viewType); viewHolder.setOnLongClickListener(new MessageViewHolder.LongClickListener() { @Override public void onLongClick(View view, int position, String id, PaymentRequest pr) { AlertDialog.Builder ImageDialog = new AlertDialog.Builder(getActivity()); ImageDialog.setTitle("Receipt Preview - " + pr.getDescription()); ImageView showImage = new ImageView(getActivity()); Bitmap bitmap = null; if (pr.getStrReceiptPic() != null && !pr.getStrReceiptPic().equals("")) { String encodedReceipt = pr.getStrReceiptPic(); byte[] encodeByte = Base64.decode(encodedReceipt, Base64.DEFAULT); bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length); } if (bitmap != null) { showImage.setImageBitmap(bitmap); } ImageDialog.setView(showImage); ImageDialog.setNegativeButton("Close Preview", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { } }); ImageDialog.show(); } }); viewHolder.setOnClickListener(new MessageViewHolder.ClickListener() { @Override public void onItemClick(View view, int position, String id, PaymentRequest pr) { //Toast.makeText(getActivity(), "Item clicked at " + position, Toast.LENGTH_SHORT).show(); Bundle bundle = new Bundle(); bundle.putSerializable("pr", pr); if (initCipher(mCipher, DEFAULT_KEY_NAME)) { // Show the fingerprint dialog. The user has the option to use the fingerprint with // crypto, or you can fall back to using a server-side verified password. DialogFragmentFingerprintAuthentication fragment = new DialogFragmentFingerprintAuthentication(); fragment.setCryptoObject(new FingerprintManager.CryptoObject(mCipher)); boolean useFingerprintPreference = mSharedPreferences .getBoolean(getString(R.string.use_fingerprint_to_authenticate_key), true); if (useFingerprintPreference) { fragment.setStage(DialogFragmentFingerprintAuthentication.Stage.FINGERPRINT); } else { fragment.setStage(DialogFragmentFingerprintAuthentication.Stage.PASSWORD); } fragment.setArguments(bundle); fragment.setTargetFragment(mFragment, 0); fragment.show(getFragmentManager(), DIALOG_FRAGMENT_TAG); } else { // This happens if the lock screen has been disabled or or a fingerprint got // enrolled. Thus show the dialog to authenticate with their password first // and ask the user if they want to authenticate with fingerprints in the // future DialogFragmentFingerprintAuthentication fragment = new DialogFragmentFingerprintAuthentication(); fragment.setCryptoObject(new FingerprintManager.CryptoObject(mCipher)); fragment.setStage( DialogFragmentFingerprintAuthentication.Stage.NEW_FINGERPRINT_ENROLLED); fragment.setArguments(bundle); fragment.setTargetFragment(mFragment, 0); fragment.show(getFragmentManager(), DIALOG_FRAGMENT_TAG); } } }); return viewHolder; } }; mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { super.onItemRangeInserted(positionStart, itemCount); int friendlyMessageCount = mFirebaseAdapter.getItemCount(); int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition(); // If the recycler view is initially being loaded or the user is at the bottom of the list, scroll // to the bottom of the list to show the newly added message. if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1) && lastVisiblePosition == (positionStart - 1))) { mMessageRecyclerView.scrollToPosition(positionStart); } } }); mMessageRecyclerView.setLayoutManager(mLinearLayoutManager); mMessageRecyclerView.setAdapter(mFirebaseAdapter); try { mKeyStore = KeyStore.getInstance("AndroidKeyStore"); } catch (KeyStoreException e) { throw new RuntimeException("Failed to get an instance of KeyStore", e); } try { mKeyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore"); } catch (NoSuchAlgorithmException | NoSuchProviderException e) { throw new RuntimeException("Failed to get an instance of KeyGenerator", e); } //Cipher defaultCipher; Cipher cipherNotInvalidated; try { mCipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7); cipherNotInvalidated = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7); } catch (NoSuchAlgorithmException | NoSuchPaddingException e) { throw new RuntimeException("Failed to get an instance of Cipher", e); } mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); KeyguardManager keyguardManager = getActivity().getSystemService(KeyguardManager.class); FingerprintManager fingerprintManager = getActivity().getSystemService(FingerprintManager.class); if (!keyguardManager.isKeyguardSecure()) { // Show a message that the user hasn't set up a fingerprint or lock screen. Toast.makeText(getActivity(), "Secure lock screen hasn't set up.\n" + "Go to 'Settings -> Security -> Fingerprint' to set up a fingerprint", Toast.LENGTH_LONG).show(); //return; } // Now the protection level of USE_FINGERPRINT permission is normal instead of dangerous. // See http://developer.android.com/reference/android/Manifest.permission.html#USE_FINGERPRINT // The line below prevents the false positive inspection from Android Studio // noinspection ResourceType if (!fingerprintManager.hasEnrolledFingerprints()) { // This happens when no fingerprints are registered. Toast.makeText(getActivity(), "Go to 'Settings -> Security -> Fingerprint' and register at least one fingerprint", Toast.LENGTH_LONG).show(); //return; } createKey(DEFAULT_KEY_NAME, true); createKey(KEY_NAME_NOT_INVALIDATED, false); return view; }
From source file:com.amaze.carbonfilemanager.fragments.preference_fragments.Preffrag.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); utilsProvider = (UtilitiesProviderInterface) getActivity(); PreferenceUtils.reset();/*from w w w . j a v a 2 s . c o m*/ // Load the preferences from an XML resource addPreferencesFromResource(R.xml.preferences); sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); for (String PREFERENCE_KEY : PREFERENCE_KEYS) { findPreference(PREFERENCE_KEY).setOnPreferenceClickListener(this); } gplus = (CheckBox) findPreference("plus_pic"); if (BuildConfig.IS_VERSION_FDROID) gplus.setEnabled(false); // crypt master password final EditTextPreference masterPasswordPreference = (EditTextPreference) findPreference( PREFERENCE_CRYPT_MASTER_PASSWORD); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { // encryption feature not available masterPasswordPreference.setEnabled(false); } if (sharedPref.getBoolean(PREFERENCE_CRYPT_FINGERPRINT, false)) { masterPasswordPreference.setEnabled(false); } CheckBox checkBoxFingerprint = (CheckBox) findPreference(PREFERENCE_CRYPT_FINGERPRINT); try { // finger print sensor final FingerprintManager fingerprintManager = (FingerprintManager) getActivity() .getSystemService(Context.FINGERPRINT_SERVICE); final KeyguardManager keyguardManager = (KeyguardManager) getActivity() .getSystemService(Context.KEYGUARD_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && fingerprintManager.isHardwareDetected()) { checkBoxFingerprint.setEnabled(true); } checkBoxFingerprint.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_no_permission), Toast.LENGTH_LONG).show(); return false; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !fingerprintManager.hasEnrolledFingerprints()) { Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_not_enrolled), Toast.LENGTH_LONG).show(); return false; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !keyguardManager.isKeyguardSecure()) { Toast.makeText(getActivity(), getResources().getString(R.string.crypt_fingerprint_no_security), Toast.LENGTH_LONG) .show(); return false; } masterPasswordPreference.setEnabled(false); return true; } }); } catch (NoClassDefFoundError error) { error.printStackTrace(); // fingerprint manager class not defined in the framework checkBoxFingerprint.setEnabled(false); } // Hide root preference Preference mRootMode = findPreference("rootmode"); PreferenceCategory mMisc = (PreferenceCategory) findPreference("misc"); mMisc.removePreference(mRootMode); }
From source file:nl.hnogames.domoticz.Preference.Preference.java
private void setPreferences() { final android.preference.SwitchPreference MultiServerPreference = (android.preference.SwitchPreference) findPreference( "enableMultiServers"); android.preference.Preference ServerSettings = findPreference("server_settings"); android.preference.Preference PermissionsSettings = findPreference("permissionssettings"); android.preference.Preference NotificationLogged = findPreference("notification_show_logs"); android.preference.Preference fetchServerConfig = findPreference("server_force_fetch_config"); android.preference.Preference resetApplication = findPreference("reset_settings"); android.preference.ListPreference displayLanguage = (ListPreference) findPreference("displayLanguage"); final android.preference.Preference registrationId = findPreference("notification_registration_id"); android.preference.Preference GeoSettings = findPreference("geo_settings"); android.preference.SwitchPreference WearPreference = (android.preference.SwitchPreference) findPreference( "enableWearItems"); android.preference.Preference NFCPreference = findPreference("nfc_settings"); android.preference.Preference QRCodePreference = findPreference("qrcode_settings"); android.preference.Preference SpeechPreference = findPreference("speech_settings"); android.preference.SwitchPreference EnableNFCPreference = (android.preference.SwitchPreference) findPreference( "enableNFC"); android.preference.SwitchPreference EnableQRCodePreference = (android.preference.SwitchPreference) findPreference( "enableQRCode"); android.preference.SwitchPreference EnableSpeechPreference = (android.preference.SwitchPreference) findPreference( "enableSpeech"); android.preference.SwitchPreference EnableTalkBackPreference = (android.preference.SwitchPreference) findPreference( "talkBack"); MultiSelectListPreference drawerItems = (MultiSelectListPreference) findPreference("enable_menu_items"); @SuppressWarnings("SpellCheckingInspection") android.preference.SwitchPreference AlwaysOnPreference = (android.preference.SwitchPreference) findPreference( "alwayson"); @SuppressWarnings("SpellCheckingInspection") android.preference.PreferenceScreen preferenceScreen = (android.preference.PreferenceScreen) findPreference( "settingsscreen"); android.preference.PreferenceCategory premiumCategory = (android.preference.PreferenceCategory) findPreference( "premium_category"); android.preference.Preference premiumPreference = findPreference("premium_settings"); NotificationsMultiSelectListPreference notificationsMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference( "suppressNotifications"); NotificationsMultiSelectListPreference alarmMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference( "alarmNotifications"); android.preference.SwitchPreference ThemePreference = (android.preference.SwitchPreference) findPreference( "darkTheme"); android.preference.Preference FingerPrintSettingsPreference = findPreference("SecuritySettings"); android.preference.SwitchPreference FingerPrintPreference = (android.preference.SwitchPreference) findPreference( "enableSecurity"); if (!BuildConfig.DEBUG) { PreferenceCategory oAndroidAutoCategory = (android.preference.PreferenceCategory) findPreference( "androidautocategory"); PreferenceScreen oNotificationScreen = (android.preference.PreferenceScreen) findPreference( "notificationscreen"); oNotificationScreen.removePreference(oAndroidAutoCategory); }/*from www.java2 s. c o m*/ List<String> notifications = mSharedPrefs.getReceivedNotifications(); if (notifications == null || notifications.size() <= 0) { notificationsMultiSelectListPreference.setEnabled(false); alarmMultiSelectListPreference.setEnabled(false); } else { notificationsMultiSelectListPreference.setEnabled(true); alarmMultiSelectListPreference.setEnabled(true); } PermissionsSettings .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { permissionHelper.openSettingsScreen(); return true; } }); drawerItems.setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { try { final HashSet selectedDrawerItems = (HashSet) newValue; if (selectedDrawerItems.size() < 1) { showSnackbar(mContext.getString(R.string.error_atLeastOneItemInDrawer)); return false; } } catch (Exception ex) { ex.printStackTrace(); return false; } return true; } }); ThemePreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_theme)); return false; } else { ((SettingsActivity) getActivity()).reloadSettings(); return true; } } }); MultiServerPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.multi_server)); return false; } return true; } }); ServerSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (!MultiServerPreference.isChecked()) { Intent intent = new Intent(mContext, ServerSettingsActivity.class); startActivity(intent); } else { Intent intent = new Intent(mContext, ServerListSettingsActivity.class); startActivity(intent); } return true; } }); FingerPrintSettingsPreference .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { mContext.startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS)); return true; } }); fetchServerConfig .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { UsefulBits.getServerConfigForActiveServer(mContext, true, new ConfigReceiver() { @Override public void onReceiveConfig(ConfigInfo settings) { showSnackbar(mContext.getString(R.string.fetched_server_config_success)); } @Override public void onError(Exception error) { showSnackbar(mContext.getString(R.string.fetched_server_config_failed)); } }, null); return true; } }); displayLanguage .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { showRestartMessage(); return true; } }); registrationId.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!PermissionsUtil.canAccessDeviceState(mContext)) { permissionHelper.request(PermissionsUtil.INITIAL_DEVICE_PERMS); } else { pushGCMRegistrationIds(); } } else { pushGCMRegistrationIds(); } return true; } }); GeoSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.geofence)); return false; } else { Intent intent = new Intent(mContext, GeoSettingsActivity.class); startActivity(intent); return true; } } }); EnableNFCPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_nfc)); return false; } if (NfcAdapter.getDefaultAdapter(mContext) == null) { showSnackbar(mContext.getString(R.string.nfc_not_supported)); return false; } return true; } }); EnableQRCodePreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_QRCode)); return false; } return true; } }); EnableSpeechPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_Speech)); return false; } return true; } }); EnableTalkBackPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_talk_back)); return false; } return true; } }); NFCPreference.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_nfc)); return false; } else { Intent intent = new Intent(mContext, NFCSettingsActivity.class); startActivity(intent); return true; } } }); QRCodePreference .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_QRCode)); return false; } else { Intent intent = new Intent(mContext, QRCodeSettingsActivity.class); startActivity(intent); return true; } } }); SpeechPreference .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_Speech)); return false; } else { Intent intent = new Intent(mContext, SpeechSettingsActivity.class); startActivity(intent); return true; } } }); WearPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_wear)); return false; } return true; } }); AlwaysOnPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) { if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.always_on_title)); return false; } return true; } }); NotificationLogged .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { //show dialog List<String> logs = mSharedPrefs.getLoggedNotifications(); if (logs != null && logs.size() > 0) { Collections.reverse(logs); new MaterialDialog.Builder(mContext) .title(mContext.getString(R.string.notification_show_title)) .items((CharSequence[]) logs.toArray(new String[0])).show(); } else UsefulBits.showSimpleToast(mContext, getString(R.string.notification_show_nothing), Toast.LENGTH_LONG); return true; } }); //noinspection PointlessBooleanExpression if (!BuildConfig.LITE_VERSION) { preferenceScreen.removePreference(premiumCategory); } else { premiumPreference .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { String packageID = mContext.getPackageName() + ".premium"; try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageID))); } catch (android.content.ActivityNotFoundException ignored) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageID))); } return true; } }); } resetApplication .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(android.preference.Preference preference) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { new MaterialDialog.Builder(mContext).title(R.string.category_Reset) .content(R.string.are_you_sure).positiveText(R.string.ok) .negativeText(R.string.cancel) .onPositive(new MaterialDialog.SingleButtonCallback() { @SuppressLint("NewApi") @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE)) .clearApplicationUserData(); } }).show(); } else { startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0); } return true; } }); FingerPrintPreference .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() { @SuppressLint("NewApi") @Override public boolean onPreferenceChange(android.preference.Preference preference, Object o) { if (mSharedPrefs.isStartupSecurityEnabled()) return true; if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) { showPremiumSnackbar(getString(R.string.category_startup_security)); return false; } else { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_supported), Toast.LENGTH_LONG); return false; } if (!PermissionsUtil.canAccessFingerprint(mContext)) { permissionHelper.request(PermissionsUtil.INITIAL_FINGERPRINT_PERMS); } else { FingerprintManager fingerprintManager = (FingerprintManager) mContext .getSystemService(Context.FINGERPRINT_SERVICE); if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) { return false; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (!fingerprintManager.isHardwareDetected()) { return false; } else if (!fingerprintManager.hasEnrolledFingerprints()) { UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_setup_in_android), Toast.LENGTH_LONG); return false; } else { new MaterialDialog.Builder(mContext) .title(R.string.category_startup_security) .content(R.string.fingerprint_sure).positiveText(R.string.ok) .negativeText(R.string.cancel) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { mSharedPrefs.setStartupSecurityEnabled(true); ((SettingsActivity) getActivity()).reloadSettings(); } }).show(); return false; } } } } return false; } }); }