List of usage examples for android.app Dialog setCancelable
public void setCancelable(boolean flag)
From source file:net.evendanan.android.hagarfingerpainting.HagarFingerpaintingActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_NEW_PAPER: final Dialog newPaper = new Dialog(this); newPaper.setTitle(R.string.new_paper_dialog_title); newPaper.setContentView(R.layout.new_paper_dialog); newPaper.setCancelable(true); final EditText painterName = (EditText) newPaper.findViewById(R.id.painter_name_input_text); Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/schoolbell.ttf"); painterName.setTypeface(tf);/* w w w . ja va2 s.c om*/ final Gallery colors = (Gallery) newPaper.findViewById(R.id.colors_list); colors.setAdapter(new PaperColorListAdapter(getApplicationContext())); colors.setOnItemSelectedListener(new OnItemSelectedListener() { private View mSelectedItem = null; @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { if (mSelectedItem != null) mSelectedItem.setBackgroundDrawable(null); mSelectedItem = v; if (mSelectedItem != null) mSelectedItem.setBackgroundResource(R.drawable.selected_color_background); } @Override public void onNothingSelected(AdapterView<?> arg0) { if (mSelectedItem != null) mSelectedItem.setBackgroundDrawable(null); } }); colors.setSelection(2); View createButton = newPaper.findViewById(R.id.new_paper_create_button); createButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Editor e = sp.edit(); final CharSequence painterNameFromUI = painterName.getText().toString(); final String newPainterName = TextUtils.isEmpty(painterNameFromUI) ? getString(R.string.settings_key_painter_name_default_value) : painterNameFromUI.toString(); e.putString(getString(R.string.settings_key_painter_name), newPainterName); e.commit(); PaperBackground paper = (PaperBackground) colors.getSelectedItem(); newPaper.dismiss(); createNewPaper(paper); } }); View cancelButton = newPaper.findViewById(R.id.new_paper_cancel_button); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { newPaper.dismiss(); if (!mPaperCreated) HagarFingerpaintingActivity.this.finish(); } }); newPaper.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!mPaperCreated) HagarFingerpaintingActivity.this.finish(); } }); return newPaper; default: return super.onCreateDialog(id); } }
From source file:com.eng.arab.translator.androidtranslator.activity.NumberViewActivity.java
public void displayDialog(String vid) { if (getResources().getIdentifier(vid, "raw", getPackageName()) == 0) { /* TEST if RAW file doesn't exist then do nothing*/ } else {/*from w w w . j a v a2 s .c om*/ final Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar); dialog.setContentView(R.layout.number_video_view); dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(true); mVideoView = (VideoView) dialog.findViewById(R.id.videoView); mVideoView.setZOrderMediaOverlay(true); String path = "android.resource://" + getPackageName() + "/" + //R.raw.alif; getResources().getIdentifier(vid, "raw", getPackageName()); FrameLayout fl = (FrameLayout) dialog.findViewById(R.id.VideoFrameLayout); ImageButton imageButtonClose = (ImageButton) fl.findViewById(R.id.imageButtonClose); imageButtonClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //dialog.dismiss(); if (v.getId() == R.id.imageButtonClose) { dialog.dismiss(); } } // Perform button logic }); // Set the media controller buttons if (mediaController == null) { mediaController = new MediaController(NumberViewActivity.this); // Set the videoView that acts as the anchor for the MediaController. mediaController.setAnchorView(mVideoView); // Set MediaController for VideoView mVideoView.setMediaController(mediaController); } mVideoView.setVideoURI(Uri.parse(path)); mVideoView.requestFocus(); // When the video file ready for playback. mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { public void onPrepared(MediaPlayer mediaPlayer) { mVideoView.seekTo(position); if (position == 0) { mVideoView.start(); } // When video Screen change size. mediaPlayer.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() { @Override public void onVideoSizeChanged(MediaPlayer mp, int width, int height) { // Re-Set the videoView that acts as the anchor for the MediaController mediaController.setAnchorView(mVideoView); } }); } }); dialog.show(); } }
From source file:org.tigase.mobile.chat.ChatHistoryFragment.java
private void showMessageDetails(final long id) { Cursor cc = null;/*from w ww. ja va2 s. c o m*/ final java.text.DateFormat df = DateFormat.getDateFormat(getActivity()); final java.text.DateFormat tf = DateFormat.getTimeFormat(getActivity()); try { cc = getChatEntry(id); Dialog alertDialog = new Dialog(getActivity()); alertDialog.setContentView(R.layout.chat_item_details_dialog); alertDialog.setCancelable(true); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setTitle("Message details"); TextView msgDetSender = (TextView) alertDialog.findViewById(R.id.msgDetSender); msgDetSender.setText(cc.getString(cc.getColumnIndex(ChatTableMetaData.FIELD_JID))); Date timestamp = new Date(cc.getLong(cc.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP))); TextView msgDetReceived = (TextView) alertDialog.findViewById(R.id.msgDetReceived); msgDetReceived.setText(df.format(timestamp) + " " + tf.format(timestamp)); final int state = cc.getInt(cc.getColumnIndex(ChatTableMetaData.FIELD_STATE)); TextView msgDetState = (TextView) alertDialog.findViewById(R.id.msgDetState); switch (state) { case ChatTableMetaData.STATE_INCOMING: msgDetState.setText("Received"); break; case ChatTableMetaData.STATE_OUT_SENT: msgDetState.setText("Sent"); break; case ChatTableMetaData.STATE_OUT_NOT_SENT: msgDetState.setText("Not sent"); break; default: msgDetState.setText("?"); break; } alertDialog.show(); } finally { if (cc != null && !cc.isClosed()) cc.close(); } }
From source file:com.tingtingapps.securesms.ConversationListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { final View view = inflater.inflate(R.layout.conversation_list_fragment, container, false); reminderView = (ReminderView) view.findViewById(R.id.reminder); list = (RecyclerView) view.findViewById(R.id.list); fab = (FloatingActionButton) view.findViewById(R.id.fab); list.setHasFixedSize(true);//from w w w.j a va 2 s .c o m list.setLayoutManager(new LinearLayoutManager(getActivity())); Calendar calendar = Calendar.getInstance(); int day = calendar.get(Calendar.DAY_OF_WEEK); int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); SharedPreferences sp1 = getActivity().getSharedPreferences("myPrefs", Activity.MODE_PRIVATE); int dayShowPopup = sp1.getInt("dayShowPopup", 0); /* //test data day = 7; dayShowPopup = 15; dayOfMonth = 26;*/ if (day == 7 && dayOfMonth != dayShowPopup) { SharedPreferences sp2 = getActivity().getSharedPreferences("myPrefs", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = sp2.edit(); editor.putInt("dayShowPopup", dayOfMonth); editor.commit(); final Dialog dialogRating = new Dialog(getActivity()); dialogRating.requestWindowFeature(Window.FEATURE_NO_TITLE); dialogRating.setContentView(R.layout.dlg_rating_sharing_donating); int height = 850; dialogRating.getWindow().setLayout(LinearLayout.LayoutParams.FILL_PARENT, height); dialogRating.setCancelable(true); dialogRating.show(); Button btnRate = (Button) dialogRating.findViewById(R.id.btn_rate); btnRate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Context context = getActivity().getApplicationContext(); String packageName = context.getPackageName(); Intent intentRateApp = new Intent(Intent.ACTION_VIEW); intentRateApp.setData(Uri.parse("market://details?id=" + packageName)); startActivity(intentRateApp); } }); /*Button btnRemoveAds = (Button) dialogRating.findViewById(R.id.btn_remove_ads); btnRemoveAds.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intentInAppBilling = new Intent(getActivity(), InAppBillingActivity.class); startActivity(intentInAppBilling); } });*/ Button btnShare = (Button) dialogRating.findViewById(R.id.btn_share); btnShare.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); String shareBody = getString(R.string.socail_share_body); sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.socail_share_title)); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); startActivity(Intent.createChooser(sharingIntent, getString(R.string.socail_share_via))); } }); Button btnClose = (Button) dialogRating.findViewById(R.id.btn_close); btnClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialogRating.dismiss(); } }); } return view; }
From source file:com.gunz.carrental.Fragments.CarsFragment.java
private void addCar(final boolean isAddCar, final int position) { final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.custom_dialog_car); dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false); TextView lblTitle = (TextView) dialog.findViewById(R.id.lblTitle); final MaterialEditText txBrand = (MaterialEditText) dialog.findViewById(R.id.txBrand); final MaterialEditText txModel = (MaterialEditText) dialog.findViewById(R.id.txModel); final MaterialEditText txLicense = (MaterialEditText) dialog.findViewById(R.id.txLicense); final MaterialEditText txFare = (MaterialEditText) dialog.findViewById(R.id.txFare); Button btnSave = (Button) dialog.findViewById(R.id.btnSave); ImageView imgClose = (ImageView) dialog.findViewById(R.id.imgClose); dialog.show();//from www .ja v a 2 s. com clearErrorMsg(dialog); if (!isAddCar) { lblTitle.setText(getActivity().getResources().getString(R.string.update_car_title)); txBrand.setText(cars.get(position).brand); txModel.setText(cars.get(position).type); txLicense.setText(cars.get(position).licensePlat); txFare.setText(String.valueOf((int) cars.get(position).farePerDay)); } else { lblTitle.setText(getActivity().getResources().getString(R.string.add_new_car_title)); } btnSave.setOnClickListener(new OnOneClickListener() { @Override public void onOneClick(View v) { if (TextUtils.isEmpty(txBrand.getText().toString().trim())) { txBrand.setText(""); txBrand.setError(getActivity().getResources().getString(R.string.validation_required)); txBrand.requestFocus(); } else if (TextUtils.isEmpty(txModel.getText().toString().trim())) { txModel.setText(""); txModel.setError(getActivity().getResources().getString(R.string.validation_required)); txModel.requestFocus(); } else if (TextUtils.isEmpty(txLicense.getText().toString().trim())) { txLicense.setText(""); txLicense.setError(getActivity().getResources().getString(R.string.validation_required)); txLicense.requestFocus(); } else if (TextUtils.isEmpty(txFare.getText().toString().trim())) { txFare.setText(""); txFare.setError(getActivity().getResources().getString(R.string.validation_required)); txFare.requestFocus(); } else { String confirmText; if (isAddCar) { confirmText = getActivity().getResources().getString(R.string.dialog_add_car_question); } else { confirmText = getActivity().getResources().getString(R.string.dialog_update_car_question); } new SweetAlertDialog(getActivity(), SweetAlertDialog.NORMAL_TYPE) .setTitleText(getActivity().getResources().getString(R.string.dialog_confirmation)) .setContentText(confirmText) .setCancelText(getActivity().getResources().getString(R.string.btn_cancel)) .setConfirmText(getActivity().getResources().getString(R.string.btn_save)) .showCancelButton(true) .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sweetAlertDialog) { if (isAddCar) { saveNewCar(dialog, txBrand.getText().toString().trim(), txModel.getText().toString().trim(), Integer.parseInt(txFare.getText().toString().trim()), txLicense.getText().toString().trim()); } else { updateCar(dialog, cars.get(position).id, txBrand.getText().toString().trim(), txModel.getText().toString().trim(), Integer.parseInt(txFare.getText().toString().trim()), txLicense.getText().toString().trim()); } sweetAlertDialog.dismiss(); } }).show(); } } }); imgClose.setOnClickListener(new OnOneClickListener() { @Override public void onOneClick(View v) { Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.bounce); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { dialog.dismiss(); } @Override public void onAnimationRepeat(Animation animation) { } }); v.startAnimation(animation); } }); }
From source file:com.cellobject.oikos.FormActivity.java
private void initializeSettingsAndInfoButtons() { preferencesBtn = (ImageButton) findViewById(R.id.preferences_btn); preferencesBtn.setOnClickListener(new View.OnClickListener() { public void onClick(final View view) { final Intent intent = new Intent(FormActivity.this, OikosPreferenceActivity.class); startActivity(intent);/*from w w w . j a va2 s.co m*/ } }); infoBtn = (ImageButton) findViewById(R.id.info_btn); infoBtn.setOnClickListener(new View.OnClickListener() { public void onClick(final View view) { final Dialog dialog = new Dialog(FormActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setContentView(R.layout.info); final Button button = (Button) dialog.findViewById(R.id.aboutOk); button.setOnClickListener(new OnClickListener() { public void onClick(final View v) { dialog.dismiss(); } }); dialog.show(); } }); }
From source file:com.beza.briver.fragments.ProfileFragment.java
private void showDocumentsAttachmentCustomDialog() { final Dialog customAttachmentsDialog = new Dialog(getActivity()); customAttachmentsDialog.setContentView(R.layout.layout_custom_attachment_dialog); customAttachmentsDialog.setCancelable(false); customAttachmentsDialog.setTitle("Attach Documents"); Button buttonNo = (Button) customAttachmentsDialog.findViewById(R.id.btn_driver_hire_dialog_cancel); buttonNo.setOnClickListener(new View.OnClickListener() { @Override/*from w w w.j a v a2 s. c o m*/ public void onClick(View v) { customAttachmentsDialog.dismiss(); } }); Button buttonYes = (Button) customAttachmentsDialog.findViewById(R.id.btn_driver_hire_dialog_hire); buttonYes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (imageChanged) { customAttachmentsDialog.dismiss(); etProfileAttachments.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_edit_text_attachment, 0, R.mipmap.ic_edit_text_add_image, 0); File destination = new File(Environment.getExternalStorageDirectory() + File.separator + "Android/data" + File.separator + AppGlobals.getContext().getPackageName()); for (int i = 0; i < 3; i++) { if (hashMapTemp.containsKey(i)) { File file = new File(destination, i + ".jpg"); file.delete(); File from = new File(destination, i + "temp" + ".jpg"); File to = new File(destination, i + ".jpg"); from.renameTo(to); } } Log.i("images array", String.valueOf(imagePathsArray)); imageChanged = false; } else { Toast.makeText(getActivity(), "No Change to submit", Toast.LENGTH_SHORT).show(); } } }); ibPhotoOne = (ImageButton) customAttachmentsDialog.findViewById(R.id.ib_photo_one); ibPhotoTwo = (ImageButton) customAttachmentsDialog.findViewById(R.id.ib_photo_two); ibPhotoThree = (ImageButton) customAttachmentsDialog.findViewById(R.id.ib_photo_three); ibPhotoOne.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ibPosition = 0; Helpers.AlertDialogWithPositiveNegativeFunctionsNeutralButton(getActivity(), "License Front", "Select an option to add photo", "Camera", "Gallery", "Cancel", openCameraIntent, openGalleryIntent); } }); ibPhotoTwo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ibPosition = 1; Helpers.AlertDialogWithPositiveNegativeFunctionsNeutralButton(getActivity(), "License Back", "Select an option to add photo", "Camera", "Gallery", "Cancel", openCameraIntent, openGalleryIntent); } }); ibPhotoThree.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ibPosition = 2; Helpers.AlertDialogWithPositiveNegativeFunctionsNeutralButton(getActivity(), "Police Verification", "Select an option to add photo", "Camera", "Gallery", "Cancel", openCameraIntent, openGalleryIntent); } }); ibPhotoOne.setBackgroundDrawable(null); ibPhotoOne.setImageBitmap(Helpers.getCroppedBitmap( Helpers.getResizedBitmapToDisplay(BitmapFactory.decodeFile(hashMap.get(0)), 120))); ibPhotoTwo.setBackgroundDrawable(null); ibPhotoTwo.setImageBitmap(Helpers.getCroppedBitmap( Helpers.getResizedBitmapToDisplay(BitmapFactory.decodeFile(hashMap.get(1)), 120))); ibPhotoThree.setBackgroundDrawable(null); ibPhotoThree.setImageBitmap(Helpers.getCroppedBitmap( Helpers.getResizedBitmapToDisplay(BitmapFactory.decodeFile(hashMap.get(2)), 120))); customAttachmentsDialog.show(); }
From source file:dev.datvt.cloudtracks.sound_cloud.LocalTracksFragment.java
public void showChangeLangDialog() { final Dialog dialog = new Dialog(ctx); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(false); dialog.setContentView(R.layout.dialog_create_playlist); final EditText edt = (EditText) dialog.findViewById(R.id.edtInput); final TextView btnCreate = (TextView) dialog.findViewById(R.id.btnCreate); final TextView btnCancel = (TextView) dialog.findViewById(R.id.btnCancel); final ImageView btnDel = (ImageView) dialog.findViewById(R.id.btnDel); btnCreate.setOnClickListener(new View.OnClickListener() { @Override//from w w w .ja v a2 s. co m public void onClick(View view) { ret = edt.getText().toString(); if (ret != null && !ret.isEmpty()) { try { ToolsHelper.createPlaylist(ctx, ret); setUpListPlaylist(); Log.d("CREATE_2", "COMPLETE"); } catch (Exception e) { e.printStackTrace(); } } else { ToolsHelper.toast(ctx, getString(R.string.info_not_name_playlist)); showChangeLangDialog(); } dialog.dismiss(); } }); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ret = null; dialog.cancel(); } }); btnDel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { edt.setText(""); } }); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show(); }
From source file:com.vkassin.mtrade.Common.java
public static void login(final Context ctx) { // ctx = Common.app_ctx; Common.connected = false;//from w w w . j av a 2 s . co m if (inLogin) return; inLogin = true; if (Common.mainActivity != null) Common.mainActivity.handler.sendMessage( Message.obtain(Common.mainActivity.handler, Common.mainActivity.DISMISS_PROGRESS_DIALOG)); // while(true) { final Dialog dialog = new Dialog(ctx); dialog.setContentView(R.layout.login_dialog); dialog.setTitle(R.string.LoginDialogTitle); dialog.setCancelable(false); final EditText nametxt = (EditText) dialog.findViewById(R.id.loginnameedit); final EditText passtxt = (EditText) dialog.findViewById(R.id.passwordedit); final EditText passtxt1 = (EditText) dialog.findViewById(R.id.passwordedit1); final EditText passtxt2 = (EditText) dialog.findViewById(R.id.passwordedit2); final EditText mailtxt = (EditText) dialog.findViewById(R.id.emailedit2); String nam = myaccount.get("name"); Common.oldName = nam; if (nam != null) { nametxt.setText(nam); passtxt.requestFocus(); } Button customDialog_Register = (Button) dialog.findViewById(R.id.goregister); customDialog_Register.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { dialog.setTitle(R.string.LoginDialogTitle1); final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354); layreg.setVisibility(View.VISIBLE); final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543); laylog.setVisibility(View.GONE); } }); Button customDialog_Register1 = (Button) dialog.findViewById(R.id.goregister1); customDialog_Register1.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { if (mailtxt.getText().length() < 1) { Toast toast = Toast.makeText(mainActivity, R.string.CorrectEmail, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return; } if (passtxt1.getText().length() < 1) { Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return; } if (!passtxt2.getText().toString().equals(passtxt1.getText().toString())) { Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword1, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); return; } try { Socket sock = new Socket(ip_addr, port_register); JSONObject msg = new JSONObject(); msg.put("objType", Common.MSG_REGISTER); msg.put("time", Calendar.getInstance().getTimeInMillis()); msg.put("user", mailtxt.getText().toString()); msg.put("passwd", passtxt1.getText().toString()); msg.put("version", Common.PROTOCOL_VERSION); msg.put("sign", sign(mailtxt.getText().toString(), passtxt1.getText().toString())); byte[] array = msg.toString().getBytes(); ByteBuffer buff = ByteBuffer.allocate(array.length + 4); buff.putInt(array.length); buff.put(array); sock.getOutputStream().write(buff.array()); ByteBuffer buff1 = ByteBuffer.allocate(4); buff1.put(readMsg(sock.getInputStream(), 4)); buff1.position(0); int pkgSize = buff1.getInt(); // Log.i(TAG, "size = "+pkgSize); String s = new String(readMsg(sock.getInputStream(), pkgSize)); sock.close(); JSONObject jo = new JSONObject(s); Log.i(TAG, "register answer = " + jo); int t = jo.getInt("status"); switch (t) { case 1: Toast toast = Toast.makeText(mainActivity, R.string.RegisterStatus1, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); dialog.setTitle(R.string.LoginDialogTitle); final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354); layreg.setVisibility(View.GONE); final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543); laylog.setVisibility(View.VISIBLE); nametxt.setText(mailtxt.getText()); break; case -2: Toast toast1 = Toast.makeText(mainActivity, R.string.RegisterStatus3, Toast.LENGTH_LONG); toast1.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast1.show(); break; default: Toast toast2 = Toast.makeText(mainActivity, R.string.RegisterStatus2, Toast.LENGTH_LONG); toast2.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast2.show(); break; } } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "Error in registration process!!", e); Toast toast = Toast.makeText(mainActivity, R.string.ConnectError, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); } } }); Button customDialog_CancelReg = (Button) dialog.findViewById(R.id.cancelreg); customDialog_CancelReg.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { dialog.setTitle(R.string.LoginDialogTitle); final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354); layreg.setVisibility(View.GONE); final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543); laylog.setVisibility(View.VISIBLE); } }); Button customDialog_Dismiss = (Button) dialog.findViewById(R.id.gologin); customDialog_Dismiss.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.lradio0); Common.isSSL = bu0.isChecked(); inLogin = false; JSONObject msg = new JSONObject(); try { msg.put("objType", Common.LOGOUT); msg.put("time", Calendar.getInstance().getTimeInMillis()); msg.put("version", Common.PROTOCOL_VERSION); msg.put("status", 1); mainActivity.writeJSONMsg(msg); } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "Error! Cannot create JSON logout object", e); } myaccount.put("name", nametxt.getText().toString()); myaccount.put("password", passtxt.getText().toString()); Log.i(TAG, "myaccount username: " + myaccount.get("name") + " password: " + myaccount.get("password")); dialog.dismiss(); mainActivity.stop(); // saveAccountDetails(); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } loginFromDialog = true; // mainActivity.refresh(); Common.keypassword(ctx); } }); dialog.show(); // Common.confChanged = false; // }//while(true); }
From source file:com.ibm.hellotodo.MainActivity.java
/** * Launches a dialog for adding a new TodoItem. Called when plus button is tapped. * * @param view The plus button that is tapped. *//*from ww w . ja va2 s .c o m*/ public void addTodo(View view) { final Dialog addDialog = new Dialog(this); addDialog.setContentView(R.layout.add_edit_dialog); addDialog.setTitle("Add Todo"); TextView textView = (TextView) addDialog.findViewById(android.R.id.title); if (textView != null) { textView.setGravity(Gravity.CENTER); } addDialog.setCancelable(true); Button add = (Button) addDialog.findViewById(R.id.Add); addDialog.show(); // When done is pressed, send POST request to create TodoItem on Bluemix add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo); final String name = itemToAdd.getText().toString(); // If text was added, continue with normal operations if (!name.isEmpty()) { // Create JSON for new TodoItem, id should be 0 for new items String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}"; // Create POST request with IBM Mobile First SDK and set HTTP headers so Bluemix knows what to expect in the request Request request = new Request(client.getBluemixAppRoute() + "/api/Items", Request.POST); HashMap headers = new HashMap(); List<String> cType = new ArrayList<>(); cType.add("application/json"); List<String> accept = new ArrayList<>(); accept.add("Application/json"); headers.put("Content-Type", cType); headers.put("Accept", accept); request.setHeaders(headers); request.send(getApplicationContext(), json, new ResponseListener() { // On success, update local list with new TodoItem @Override public void onSuccess(Response response) { Log.i(TAG, "Item created successfully"); loadList(); } // On failure, log errors @Override public void onFailure(Response response, Throwable t, JSONObject extendedInfo) { String errorMessage = ""; if (response != null) { errorMessage += response.toString() + "\n"; } if (t != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); errorMessage += "THROWN" + sw.toString() + "\n"; } if (extendedInfo != null) { errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n"; } if (errorMessage.isEmpty()) errorMessage = "Request Failed With Unknown Error."; Log.e(TAG, "addTodo failed with error: " + errorMessage); } }); } // Kill dialog when finished, or if no text was added addDialog.dismiss(); } }); }