Java Code Examples for android.app.Dialog#dismiss()

The following examples show how to use android.app.Dialog#dismiss() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsFragment.java    From JPPF with Apache License 2.0 8 votes vote down vote up
/**
 * Sets up the action bar for an {@link PreferenceScreen}.
 * @param preferenceScreen the preference screen on which to set the action bar.
 */
private static void initializeActionBar(PreferenceScreen preferenceScreen) {
  final Dialog dialog = preferenceScreen.getDialog();
  if (dialog != null) {
    dialog.getActionBar().setDisplayHomeAsUpEnabled(true);
    View homeBtn = dialog.findViewById(android.R.id.home);
    if (homeBtn != null) {
      View.OnClickListener dismissDialogClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          dialog.dismiss();
        }
      };
      ViewParent homeBtnContainer = homeBtn.getParent();
      if (homeBtnContainer instanceof FrameLayout) {
        ViewGroup containerParent = (ViewGroup) homeBtnContainer.getParent();
        if (containerParent instanceof LinearLayout) containerParent.setOnClickListener(dismissDialogClickListener);
        else ((FrameLayout) homeBtnContainer).setOnClickListener(dismissDialogClickListener);
      } else  homeBtn.setOnClickListener(dismissDialogClickListener);
    }
  }
}
 
Example 2
Source File: NewTabPage.java    From delion with Apache License 2.0 6 votes vote down vote up
public static void launchInterestsDialog(Activity activity, final Tab tab) {
    InterestsPage page =
            new InterestsPage(activity, tab, Profile.getLastUsedProfile());
    final Dialog dialog = new NativePageDialog(activity, page);

    InterestsClickListener listener = new InterestsClickListener() {
        @Override
        public void onInterestClicked(String name) {
            tab.loadUrl(new LoadUrlParams(
                    TemplateUrlService.getInstance().getUrlForSearchQuery(name)));
            dialog.dismiss();
        }
    };

    page.setListener(listener);
    dialog.show();
}
 
Example 3
Source File: BaldActivity.java    From BaldPhone with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPause() {
    for (WeakReference<Dialog> dialogWeakReference : dialogsToClose) {
        final Dialog dialog = dialogWeakReference.get();
        if (dialog != null)
            dialog.dismiss();
    }

    for (WeakReference<PopupWindow> windowWeakReference : popupWindowsToClose) {
        final PopupWindow window = windowWeakReference.get();
        if (window != null)
            window.dismiss();
    }

    if (useAccidentalGuard)
        sensorManager.unregisterListener(this);
    super.onPause();
}
 
Example 4
Source File: OverlaySpecialOperation.java    From PermissionAgent with Apache License 2.0 6 votes vote down vote up
private boolean tryDisplayDialog(Context context) {
    Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
    int windowType;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        windowType = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
    } else {
        windowType = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    }
    Window window = dialog.getWindow();
    if (window != null) {
        window.setType(windowType);
    }
    try {
        dialog.show();
    } catch (Exception e) {
        return false;
    } finally {
        if (dialog.isShowing()) dialog.dismiss();
    }
    return true;
}
 
Example 5
Source File: LinkFragment.java    From memoir with Apache License 2.0 5 votes vote down vote up
private void validate(Dialog dialog, TextView addressView, TextView textView) {
    // retrieve link address and do some cleanup
    final String address = addressView.getText().toString().trim();

    boolean isEmail = sEmailValidator.isValid(address);
    boolean isUrl = sUrlValidator.isValid(address);
    if (requiredFieldValid(addressView) && (isUrl || isEmail)) {
        // valid url or email address

        // encode address
        String newAddress = Helper.encodeQuery(address);

        // add mailto: for email addresses
        if (isEmail && !startsWithMailto(newAddress)) {
            newAddress = "mailto:" + newAddress;
        }

        // use the original address text as link text if the user didn't enter anything
        String linkText = textView.getText().toString();
        if (linkText.length() == 0) {
            linkText = address;
        }

        EventBus.getDefault().post(new LinkEvent(LinkFragment.this, new Link(linkText, newAddress), false));
        try { dialog.dismiss(); } catch (Exception ignore) {}
    } else {
        // invalid address (neither a url nor an email address
        String errorMessage = getString(R.string.rte_invalid_link, address);
        addressView.setError(errorMessage);
    }
}
 
