/** Called through sendMessage with id MSG_BROWSER_SAVEDIALOG_SHOW */ public AlertDialog saveDialog(final Context context, Object obj) { final ResourceBuilder resourceBuilder = (ResourceBuilder) obj; LayoutInflater factory = LayoutInflater.from(context); final View root = factory.inflate(R.layout.savefiledialog, null); TextView title = (TextView) root.findViewById(R.id.savefile_title); title.setText(resourceBuilder.getTitle(mVizWebView)); final EditText editor = (EditText) root.findViewById(R.id.savefile_filename); final AlertDialog dialog = new AlertDialog.Builder(context) .setIcon(R.drawable.ic_launcher) .setTitle(VizApp.getResString(R.string.savedialog_ok)) .setView(root) .setPositiveButton( R.string.savedialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String userFilename = editor.getText().toString(); if (!errorCheckPathAndFile(userFilename)) { sendMessage( ActivityDelegate.MSG_BROWSER, ActivityDelegate.MSG_BROWSER_SAVEDIALOG_SHOW, resourceBuilder); return; } Log.d("User downloading to: " + userFilename); resourceBuilder.setFilename(userFilename); startDownload(resourceBuilder.build()); } }) .setNegativeButton( R.string.savedialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Log.d("User canceled download"); mConfirmationInProgress = false; } }) .create(); editor.setText(resourceBuilder.getDefaultFilename(mVizWebView)); editor.setSingleLine(); editor.setOnEditorActionListener( new TextView.OnEditorActionListener() { // an enter on the keyboard triggers the download. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { String userFilename = null; if (editor.getText() != null) { userFilename = editor.getText().toString(); } if (!errorCheckPathAndFile(userFilename)) { sendMessage( ActivityDelegate.MSG_BROWSER, ActivityDelegate.MSG_BROWSER_SAVEDIALOG_SHOW, resourceBuilder); return true; } resourceBuilder.setFilename(userFilename); Log.d("User downloading to: " + userFilename); startDownload(resourceBuilder.build()); dialog.dismiss(); return true; } }); return dialog; }