use of android.preference.Preference.OnPreferenceClickListener in project android by owncloud.
the class Preferences method onCreate.
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.actionbar_settings);
// For adding content description tag to a title field in the action bar
int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
if (actionBarTitleView != null) {
// it's null in Android 2.x
getWindow().getDecorView().findViewById(actionBarTitleId).setContentDescription(getString(R.string.actionbar_settings));
}
// Load package info
String temp;
try {
PackageInfo pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
temp = pkg.versionName;
} catch (NameNotFoundException e) {
temp = "";
Log_OC.e(TAG, "Error while showing about dialog", e);
}
final String appVersion = temp;
// Register context menu for list of preferences.
registerForContextMenu(getListView());
pCode = (CheckBoxPreference) findPreference(PassCodeActivity.PREFERENCE_SET_PASSCODE);
if (pCode != null) {
pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Intent i = new Intent(getApplicationContext(), PassCodeActivity.class);
Boolean incoming = (Boolean) newValue;
i.setAction(incoming ? PassCodeActivity.ACTION_REQUEST_WITH_RESULT : PassCodeActivity.ACTION_CHECK_WITH_RESULT);
startActivityForResult(i, incoming ? ACTION_REQUEST_PASSCODE : ACTION_CONFIRM_PASSCODE);
// Don't update just yet, we will decide on it in onActivityResult
return false;
}
});
}
PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
Preference pHelp = findPreference("help");
if (pHelp != null) {
if (helpEnabled) {
pHelp.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String helpWeb = (String) getText(R.string.url_help);
if (helpWeb != null && helpWeb.length() > 0) {
Uri uriUrl = Uri.parse(helpWeb);
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(intent);
}
return true;
}
});
} else {
preferenceCategory.removePreference(pHelp);
}
}
boolean recommendEnabled = getResources().getBoolean(R.bool.recommend_enabled);
Preference pRecommend = findPreference("recommend");
if (pRecommend != null) {
if (recommendEnabled) {
pRecommend.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
intent.setData(Uri.parse(getString(R.string.mail_recommend)));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String appName = getString(R.string.app_name);
String downloadUrl = getString(R.string.url_app_download);
String recommendSubject = String.format(getString(R.string.recommend_subject), appName);
String recommendText = String.format(getString(R.string.recommend_text), appName, downloadUrl);
intent.putExtra(Intent.EXTRA_SUBJECT, recommendSubject);
intent.putExtra(Intent.EXTRA_TEXT, recommendText);
startActivity(intent);
return (true);
}
});
} else {
preferenceCategory.removePreference(pRecommend);
}
}
boolean feedbackEnabled = getResources().getBoolean(R.bool.feedback_enabled);
Preference pFeedback = findPreference("feedback");
if (pFeedback != null) {
if (feedbackEnabled) {
pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String feedbackMail = (String) getText(R.string.mail_feedback);
String feedback = (String) getText(R.string.prefs_feedback) + " - android v" + appVersion;
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, feedback);
intent.setData(Uri.parse(feedbackMail));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;
}
});
} else {
preferenceCategory.removePreference(pFeedback);
}
}
boolean privacyPolicyEnabled = getResources().getBoolean(R.bool.privacy_policy_enabled);
Preference pPrivacyPolicy = findPreference("privacyPolicy");
if (pPrivacyPolicy != null) {
if (privacyPolicyEnabled) {
pPrivacyPolicy.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent privacyPolicyIntent = new Intent(getApplicationContext(), PrivacyPolicyActivity.class);
startActivity(privacyPolicyIntent);
return true;
}
});
} else {
preferenceCategory.removePreference(pPrivacyPolicy);
}
}
boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG;
Preference pLogger = findPreference("logger");
if (pLogger != null) {
if (loggerEnabled) {
pLogger.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent loggerIntent = new Intent(getApplicationContext(), LogHistoryActivity.class);
startActivity(loggerIntent);
return true;
}
});
} else {
preferenceCategory.removePreference(pLogger);
}
}
boolean imprintEnabled = getResources().getBoolean(R.bool.imprint_enabled);
Preference pImprint = findPreference("imprint");
if (pImprint != null) {
if (imprintEnabled) {
pImprint.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String imprintWeb = (String) getText(R.string.url_imprint);
if (imprintWeb != null && imprintWeb.length() > 0) {
Uri uriUrl = Uri.parse(imprintWeb);
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(intent);
}
//ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
return true;
}
});
} else {
preferenceCategory.removePreference(pImprint);
}
}
mPrefInstantUploadPath = findPreference("instant_upload_path");
if (mPrefInstantUploadPath != null) {
mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (!mUploadPath.endsWith(OCFile.PATH_SEPARATOR)) {
mUploadPath += OCFile.PATH_SEPARATOR;
}
Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadPath);
startActivityForResult(intent, ACTION_SELECT_UPLOAD_PATH);
return true;
}
});
}
mPrefInstantUploadCategory = (PreferenceCategory) findPreference("instant_uploading_category");
mPrefInstantUploadWiFi = findPreference("instant_upload_on_wifi");
mPrefInstantUpload = findPreference("instant_uploading");
toggleInstantPictureOptions(((CheckBoxPreference) mPrefInstantUpload).isChecked());
mPrefInstantUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enableInstantPicture = (Boolean) newValue;
toggleInstantPictureOptions(enableInstantPicture);
toggleInstantUploadCommonOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked(), enableInstantPicture);
return true;
}
});
mPrefInstantVideoUploadPath = findPreference("instant_video_upload_path");
if (mPrefInstantVideoUploadPath != null) {
mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (!mUploadVideoPath.endsWith(OCFile.PATH_SEPARATOR)) {
mUploadVideoPath += OCFile.PATH_SEPARATOR;
}
Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadVideoPath);
startActivityForResult(intent, ACTION_SELECT_UPLOAD_VIDEO_PATH);
return true;
}
});
}
mPrefInstantVideoUploadWiFi = findPreference("instant_video_upload_on_wifi");
mPrefInstantVideoUpload = findPreference("instant_video_uploading");
toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked());
mPrefInstantVideoUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
toggleInstantVideoOptions((Boolean) newValue);
toggleInstantUploadCommonOptions((Boolean) newValue, ((CheckBoxPreference) mPrefInstantUpload).isChecked());
return true;
}
});
mPrefInstantUploadSourcePath = findPreference("instant_upload_source_path");
if (mPrefInstantUploadSourcePath != null) {
mPrefInstantUploadSourcePath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (!mSourcePath.endsWith(File.separator)) {
mSourcePath += File.separator;
}
LocalFolderPickerActivity.startLocalFolderPickerActivityForResult(Preferences.this, mSourcePath, ACTION_SELECT_SOURCE_PATH);
return true;
}
});
} else {
Log_OC.e(TAG, "Lost preference instant_upload_source_path");
}
mPrefInstantUploadBehaviour = findPreference("prefs_instant_behaviour");
toggleInstantUploadCommonOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked(), ((CheckBoxPreference) mPrefInstantUpload).isChecked());
/* About App */
pAboutApp = (Preference) findPreference("about_app");
if (pAboutApp != null) {
pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name)));
pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion));
}
loadInstantUploadPath();
loadInstantUploadVideoPath();
loadInstantUploadSourcePath();
}
use of android.preference.Preference.OnPreferenceClickListener in project Float-Bar by tianzhijiexian.
the class MainActivity method onCreate.
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prefs_list_content);
addPreferencesFromResource(R.xml.float_preference);
prefs = new Prefs(MainActivity.this);
startcBox = (CheckBoxPreference) findPreference("started");
startcBox.setOnPreferenceChangeListener(this);
sendMail = (Preference) findPreference("mail");
sendMail.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Util.sendMail(MainActivity.this, "联系作者");
return false;
}
});
returnDefault = (Preference) findPreference("returnDefaultSetting");
returnDefault.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showDialog(MainActivity.this, "恢复默认设置", "确认后悬浮窗将会采用默认的设置", "确定", "取消");
return false;
}
});
// startActivity(new Intent(MainActivity.this,TestActivity.class));
}
use of android.preference.Preference.OnPreferenceClickListener in project AndroidChromium by JackyAndroid.
the class TranslatePreferences method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.translate_preferences);
getActivity().setTitle(R.string.google_translate);
setHasOptionsMenu(true);
final Context context = getActivity();
if (context == null)
return;
ChromeSwitchPreference translateSwitch = (ChromeSwitchPreference) findPreference(PREF_TRANSLATE_SWITCH);
boolean isTranslateEnabled = PrefServiceBridge.getInstance().isTranslateEnabled();
translateSwitch.setChecked(isTranslateEnabled);
translateSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
PrefServiceBridge.getInstance().setTranslateEnabled((boolean) newValue);
return true;
}
});
translateSwitch.setManagedPreferenceDelegate(new ManagedPreferenceDelegate() {
@Override
public boolean isPreferenceControlledByPolicy(Preference preference) {
return PrefServiceBridge.getInstance().isTranslateManaged();
}
});
ButtonPreference resetTranslateButton = (ButtonPreference) findPreference(PREF_RESET_TRANSLATE_BUTTON);
resetTranslateButton.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
PrefServiceBridge.getInstance().resetTranslateDefaults();
Toast.makeText(getActivity(), getString(R.string.translate_prefs_toast_description), Toast.LENGTH_SHORT).show();
return true;
}
});
}
use of android.preference.Preference.OnPreferenceClickListener in project AndroidChromium by JackyAndroid.
the class AccountManagementFragment method configureSignOutSwitch.
private void configureSignOutSwitch() {
boolean isChildAccount = ChildAccountService.isChildAccount();
Preference signOutSwitch = findPreference(PREF_SIGN_OUT);
if (isChildAccount) {
getPreferenceScreen().removePreference(signOutSwitch);
} else {
signOutSwitch.setEnabled(getSignOutAllowedPreferenceValue(getActivity()));
signOutSwitch.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (!isVisible() || !isResumed())
return false;
if (ChromeSigninController.get(getActivity()).isSignedIn() && getSignOutAllowedPreferenceValue(getActivity())) {
AccountManagementScreenHelper.logEvent(ProfileAccountManagementMetrics.TOGGLE_SIGNOUT, mGaiaServiceType);
String managementDomain = SigninManager.get(getActivity()).getManagementDomain();
if (managementDomain != null) {
// Show the 'You are signing out of a managed account' dialog.
ConfirmManagedSyncDataDialog.showSignOutFromManagedAccountDialog(AccountManagementFragment.this, getFragmentManager(), getResources(), managementDomain);
} else {
// Show the 'You are signing out' dialog.
SignOutDialogFragment signOutFragment = new SignOutDialogFragment();
Bundle args = new Bundle();
args.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaServiceType);
signOutFragment.setArguments(args);
signOutFragment.setTargetFragment(AccountManagementFragment.this, 0);
signOutFragment.show(getFragmentManager(), SIGN_OUT_DIALOG_TAG);
}
return true;
}
return false;
}
});
}
}
use of android.preference.Preference.OnPreferenceClickListener in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class AccountsSettingsFragment method enableSyncPreferences.
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;
}
});
}
}
Aggregations