android.preference.Preference.OnPreferenceClickListener Java Examples

The following examples show how to use android.preference.Preference.OnPreferenceClickListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecurityPreferenceFragment.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.pref_security);

      findPreference(KEY_PIN_ENABLED).setOnPreferenceClickListener(this);


      pin_set_preference = findPreference(KEY_PIN_SET);
pin_set_preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
	
	@Override
	public boolean onPreferenceClick(Preference preference) {
              SettingsActivity.logSettingEvent(preference.getKey());
		checkPin();
		return false;
	}
});
pin_set_preference.setSummary(SettingsActivity.isPinProtected(getActivity()) ? R.string.pin_set : R.string.pin_disabled);
  }
 
Example #2
Source File: Preferences.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create the preference for allow adding new accounts
 */
private void createAddAccountPreference() {
    Preference addAccountPref = new Preference(this);
    addAccountPref.setKey("add_account");
    addAccountPref.setTitle(getString(R.string.prefs_add_account));
    mAccountsPrefCategory.addPreference(addAccountPref);

    addAccountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AccountManager am = AccountManager.get(getApplicationContext());
            am.addAccount(MainApp.getAccountType(), null, null, null, Preferences.this,
                    null, null);
            return true;
        }
    });

}
 
Example #3
Source File: MediaButtonConfigure.java    From media-button-router with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TEXT_TO_SPEECH_CHECK_CODE) {
        Preference ttsWarningPreference = findPreference("tts_warning");

        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            ttsWarningPreference.setEnabled(false);
        } else {
            ttsWarningPreference.setEnabled(true);
            ttsWarningPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                public boolean onPreferenceClick(Preference preference) {
                    Intent installIntent = new Intent();
                    installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                    startActivity(installIntent);
                    return true;
                }
            });
        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}
 
Example #4
Source File: AccountManagementFragment.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void configureSyncSettings() {
    final Preferences preferences = (Preferences) getActivity();
    final Account account = ChromeSigninController.get(getActivity()).getSignedInUser();
    findPreference(PREF_SYNC_SETTINGS)
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    if (!isVisible() || !isResumed()) return false;

                    if (ProfileSyncService.get() == null) return true;

                    Bundle args = new Bundle();
                    args.putString(SyncCustomizationFragment.ARGUMENT_ACCOUNT, account.name);
                    preferences.startFragment(SyncCustomizationFragment.class.getName(), args);

                    return true;
                }
            });
}
 
Example #5
Source File: AccountManagementFragment.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void configureSyncSettings() {
    final Preferences preferences = (Preferences) getActivity();
    findPreference(PREF_SYNC_SETTINGS)
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    if (!isVisible() || !isResumed()) return false;

                    if (ProfileSyncService.get() == null) return true;

                    Bundle args = new Bundle();
                    args.putString(
                            SyncCustomizationFragment.ARGUMENT_ACCOUNT, mSignedInAccountName);
                    preferences.startFragment(SyncCustomizationFragment.class.getName(), args);

                    return true;
                }
            });
}
 
Example #6
Source File: AccountManagementFragment.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void configureGoogleActivityControls() {
    Preference pref = findPreference(PREF_GOOGLE_ACTIVITY_CONTROLS);
    if (mProfile.isChild()) {
        pref.setSummary(R.string.sign_in_google_activity_controls_message_child_account);
    }
    pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Activity activity = getActivity();
            AppHooks.get().createGoogleActivityController().openWebAndAppActivitySettings(
                    activity, mSignedInAccountName);
            RecordUserAction.record("Signin_AccountSettings_GoogleActivityControlsClicked");
            return true;
        }
    });
}
 
Example #7
Source File: PreferenceFragment.java    From AndroidBottomSheet with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the preference, which allows to display the applications, which are suited for
 * handling an intent.
 */
private void initializeShowIntentBottmSheetPreference() {
    Preference showIntentBottomSheetPreference =
            findPreference(getString(R.string.show_intent_bottom_sheet_preference_key));
    showIntentBottomSheetPreference
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    initializeIntentBottomSheet();
                    intentBottomSheet.show();
                    return true;
                }

            });
}
 
