use of android.support.v7.app.AppCompatDialog in project Rashr by DsLNeXuS.
the class BackupRestoreFragment method showPopup.
public void showPopup(final View v) {
PopupMenu popup = new PopupMenu(mActivity, v);
popup.getMenuInflater().inflate(R.menu.bakmgr_menu, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(final MenuItem menuItem) {
final CharSequence text = ((AppCompatTextView) v).getText();
final String FileName = text.toString();
final AppCompatDialog dialog = new AppCompatDialog(mActivity);
dialog.setTitle(R.string.setname);
dialog.setContentView(R.layout.dialog_input);
final AppCompatButton bGo = (AppCompatButton) dialog.findViewById(R.id.bGoBackup);
final AppCompatEditText etFileName = (AppCompatEditText) dialog.findViewById(R.id.etFileName);
if (bGo == null || etFileName == null)
return false;
//If current item is 0 (first item) a recovery backup will be edited or created
final File path = mPager.getCurrentItem() == 0 ? Const.PathToRecoveryBackups : Const.PathToKernelBackups;
try {
switch(menuItem.getItemId()) {
case R.id.iRestore:
File backup = new File(path, FileName);
FlashUtil RestoreUtil = new FlashUtil(mActivity, backup, mPager.getCurrentItem() == 0 ? FlashUtil.JOB_RESTORE_RECOVERY : FlashUtil.JOB_RESTORE_KERNEL);
RestoreUtil.execute();
return true;
case R.id.iRename:
etFileName.setHint(FileName);
bGo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String Name;
if (etFileName.getText() != null && etFileName.isEnabled() && !etFileName.getText().toString().equals("")) {
//User has defined a name for the backup. Use it.
Name = etFileName.getText().toString();
} else {
//Use hint as backup name. Normally the correct version
//and Recovery System (if Rashr could read it out of
//"/cache/recovery/last_log"
Name = String.valueOf(etFileName.getHint());
}
if (!Name.endsWith(RashrApp.DEVICE.getRecoveryExt())) {
//Append extension
Name += RashrApp.DEVICE.getRecoveryExt();
}
File renamedBackup = new File(path, Name);
if (renamedBackup.exists()) {
Toast.makeText(mActivity, R.string.backupalready, Toast.LENGTH_SHORT).show();
// if backup already exists, let the user chose a new name
onMenuItemClick(menuItem);
} else {
File Backup = new File(path, FileName);
if (Backup.renameTo(renamedBackup)) {
mAdapter.reload();
} else {
Toast.makeText(mActivity, R.string.rename_failed, Toast.LENGTH_SHORT).show();
}
}
dialog.dismiss();
}
});
dialog.show();
return true;
case R.id.iDeleteBackup:
backup = new File(path, text.toString());
if (backup.delete()) {
Toast.makeText(mActivity, mContext.getString(R.string.bak_deleted), Toast.LENGTH_SHORT).show();
}
mAdapter.reload();
return true;
default:
return false;
}
} catch (Exception e) {
if (e.getMessage().contains("EINVAL") && text.toString().contains(":")) {
AlertDialog.Builder adialog = new AlertDialog.Builder(mContext);
adialog.setMessage(R.string.check_name);
adialog.setMessage(R.string.ok);
adialog.show();
}
RashrApp.ERRORS.add(Const.RASHR_TAG + " " + e);
return false;
}
}
});
popup.show();
}
Aggregations