下面列出了android.app.Dialog#show ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Starts or restarts the camera source, if it exists. If the camera source doesn't exist yet
* (e.g., because onResume was called before the camera source was created), this will be called
* again when the camera source is created.
*/
private void startCameraSource() throws SecurityException {
// Check that the device has play services available.
int code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
getApplicationContext());
if (code != ConnectionResult.SUCCESS) {
Dialog dlg =
GoogleApiAvailability.getInstance().getErrorDialog(this, code, RC_HANDLE_GMS);
dlg.show();
}
if (mCameraSource != null) {
try {
mPreview.start(mCameraSource, mGraphicOverlay);
} catch (IOException e) {
Log.e(TAG, "Unable to start camera source.", e);
mCameraSource.release();
mCameraSource = null;
}
}
}
private void eula(Context context) {
// Run the guardian
Guardian.initiate(this);
// Load the EULA
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.eula);
dialog.setTitle("EULA");
WebView web = (WebView) dialog.findViewById(R.id.eula);
web.loadUrl("file:///android_asset/eula.html");
Button accept = (Button) dialog.findViewById(R.id.accept);
accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
/**
* Starts or restarts the camera source, if it exists. If the camera source doesn't exist yet
* (e.g., because onResume was called before the camera source was created), this will be called
* again when the camera source is created.
*/
private void startCameraSource() {
// check that the device has play services available.
int code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(
getApplicationContext());
if (code != ConnectionResult.SUCCESS) {
Dialog dlg =
GoogleApiAvailability.getInstance().getErrorDialog(this, code, RC_HANDLE_GMS);
dlg.show();
}
if (mCameraSource != null) {
try {
mPreview.start(mCameraSource, mGraphicOverlay);
} catch (IOException e) {
Log.e(TAG, "Unable to start camera source.", e);
mCameraSource.release();
mCameraSource = null;
}
}
}
private void updateUserInfo() {
final Dialog dialog = DialogCreator.createLoadingDialog(FriendInfoActivity.this,
FriendInfoActivity.this.getString(R.string.jmui_loading));
dialog.show();
if (TextUtils.isEmpty(mTargetId) && !TextUtils.isEmpty(mUserID)) {
mTargetId = mUserID;
}
JMessageClient.getUserInfo(mTargetId, mTargetAppKey, new GetUserInfoCallback() {
@Override
public void gotResult(int responseCode, String responseMessage, UserInfo info) {
dialog.dismiss();
if (responseCode == 0) {
//拉取好友信息时候要更新数据库中的nickName.因为如果对方修改了nickName我们是无法感知的.如果不在拉取信息
//时候更新数据库的话会影响到搜索好友的nickName, 注意要在没有备注名并且有昵称时候去更新.因为备注名优先级更高
new Update(FriendEntry.class).set("DisplayName=?", info.getDisplayName()).where("Username=?", mTargetId).execute();
new Update(FriendEntry.class).set("NickName=?", info.getNickname()).where("Username=?", mTargetId).execute();
new Update(FriendEntry.class).set("NoteName=?", info.getNotename()).where("Username=?", mTargetId).execute();
if (info.getAvatarFile() != null) {
new Update(FriendEntry.class).set("Avatar=?", info.getAvatarFile().getAbsolutePath()).where("Username=?", mTargetId).execute();
}
mUserInfo = info;
mFriendInfoController.setFriendInfo(info);
mTitle = info.getNotename();
if (TextUtils.isEmpty(mTitle)) {
mTitle = info.getNickname();
}
mFriendInfoView.initInfo(info);
} else {
HandleResponseCode.onHandle(FriendInfoActivity.this, responseCode, false);
}
}
});
}
/**
* Shows the dialog associated with this Preference. This is normally initiated
* automatically on clicking on the preference. Call this method if you need to
* show the dialog on some other event.
*
* @param state Optional instance state to restore on the dialog
*/
protected void showDialog(Bundle state) {
Context context = getContext();
mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;
mBuilder = new AlertDialog.Builder(context)
.setTitle(mDialogTitle)
.setIcon(mDialogIcon)
.setPositiveButton(mPositiveButtonText, this)
.setNegativeButton(mNegativeButtonText, this);
View contentView = onCreateDialogView();
if (contentView != null) {
onBindDialogView(contentView);
mBuilder.setView(contentView);
} else {
mBuilder.setMessage(mDialogMessage);
}
onPrepareDialogBuilder(mBuilder);
PreferenceManagerEx.getInstance().registerOnActivityDestroyListener(getPreferenceManager(), this);
// Create the dialog
final Dialog dialog = mDialog = mBuilder.create();
if (state != null) {
dialog.onRestoreInstanceState(state);
}
if (needInputMethod()) {
requestInputMethod(dialog);
}
dialog.setOnDismissListener(this);
dialog.show();
}
/**
* Show a {@link android.app.Dialog} with the correct message for a connection error.
* @param activity the Activity in which the Dialog should be displayed.
* @param requestCode the request code from onActivityResult.
* @param actResp the response code from onActivityResult.
* @param errorDescription the resource id of a String for a generic error message.
*/
public static void showActivityResultError(Activity activity, int requestCode, int actResp, int errorDescription) {
if (activity == null) {
Log.e("BaseGameUtils", "*** No Activity. Can't show failure dialog!");
return;
}
Dialog errorDialog;
switch (actResp) {
case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED:
errorDialog = makeSimpleDialog(activity,
activity.getString(R.string.app_misconfigured));
break;
case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED:
errorDialog = makeSimpleDialog(activity,
activity.getString(R.string.sign_in_failed));
break;
case GamesActivityResultCodes.RESULT_LICENSE_FAILED:
errorDialog = makeSimpleDialog(activity,
activity.getString(R.string.license_failed));
break;
default:
// No meaningful Activity response code, so generate default Google
// Play services dialog
final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
activity, requestCode, null);
if (errorDialog == null) {
// get fallback dialog
Log.e("BaseGamesUtils",
"No standard error dialog available. Making fallback dialog.");
errorDialog = makeSimpleDialog(activity, activity.getString(errorDescription));
}
}
errorDialog.show();
}
void showSplash(){
splashScreenDialog=new Dialog(this,android.R.style.Theme_DeviceDefault_Light_NoActionBar_Fullscreen);
splashScreenDialog.setContentView(R.layout.splash_screen);
splashScreenDialog.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
splashScreenDialog.dismiss();
}
}, 4000);
}
public static Dialog show(Context ctx, String text) {
final Dialog dialog = new Dialog(ctx, R.style.full_screen_dialog);
dialog.setContentView(R.layout.progress_dialog);
((TextView) dialog.findViewById(R.id.label_loading)).setText(text);
dialog.setCancelable(false);
dialog.show();
return dialog;
}
public static boolean isPlayServicesAvailable(final Activity ctx) {
GoogleApiAvailability availability = GoogleApiAvailability.getInstance();
int isAvailable = availability.isGooglePlayServicesAvailable(ctx);
if (isAvailable == ConnectionResult.SUCCESS) {
return true;
} else if (availability.isUserResolvableError(isAvailable)) {
Dialog dialog = availability.getErrorDialog(ctx, isAvailable, 0);
dialog.show();
}else{
L.err("cant find play services.");
Toasty.error(ctx,"cant find play services").show();
}
return false;
}
/**
* Show a {@link android.app.Dialog} with the correct message for a connection error.
* @param activity the Activity in which the Dialog should be displayed.
* @param requestCode the request code from onActivityResult.
* @param actResp the response code from onActivityResult.
* @param errorDescription the resource id of a String for a generic error message.
*/
public static void showActivityResultError(Activity activity, int requestCode, int actResp, int errorDescription) {
if (activity == null) {
Log.e("BaseGameUtils", "*** No Activity. Can't show failure dialog!");
return;
}
Dialog errorDialog;
switch (actResp) {
case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED:
errorDialog = makeSimpleDialog(activity,
activity.getString(R.string.app_misconfigured));
break;
case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED:
errorDialog = makeSimpleDialog(activity,
activity.getString(R.string.sign_in_failed));
break;
case GamesActivityResultCodes.RESULT_LICENSE_FAILED:
errorDialog = makeSimpleDialog(activity,
activity.getString(R.string.license_failed));
break;
default:
// No meaningful Activity response code, so generate default Google
// Play services dialog
final int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
errorDialog = GooglePlayServicesUtil.getErrorDialog(errorCode,
activity, requestCode, null);
if (errorDialog == null) {
// get fallback dialog
Log.e("BaseGamesUtils",
"No standard error dialog available. Making fallback dialog.");
errorDialog = makeSimpleDialog(activity, activity.getString(errorDescription));
}
}
errorDialog.show();
}
private void showDialog(Dialog dlg) {
if (dlg != null) {
if (dlg.isShowing()) {
dlg.cancel();
} else {
dlg.show();
}
}
}
public static void call(Context context, Activity activity, int messageId, int yes, int no, OnClickListener yesListener, OnClickListener noListener) {
if (activity != null) {
String title = context.getString(2131100003);
String msg = context.getString(messageId);
String y = context.getString(yes);
Dialog dialog = new Builder(activity).setTitle(title).setMessage(msg).setPositiveButton(y, yesListener).setNegativeButton(context.getString(no), noListener).create();
if (!activity.isFinishing() && !activity.isRestricted()) {
try {
dialog.show();
} catch (Exception e) {
}
}
}
}
public static void call(Activity activity, int messageId, int yes, int no, OnClickListener yesListener, OnClickListener noListener, View view) {
if (activity != null) {
Dialog dialog = new Builder(activity).setTitle(R.string.dialog_default_title).setIcon(R.drawable.dialog_icon).setMessage(messageId).setView(view).setPositiveButton(yes, yesListener).setNegativeButton(no, noListener).create();
if (!activity.isFinishing() && !activity.isRestricted()) {
dialog.show();
}
}
}
private static Dialog showIosAlert(Context context, boolean isButtonVerticle, String title, String msg,
String firstTxt, String secondTxt, String thirdTxt,
boolean outsideCancleable, boolean cancleable,
final MyDialogListener listener){
Dialog dialog = buildDialog(context,cancleable,outsideCancleable);
int height = assigIosAlertView(context,dialog,isButtonVerticle,title,msg,firstTxt,secondTxt,thirdTxt,listener);
setDialogStyle(context,dialog,height);
dialog.show();
return dialog;
}
/**
* 统一显示
* 解决badtoken问题,一劳永逸
*
* @param dialog
*/
public static void showDialog(Dialog dialog) {
try {
dialog.show();
} catch (Exception e) {
}
}
private void showDialogErrorPlayServices(int errorCode)
{
Dialog dialog = GoogleApiAvailability.getInstance().getErrorDialog(this, errorCode,
Constants.REQUEST_PLAY_SERVICES_ERROR);
dialog.show();
}
/**
* Shows the splash screen over the full Activity
*/
@SuppressWarnings("deprecation")
protected void showSplashScreen(final int time) {
final CordovaActivity that = this;
Runnable runnable = new Runnable() {
public void run() {
// Get reference to display
Display display = getWindowManager().getDefaultDisplay();
// Create the layout for the dialog
LinearLayout root = new LinearLayout(that.getActivity());
root.setMinimumHeight(display.getHeight());
root.setMinimumWidth(display.getWidth());
root.setOrientation(LinearLayout.VERTICAL);
root.setBackgroundColor(that.getIntegerProperty("backgroundColor", Color.BLACK));
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
root.setBackgroundResource(that.splashscreen);
// Create and show the dialog
splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar);
// check to see if the splash screen should be full screen
if ((getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
== WindowManager.LayoutParams.FLAG_FULLSCREEN) {
splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
splashDialog.setContentView(root);
splashDialog.setCancelable(false);
splashDialog.show();
// Set Runnable to remove splash screen just in case
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
removeSplashScreen();
}
}, time);
}
};
this.runOnUiThread(runnable);
}
@Override
public void onLongPress(MotionEvent e) {
final Dialog dialog = new Dialog(getContext() , R.style.phoneNumDialog);
setupDialogViews(dialog);
dialog.show();
}
/**
* Shows the splash screen over the full Activity
*/
@SuppressWarnings("deprecation")
protected void showSplashScreen(final int time) {
final CordovaActivity that = this;
Runnable runnable = new Runnable() {
public void run() {
// Get reference to display
Display display = getWindowManager().getDefaultDisplay();
// Create the layout for the dialog
LinearLayout root = new LinearLayout(that.getActivity());
root.setMinimumHeight(display.getHeight());
root.setMinimumWidth(display.getWidth());
root.setOrientation(LinearLayout.VERTICAL);
root.setBackgroundColor(preferences.getInteger("backgroundColor", Color.BLACK));
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
root.setBackgroundResource(that.splashscreen);
// Create and show the dialog
splashDialog = new Dialog(that, android.R.style.Theme_Translucent_NoTitleBar);
// check to see if the splash screen should be full screen
if ((getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
== WindowManager.LayoutParams.FLAG_FULLSCREEN) {
splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
splashDialog.setContentView(root);
splashDialog.setCancelable(false);
splashDialog.show();
// Set Runnable to remove splash screen just in case
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
removeSplashScreen();
}
}, time);
}
};
this.runOnUiThread(runnable);
}
private void sendAddReason() {
final String userName;
String displayName;
String targetAvatar;
Long targetUid;
if (getIntent().getFlags() == 1) {
//添加好友申请时对方信息
userName = getIntent().getStringExtra("detail_add_friend");
displayName = getIntent().getStringExtra("detail_add_nick_name");
targetAvatar = getIntent().getStringExtra("detail_add_avatar_path");
targetUid = getIntent().getLongExtra("detail_add_uid", 0);
if (TextUtils.isEmpty(displayName)) {
displayName = userName;
}
//搜索方式添加好友
} else {
targetAvatar = InfoModel.getInstance().getAvatarPath();
displayName = InfoModel.getInstance().getNickName();
targetUid = InfoModel.getInstance().getUid();
if (TextUtils.isEmpty(displayName)) {
displayName = InfoModel.getInstance().getUserName();
}
userName = InfoModel.getInstance().getUserName();
}
final String reason = mEt_reason.getText().toString();
final String finalTargetAvatar = targetAvatar;
final String finalDisplayName = displayName;
final Long finalUid = targetUid;
final Dialog dialog = DialogCreator.createLoadingDialog(this, this.getString(R.string.jmui_loading));
dialog.show();
ContactManager.sendInvitationRequest(userName, null, reason, new BasicCallback() {
@Override
public void gotResult(int responseCode, String responseMessage) {
dialog.dismiss();
if (responseCode == 0) {
UserEntry userEntry = UserEntry.getUser(mMyInfo.getUserName(), mMyInfo.getAppKey());
FriendRecommendEntry entry = FriendRecommendEntry.getEntry(userEntry,
userName, mTargetAppKey);
if (null == entry) {
entry = new FriendRecommendEntry(finalUid, userName, "", finalDisplayName, mTargetAppKey,
finalTargetAvatar, finalDisplayName, reason, FriendInvitation.INVITING.getValue(), userEntry, 100);
} else {
entry.state = FriendInvitation.INVITING.getValue();
entry.reason = reason;
}
entry.save();
ToastUtil.shortToast(VerificationActivity.this, "申请成功");
finish();
} else if (responseCode == 871317) {
ToastUtil.shortToast(VerificationActivity.this, "不能添加自己为好友");
} else {
ToastUtil.shortToast(VerificationActivity.this, "申请失败");
}
}
});
}