Example #8
Source File: AccountManagementFragment.java    From delion with Apache License 2.0 6 votes vote down vote up
private void configureSyncSettings() {
    final Preferences preferences = (Preferences) getActivity();
    final Account account = ChromeSigninController.get(getActivity()).getSignedInUser();
    findPreference(PREF_SYNC_SETTINGS)
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    if (!isVisible() || !isResumed()) return false;

                    if (ProfileSyncService.get() == null) return true;

                    if (AndroidSyncSettings.isMasterSyncEnabled(preferences)) {
                        Bundle args = new Bundle();
                        args.putString(
                                SyncCustomizationFragment.ARGUMENT_ACCOUNT, account.name);
                        preferences.startFragment(
                                SyncCustomizationFragment.class.getName(), args);
                    } else {
                        openSyncSettingsPage(preferences);
                    }

                    return true;
                }
            });
}
 
Example #9
Source File: PreferencesActivity.java    From AndroidPirateBox with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	activity = this;
	preferences = PreferenceManager.getDefaultSharedPreferences(this);
	addPreferencesFromResource(R.xml.preferences);
	
	updateExternalServerPreference();
	
	CheckBoxPreference extServerCheckBoxPref = (CheckBoxPreference) findPreference(Constants.PREF_USE_EXTERNAL_SERVER);
	extServerCheckBoxPref.setOnPreferenceClickListener(
			new OnPreferenceClickListener() {

				@Override
				public boolean onPreferenceClick(
						Preference preference) {
					updateExternalServerPreference();

					return true;
				}
			});
}
 
Example #10
Source File: SecurityPreferenceFragment.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.pref_security);

      findPreference(KEY_PIN_ENABLED).setOnPreferenceClickListener(this);


      pin_set_preference = findPreference(KEY_PIN_SET);
pin_set_preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
	
	@Override
	public boolean onPreferenceClick(Preference preference) {
              SettingsActivity.logSettingEvent(preference.getKey());
		checkPin();
		return false;
	}
});
pin_set_preference.setSummary(SettingsActivity.isPinProtected(getActivity()) ? R.string.pin_set : R.string.pin_disabled);
  }
 
Example #11
Source File: SecurityPreferenceFragment.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.pref_security);

      findPreference(KEY_PIN_ENABLED).setOnPreferenceClickListener(this);


      pin_set_preference = findPreference(KEY_PIN_SET);
pin_set_preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
	
	@Override
	public boolean onPreferenceClick(Preference preference) {
              SettingsActivity.logSettingEvent(preference.getKey());
		checkPin();
		return false;
	}
});
pin_set_preference.setSummary(SettingsActivity.isPinProtected(getActivity()) ? R.string.pin_set : R.string.pin_disabled);
  }
 
Example #12
Source File: SettingsHolder.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
private void initDependencies(){
    final Preference buildDepend = findPreference(BUILD_DEPENDS);
    buildDepend.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(final Preference preference) {
        	
        	final WebView webView = new WebView(mContext);
            webView.loadUrl("file:///android_asset/licenses.html");
            new AlertDialog.Builder(mContext)
                    .setTitle(R.string.dependencies_title)
                    .setView(webView)
                    .setPositiveButton(android.R.string.ok, null)
                    .create()
                    .show();
            return true;
        }
    });
}
 
Example #13
Source File: SensorSettingsActivity.java    From mytracks with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
  super.onCreate(bundle);
  addPreferencesFromResource(R.xml.sensor_settings);

  boolean hasAntSupport = AntInterface.hasAntSupport(this);

  configSensorType(hasAntSupport);

  findPreference(getString(R.string.settings_sensor_bluetooth_pairing_key))
      .setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
          Intent settingsIntent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
          startActivity(settingsIntent);
          return true;
        }
      });

  if (!hasAntSupport) {
    PreferenceScreen rootPreferenceScreen = (PreferenceScreen) findPreference(
        getString(R.string.settings_sensor_root_key));
    rootPreferenceScreen.removePreference(
        findPreference(getString(R.string.settings_sensor_ant_key)));
  }
}
 
Example #14
Source File: SensorSettingsActivity.java    From mytracks with Apache License 2.0 6 votes vote down vote up
/**
 * Updates an ant sensor.
 * 
 * @param preferenceKey the preference key
 * @param valueKey the value key
 * @param enabled true if enabled
 */