Example 6
Source File: ScanningMethodPreference.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
protected void onBindDialogView(@NonNull View dialogView) {
  for (int i = 0; i < radioButtonIds.length; i++) {
    RadioButton radioButton = dialogView.findViewById(radioButtonIds[i]);
    View summaryView = dialogView.findViewById(scanningMethodSummaryViewIds[i]);
    if (isScanningMethodEnabled[i]) {
      radioButton.setVisibility(View.VISIBLE);
      summaryView.setVisibility(View.VISIBLE);
      // Use an OnClickListener instead of on OnCheckChangedListener so we are informed when the
      // currently checked item is tapped. (The OnCheckChangedListener is only called when a
      // different radio button is selected.)
      final int keyIndex = i;
      View.OnClickListener scanningMethodOnClickListener =
          v -> {
            SwitchAccessPreferenceUtils.setScanningMethod(context, scanningMethodKeys[keyIndex]);

            Dialog dialog = getDialog();
            if (dialog != null) {
              dialog.dismiss();
            }
          };
      radioButton.setOnClickListener(scanningMethodOnClickListener);
      summaryView.setOnClickListener(scanningMethodOnClickListener);

    } else {
      radioButton.setVisibility(View.GONE);
      summaryView.setVisibility(View.GONE);
    }
  }
  RadioGroup scanningMethodRadioGroup =
      dialogView.findViewById(R.id.scanning_options_radio_group);
  updateCheckedBasedOnCurrentValue(scanningMethodRadioGroup);
}
 
Example 7
Source File: LinkFragment.java    From memoir with Apache License 2.0 5 votes vote down vote up
private void validate(Dialog dialog, TextView addressView, TextView textView) {
    // retrieve link address and do some cleanup
    final String address = addressView.getText().toString().trim();

    boolean isEmail = sEmailValidator.isValid(address);
    boolean isUrl = sUrlValidator.isValid(address);
    if (requiredFieldValid(addressView) && (isUrl || isEmail)) {
        // valid url or email address

        // encode address
        String newAddress = Helper.encodeQuery(address);

        // add mailto: for email addresses
        if (isEmail && !startsWithMailto(newAddress)) {
            newAddress = "mailto:" + newAddress;
        }

        // use the original address text as link text if the user didn't enter anything
        String linkText = textView.getText().toString();
        if (linkText.length() == 0) {
            linkText = address;
        }

        EventBus.getDefault().post(new LinkEvent(LinkFragment.this, new Link(linkText, newAddress), false));
        try { dialog.dismiss(); } catch (Exception ignore) {}
    } else {
        // invalid address (neither a url nor an email address
        String errorMessage = getString(R.string.rte_invalid_link, address);
        addressView.setError(errorMessage);
    }
}
 
Example 8
Source File: ConfigurationTestHelper.java    From android-app with GNU General Public License v3.0 5 votes vote down vote up
private void dismissDialog(Dialog dialog) {
    if(dialog == null || !dialog.isShowing()) return;

    if(context instanceof Activity) {
        if(!((Activity)context).isFinishing()) {
            dialog.dismiss();
        }
    } else {
        dialog.dismiss();
    }
}
 
Example 9
Source File: GroupActivity.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public void setAdapter(List<GroupInfo> infoList, Dialog dialog) {
    dialog.dismiss();
    //来自转发时flag是1
    if (getIntent().getFlags() == 1) {
        isFromForward = true;
    }
    //来自名片的请求设置flag==2
    if (getIntent().getFlags() == 2) {
        isBusinessCard = true;
    }
    mGroupListAdapter = new GroupListAdapter(mContext, infoList, isFromForward, mWidth, isBusinessCard, mUserName, mAppKey, mAvatarPath);
    mGroupList.setAdapter(mGroupListAdapter);
}
 
Example 10
Source File: CommonActivity.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
/**
 * 关闭对话框
 *
 * @param dialog Dialog
 */
public void dismissDialog(Dialog dialog) {
    if (dialog.isShowing()) {
        dialog.dismiss();
    }
    mShowDialogs.remove(dialog);
}
 
Example 11
Source File: Utils.java    From KUAS-AP-Material with MIT License 5 votes vote down vote up
public static void dismissDialog(Dialog dialog) {
	try {
		if (dialog != null && dialog.isShowing()) {
			dialog.dismiss();
		}
	} catch (IllegalArgumentException e) {
		// ignore
	}
}
 
