List of usage examples for android.app AlertDialog dismiss
@Override public void dismiss()
From source file:org.opendatakit.survey.android.activities.MainMenuActivity.java
protected void createPasswordDialog() { if (mAlertDialog != null) { mAlertDialog.dismiss();// ww w .ja v a2 s. c om mAlertDialog = null; } final AlertDialog passwordDialog = new AlertDialog.Builder(this).create(); passwordDialog.setTitle(getString(R.string.enter_admin_password)); final EditText input = new EditText(this); input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); input.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordDialog.setView(input, 20, 10, 20, 10); passwordDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); String pw = PropertiesSingleton.getProperty(appName, AdminPreferencesActivity.KEY_ADMIN_PW); if (pw != null && pw.compareTo(value) == 0) { Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class); // TODO: convert this activity into a preferences fragment i.putExtra(APP_NAME, getAppName()); startActivity(i); input.setText(""); passwordDialog.dismiss(); } else { Toast.makeText(MainMenuActivity.this, getString(R.string.admin_password_incorrect), Toast.LENGTH_SHORT).show(); } } }); passwordDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { input.setText(""); return; } }); passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); mAlertDialog = passwordDialog; mAlertDialog.show(); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Creates a application informative dialog with options to * uninstall/launch or cancel./*from w w w. j av a 2s . c o m*/ * * @param context * @param appPackage */ public static void appInfo_getLaunchUninstallDialog(final Context context, String appPackage) { try { final PackageManager packageManager = context.getPackageManager(); final PackageInfo app = packageManager.getPackageInfo(appPackage, PackageManager.GET_META_DATA); AlertDialog dialog = new AlertDialog.Builder(context).create(); dialog.setTitle(app.applicationInfo.loadLabel(packageManager)); String description = null; if (app.applicationInfo.loadDescription(packageManager) != null) { description = app.applicationInfo.loadDescription(packageManager).toString(); } String msg = app.applicationInfo.loadLabel(packageManager) + "\n\n" + "Version " + app.versionName + " (" + app.versionCode + ")" + "\n" + (description != null ? (description + "\n") : "") + app.applicationInfo.sourceDir + "\n" + appInfo_getSize(app.applicationInfo.sourceDir); dialog.setMessage(msg); dialog.setCancelable(true); dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Uninstall", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(Intent.ACTION_DELETE); intent.setData(Uri.parse("package:" + app.packageName)); context.startActivity(intent); } }); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Launch", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i = packageManager.getLaunchIntentForPackage(app.packageName); context.startActivity(i); } }); dialog.show(); } catch (Exception e) { if (LOG_ENABLE) { Log.e(TAG, "Dialog could not be made for the specified application '" + appPackage + "'. [" + e.getMessage() + "].", e); } } }
From source file:io.jari.geenstijl.Dialogs.LoginDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout final View view = inflater.inflate(R.layout.dialog_login, null); builder.setView(view)//from www . ja va 2 s .co m // Add action buttons .setPositiveButton(R.string.signin, null) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { LoginDialog.this.getDialog().cancel(); } }).setTitle(R.string.signin); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { //i wrote this code with a certain amount of alcohol in my blood, so i can't vouch for it's readability final View error = view.findViewById(R.id.error); final Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); final Button negative = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE); positive.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { positive.setEnabled(false); negative.setEnabled(false); final TextView username = (TextView) view.findViewById(R.id.username); final TextView password = (TextView) view.findViewById(R.id.password); final View loading = view.findViewById(R.id.loading); username.setVisibility(View.GONE); password.setVisibility(View.GONE); loading.setVisibility(View.VISIBLE); error.setVisibility(View.GONE); alertDialog.setCancelable(false); new Thread(new Runnable() { public void run() { boolean success; try { success = API.logIn(username.getText().toString(), password.getText().toString(), LoginDialog.this.getActivity()); } catch (Exception e) { e.printStackTrace(); success = false; } alertDialog.setCancelable(true); if (!success) activity.runOnUiThread(new Runnable() { public void run() { username.setVisibility(View.VISIBLE); password.setVisibility(View.VISIBLE); error.setVisibility(View.VISIBLE); positive.setEnabled(true); negative.setEnabled(true); loading.setVisibility(View.GONE); } }); else activity.runOnUiThread(new Runnable() { public void run() { alertDialog.dismiss(); forceOptionsReload(); Crouton.makeText(activity, getString(R.string.loggedin, API.getUsername(activity)), Style.CONFIRM).show(); } }); } }).start(); } }); } }); return alertDialog; }
From source file:info.zamojski.soft.towercollector.MainActivity.java
private void displayNewVersionDownloadOptions(Bundle extras) { UpdateInfo updateInfo = (UpdateInfo) extras.getSerializable(UpdateCheckAsyncTask.INTENT_KEY_UPDATE_INFO); // display dialog AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); LayoutInflater inflater = LayoutInflater.from(this); View dialogLayout = inflater.inflate(R.layout.new_version, null); dialogBuilder.setView(dialogLayout); final AlertDialog alertDialog = dialogBuilder.create(); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setCancelable(true);/*from w w w .j av a2s.c om*/ alertDialog.setTitle(R.string.updater_dialog_new_version_available); // load data ArrayAdapter<UpdateInfo.DownloadLink> adapter = new UpdateDialogArrayAdapter(alertDialog.getContext(), inflater, updateInfo.getDownloadLinks()); ListView listView = (ListView) dialogLayout.findViewById(R.id.download_options_list); listView.setAdapter(adapter); // bind events final CheckBox disableAutoUpdateCheckCheckbox = (CheckBox) dialogLayout .findViewById(R.id.download_options_disable_auto_update_check_checkbox); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { DownloadLink downloadLink = (DownloadLink) parent.getItemAtPosition(position); Log.d("displayNewVersionDownloadOptions(): Selected position: %s", downloadLink.getLabel()); boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked(); Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s", disableAutoUpdateCheckCheckboxChecked); if (disableAutoUpdateCheckCheckboxChecked) { MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false); } MyApplication.getAnalytics().sendUpdateAction(downloadLink.getLabel()); String link = downloadLink.getLink(); try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link))); } catch (ActivityNotFoundException ex) { Toast.makeText(getApplication(), R.string.web_browser_missing, Toast.LENGTH_LONG).show(); } alertDialog.dismiss(); } }); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked(); Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s", disableAutoUpdateCheckCheckboxChecked); if (disableAutoUpdateCheckCheckboxChecked) { MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false); } } }); alertDialog.show(); }
From source file:it.iziozi.iziozi.gui.IOBoardActivity.java
public void tapOnSpeakableButton(final IOSpeakableImageButton spkBtn, final Integer level) { if (IOGlobalConfiguration.isEditing) { AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = getLayoutInflater(); View layoutView = inflater.inflate(R.layout.editmode_alertview, null); builder.setTitle(getString(R.string.choose)); builder.setView(layoutView);/*from w w w.j a v a 2 s. c om*/ final AlertDialog dialog = builder.create(); final Switch matrioskaSwitch = (Switch) layoutView.findViewById(R.id.editModeAlertToggleBoard); Button editPictoButton = (Button) layoutView.findViewById(R.id.editModeAlertActionPicture); final Button editBoardButton = (Button) layoutView.findViewById(R.id.editModeAlertActionBoard); matrioskaSwitch.setChecked(spkBtn.getIsMatrioska()); editBoardButton.setEnabled(spkBtn.getIsMatrioska()); matrioskaSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { spkBtn.setIsMatrioska(isChecked); editBoardButton.setEnabled(isChecked); } }); editPictoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //spkBtn.showInsertDialog(); Intent cIntent = new Intent(getApplicationContext(), IOCreateButtonActivity.class); cIntent.putExtra(BUTTON_INDEX, mActualLevel.getBoardAtIndex(mActualIndex).getButtons().indexOf(spkBtn)); cIntent.putExtra(BUTTON_TEXT, spkBtn.getSentence()); cIntent.putExtra(BUTTON_TITLE, spkBtn.getmTitle()); cIntent.putExtra(BUTTON_IMAGE_FILE, spkBtn.getmImageFile()); cIntent.putExtra(BUTTON_AUDIO_FILE, spkBtn.getAudioFile()); startActivityForResult(cIntent, CREATE_BUTTON_CODE); matrioskaSwitch.setOnCheckedChangeListener(null); dialog.dismiss(); } }); editBoardButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IOLevel nestedBoard = spkBtn.getLevel(); pushLevel(nestedBoard); matrioskaSwitch.setOnCheckedChangeListener(null); dialog.dismiss(); } }); dialog.show(); } else { if (IOGlobalConfiguration.isScanMode) { IOSpeakableImageButton scannedButton = mActualLevel.getBoardAtIndex(mActualIndex).getButtons() .get(mActualScanIndex); if (scannedButton.getAudioFile() != null && scannedButton.getAudioFile().length() > 0) { final MediaPlayer mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(scannedButton.getAudioFile()); mPlayer.prepare(); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mPlayer.release(); } }); mPlayer.start(); } catch (IOException e) { Log.e("playback_debug", "prepare() failed"); } } else if (mCanSpeak) { Log.d("speakable_debug", "should say: " + scannedButton.getSentence()); if (scannedButton.getSentence() == "") tts.speak(getResources().getString(R.string.tts_nosentence), TextToSpeech.QUEUE_FLUSH, null); else tts.speak(scannedButton.getSentence(), TextToSpeech.QUEUE_FLUSH, null); } else { Toast.makeText(this, getResources().getString(R.string.tts_notinitialized), Toast.LENGTH_LONG) .show(); } if (scannedButton.getIsMatrioska() && null != scannedButton.getLevel()) { pushLevel(scannedButton.getLevel()); } } else { if (spkBtn.getAudioFile() != null && spkBtn.getAudioFile().length() > 0) { final MediaPlayer mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(spkBtn.getAudioFile()); mPlayer.prepare(); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mPlayer.release(); } }); mPlayer.start(); } catch (IOException e) { Log.e("playback_debug", "prepare() failed"); } } else if (mCanSpeak) { Log.d("speakable_debug", "should say: " + spkBtn.getSentence()); if (spkBtn.getSentence() == "") tts.speak(getResources().getString(R.string.tts_nosentence), TextToSpeech.QUEUE_FLUSH, null); else tts.speak(spkBtn.getSentence(), TextToSpeech.QUEUE_FLUSH, null); } else { Toast.makeText(this, getResources().getString(R.string.tts_notinitialized), Toast.LENGTH_LONG) .show(); } if (spkBtn.getIsMatrioska() && null != spkBtn.getLevel()) { pushLevel(spkBtn.getLevel()); } } } }
From source file:com.nttec.everychan.ui.NewTabFragment.java
private void openChansList() { final ArrayAdapter<ChanModule> chansAdapter = new ArrayAdapter<ChanModule>(activity, 0) { private LayoutInflater inflater = LayoutInflater.from(activity); private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f); {//from ww w .j ava 2 s. co m for (ChanModule chan : MainApplication.getInstance().chanModulesList) add(chan); } @Override public View getView(int position, View convertView, ViewGroup parent) { ChanModule chan = getItem(position); TextView view = (TextView) (convertView == null ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false) : convertView); view.setText(chan.getDisplayingName()); view.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null); view.setCompoundDrawablePadding(drawablePadding); return view; } }; DialogInterface.OnClickListener onChanSelected = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ChanModule chan = chansAdapter.getItem(which); UrlPageModel model = new UrlPageModel(); model.chanName = chan.getChanName(); model.type = UrlPageModel.TYPE_INDEXPAGE; openNewTab(chan.buildUrl(model)); } }; final AlertDialog chansListDialog = new AlertDialog.Builder(activity) .setTitle(R.string.newtab_quickaccess_all_boards).setAdapter(chansAdapter, onChanSelected) .setNegativeButton(android.R.string.cancel, null).create(); chansListDialog.getListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { MenuItem.OnMenuItemClickListener contextMenuHandler = new MenuItem.OnMenuItemClickListener() { @SuppressLint("InlinedApi") @Override public boolean onMenuItemClick(MenuItem item) { final ChanModule chan = chansAdapter .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position); switch (item.getItemId()) { case R.id.context_menu_favorites_from_fragment: if (MainApplication.getInstance().database.isFavorite(chan.getChanName(), null, null, null)) { MainApplication.getInstance().database.removeFavorite(chan.getChanName(), null, null, null); } else { try { UrlPageModel indexPage = new UrlPageModel(); indexPage.chanName = chan.getChanName(); indexPage.type = UrlPageModel.TYPE_INDEXPAGE; MainApplication.getInstance().database.addFavorite(chan.getChanName(), null, null, null, chan.getChanName(), chan.buildUrl(indexPage)); } catch (Exception e) { Logger.e(TAG, e); } } return true; case R.id.context_menu_quickaccess_add: QuickAccess.Entry newEntry = new QuickAccess.Entry(); newEntry.chan = chan; list.add(0, newEntry); adapter.notifyDataSetChanged(); saveQuickAccessToPreferences(); chansListDialog.dismiss(); return true; case R.id.context_menu_quickaccess_custom_board: LinearLayout dialogLayout = new LinearLayout(activity); dialogLayout.setOrientation(LinearLayout.VERTICAL); final EditText boardField = new EditText(activity); final EditText descriptionField = new EditText(activity); boardField.setHint(R.string.newtab_quickaccess_addcustom_boardcode); descriptionField.setHint(R.string.newtab_quickaccess_addcustom_boarddesc); LinearLayout.LayoutParams fieldsParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); dialogLayout.addView(boardField, fieldsParams); dialogLayout.addView(descriptionField, fieldsParams); DialogInterface.OnClickListener onOkClicked = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String boardName = boardField.getText().toString(); for (QuickAccess.Entry entry : list) if (entry.boardName != null && entry.chan != null) if (entry.chan.getChanName().equals(chan.getChanName()) && entry.boardName.equals(boardName)) { Toast.makeText(activity, R.string.newtab_quickaccess_addcustom_already_exists, Toast.LENGTH_LONG).show(); return; } try { if (boardName.trim().length() == 0) throw new Exception(); UrlPageModel boardPageModel = new UrlPageModel(); boardPageModel.type = UrlPageModel.TYPE_BOARDPAGE; boardPageModel.chanName = chan.getChanName(); boardPageModel.boardName = boardName; boardPageModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE; chan.buildUrl(boardPageModel); //, ?? ? } catch (Exception e) { Toast.makeText(activity, R.string.newtab_quickaccess_addcustom_incorrect_code, Toast.LENGTH_LONG).show(); return; } QuickAccess.Entry newEntry = new QuickAccess.Entry(); newEntry.chan = chan; newEntry.boardName = boardName; newEntry.boardDescription = descriptionField.getText().toString(); list.add(0, newEntry); adapter.notifyDataSetChanged(); saveQuickAccessToPreferences(); chansListDialog.dismiss(); } }; new AlertDialog.Builder(activity) .setTitle(resources.getString(R.string.newtab_quickaccess_addcustom_title, chan.getChanName())) .setView(dialogLayout).setPositiveButton(android.R.string.ok, onOkClicked) .setNegativeButton(android.R.string.cancel, null).show(); return true; } return false; } }; String thisChanName = chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position) .getChanName(); boolean canAddToQuickAccess = true; for (QuickAccess.Entry entry : list) if (entry.boardName == null && entry.chan != null && entry.chan.getChanName().equals(thisChanName)) { canAddToQuickAccess = false; break; } menu.add(Menu.NONE, R.id.context_menu_favorites_from_fragment, 1, MainApplication.getInstance().database.isFavorite(thisChanName, null, null, null) ? R.string.context_menu_remove_favorites : R.string.context_menu_add_favorites) .setOnMenuItemClickListener(contextMenuHandler); menu.add(Menu.NONE, R.id.context_menu_quickaccess_add, 2, R.string.context_menu_quickaccess_add) .setOnMenuItemClickListener(contextMenuHandler).setVisible(canAddToQuickAccess); menu.add(Menu.NONE, R.id.context_menu_quickaccess_custom_board, 3, R.string.context_menu_quickaccess_custom_board) .setOnMenuItemClickListener(contextMenuHandler); if (isSingleboardChan( chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position))) menu.findItem(R.id.context_menu_quickaccess_custom_board).setVisible(false); } }); chansListDialog.show(); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * This function creates a pop up dialog which takes in the context of the * current activity/*from ww w.j av a2 s . c om*/ * * @param activityContext * the context of the current activity * @param rPathToTitleOfPopup * The R.path to the title * @param customView * the custom view for the dialog */ public void ShowLoginDialog(Context activityContext, int rPathToTitleOfPopup, View customView) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.dialog_login, null); AlertDialog.Builder builder = new AlertDialog.Builder(activityContext); builder.setTitle(rPathToTitleOfPopup); final EditText usernameEditText = (EditText) view.findViewById(R.id.LoginDialogEmailField); final EditText passwordEditText = (EditText) view.findViewById(R.id.loginDialogPasswordField); final TextView incorrectCredentialsTextView = (TextView) view .findViewById(R.id.loginIncorrectCredentialsTextView); Button loginButton = (Button) view.findViewById(R.id.loginDialogButton); Button cancelButton = (Button) view.findViewById(R.id.cancel_login_button); builder.setView(view); final AlertDialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); loginButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (incorrectCredentialsTextView.getVisibility() == 0) { incorrectCredentialsTextView.setVisibility(android.view.View.INVISIBLE); } if (!isNetworkAvailable()) { incorrectCredentialsTextView.setText(getString(R.string.no_internet_access)); incorrectCredentialsTextView.setVisibility(android.view.View.VISIBLE); return; } String usernameText = usernameEditText.getText().toString(); String passwordText = passwordEditText.getText().toString(); if (!validateEmail(usernameText)) { usernameEditText.requestFocus(); usernameEditText.setError(getString(R.string.login_invalid_email)); return; } usernameEditText.setError(null); if (passwordText.length() == 0) { passwordEditText.requestFocus(); passwordEditText.setError(getString(R.string.login_password_field_empty_string)); return; } passwordEditText.setError(null); try { authenticateUserCredentials(usernameText, passwordText); } catch (Exception e) { e.printStackTrace(); } if (userIsAuthenticated) { loadView(MyPageActivity.class); } else { incorrectCredentialsTextView.setText(getString(R.string.login_incorrect_credentials)); incorrectCredentialsTextView.setVisibility(android.view.View.VISIBLE); return; } } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // TODO Auto-generated method stub actionBar.setSelectedNavigationItem(adapter.getCount()); } }); dialog.show(); }
From source file:de.gebatzens.ggvertretungsplan.fragment.RemoteDataFragment.java
public void createRootView(final LayoutInflater inflater, ViewGroup vg) { RemoteData data = GGApp.GG_APP.getDataForFragment(type); if (data == null) { setFragmentLoading();/*from www . j a v a 2s.c o m*/ } else if (data.getThrowable() != null) { Throwable t = data.getThrowable(); if (t instanceof VPLoginException) { createButtonWithText(getActivity(), vg, getResources().getString(R.string.login_required), getResources().getString(R.string.do_login), new View.OnClickListener() { @Override public void onClick(View c) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog dialog; builder.setTitle(getResources().getString(R.string.login)); builder.setView(inflater.inflate(R.layout.login_dialog, null)); builder.setPositiveButton(getResources().getString(R.string.do_login_submit), new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { GGApp.GG_APP.activity.mContent.setFragmentLoading(); new AsyncTask<Integer, Integer, Integer>() { @Override public void onPostExecute(Integer v) { switch (v) { case 1: GGApp.GG_APP.showToast(getResources().getString( R.string.username_or_password_wrong)); break; case 2: GGApp.GG_APP.showToast(getResources().getString( R.string.could_not_contact_logon_server)); break; case 3: GGApp.GG_APP.showToast(getResources() .getString(R.string.unknown_error_at_logon)); break; } if (v != 0) ((MainActivity) GGApp.GG_APP.activity).mContent .updateFragment(); } @Override protected Integer doInBackground(Integer... params) { String user = ((EditText) ((Dialog) dialog) .findViewById(R.id.usernameInput)).getText() .toString(); String pass = ((EditText) ((Dialog) dialog) .findViewById(R.id.passwordInput)).getText() .toString(); return GGApp.GG_APP.provider.login(user, pass); } }.execute(); dialog.dismiss(); } }); builder.setNegativeButton(getResources().getString(R.string.abort), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); dialog.show(); } }); } else { createButtonWithText(getActivity(), vg, getResources().getString(R.string.check_connection_and_repeat), getResources().getString(R.string.again), new View.OnClickListener() { @Override public void onClick(View v) { GGApp.GG_APP.refreshAsync(null, true, GGApp.FragmentType.PLAN); } }); } } else { createView(inflater, vg); } }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
private void acceptButtonRegister(View view, final AlertDialog builder, final EditText startingCoordinates, final EditText endCoordinates, final TextView invalidInputFeedback, final Spinner projectionSpinner, final Spinner itemSpinner) { Button acceptButton = (Button) view.findViewById(R.id.dialogAcceptRegistration); acceptButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Handle registration here. It is not yet implemented in the BW // API String ToolstartingCoordinates = startingCoordinates.getText().toString(); String ToolendCoordinates = endCoordinates.getText().toString(); invalidInputFeedback.setVisibility(android.view.View.INVISIBLE); if (projectionSpinner.getSelectedItem() == null) { invalidInputFeedback.setText(getString(R.string.register_tool_no_projection_selected)); invalidInputFeedback.setVisibility(android.view.View.VISIBLE); return; } else if (itemSpinner.getSelectedItem() == null) { invalidInputFeedback.setText(getString(R.string.register_tool_no_tool_selected)); invalidInputFeedback.setVisibility(android.view.View.VISIBLE); return; }/*from w ww. jav a2 s .c o m*/ if (new FiskInfoUtility().checkCoordinates(ToolstartingCoordinates, projectionSpinner.getSelectedItem().toString()) == false) { invalidInputFeedback.setText(getString(R.string.register_tool_invalid_coordinate_format)); invalidInputFeedback.setVisibility(android.view.View.VISIBLE); startingCoordinates.requestFocus(); startingCoordinates.setError(getString(R.string.register_tool_invalid_coordinate_format)); } else if (new FiskInfoUtility().checkCoordinates(ToolendCoordinates, projectionSpinner.getSelectedItem().toString()) == false) { invalidInputFeedback.setText(getString(R.string.register_tool_invalid_coordinate_format)); invalidInputFeedback.setVisibility(android.view.View.VISIBLE); endCoordinates.requestFocus(); endCoordinates.setError(getString(R.string.register_tool_invalid_coordinate_format)); } else { startingCoordinates.setError(null); endCoordinates.setError(null); // TODO: send data to whoever should receive it and wait for // confirmation that things went OK Toast result = Toast.makeText(getContext(), "item registered", Toast.LENGTH_LONG); result.show(); builder.dismiss(); } } }); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * This function creates a dialog which allows the user to register a item * or tool used.// w w w. j a v a 2s . c om * * @param activityContext * The context of the current activity. */ public void registerItemAndToolUsed(Context activityContext) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.dialog_register_tool, (null)); final AlertDialog builder = new AlertDialog.Builder(activityContext).create(); builder.setTitle(R.string.register_tool_dialog_title); builder.setView(view); final EditText startingCoordinates = (EditText) view.findViewById(R.id.registerStartingCoordinatesOfTool); final EditText endCoordinates = (EditText) view.findViewById(R.id.registerEndCoordinatesOfTool); final TextView invalidInputFeedback = (TextView) view.findViewById(R.id.RegisterToolInvalidInputTextView); if (lastSetStartingPosition != null) { startingCoordinates.setText(lastSetStartingPosition); } if (lastSetEndPosition != null) { endCoordinates.setText(lastSetEndPosition); } final Spinner projectionSpinner = (Spinner) view.findViewById(R.id.projectionChangingSpinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.projections, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); projectionSpinner.setPrompt("Velg projeksjon"); projectionSpinner.setAdapter( new NoDefaultSpinner(adapter, R.layout.spinner_layout_select_projection, activityContext)); final Spinner itemSpinner = (Spinner) view.findViewById(R.id.registerMiscType); ArrayAdapter<CharSequence> itemAdapter = ArrayAdapter.createFromResource(this, R.array.tool_types, android.R.layout.simple_spinner_item); itemAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); itemSpinner.setPrompt("Velg redskapstype"); itemSpinner.setAdapter( new NoDefaultSpinner(itemAdapter, R.layout.spinner_layout_choose_tool, activityContext)); Button fetchToolStartingCoordinatesButton = (Button) view .findViewById(R.id.dialogFetchUserStartingCoordinates); Button fetchToolEndCoordinatesButton = (Button) view.findViewById(R.id.dialogFetchUserEndCoordinates); fetchToolStartingCoordinatesButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { setToolCoordinatesPosition(startingCoordinates); } }); fetchToolEndCoordinatesButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { setToolCoordinatesPosition(endCoordinates); } }); acceptButtonRegister(view, builder, startingCoordinates, endCoordinates, invalidInputFeedback, projectionSpinner, itemSpinner); Button cancelButton = (Button) view.findViewById(R.id.DialogCancelRegistration); cancelButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { builder.dismiss(); } }); builder.show(); }