@SuppressWarnings("deprecation")
private void updateAntSensor(int preferenceKey, final int valueKey, boolean enabled) {
  Preference preference = findPreference(getString(preferenceKey));
  if (preference != null) {
    preference.setEnabled(enabled);
    int deviceId = PreferencesUtils.getInt(this, valueKey, AntSensorManager.WILDCARD);
    if (deviceId == AntSensorManager.WILDCARD) {
      preference.setSummary(R.string.settings_sensor_ant_not_connected);
    } else {
      preference.setSummary(getString(R.string.settings_sensor_ant_paired, deviceId));
    }
    preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
      public boolean onPreferenceClick(Preference pref) {
        PreferencesUtils.setInt(SensorSettingsActivity.this, valueKey, AntSensorManager.WILDCARD);
        pref.setSummary(R.string.settings_sensor_ant_not_connected);
        return true;
      }
    });
  }
}
 
Example #15
Source File: lua.java    From stynico with MIT License 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState)
    {
	super.onCreate(savedInstanceState);
//		setContentView(R.layout.activity_setting);StatusBarUtil.setStatusBarLightMode(this, getResources().getColor(R.color.colorAccent));
	StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary));
	addPreferencesFromResource(R.xml.preferences);
	
	preference1 = findPreference("donate_alipay");
	preference1.setOnPreferenceClickListener(new OnPreferenceClickListener() {

		@Override
		public boolean onPreferenceClick(Preference preference)
		{
		    Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
		    startActivity(intent);
		    return false;
		}
	    });

    }
 
Example #16
Source File: SettingsFragment.java    From Augendiagnose with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Add the listener for unlocker app.
 */
private void addUnlockerAppButtonListener() {
	Preference unlockPreference = findPreference(getString(R.string.key_dummy_unlocker_app));
	unlockPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
		@Override
		public boolean onPreferenceClick(final Preference preference) {
			Intent googlePlayIntent = new Intent(Intent.ACTION_VIEW);
			googlePlayIntent.setData(Uri.parse("market://details?id=de.jeisfeld.augendiagnoseunlocker"));
			try {
				startActivity(googlePlayIntent);
			}
			catch (Exception e) {
				DialogUtil.displayError(getActivity(), R.string.message_dialog_failed_to_open_google_play, false);
			}
			return true;
		}
	});
	unlockPreference.setEnabled(!SystemUtil.isAppInstalled("de.jeisfeld.augendiagnoseunlocker"));
}
 
Example #17
Source File: SettingsFragment.java    From Linphone4Android with GNU General Public License v3.0 6 votes vote down vote up
private void initSettings() {
	initTunnelSettings();
	initAudioSettings();
	initVideoSettings();
	initCallSettings();
	initChatSettings();
	initNetworkSettings();
	initAdvancedSettings();

	findPreference(getString(R.string.pref_add_account_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
		@Override
		public boolean onPreferenceClick(Preference preference) {
			int nbAccounts = mPrefs.getAccountCount();
			LinphoneActivity.instance().displayAccountSettings(nbAccounts);
			return true;
		}
	});
}
 
Example #18
Source File: lua.java    From styT with Apache License 2.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
//		setContentView(R.layout.activity_setting);StatusBarUtil.setStatusBarLightMode(this, getResources().getColor(R.color.colorAccent));

        addPreferencesFromResource(R.xml.preferences);
        Toast.makeText(this, "聊天界面不自动发,长按+音量键", Toast.LENGTH_SHORT).show();
        preference1 = findPreference("donate_alipay");
        preference1.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
                startActivity(intent);
                return false;
            }
        });

    }
 
Example #19
Source File: PreferenceFragment.java    From AndroidBottomSheet with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the preference, which allows to show a bottom sheet with custom content.
 */
private void initializeShowCustomBottomSheetPreference() {
    Preference showCustomBottomSheetPreference =
            findPreference(getString(R.string.show_custom_bottom_sheet_preference_key));
    showCustomBottomSheetPreference
            .setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(final Preference preference) {
                    initializeCustomBottomSheet();
                    customBottomSheet.show();
                    return true;
                }

            });
}
 