Example 12
Source File: UI.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public static MaterialDialog dismiss(final Activity a, final Dialog d) {
    if (d != null)
        if (a != null)
            a.runOnUiThread(new Runnable() { public void run() { d.dismiss(); } });
        else
            d.dismiss();
    return null;

}
 
Example 13
Source File: DialogAsyncTask.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
private void tryToDismiss() {
    supposedToBeDismissed = true;
    try {
        Dialog dialog = getDialog();
        if (dialog != null)
            dialog.dismiss();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 14
Source File: DialogUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 关闭 Dialog
 * @param dialog {@link Dialog}
 * @return {@code true} success, {@code false} fail
 */
public static boolean closeDialog(final Dialog dialog) {
    if (dialog != null && dialog.isShowing()) {
        try {
            dialog.dismiss();
            return true;
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "closeDialog");
        }
    }
    return false;
}
 
Example 15
Source File: SettingActivity.java    From SimplePomodoro-android with MIT License 4 votes vote down vote up
/** Sets up the action bar for an {@link PreferenceScreen} */
   @SuppressLint("NewApi")
public static void initializeActionBar(PreferenceScreen preferenceScreen) {
       final Dialog dialog = preferenceScreen.getDialog();

       if (dialog != null) {
           // Inialize the action bar
           dialog.getActionBar().setDisplayHomeAsUpEnabled(true);

           // Apply custom home button area click listener to close the PreferenceScreen because PreferenceScreens are dialogs which swallow
           // events instead of passing to the activity
           // Related Issue: https://code.google.com/p/android/issues/detail?id=4611
           View homeBtn = dialog.findViewById(android.R.id.home);

           if (homeBtn != null) {
               OnClickListener dismissDialogClickListener = new OnClickListener() {
                   @Override
                   public void onClick(View v) {
                       dialog.dismiss();
                   }
               };

               // Prepare yourselves for some hacky programming
               ViewParent homeBtnContainer = homeBtn.getParent();

               // The home button is an ImageView inside a FrameLayout
               if (homeBtnContainer instanceof FrameLayout) {
                   ViewGroup containerParent = (ViewGroup) homeBtnContainer.getParent();

                   if (containerParent instanceof LinearLayout) {
                       // This view also contains the title text, set the whole view as clickable
                       ((LinearLayout) containerParent).setOnClickListener(dismissDialogClickListener);
                   } else {
                       // Just set it on the home button
                       ((FrameLayout) homeBtnContainer).setOnClickListener(dismissDialogClickListener);
                   }
               } else {
                   // The 'If all else fails' default case
                   homeBtn.setOnClickListener(dismissDialogClickListener);
               }
           }    
       }
   }
 
Example 16
Source File: DialogUIUtils.java    From KUtils with Apache License 2.0 4 votes vote down vote up
/**
 * 关闭弹出框
 */
public static void dismiss(Dialog dialog) {
    if (dialog != null && dialog.isShowing()) {
        dialog.dismiss();
    }
}
 
Example 17
Source File: ProxyPreference.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
    Dialog dialog = getDialog();
    Context context = getContext();
    if (null == dialog || null == context || null == mType ||
            null == mIpInputLayout || null == mIp ||
            null == mPortInputLayout || null == mPort) {
        return;
    }

    int type = mType.getSelectedItemPosition();

    String ip = mIp.getText().toString().trim();
    if (ip.isEmpty()) {
        if (type == EhProxySelector.TYPE_HTTP || type == EhProxySelector.TYPE_SOCKS) {
            mIpInputLayout.setError(context.getString(R.string.text_is_empty));
            return;
        }
    }
    mIpInputLayout.setError(null);

    int port;
    String portString = mPort.getText().toString().trim();
    if (portString.isEmpty()) {
        if (type == EhProxySelector.TYPE_HTTP || type == EhProxySelector.TYPE_SOCKS) {
            mPortInputLayout.setError(context.getString(R.string.text_is_empty));
            return;
        } else {
            port = -1;
        }
    } else {
        try {
            port = Integer.parseInt(portString);
        } catch (NumberFormatException e) {
            port = -1;
        }
        if (!InetValidator.isValidInetPort(port)) {
            mPortInputLayout.setError(context.getString(R.string.proxy_invalid_port));
            return;
        }
    }
    mPortInputLayout.setError(null);

    Settings.putProxyType(type);
    Settings.putProxyIp(ip);
    Settings.putProxyPort(port);

    updateSummary(type, ip, port);

    EhApplication.getEhProxySelector(getContext()).updateProxy();

    dialog.dismiss();
}
 
