use of com.afollestad.materialdialogs.DialogAction in project PhoneProfilesPlus by henrichg.
the class NFCTagPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
value = getPersistedString(value);
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_nfc_tag_pref_dialog, false).dividerColor(0).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
if (shouldPersist()) {
if (callChangeListener(value)) {
persistString(value);
}
}
mDialog.dismiss();
}
}).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
mDialog.dismiss();
}
});
mDialog = mBuilder.build();
View layout = mDialog.getCustomView();
// progressLinearLayout = layout.findViewById(R.id.nfc_tag_pref_dlg_linla_progress);
// dataRelativeLayout = layout.findViewById(R.id.nfc_tag_pref_dlg_rella_data);
// noinspection ConstantConditions
addIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_addIcon);
addIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String tag = nfcTagName.getText().toString();
addNfcTag(tag);
DatabaseHandler.getInstance(context).addNFCTag(tag);
refreshListView(tag);
}
});
// noinspection ConstantConditions
nfcTagName = layout.findViewById(R.id.nfc_tag_pref_dlg_bt_name);
nfcTagName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
GlobalGUIRoutines.setImageButtonEnabled(!nfcTagName.getText().toString().isEmpty(), addIcon, R.drawable.ic_action_location_add, context.getApplicationContext());
}
});
GlobalGUIRoutines.setImageButtonEnabled(!nfcTagName.getText().toString().isEmpty(), addIcon, R.drawable.ic_action_location_add, context.getApplicationContext());
nfcTagListView = layout.findViewById(R.id.nfc_tag_pref_dlg_listview);
listAdapter = new NFCTagPreferenceAdapter(context, this);
nfcTagListView.setAdapter(listAdapter);
refreshListView("");
nfcTagListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// NFCTagPreferenceAdapter.ViewHolder viewHolder =
// (NFCTagPreferenceAdapter.ViewHolder) v.getTag();
String nfcTag = nfcTagList.get(position).name;
nfcTagName.setText(nfcTag);
}
});
/*
final TextView helpText = layout.findViewById(R.id.nfc_tag_pref_dlg_helpText);
final ImageView helpIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_helpIcon);
ApplicationPreferences.getSharedPreferences(context);
if (ApplicationPreferences.preferences.getBoolean(PREF_SHOW_HELP, true)) {
helpIcon.setImageResource(R.drawable.ic_action_profileicon_help_closed);
helpText.setVisibility(View.VISIBLE);
}
else {
helpIcon.setImageResource(R.drawable.ic_action_profileicon_help);
helpText.setVisibility(View.GONE);
}
helpIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ApplicationPreferences.getSharedPreferences(context);
SharedPreferences.Editor editor = ApplicationPreferences.preferences.edit();
int visibility = helpText.getVisibility();
if (visibility == View.VISIBLE) {
helpIcon.setImageResource(R.drawable.ic_action_profileicon_help);
visibility = View.GONE;
editor.putBoolean(PREF_SHOW_HELP, false);
}
else {
helpIcon.setImageResource(R.drawable.ic_action_profileicon_help_closed);
visibility = View.VISIBLE;
editor.putBoolean(PREF_SHOW_HELP, true);
}
helpText.setVisibility(visibility);
editor.apply();
}
});
*/
final ImageView helpIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_helpIcon);
helpIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogHelpPopupWindow.showPopup(helpIcon, context, R.string.nfc_tag_pref_dlg_help);
}
});
ImageView changeSelectionIcon = layout.findViewById(R.id.nfc_tag_pref_dlg_changeSelection);
changeSelectionIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSelectorDialog = new MaterialDialog.Builder(context).title(R.string.pref_dlg_change_selection_title).items(R.array.nfcTagsChangeSelectionArray).itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
switch(which) {
case 0:
value = "";
break;
case 1:
for (NFCTagData nfcTag : nfcTagList) {
if (nfcTag.name.equals(nfcTagName.getText().toString()))
addNfcTag(nfcTag.name);
}
break;
default:
}
refreshListView("");
return true;
}
}).positiveText(R.string.pref_dlg_change_selection_button).negativeText(getNegativeButtonText()).show();
}
});
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of com.afollestad.materialdialogs.DialogAction in project PhoneProfilesPlus by henrichg.
the class BluetoothNamePreference method showDialog.
@Override
protected void showDialog(Bundle state) {
value = getPersistedString(value);
PPApplication.forceRegisterReceiversForBluetoothScanner(context);
forceRegister = true;
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_bluetooth_name_pref_dialog, false).dividerColor(0).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
if (shouldPersist()) {
if (callChangeListener(value)) {
persistString(value);
}
}
mDialog.dismiss();
}
}).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
mDialog.dismiss();
}
});
mDialog = mBuilder.build();
View layout = mDialog.getCustomView();
// noinspection ConstantConditions
progressLinearLayout = layout.findViewById(R.id.bluetooth_name_pref_dlg_linla_progress);
// noinspection ConstantConditions
dataRelativeLayout = layout.findViewById(R.id.bluetooth_name_pref_dlg_rella_data);
addIcon = layout.findViewById(R.id.bluetooth_name_pref_dlg_addIcon);
addIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String btName = bluetoothName.getText().toString();
addBluetoothName(btName);
boolean found = false;
for (BluetoothDeviceData customBtNameData : customBluetoothList) {
if (customBtNameData.getName().equalsIgnoreCase(btName)) {
found = true;
break;
}
}
if (!found) {
// if (android.os.Build.VERSION.SDK_INT >= 18)
customBluetoothList.add(new BluetoothDeviceData(btName, "", BluetoothDevice.DEVICE_TYPE_DUAL, true, 0));
// else
// customBluetoothList.add(new BluetoothDeviceData(btName, "", 0, true, 0));
}
refreshListView(false, btName);
}
});
bluetoothName = layout.findViewById(R.id.bluetooth_name_pref_dlg_bt_name);
bluetoothName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
GlobalGUIRoutines.setImageButtonEnabled(!bluetoothName.getText().toString().isEmpty(), addIcon, R.drawable.ic_action_location_add, context.getApplicationContext());
}
});
GlobalGUIRoutines.setImageButtonEnabled(!bluetoothName.getText().toString().isEmpty(), addIcon, R.drawable.ic_action_location_add, context.getApplicationContext());
bluetoothListView = layout.findViewById(R.id.bluetooth_name_pref_dlg_listview);
listAdapter = new BluetoothNamePreferenceAdapter(context, this);
bluetoothListView.setAdapter(listAdapter);
refreshListView(false, "");
bluetoothListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// BluetoothNamePreferenceAdapter.ViewHolder viewHolder =
// (BluetoothNamePreferenceAdapter.ViewHolder) v.getTag();
String btName = bluetoothList.get(position).getName();
if (!(btName.equals(EventPreferencesBluetooth.ALL_BLUETOOTH_NAMES_VALUE) || btName.equals(EventPreferencesBluetooth.CONFIGURED_BLUETOOTH_NAMES_VALUE))) {
bluetoothName.setText(btName);
}
/*
viewHolder.checkBox.setChecked(!viewHolder.checkBox.isChecked());
if (viewHolder.checkBox.isChecked()) {
addBluetoothName(bluetoothList.get(position).getName());
}
else {
removeBluetoothName(bluetoothList.get(position).getName());
}
*/
}
});
final ImageView helpIcon = layout.findViewById(R.id.bluetooth_name_pref_dlg_helpIcon);
helpIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String helpString = context.getString(R.string.event_preference_bluetooth_bt_types) + "\n\n" + context.getString(R.string.pref_dlg_info_about_wildcards_1) + " " + context.getString(R.string.pref_dlg_info_about_wildcards_2) + " " + context.getString(R.string.bluetooth_name_pref_dlg_info_about_wildcards) + " " + context.getString(R.string.pref_dlg_info_about_wildcards_3);
DialogHelpPopupWindow.showPopup(helpIcon, context, helpString);
}
});
ImageView changeSelectionIcon = layout.findViewById(R.id.bluetooth_name_pref_dlg_changeSelection);
changeSelectionIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSelectorDialog = new MaterialDialog.Builder(context).title(R.string.pref_dlg_change_selection_title).items(R.array.bluetoothNameDChangeSelectionArray).itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
switch(which) {
case 0:
value = "";
break;
case 1:
for (BluetoothDeviceData bluetooth : bluetoothList) {
if (bluetooth.name.equals(bluetoothName.getText().toString()))
addBluetoothName(bluetooth.name);
}
break;
default:
}
refreshListView(false, "");
return true;
}
}).positiveText(R.string.pref_dlg_change_selection_button).negativeText(getNegativeButtonText()).show();
}
});
final Button rescanButton = layout.findViewById(R.id.bluetooth_name_pref_dlg_rescanButton);
rescanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Permissions.grantBluetoothScanDialogPermissions(context, BluetoothNamePreference.this))
refreshListView(true, "");
}
});
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of com.afollestad.materialdialogs.DialogAction in project PhoneProfilesPlus by henrichg.
the class BrightnessDialogPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).content(getDialogMessage()).customView(R.layout.activity_brightness_pref_dialog, true).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
if (shouldPersist()) {
persistString(Integer.toString(value + minimumValue) + "|" + Integer.toString(noChange) + "|" + Integer.toString(automatic) + "|" + Integer.toString(defaultProfile));
setSummaryBDP();
}
}
});
mBuilder.showListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
BrightnessDialogPreference.this.onShow();
}
});
mDialog = mBuilder.build();
View layout = mDialog.getCustomView();
// noinspection ConstantConditions
seekBar = layout.findViewById(R.id.brightnessPrefDialogSeekbar);
// noinspection ConstantConditions
valueText = layout.findViewById(R.id.brightnessPrefDialogValueText);
// noinspection ConstantConditions
noChangeChBox = layout.findViewById(R.id.brightnessPrefDialogNoChange);
// noinspection ConstantConditions
automaticChBox = layout.findViewById(R.id.brightnessPrefDialogAutomatic);
// noinspection ConstantConditions
defaultProfileChBox = layout.findViewById(R.id.brightnessPrefDialogDefaultProfile);
if (android.os.Build.VERSION.SDK_INT >= 21) {
// for Android 5.0: adaptive brightness
String text = _context.getString(R.string.preference_profile_adaptiveBrightness);
automaticChBox.setText(text);
}
if (adaptiveAllowed) {
layout.findViewById(R.id.brightnessPrefDialogAdaptiveLevelRoot).setVisibility(View.GONE);
}
seekBar.setOnSeekBarChangeListener(this);
seekBar.setKeyProgressIncrement(stepSize);
seekBar.setMax(maximumValue - minimumValue);
getValueBDP();
seekBar.setProgress(value);
noChangeChBox.setOnCheckedChangeListener(this);
noChangeChBox.setChecked((noChange == 1));
automaticChBox.setOnCheckedChangeListener(this);
automaticChBox.setChecked(automatic == 1);
defaultProfileChBox.setOnCheckedChangeListener(this);
defaultProfileChBox.setChecked((defaultProfile == 1));
defaultProfileChBox.setEnabled(disableDefaultProfile == 0);
if (noChange == 1)
defaultProfileChBox.setChecked(false);
if (defaultProfile == 1)
noChangeChBox.setChecked(false);
enableViews();
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.show();
}
use of com.afollestad.materialdialogs.DialogAction in project PhoneProfilesPlus by henrichg.
the class ApplicationsMultiSelectDialogPreference method showDialog.
protected void showDialog(Bundle state) {
PPApplication.logE("ApplicationsMultiSelectDialogPreference.showDialog", "xxx");
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).autoDismiss(false).onPositive(new MaterialDialog.SingleButtonCallback() {
@SuppressWarnings("StringConcatenationInLoop")
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
if (shouldPersist()) {
// fill with contact strings separated with |
value = "";
if (applicationList != null) {
for (Application application : applicationList) {
if (application.checked) {
if (!value.isEmpty())
value = value + "|";
if (application.shortcut)
value = value + "(s)";
value = value + application.packageName + "/" + application.activityName;
}
}
}
persistString(value);
setIcons();
setSummaryAMSDP();
mDialog.dismiss();
}
}
}).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
mDialog.dismiss();
}
}).content(getDialogMessage()).customView(R.layout.activity_applications_multiselect_pref_dialog, false).dividerColor(0);
mBuilder.showListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
ApplicationsMultiSelectDialogPreference.this.onShow();
}
});
mDialog = mBuilder.build();
View layout = mDialog.getCustomView();
// noinspection ConstantConditions
linlaProgress = layout.findViewById(R.id.applications_multiselect_pref_dlg_linla_progress);
// noinspection ConstantConditions
rellaData = layout.findViewById(R.id.applications_multiselect_pref_dlg_rella_data);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
// noinspection ConstantConditions
FastScrollRecyclerView listView = layout.findViewById(R.id.applications_multiselect_pref_dlg_listview);
listView.setLayoutManager(layoutManager);
listView.setHasFixedSize(true);
listAdapter = new ApplicationsMultiSelectPreferenceAdapter(_context, this, addShortcuts);
listView.setAdapter(listAdapter);
/*
// added touch helper for drag and drop items
ItemTouchHelper.Callback callback = new ItemTouchHelperCallback(listAdapter, false, false);
itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(listView);
*/
final Button unselectAllButton = layout.findViewById(R.id.applications_multiselect_pref_dlg_unselect_all);
unselectAllButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
value = "";
refreshListView(false);
}
});
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of com.afollestad.materialdialogs.DialogAction in project PhoneProfilesPlus by henrichg.
the class ConnectToSSIDDialogPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
getValueCTSDP();
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_connect_to_ssid_pref_dialog, false);
mBuilder.positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText());
mBuilder.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
if (callChangeListener(value)) {
persistString(value);
setSummaryCTSDP();
}
mDialog.dismiss();
}
});
mBuilder.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
mDialog.dismiss();
}
});
mBuilder.showListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
ConnectToSSIDDialogPreference.this.onShow();
}
});
mDialog = mBuilder.build();
View layout = mDialog.getCustomView();
// noinspection ConstantConditions
listView = layout.findViewById(R.id.connect_to_ssid_pref_dlg_listview);
// noinspection ConstantConditions
linlaProgress = layout.findViewById(R.id.connect_to_ssid_pref_dlg_linla_progress);
listAdapter = new ConnectToSSIDPreferenceAdapter(context, this);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
value = ssidList.get(position).ssid;
listAdapter.notifyDataSetChanged();
}
});
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
Aggregations