Example #20
Source File: PreferenceFragment.java    From AndroidBottomSheet with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes the preference, which allows to show a bottom sheet.
 */
private void initializeShowBottomSheetPreference() {
    Preference showBottomSheetPreference =
            findPreference(getString(R.string.show_bottom_sheet_preference_key));
    showBottomSheetPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(final Preference preference) {
            initializeBottomSheet();
            bottomSheet.show();
            return true;
        }

    });
}
 
Example #21
Source File: AccountsSettingsFragment.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
private void enableSyncPreferences(final String[] accountsForLogin,
        final String currentAccountName) {
    if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
        return;
    }
    mAccountSwitcher.setEnabled(true);

    mEnableSyncPreference.setEnabled(true);
    mEnableSyncPreference.setOnPreferenceClickListener(mEnableSyncClickListener);

    mSyncNowPreference.setEnabled(true);
    mSyncNowPreference.setOnPreferenceClickListener(mSyncNowListener);

    mClearSyncDataPreference.setEnabled(true);
    mClearSyncDataPreference.setOnPreferenceClickListener(mDeleteSyncDataListener);

    if (currentAccountName != null) {
        mAccountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(final Preference preference) {
                if (accountsForLogin.length > 0) {
                    // TODO: Add addition of account.
                    createAccountPicker(accountsForLogin, getSignedInAccountName(),
                            new AccountChangedListener(null)).show();
                }
                return true;
            }
        });
    }
}
 
Example #22
Source File: SettingsFragment.java    From droidddle with Apache License 2.0 5 votes vote down vote up
public static void setupTranslatePref(Preference findPreference) {
    findPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {

            final Context ctx = preference.getContext();
            //                new MaterialDialog.Builder((Activity) preference.getContext()).title(R.string.translate_title).content(R.string.translate_message).positiveText(R.string.translate_button).callback(new MaterialDialog.SimpleCallback() {
            //                    @Override
            //                    public void onPositive(MaterialDialog materialDialog) {
            //                        Intent intent = new Intent(Intent.ACTION_VIEW);
            //                        intent.setData(Uri.parse("https://goodev.oneskyapp.com"));
            //                        ctx.startActivity(intent);
            //                    }
            //                }).build().show();
            new AlertDialog.Builder((Activity) preference.getContext())
                    .setTitle(R.string.translate_title).setMessage(R.string.translate_message)
                    .setPositiveButton(R.string.translate_button,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Intent intent = new Intent(Intent.ACTION_VIEW);
                                    intent.setData(Uri.parse("https://goodev.oneskyapp.com"));
                                    ctx.startActivity(intent);
                                }
                            }).create().show();

            return true;
        }
    });
}
 
Example #23
Source File: PhysicalWebPreferenceFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void initLaunchButton() {
    ButtonPreference physicalWebLaunch =
            (ButtonPreference) findPreference(PREF_PHYSICAL_WEB_LAUNCH);

    physicalWebLaunch.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            PhysicalWebUma.onActivityReferral(PhysicalWebUma.PREFERENCE_REFERER);
            PhysicalWeb.showUrlList();
            return true;
        }
    });
}
 
Example #24
Source File: SettingsFragment.java    From loaned-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	// Load the preferences from an XML resource
	addPreferencesFromResource(R.xml.pref_general);
	// Response for when the feedback option is used
	findPreference("feedback").setOnPreferenceClickListener(new OnPreferenceClickListener() {
		@Override
		public boolean onPreferenceClick(Preference preference) {
			SendMail.sendFeedback(getActivity());
			return true;
		}
	});
}
 
Example #25
Source File: AccountsSettingsFragment.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
private void enableSyncPreferences(final String[] accountsForLogin,
        final String currentAccountName) {
    if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
        return;
    }
    mAccountSwitcher.setEnabled(true);

    mEnableSyncPreference.setEnabled(true);
    mEnableSyncPreference.setOnPreferenceClickListener(mEnableSyncClickListener);

    mSyncNowPreference.setEnabled(true);
    mSyncNowPreference.setOnPreferenceClickListener(mSyncNowListener);

    mClearSyncDataPreference.setEnabled(true);
    mClearSyncDataPreference.setOnPreferenceClickListener(mDeleteSyncDataListener);

    if (currentAccountName != null) {
        mAccountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(final Preference preference) {
                if (accountsForLogin.length > 0) {
                    // TODO: Add addition of account.
                    createAccountPicker(accountsForLogin, getSignedInAccountName(),
                            new AccountChangedListener(null)).show();
                }
                return true;
            }
        });
    }
}
 
