package gn.com.android.theme.utils;
import java.io.ObjectInputStream.GetField;
import org.apache.cordova.api.LOG;
import gn.com.android.theme.R;
import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.content.DialogInterface;
import amigo.app.AmigoAlertDialog;
import amigo.app.AmigoProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class DialogFragmentUtil extends DialogFragment {
public static final int CONFIGDIALOG = 201301017;
public static final int DELETEDIALOG = 201301018;
public static final int TYPE_LOCAL = 1, TYPE_NET = 2;
private static final String TAG = "DialogFragmentUtil";
private static OnClickCallBack mClickCallBack;
private static int mWhere;
public static DialogFragmentUtil newInstance(int flag, int title) {
DialogFragmentUtil frag = new DialogFragmentUtil();
Bundle args = new Bundle();
args.putInt("title", title);
args.putInt("flag", flag);
frag.setArguments(args);
return frag;
}
public static DialogFragment getDialogFragment(int title, int flag,
OnClickCallBack onClickCallBack) {
Log.e(TAG, "----------getDialogFragment-----begin------");
DialogFragmentUtil fragment = newInstance(flag, title);
fragment.mClickCallBack = onClickCallBack;
Log.e(TAG, "----------getDialogFragment------end-----");
return fragment;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = null;
int flag = getArguments().getInt("flag");
int title = getArguments().getInt("title");
switch (flag) {
case CONFIGDIALOG: {
switch (mWhere) {
case TYPE_NET:
dialog = new AmigoProgressDialog(getActivity(),
AmigoAlertDialog.THEME_AMIGO_FULLSCREEN);
break;
default:
dialog = new AmigoProgressDialog(getActivity());
break;
}
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
((AmigoProgressDialog) dialog).setMessage(getActivity().getString(
R.string.apply_loading));
return dialog;
}
case DELETEDIALOG: {
AmigoAlertDialog.Builder builder = null;
switch (mWhere) {
case TYPE_NET:
builder = new AmigoAlertDialog.Builder(getActivity(),
AmigoAlertDialog.THEME_AMIGO_FULLSCREEN);
break;
default:
builder = new AmigoAlertDialog.Builder(getActivity());
break;
}
builder.setMessage(R.string.batch_del_body);
builder.setTitle(title);
builder.setPositiveButton(R.string.alert_dialog_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
mClickCallBack.onPositiveButtonClick();
}
});
builder.setNegativeButton(R.string.alert_dialog_cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
dialog = builder.create();
return dialog;
}
}
return null;
}
public interface OnClickCallBack {
/**
* if delete theme,it should be implemented to delete operation
*/
void onPositiveButtonClick();
// void onNegativeButtonClick();
}
private static void show(FragmentManager manager, int title, int flag,
OnClickCallBack onClickCallBack) {
Log.e(TAG, "----------show-----------");
DialogFragment fragment = getDialogFragment(title, flag,
onClickCallBack);
fragment.show(manager, "dialog");
}
/**
* if delete theme,the OnClickCallBack should be implemented to refresh view
*/
public static void showDeleteDialogForLocal(FragmentManager manager,
OnClickCallBack onClickCallBack) {
mWhere = TYPE_LOCAL;
show(manager, R.string.delete_theme_btn, DELETEDIALOG, onClickCallBack);
}
/**
* if delete theme,the OnClickCallBack should be implemented to refresh view
*/
public static void showDeleteDialogForNet(FragmentManager manager,
OnClickCallBack onClickCallBack) {
mWhere = TYPE_NET;
show(manager, R.string.batch_del_title, DELETEDIALOG, onClickCallBack);
}
public static void showApplyDialogForlocal(FragmentManager manager) {
mWhere = TYPE_LOCAL;
show(manager, 0, CONFIGDIALOG, null);
}
public static void showApplyDialogForNet(FragmentManager manager) {
mWhere = TYPE_NET;
show(manager, 0, CONFIGDIALOG, null);
}
}
DialogFragmentUtil
最新推荐文章于 2020-10-12 16:22:28 发布
本文介绍了Android中对话框组件的实现方式,包括配置对话框、删除对话框、本地应用对话框和网络应用对话框的展示逻辑。通过使用AmigoAlertDialog和AmigoProgressDialog,实现了不同场景下的对话框交互,包括点击事件的回调处理。
264

被折叠的 条评论
为什么被折叠?



