use of androidx.preference.Preference in project AntennaPod by AntennaPod.
the class MainPreferencesFragment method onCreatePreferences.
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences);
setupMainScreen();
setupSearch();
// If you are writing a spin-off, please update the details on screens like "About" and "Report bug"
// and afterwards remove the following lines. Please keep in mind that AntennaPod is licensed under the GPL.
// This means that your application needs to be open-source under the GPL, too.
// It must also include a prominent copyright notice.
int packageHash = getContext().getPackageName().hashCode();
if (packageHash != 1790437538 && packageHash != -1190467065) {
findPreference(PREF_CATEGORY_PROJECT).setVisible(false);
Preference copyrightNotice = new Preference(getContext());
copyrightNotice.setIcon(R.drawable.ic_info_white);
copyrightNotice.getIcon().mutate().setColorFilter(new PorterDuffColorFilter(0xffcc0000, PorterDuff.Mode.MULTIPLY));
copyrightNotice.setSummary("This application is based on AntennaPod." + " The AntennaPod team does NOT provide support for this unofficial version." + " If you can read this message, the developers of this modification" + " violate the GNU General Public License (GPL).");
findPreference(PREF_CATEGORY_PROJECT).getParent().addPreference(copyrightNotice);
} else if (packageHash == -1190467065) {
Preference debugNotice = new Preference(getContext());
debugNotice.setIcon(R.drawable.ic_info_white);
debugNotice.getIcon().mutate().setColorFilter(new PorterDuffColorFilter(0xffcc0000, PorterDuff.Mode.MULTIPLY));
debugNotice.setOrder(-1);
debugNotice.setSummary("This is a development version of AntennaPod and not meant for daily use");
findPreference(PREF_CATEGORY_PROJECT).getParent().addPreference(debugNotice);
}
}
use of androidx.preference.Preference in project kcanotify by antest1.
the class MainPreferenceFragment method onActivityResult.
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (checkActivityValid()) {
if (requestCode == REQUEST_OVERLAY_PERMISSION) {
int delay = Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? 0 : 1000;
new Handler().postDelayed(() -> {
Context context = getContext();
if (context != null) {
if (Settings.canDrawOverlays(getContext())) {
showToast(getActivity(), getStringWithLocale(R.string.sa_overlay_ok), Toast.LENGTH_SHORT);
} else {
showToast(getActivity(), getStringWithLocale(R.string.sa_overlay_no), Toast.LENGTH_SHORT);
}
}
}, delay);
} else if (requestCode == REQUEST_USAGESTAT_PERMISSION) {
if (hasUsageStatPermission(getContext())) {
showToast(getActivity(), getStringWithLocale(R.string.sa_usagestat_ok), Toast.LENGTH_SHORT);
} else {
showToast(getActivity(), getStringWithLocale(R.string.sa_usagestat_no), Toast.LENGTH_SHORT);
}
} else if (requestCode == REQUEST_ALERT_RINGTONE && data != null) {
Preference pref = findPreference(PREF_KCA_NOTI_RINGTONE);
Uri ringtoneUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
String ringtoneTitle = getRingtoneTitle(ringtoneUri);
pref.setSummary(ringtoneTitle);
if (ringtoneUri != null) {
sharedPref.edit().putString(PREF_KCA_NOTI_RINGTONE, ringtoneUri.toString()).apply();
} else {
sharedPref.edit().putString(PREF_KCA_NOTI_RINGTONE, "").apply();
}
}
}
}
use of androidx.preference.Preference in project kcanotify by antest1.
the class MainPreferenceFragment method onSharedPreferenceChanged.
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (sHandler != null) {
JsonObject dmpData = new JsonObject();
String kca_url = "";
Bundle bundle = new Bundle();
switch(key) {
case PREF_KCA_SEEK_CN:
kca_url = KCA_API_PREF_CN_CHANGED;
break;
case PREF_KCA_EXP_VIEW:
kca_url = KCA_API_PREF_EXPVIEW_CHANGED;
break;
case PREF_KCA_SET_PRIORITY:
kca_url = KCA_API_PREF_PRIORITY_CHANGED;
break;
case PREF_FAIRY_SIZE:
kca_url = KCA_API_PREF_FAIRYSIZE_CHANGED;
break;
default:
break;
}
if (kca_url.length() > 0) {
bundle.putString("url", kca_url);
bundle.putString("data", gson.toJson(dmpData));
Message sMsg = sHandler.obtainMessage();
sMsg.setData(bundle);
sHandler.sendMessage(sMsg);
}
}
Preference preference = findPreference(key);
if (preference instanceof ListPreference) {
ListPreference lp = (ListPreference) preference;
if (!preference.getKey().equals(PREF_KCA_HP_FORMAT)) {
// PREF_KCA_HP_FORMAT already has a summary
preference.setSummary(lp.getEntry());
}
}
if (preference instanceof EditTextPreference) {
EditTextPreference etp = (EditTextPreference) preference;
preference.setSummary(getEditTextSummary(key, etp.getText()));
}
}
use of androidx.preference.Preference in project Gadgetbridge by Freeyourgadget.
the class SonyHeadphonesSettingsCustomizer method onPreferenceChange.
@Override
public void onPreferenceChange(final Preference preference, final DeviceSpecificSettingsHandler handler) {
// TODO: Should the coordinator be responsible for this compatibility check?
if (preference.getKey().equals(PREF_SONY_AUDIO_CODEC) && device.getType().equals(DeviceType.SONY_WH_1000XM3)) {
final boolean isSbcCodec = ((EditTextPreference) preference).getText().equalsIgnoreCase("sbc");
final List<Preference> prefsToDisable = Arrays.asList(handler.findPreference(PREF_SONY_EQUALIZER), handler.findPreference(PREF_SONY_EQUALIZER_MODE), handler.findPreference(PREF_SONY_EQUALIZER_BAND_400), handler.findPreference(PREF_SONY_EQUALIZER_BAND_1000), handler.findPreference(PREF_SONY_EQUALIZER_BAND_2500), handler.findPreference(PREF_SONY_EQUALIZER_BAND_6300), handler.findPreference(PREF_SONY_EQUALIZER_BAND_16000), handler.findPreference(PREF_SONY_EQUALIZER_BASS), handler.findPreference(PREF_SONY_SOUND_POSITION), handler.findPreference(PREF_SONY_SURROUND_MODE));
for (Preference pref : prefsToDisable) {
if (pref != null) {
pref.setEnabled(isSbcCodec);
}
}
}
// Handle ANC Optimizer status
if (preference.getKey().equals(PREF_SONY_NOISE_OPTIMIZER_STATUS)) {
final EditTextPreference optimizerStatusPreference = (EditTextPreference) preference;
final NoiseCancellingOptimizerStatus optimizerStatus = NoiseCancellingOptimizerStatus.valueOf(optimizerStatusPreference.getText().toUpperCase(Locale.ROOT));
if (ancOptimizerProgressDialog != null) {
switch(optimizerStatus) {
case FINISHED:
case NOT_RUNNING:
ancOptimizerProgressDialog.dismiss();
ancOptimizerProgressDialog = null;
break;
default:
ancOptimizerProgressDialog.setMessage(optimizerStatus.i18n(preference.getContext()));
}
}
}
}
use of androidx.preference.Preference in project Gadgetbridge by Freeyourgadget.
the class SonyHeadphonesSettingsCustomizer method customizeSettings.
@Override
public void customizeSettings(final DeviceSpecificSettingsHandler handler) {
// Only enable the focus on voice check and voice level slider if the ambient sound control mode is ambient sound
final ListPreference ambientSoundControl = handler.findPreference(PREF_SONY_AMBIENT_SOUND_CONTROL);
if (ambientSoundControl != null) {
final Preference focusOnVoice = handler.findPreference(PREF_SONY_FOCUS_VOICE);
final Preference ambientSoundLevel = handler.findPreference(PREF_SONY_AMBIENT_SOUND_LEVEL);
final Preference.OnPreferenceChangeListener ambientSoundControlPrefListener = new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newVal) {
boolean isAmbientSoundEnabled = AmbientSoundControl.Mode.AMBIENT_SOUND.name().toLowerCase(Locale.getDefault()).equals(newVal);
focusOnVoice.setEnabled(isAmbientSoundEnabled);
ambientSoundLevel.setEnabled(isAmbientSoundEnabled);
return true;
}
};
ambientSoundControlPrefListener.onPreferenceChange(ambientSoundControl, ambientSoundControl.getValue());
handler.addPreferenceHandlerFor(PREF_SONY_AMBIENT_SOUND_CONTROL, ambientSoundControlPrefListener);
}
// ANC Optimizer
final Preference ancOptimizer = handler.findPreference("pref_sony_anc_optimizer");
if (ancOptimizer != null) {
ancOptimizer.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(final Preference preference) {
if (ancOptimizerProgressDialog != null) {
// Already optimizing
return true;
}
final Context context = preference.getContext();
new AlertDialog.Builder(context).setTitle(R.string.sony_anc_optimize_confirmation_title).setMessage(R.string.sony_anc_optimize_confirmation_description).setIcon(R.drawable.ic_hearing).setPositiveButton(R.string.start, new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int whichButton) {
handler.notifyPreferenceChanged(PREF_SONY_NOISE_OPTIMIZER_START);
ancOptimizerProgressDialog = new ProgressDialog(context);
ancOptimizerProgressDialog.setCancelable(false);
ancOptimizerProgressDialog.setMessage(context.getString(R.string.sony_anc_optimizer_status_starting));
ancOptimizerProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
ancOptimizerProgressDialog.setProgress(0);
ancOptimizerProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.Cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
dialog.dismiss();
ancOptimizerProgressDialog = null;
handler.notifyPreferenceChanged(PREF_SONY_NOISE_OPTIMIZER_CANCEL);
}
});
ancOptimizerProgressDialog.show();
}
}).setNegativeButton(android.R.string.cancel, null).show();
return true;
}
});
}
}
Aggregations