Example #26
Source File: SettingsFragment.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add the listener for a "hints" button.
 *
 * @param preferenceId        The id of the button.
 * @param hintPreferenceValue The value to be set to all the hints preferences.
 */
private void addHintButtonListener(final int preferenceId, final boolean hintPreferenceValue) {
	Preference showPreference = findPreference(getString(preferenceId));
	showPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
		@Override
		public boolean onPreferenceClick(final Preference preference) {
			PreferenceUtil.setAllHints(hintPreferenceValue);
			DialogUtil.displayInfo(getActivity(), null,
					hintPreferenceValue ? R.string.message_dialog_no_hints_will_be_shown : R.string.message_dialog_hints_will_be_shown);
			return true;
		}
	});
}
 
Example #27
Source File: SettingsFragment.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add the listener for developer contact.
 */
private void addDeveloperContactButtonListener() {
	Preference contactPreference = findPreference(getString(R.string.key_dummy_contact_developer));
	contactPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
		@Override
		public boolean onPreferenceClick(final Preference preference) {
			Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
					"mailto", getString(R.string.menu_email_contact_developer), null));
			intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.menu_subject_contact_developer));

			startActivity(intent);
			return true;
		}
	});
}
 
Example #28
Source File: SettingsFragment.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a preference for the SKU.
 *
 * @param skuPurchase    The SKU to be added.
 * @param isSubscription Flag indicating if it is subscription or in-app product
 * @return the preference.
 */
private Preference createSkuPreference(final SkuPurchase skuPurchase, final boolean isSubscription) {
	Preference skuPreference = new Preference(getActivity());
	final SkuDetails skuDetails = skuPurchase.getSkuDetails();
	if (skuPurchase.isPurchased()) {
		skuPreference.setTitle(getString(isSubscription
				? R.string.googlebilling_subscription_title_purchased : R.string.googlebilling_onetime_title_purchased));
	}
	else if (skuPurchase.isPending()) {
		skuPreference.setTitle(getString(isSubscription
				? R.string.googlebilling_subscription_title_pending : R.string.googlebilling_onetime_title_pending));
	}
	else {
		skuPreference.setTitle(getString(isSubscription
				? R.string.googlebilling_subscription_title : R.string.googlebilling_onetime_title, skuDetails.getPrice()));
	}

	skuPreference.setKey(SKU_KEY_PREFIX + skuDetails.getSku());
	String descriptionResourceString = getString(isSubscription ? R.string.googlebilling_subscription_text : R.string.googlebilling_onetime_text);
	skuPreference.setSummary(String.format(descriptionResourceString, skuDetails.getPrice()));

	skuPreference.setEnabled(!skuPurchase.isPurchased() && !skuPurchase.isPending());

	if (!skuPurchase.isPurchased() && !skuPurchase.isPending()) {
		skuPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
			@Override
			public boolean onPreferenceClick(@NonNull final Preference preference) {
				GoogleBillingHelper.getInstance(getActivity()).launchPurchaseFlow(getActivity(), skuDetails, mOnPurchaseSuccessListener);
				return false;
			}
		});
	}
	return skuPreference;
}
 
Example #29
Source File: SettingsActivity.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Configures a preference by starting a new activity when it is clicked.
 * 
 * @param key the preference key
 * @param cl the class to start the new activity
 */
@SuppressWarnings("deprecation")
private void configPreference(int key, final Class<?> cl) {
  Preference preference = findPreference(getString(key));
  preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
      @Override
    public boolean onPreferenceClick(Preference pref) {
      Intent intent = IntentUtils.newIntent(SettingsActivity.this, cl);
      startActivity(intent);
      return true;
    }
  });
}
 
Example #30
Source File: NotificationsActivity.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
public void initPushNotification(Preference pref) {
    pref.setOnPreferenceClickListener(
            new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                    generateMessagingStyleNotification(getContext());
                    return true;
                }
            });
}