android.app.Dialog#dismiss ( )源码实例Demo

下面列出了android.app.Dialog#dismiss ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BaldPhone   文件: BaldActivity.java
@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();
}
 
源代码2 项目: PermissionAgent   文件: OverlaySpecialOperation.java
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;
}
 
源代码3 项目: JPPF   文件: SettingsFragment.java
/**
 * 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);
    }
  }
}
 
源代码4 项目: delion   文件: NewTabPage.java
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();
}
 
源代码5 项目: ProjectX   文件: CommonActivity.java
/**
 * 关闭对话框
 *
 * @param dialog Dialog
 */
public void dismissDialog(Dialog dialog) {
    if (dialog.isShowing()) {
        dialog.dismiss();
    }
    mShowDialogs.remove(dialog);
}
 
源代码6 项目: DevUtils   文件: DialogUtils.java
/**
 * 关闭 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;
}
 
源代码7 项目: RetroMusicPlayer   文件: DialogAsyncTask.java
private void tryToDismiss() {
    supposedToBeDismissed = true;
    try {
        Dialog dialog = getDialog();
        if (dialog != null)
            dialog.dismiss();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
源代码8 项目: green_android   文件: UI.java
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;

}
 
源代码9 项目: KUAS-AP-Material   文件: Utils.java
public static void dismissDialog(Dialog dialog) {
	try {
		if (dialog != null && dialog.isShowing()) {
			dialog.dismiss();
		}
	} catch (IllegalArgumentException e) {
		// ignore
	}
}
 
源代码10 项目: o2oa   文件: GroupActivity.java
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);
}
 
源代码11 项目: android-app   文件: ConfigurationTestHelper.java
private void dismissDialog(Dialog dialog) {
    if(dialog == null || !dialog.isShowing()) return;

    if(context instanceof Activity) {
        if(!((Activity)context).isFinishing()) {
            dialog.dismiss();
        }
    } else {
        dialog.dismiss();
    }
}
 
源代码12 项目: memoir   文件: LinkFragment.java
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);
    }
}
 
源代码13 项目: talkback   文件: ScanningMethodPreference.java
@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);
}
 
源代码14 项目: memoir   文件: LinkFragment.java
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);
    }
}
 
源代码15 项目: BigApp_Discuz_Android   文件: UpdateManager.java
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();
	
}
 
源代码16 项目: ThinkMap   文件: EditMapActivity.java
private void clearDialog(Dialog dialog) {
    if (dialog != null && dialog.isShowing()) {
        dialog.dismiss();
    }
}
 
源代码17 项目: EhViewer   文件: ProxyPreference.java
@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();
}
 
源代码18 项目: o2oa   文件: PersonalActivity.java
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();
    }
}
 
源代码19 项目: SimplePomodoro-android   文件: SettingActivity.java
/** 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);
               }
           }    
       }
   }
 
源代码20 项目: KUtils   文件: DialogUIUtils.java
/**
 * 关闭弹出框
 */
public static void dismiss(Dialog dialog) {
    if (dialog != null && dialog.isShowing()) {
        dialog.dismiss();
    }
}