List of usage examples for android.app Dialog setCancelable
public void setCancelable(boolean flag)
From source file:com.ibm.hellotodo.MainActivity.java
/** * Launches a dialog for updating the TodoItem name. Called when the list item is tapped. * * @param view The TodoItem that is tapped. *//* w ww.ja v a 2s . c o m*/ public void editTodoName(View view) { // Gets position in list view of tapped item final Integer pos = mListView.getPositionForView(view); final Dialog addDialog = new Dialog(this); addDialog.setContentView(R.layout.add_edit_dialog); addDialog.setTitle("Edit Todo"); TextView textView = (TextView) addDialog.findViewById(android.R.id.title); if (textView != null) { textView.setGravity(Gravity.CENTER); } addDialog.setCancelable(true); EditText et = (EditText) addDialog.findViewById(R.id.todo); final String name = mTodoItemList.get(pos).text; final boolean isDone = mTodoItemList.get(pos).isDone; final int id = mTodoItemList.get(pos).idNumber; et.setText(name); Button addDone = (Button) addDialog.findViewById(R.id.Add); addDialog.show(); // When done is pressed, send PUT request to update TodoItem on Bluemix addDone.setOnClickListener(new View.OnClickListener() { // Save text inputted when done is tapped @Override public void onClick(View view) { EditText editedText = (EditText) addDialog.findViewById(R.id.todo); String newName = editedText.getText().toString(); // If new text is not empty, create JSON with updated info and send PUT request if (!newName.isEmpty()) { String json = "{\"text\":\"" + newName + "\",\"isDone\":" + isDone + ",\"id\":" + id + "}"; // Create PUT REST request using the 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.PUT); 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 updated TodoItem @Override public void onSuccess(Response response) { Log.i(TAG, "Item updated 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, "editTodoName failed with error: " + errorMessage); } }); } addDialog.dismiss(); } }); }
From source file:com.trukr.shipper.fragment.RequestStatus.java
public void contactalertDialog(final Context ctx, String Title, String Content) { final Dialog dialog = new Dialog(ctx, R.style.Dialog); dialog.setCancelable(false); dialog.setContentView(R.layout.contactalertdialog); TextView alertHead = (TextView) dialog.findViewById(R.id.tv_alerthead); alertHead.setText(Title);//from w w w . j ava 2 s . co m TextView alertContent = (TextView) dialog.findViewById(R.id.tv_alertcontent); alertContent.setText(Content); Button btnDialogOk = (Button) dialog.findViewById(R.id.btn_text); Button btnDialogCancel = (Button) dialog.findViewById(R.id.btn_call); // if button is clicked, close the custom dialog btnDialogOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW); smsIntent.setData(Uri.parse("sms:" + driverContactValue.toString())); startActivity(smsIntent); dialog.dismiss(); } }); btnDialogCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Uri phoneCall = Uri.parse("tel:" + driverContactValue.toString()); Intent caller = new Intent(Intent.ACTION_DIAL, phoneCall); startActivity(caller); } }); dialog.show(); }
From source file:com.trukr.shipper.fragment.RequestStatus.java
public void cancelAlertDialog(Context mContext, String Title, String Content, final int Status) { final Dialog dialog = new Dialog(mContext, R.style.Dialog); dialog.setCancelable(false); dialog.setContentView(R.layout.custom_alertdialog); // set the custom dialog components - title and content TextView alertHead = (TextView) dialog.findViewById(R.id.custom_alertdialog_tv_alerthead); alertHead.setText(Title);/*from w ww . jav a 2s .c om*/ TextView alertContent = (TextView) dialog.findViewById(R.id.custom_alertdialog_tv_alertcontent); alertContent.setText(Content); View line = (View) dialog.findViewById(R.id.centerLineDialog); Button btnDialogCancel = (Button) dialog.findViewById(R.id.custom_alertdialog_btn_cancel); line.setVisibility(View.GONE); btnDialogCancel.setVisibility(View.GONE); Button btnDialogOk = (Button) dialog.findViewById(R.id.custom_alertdialog_btn_ok); btnDialogOk.setBackgroundResource(R.drawable.dialogbtnbackground); // if button is clicked, close the custom dialog btnDialogOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Status == 100) { dialog.dismiss(); } else dialog.dismiss(); } }); dialog.show(); }
From source file:com.trukr.shipper.fragment.RequestStatus.java
public void cancelalertdialog(Context mContext, String Title, String Content, final int Status) { final Dialog dialog = new Dialog(mContext, R.style.Dialog); dialog.setCancelable(false); dialog.setContentView(R.layout.custom_alertdialog); // set the custom dialog components - title and content TextView alertHead = (TextView) dialog.findViewById(R.id.custom_alertdialog_tv_alerthead); alertHead.setText(Title);//from w w w . j a v a2 s . c o m TextView alertContent = (TextView) dialog.findViewById(R.id.custom_alertdialog_tv_alertcontent); alertContent.setText(Content); View line = (View) dialog.findViewById(R.id.centerLineDialog); Button btnDialogCancel = (Button) dialog.findViewById(R.id.custom_alertdialog_btn_cancel); /* line.setVisibility(View.GONE); btnDialogCancel.setVisibility(View.GONE);*/ Button btnDialogOk = (Button) dialog.findViewById(R.id.custom_alertdialog_btn_ok); /* btnDialogOk.setBackgroundResource(R.drawable.dialogbtnbackground);*/ // if button is clicked, close the custom dialog btnDialogOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); cancelJob(); } }); btnDialogCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); dialog.show(); }
From source file:net.lp.hivawareness.v4.HIVAwarenessActivity.java
/** * Prepare dialog for afterwards (smoking). *///from w w w . j ava 2 s. c om public Dialog createSmokingDialog() { if (!HIVAwarenessActivity.DEBUG) FlurryAgent.onEvent("show_smoking_dialog"); AnalyticsUtils.getInstance().trackGAEvent("Main", "ShowSmokingDialog"); Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.smoking_toast); dialog.setTitle(R.string.dialog_smoking_title); dialog.setCancelable(true); return dialog; }
From source file:edu.sfsu.csc780.chathub.ui.ChannelActivity.java
public void openBottomSheet() { View view = getLayoutInflater().inflate(R.layout.bottom_sheet_modal, null); final Dialog mBottomSheetDialog = new Dialog(ChannelActivity.this, R.style.MaterialDialogSheet); mBottomSheetDialog.setContentView(view); mBottomSheetDialog.setCancelable(true); mBottomSheetDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); mBottomSheetDialog.getWindow().setGravity(Gravity.BOTTOM); mBottomSheetDialog.show();// w w w . j a va2s .com mImageButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.shareImageButton); mImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { pickImage(); mBottomSheetDialog.hide(); } }); mPhotoButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.cameraButton); mPhotoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dispatchTakePhotoIntent(); mBottomSheetDialog.hide(); } }); mLocationButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.locationButton); mLocationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { loadMap(); mBottomSheetDialog.hide(); } }); mProgress = new ProgressDialog(this); mStorage = FirebaseStorage.getInstance().getReference(); mAudioButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.voiceButton); mAudioButton.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { startRecording(); Context context = getApplicationContext(); CharSequence text = "Recording Started!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { stopRecording(); mBottomSheetDialog.hide(); Context context = getApplicationContext(); CharSequence text = "Recording Stopped!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } return false; } }); mFileName = Environment.getExternalStorageDirectory().getAbsolutePath(); mFileName += "/recorded_audio.3gp"; mStickerButton = (BadgedStickersButton) mBottomSheetDialog.findViewById(R.id.stickerButton); StickersFragment stickersFragment = (StickersFragment) getSupportFragmentManager() .findFragmentById(R.id.frame); if (stickersFragment == null) { stickersFragment = new StickersFragment(); getSupportFragmentManager().beginTransaction().replace(R.id.frame, stickersFragment).commit(); } stickersFragment.setOnStickerSelectedListener(stickerSelectedListener); View stickersFrame = findViewById(R.id.frame); View chatContentGroup = findViewById(R.id.chat_content); StickersKeyboardLayout stickersLayout = (StickersKeyboardLayout) findViewById(R.id.sizeNotifierLayout); stickersKeyboardController = new StickersKeyboardController.Builder(this) .setStickersKeyboardLayout(stickersLayout).setStickersFragment(stickersFragment) .setStickersFrame(stickersFrame).setContentContainer(chatContentGroup) .setStickersButton(mStickerButton).setChatEdit(mMessageEditText).build(); mDrawButton = (ImageButton) mBottomSheetDialog.findViewById(R.id.drawButton); mDrawButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(ChannelActivity.this, DrawingActivity.class)); mBottomSheetDialog.hide(); } }); }
From source file:com.near.chimerarevo.fragments.CommentsFragment.java
@SuppressLint("SetJavaScriptEnabled") private void loadDisqusOAuth() { if (getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE) .getString(Constants.KEY_REFRESH_TOKEN, "").length() > 1) { RequestBody formBody = new FormEncodingBuilder().add("grant_type", "refresh_token") .add("client_id", Constants.DISQUS_API_KEY).add("client_secret", Constants.DISQUS_API_SECRET) .add("refresh_token", getActivity().getSharedPreferences(Constants.PREFS_TAG, Context.MODE_PRIVATE) .getString(Constants.KEY_REFRESH_TOKEN, "")) .build();/*from w ww .jav a 2 s.com*/ Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody).tag(FRAGMENT_TAG) .build(); if (mDialog == null) mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login); else mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login); mDialog.show(); OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback()); return; } final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.webview_layout); dialog.setCancelable(true); dialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { isDialogOpen = false; mFab.show(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { isDialogOpen = false; mFab.show(); } }); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) CookieManager.getInstance().removeAllCookies(null); else { CookieSyncManager.createInstance(getActivity()); CookieManager.getInstance().removeAllCookie(); } WebView wv = (WebView) dialog.findViewById(R.id.webview); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setSaveFormData(false); wv.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); dialog.findViewById(R.id.progressContainer).setVisibility(View.GONE); dialog.findViewById(R.id.webViewContainer).setVisibility(View.VISIBLE); } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); dialog.findViewById(R.id.progressContainer).setVisibility(View.VISIBLE); dialog.findViewById(R.id.webViewContainer).setVisibility(View.GONE); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { boolean state = super.shouldOverrideUrlLoading(view, url); if (url.contains(Constants.SITE_URL)) { String code = url.split("code=")[1]; RequestBody formBody = new FormEncodingBuilder().add("grant_type", "authorization_code") .add("client_id", Constants.DISQUS_API_KEY) .add("client_secret", Constants.DISQUS_API_SECRET) .add("redirect_uri", Constants.SITE_URL).add("code", code).build(); Request request = new Request.Builder().url(Constants.DISQUS_TOKEN_URL).post(formBody) .tag(FRAGMENT_TAG).build(); if (mDialog == null) mDialog = ProgressDialogUtils.getInstance(getActivity(), R.string.text_login); else mDialog = ProgressDialogUtils.modifyInstance(mDialog, R.string.text_login); dialog.dismiss(); mDialog.show(); OkHttpUtils.getInstance().newCall(request).enqueue(new PostAccessTokenCallback()); } return state; } @Override public void onReceivedSslError(WebView view, @NonNull SslErrorHandler handler, SslError error) { handler.proceed(); } }); wv.loadUrl(URLUtils.getDisqusAuthUrl()); isDialogOpen = true; mFab.hide(); dialog.show(); }
From source file:org.wso2.cdm.agent.AuthenticationActivity.java
public void showAgreement(String message, String title) { final Dialog dialog = new Dialog(context); dialog.setContentView(R.layout.custom_terms_popup); dialog.setTitle(CommonUtilities.EULA_TITLE); dialog.setCancelable(false); WebView web = (WebView) dialog.findViewById(R.id.webview); String html = "<html><body>" + message + "</body></html>"; String mime = "text/html"; String encoding = "utf-8"; web.loadDataWithBaseURL(null, html, mime, encoding, null); Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); Button cancelButton = (Button) dialog.findViewById(R.id.dialogButtonCancel); dialogButton.setOnClickListener(new OnClickListener() { @Override/* w ww . j a v a2s . c o m*/ public void onClick(View v) { Preference.put(context, getResources().getString(R.string.shared_pref_isagreed), "1"); dialog.dismiss(); loadPincodeAcitvity(); } }); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); cancelEntry(); } }); dialog.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { return true; } else if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { return true; } return false; } }); dialog.show(); }
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void addImage(final String imgUrl) { final ImageView img = new ImageView(getActivity()); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params.setMargins(15, 0, 15, 0);//from w ww. j ava 2 s. c o m params.gravity = Gravity.CENTER_HORIZONTAL; img.setLayoutParams(params); img.setScaleType(ImageView.ScaleType.CENTER_INSIDE); lay.addView(img); final DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisk(false).cacheInMemory(true) .showImageOnLoading(R.drawable.empty_cr).bitmapConfig(Bitmap.Config.RGB_565) .imageScaleType(ImageScaleType.EXACTLY).delayBeforeLoading(150).build(); ImageLoader.getInstance().displayImage(imgUrl, img, options); img.setClickable(true); img.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.img_dialog_layout); ImageLoader.getInstance().displayImage(imgUrl.split("\\?resize=")[0], ((TouchImageView) dialog.findViewById(R.id.dialog_image)), options); dialog.setCancelable(true); dialog.show(); } }); }
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void addGallery(final String[] imgUrls) { numGalleries++;/*from w w w . j a v a 2 s . c om*/ if (!PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("load_imgs_pref", true) || numGalleries > Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString("gallery_num_pref", "20"))) return; HorizontalScrollView hsv = new HorizontalScrollView(getActivity()); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER_HORIZONTAL; params.setMargins(10, 10, 10, 0); hsv.setLayoutParams(params); LinearLayout container = new LinearLayout(getActivity()); container.setOrientation(LinearLayout.HORIZONTAL); for (int i = 0; i < imgUrls.length; i++) { final ImageView img = new ImageView(getActivity()); LayoutParams imgPar = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (i == 0) imgPar.setMargins(5, 10, 0, 10); else imgPar.setMargins(10, 10, 0, 10); img.setLayoutParams(imgPar); img.setScaleType(ImageView.ScaleType.CENTER_INSIDE); container.addView(img); final DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisk(false) .cacheInMemory(true).showImageOnLoading(R.drawable.empty_cr).bitmapConfig(Bitmap.Config.RGB_565) .imageScaleType(ImageScaleType.EXACTLY).delayBeforeLoading(200).build(); ImageLoader.getInstance().displayImage(imgUrls[i], img, options); final int k = i; img.setClickable(true); img.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.img_dialog_layout); ImageLoader.getInstance().displayImage(imgUrls[k].split("\\?resize=")[0], ((TouchImageView) dialog.findViewById(R.id.dialog_image)), options); dialog.setCancelable(true); dialog.show(); } }); } hsv.addView(container); lay.addView(hsv); }