Example 18
Source File: PersonalActivity.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private void initData() {
    final Dialog dialog = DialogCreator.createLoadingDialog(PersonalActivity.this,
            PersonalActivity.this.getString(R.string.jmui_loading));
    dialog.show();
    mMyInfo = JMessageClient.getMyInfo();
    if (mMyInfo != null) {
        mTv_nickName.setText(mMyInfo.getNickname());
        SharePreferenceManager.setRegisterUsername(mMyInfo.getNickname());
        mTv_userName.setText("用户名:" + mMyInfo.getUserName());
        mTv_sign.setText(mMyInfo.getSignature());
        UserInfo.Gender gender = mMyInfo.getGender();
        if (gender != null) {
            if (gender.equals(UserInfo.Gender.male)) {
                mTv_gender.setText("男");
            } else if (gender.equals(UserInfo.Gender.female)) {
                mTv_gender.setText("女");
            } else {
                mTv_gender.setText("保密");
            }
        }
        long birthday = mMyInfo.getBirthday();
        if (birthday == 0) {
            mTv_birthday.setText("");
        } else {
            Date date = new Date(mMyInfo.getBirthday());
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            mTv_birthday.setText(format.format(date));
        }
        mTv_city.setText(mMyInfo.getAddress());
        mMyInfo.getAvatarBitmap(new GetAvatarBitmapCallback() {
            @Override
            public void gotResult(int responseCode, String responseMessage, Bitmap avatarBitmap) {
                if (responseCode == 0) {
                    mIv_photo.setImageBitmap(avatarBitmap);
                } else {
                    mIv_photo.setImageResource(R.drawable.rc_default_portrait);
                }
            }
        });
        dialog.dismiss();
    }
}
 
Example 19
Source File: EditMapActivity.java    From ThinkMap with Apache License 2.0 4 votes vote down vote up
private void clearDialog(Dialog dialog) {
    if (dialog != null && dialog.isShowing()) {
        dialog.dismiss();
    }
}
 
Example 20
Source File: UpdateManager.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
public void showNoticeDialog(final Context context, final UpdateResponse response) {
	if(response != null && TextUtils.isEmpty(response.path)){
		return;
	}
	StringBuilder updateMsg = new StringBuilder();
	updateMsg.append(response.version);
	updateMsg.append(context.getString(R.string.analysissdk_update_new_impress));
	updateMsg.append("\n");
	updateMsg.append(response.content);
	updateMsg.append("\n");
	updateMsg.append(context.getString(R.string.analysissdk_update_apk_size, sizeToString(response.size)));
	
	final Dialog dialog = new Dialog(context, R.style.AnalysisSDK_CommonDialog);
	dialog.setContentView(R.layout.analysissdk_update_notify_dialog);
	TextView tvContent = (TextView) dialog.findViewById(R.id.update_tv_dialog_content);
	tvContent.setMovementMethod(ScrollingMovementMethod.getInstance()); 
	tvContent.setText(updateMsg);

	final CheckBox cBox = (CheckBox) dialog.findViewById(R.id.update_cb_ignore);		
	if(UpdateConfig.isUpdateForce()){
		cBox.setVisibility(View.GONE);
	}else {
		cBox.setVisibility(View.VISIBLE);
	}
	
	android.view.View.OnClickListener ocl = new android.view.View.OnClickListener() {
		public void onClick(View v) {
			if(v.getId() == R.id.update_btn_dialog_ok){
				dialogBtnClick = UpdateStatus.Update;
			}else if(v.getId() == R.id.update_btn_dialog_cancel){
				if(cBox.isChecked()){
					dialogBtnClick = UpdateStatus.Ignore;
				}
			}
			dialog.dismiss();
			UpdateAgent.updateDialogDismiss(context, dialogBtnClick, response);
		}
	};
		
	dialog.findViewById(R.id.update_btn_dialog_ok).setOnClickListener(ocl);
	dialog.findViewById(R.id.update_btn_dialog_cancel).setOnClickListener(ocl);
	dialog.setCanceledOnTouchOutside(false);
	dialog.setCancelable(true);
	dialog.show();
	
}