use of com.afollestad.materialdialogs.MaterialDialog in project Phonograph by kabouzeid.
the class BlacklistFolderChooserDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
return new MaterialDialog.Builder(getActivity()).title(R.string.md_error_label).content(R.string.md_storage_perm_error).positiveText(android.R.string.ok).build();
}
if (savedInstanceState == null) {
savedInstanceState = new Bundle();
}
if (!savedInstanceState.containsKey("current_path")) {
savedInstanceState.putString("current_path", initialPath);
}
parentFolder = new File(savedInstanceState.getString("current_path", File.pathSeparator));
checkIfCanGoUp();
parentContents = listFiles();
MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(parentFolder.getAbsolutePath()).items((CharSequence[]) getContentsArray()).itemsCallback(this).autoDismiss(false).onPositive((dialog, which) -> {
dismiss();
callback.onFolderSelection(BlacklistFolderChooserDialog.this, parentFolder);
}).onNegative((materialDialog, dialogAction) -> dismiss()).positiveText(R.string.add_action).negativeText(android.R.string.cancel);
if (File.pathSeparator.equals(initialPath)) {
canGoUp = false;
}
return builder.build();
}
use of com.afollestad.materialdialogs.MaterialDialog in project Phonograph by kabouzeid.
the class BlacklistFolderChooserDialog method reload.
private void reload() {
parentContents = listFiles();
MaterialDialog dialog = (MaterialDialog) getDialog();
dialog.setTitle(parentFolder.getAbsolutePath());
dialog.setItems((CharSequence[]) getContentsArray());
}
use of com.afollestad.materialdialogs.MaterialDialog in project PhoneProfilesPlus by henrichg.
the class DurationDialogPreference method showDialog.
@SuppressLint("SetTextI18n")
@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_duration_pref_dialog, true).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
int hours = mSeekBarHours.getProgress();
int minutes = mSeekBarMinutes.getProgress();
int seconds = mSeekBarSeconds.getProgress();
int iValue = (hours * 3600 + minutes * 60 + seconds);
if (iValue < mMin)
iValue = mMin;
if (iValue > mMax)
iValue = mMax;
value = String.valueOf(iValue);
if (callChangeListener(value)) {
// persistInt(mNumberPicker.getValue());
persistString(value);
setSummaryDDP();
}
}
});
mDialog = mBuilder.build();
View layout = mDialog.getCustomView();
// noinspection ConstantConditions
TextView mTextViewRange = layout.findViewById(R.id.duration_pref_dlg_range);
mValue = layout.findViewById(R.id.duration_pref_dlg_value);
mSeekBarHours = layout.findViewById(R.id.duration_pref_dlg_hours);
mSeekBarMinutes = layout.findViewById(R.id.duration_pref_dlg_minutes);
mSeekBarSeconds = layout.findViewById(R.id.duration_pref_dlg_seconds);
// mSeekBarHours.setRotation(180);
// mSeekBarMinutes.setRotation(180);
// mSeekBarSeconds.setRotation(180);
// Initialize state
int hours;
int minutes;
int seconds;
hours = mMax / 3600;
minutes = (mMax % 3600) / 60;
seconds = mMax % 60;
final String sMax = GlobalGUIRoutines.getDurationString(mMax);
mSeekBarHours.setMax(hours);
if (hours == 0)
mSeekBarMinutes.setMax(minutes);
else
mSeekBarMinutes.setMax(59);
if ((hours == 0) && (minutes == 0))
mSeekBarSeconds.setMax(seconds);
else
mSeekBarSeconds.setMax(59);
final String sMin = GlobalGUIRoutines.getDurationString(mMin);
int iValue = Integer.valueOf(value);
hours = iValue / 3600;
minutes = (iValue % 3600) / 60;
seconds = iValue % 60;
mSeekBarHours.setProgress(hours);
mSeekBarMinutes.setProgress(minutes);
mSeekBarSeconds.setProgress(seconds);
mValue.setText(GlobalGUIRoutines.getDurationString(iValue));
mValueDialog = new TimeDurationPickerDialog(context, new TimeDurationPickerDialog.OnDurationSetListener() {
@Override
public void onDurationSet(TimeDurationPicker view, long duration) {
int iValue = (int) duration / 1000;
if (iValue < mMin)
iValue = mMin;
if (iValue > mMax)
iValue = mMax;
mValue.setText(GlobalGUIRoutines.getDurationString(iValue));
int hours = iValue / 3600;
int minutes = (iValue % 3600) / 60;
int seconds = iValue % 60;
mSeekBarHours.setProgress(hours);
mSeekBarMinutes.setProgress(minutes);
mSeekBarSeconds.setProgress(seconds);
}
}, iValue * 1000, TimeDurationPicker.HH_MM_SS);
mValue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int hours = mSeekBarHours.getProgress();
int minutes = mSeekBarMinutes.getProgress();
int seconds = mSeekBarSeconds.getProgress();
int iValue = (hours * 3600 + minutes * 60 + seconds);
if (iValue < mMin)
iValue = mMin;
if (iValue > mMax)
iValue = mMax;
mValueDialog.setDuration(iValue * 1000);
mValueDialog.show();
}
});
mSeekBarHours.setOnSeekBarChangeListener(this);
mSeekBarMinutes.setOnSeekBarChangeListener(this);
mSeekBarSeconds.setOnSeekBarChangeListener(this);
mTextViewRange.setText(sMin + " - " + sMax);
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of com.afollestad.materialdialogs.MaterialDialog in project PhoneProfilesPlus by henrichg.
the class LocationGeofencePreference method showDialog.
@Override
protected void showDialog(Bundle state) {
if (onlyEdit == 0) {
String value = "";
value = getPersistedString(value);
DatabaseHandler.getInstance(context.getApplicationContext()).checkGeofence(value, 1);
}
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_location_pref_dialog, false).dividerColor(0);
if (onlyEdit == 0) {
mBuilder.positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText());
mBuilder.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
persistGeofence(false);
mDialog.dismiss();
}
});
mBuilder.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
mDialog.dismiss();
}
});
} else {
mBuilder.positiveText(getPositiveButtonText());
mBuilder.onPositive(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.location_pref_dlg_linla_progress);
// dataRelativeLayout = layout.findViewById(R.id.location_pref_dlg_rella_data);
// geofenceName = layout.findViewById(R.id.location_pref_dlg_geofence_name);
// updateGUIWithGeofence(dataWrapper.getDatabaseHandler().getCheckedGeofences());
// noinspection ConstantConditions
AppCompatImageButton addButton = layout.findViewById(R.id.location_pref_dlg_add);
// noinspection ConstantConditions
ListView geofencesListView = layout.findViewById(R.id.location_pref_dlg_listview);
listAdapter = new LocationGeofencesPreferenceAdapter(context, DatabaseHandler.getInstance(context.getApplicationContext()).getGeofencesCursor(), this);
geofencesListView.setAdapter(listAdapter);
refreshListView();
geofencesListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
LocationGeofencesPreferenceAdapter.ViewHolder viewHolder = (LocationGeofencesPreferenceAdapter.ViewHolder) v.getTag();
/*
if (listAdapter.selectedRB != null){
long gid = (long)listAdapter.selectedRB.getTag();
Log.d("LocationGeofencePreference.onItemClick", "checked id="+gid);
listAdapter.selectedRB.setChecked(false);
}
*/
// listAdapter.selectedRB = viewHolder.radioButton;
long gid = viewHolder.geofenceId;
if (onlyEdit == 0) {
DatabaseHandler.getInstance(context.getApplicationContext()).checkGeofence(String.valueOf(gid), 2);
// viewHolder.radioButton.setChecked(true);
// updateGUIWithGeofence(gid);
refreshListView();
} else {
startEditor(gid);
}
}
});
/*
final TextView helpText = layout.findViewById(R.id.wifi_ssid_pref_dlg_helpText);
String helpString = context.getString(R.string.pref_dlg_info_about_wildcards_1) + " " +
context.getString(R.string.pref_dlg_info_about_wildcards_2) + " " +
context.getString(R.string.wifi_ssid_pref_dlg_info_about_wildcards) + " " +
context.getString(R.string.pref_dlg_info_about_wildcards_3);
helpText.setText(helpString);
ImageView helpIcon = layout.findViewById(R.id.wifi_ssid_pref_dlg_helpIcon);
helpIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int visibility = helpText.getVisibility();
if (visibility == View.VISIBLE)
visibility = View.GONE;
else
visibility = View.VISIBLE;
helpText.setVisibility(visibility);
}
});
*/
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startEditor(0);
}
});
final Button unselectAllButton = layout.findViewById(R.id.location_pref_dlg_uselectAll);
unselectAllButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatabaseHandler.getInstance(context.getApplicationContext()).checkGeofence("", 0);
refreshListView();
}
});
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of com.afollestad.materialdialogs.MaterialDialog in project PhoneProfilesPlus by henrichg.
the class MobileCellsPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
// persistedValue = getPersistedString("");
// value = persistedValue;
value = getPersistedString("");
// IntentFilter intentFilter = new IntentFilter();
// intentFilter.addAction(PhoneStateScanner.ACTION_PHONE_STATE_CHANGED);
phoneStateChangedBroadcastReceiver = new PhoneStateChangedBroadcastReceiver(this);
// context.registerReceiver(EventPreferencesNestedFragment.phoneStateChangedBroadcastReceiver, intentFilter);
LocalBroadcastManager.getInstance(context).registerReceiver(phoneStateChangedBroadcastReceiver, new IntentFilter("PhoneStateChangedBroadcastReceiver_preference"));
PPApplication.forceStartPhoneStateScanner(context);
forceStart = true;
/*
DatabaseHandler db = DatabaseHandler.getInstance(context);
db.deleteMobileCell(2826251);
db.deleteMobileCell(2843189);
db.deleteMobileCell(2877237);
db.deleteMobileCell(2649653);
db.deleteMobileCell(2649613);
*/
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_mobile_cells_pref_dialog, false).dividerColor(0).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
if (shouldPersist()) {
// Log.d("MobileCellsPreference.onPositive", "1");
if (callChangeListener(value)) {
// Log.d("MobileCellsPreference.onPositive", "2");
DatabaseHandler db = DatabaseHandler.getInstance(context);
db.saveMobileCellsList(cellsList, false, false);
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.mobile_cells_pref_dlg_linla_progress);
// dataRelativeLayout = layout.findViewById(R.id.mobile_cells_pref_dlg_rella_data);
// noinspection ConstantConditions
cellFilter = layout.findViewById(R.id.mobile_cells_pref_dlg_cells_filter_name);
if (value.isEmpty())
cellFilter.setText(R.string.mobile_cell_names_dialog_item_show_all);
else
cellFilter.setText(R.string.mobile_cell_names_dialog_item_show_selected);
cellFilter.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) {
refreshListView(false);
}
});
cellName = layout.findViewById(R.id.mobile_cells_pref_dlg_cells_name);
ListView cellsListView = layout.findViewById(R.id.mobile_cells_pref_dlg_listview);
listAdapter = new MobileCellsPreferenceAdapter(context, this);
cellsListView.setAdapter(listAdapter);
refreshListView(false);
/*
cellsListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
cellName.setText(cellsList.get(position).name);
}
});
*/
mMobileCellsFilterDialog = new MobileCellNamesDialog(context, this, true);
cellFilter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mMobileCellsFilterDialog.show();
}
});
mMobileCellNamesDialog = new MobileCellNamesDialog(context, this, false);
cellName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mMobileCellNamesDialog.show();
}
});
final ImageView editIcon = layout.findViewById(R.id.mobile_cells_pref_dlg_rename);
editIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mRenameDialog = new MaterialDialog.Builder(context).title(R.string.mobile_cells_pref_dlg_cell_rename_title).items(R.array.mobileCellsRenameArray).itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
final DatabaseHandler db = DatabaseHandler.getInstance(context);
switch(which) {
case 0:
case 1:
db.renameMobileCellsList(filteredCellsList, cellName.getText().toString(), which == 0, value);
break;
case 2:
db.renameMobileCellsList(filteredCellsList, cellName.getText().toString(), false, value);
break;
}
refreshListView(false);
return true;
}
}).positiveText(R.string.mobile_cells_pref_dlg_cell_rename_button).negativeText(getNegativeButtonText()).show();
}
});
ImageView changeSelectionIcon = layout.findViewById(R.id.mobile_cells_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.mobileCellsChangeSelectionArray).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 (MobileCellsData cell : filteredCellsList) {
if (cell.name.equals(cellName.getText().toString()))
addCellId(cell.cellId);
}
break;
case 2:
value = "";
for (MobileCellsData cell : filteredCellsList) {
addCellId(cell.cellId);
}
break;
default:
}
refreshListView(false);
return true;
}
}).positiveText(R.string.pref_dlg_change_selection_button).negativeText(getNegativeButtonText()).show();
}
});
final ImageView helpIcon = layout.findViewById(R.id.mobile_cells_pref_dlg_helpIcon);
helpIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogHelpPopupWindow.showPopup(helpIcon, context, R.string.mobile_cells_pref_dlg_help);
}
});
final Button rescanButton = layout.findViewById(R.id.mobile_cells_pref_dlg_rescanButton);
rescanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Permissions.grantMobileCellsDialogPermissions(context, MobileCellsPreference.this))
refreshListView(true);
}
});
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
Aggregations