Java tutorial
/* * Copyright (C) 2012 www.amsoft.cn * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package ab.util; import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.support.v4.app.FragmentActivity; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TextView; import java.util.ArrayList; import java.util.Calendar; import java.util.List; import ab.ProgressWheel; import ab.fragment.AbAlertDialogFragment; import ab.fragment.AbAlertDialogFragment.AbDialogOnClickListener; import ab.fragment.AbDialogFragment.AbDialogOnLoadListener; import ab.fragment.AbLoadDialogFragment; import ab.fragment.AbProgressDialogFragment; import ab.fragment.AbProgressDialogFragment2; import ab.fragment.AbRefreshDialogFragment; import ab.fragment.AbSampleDialogFragment; import ab.sweetdailog.SweetAlertDialog; import ab.sweetdailog.SweetAlertDialog.OnSweetClickListener; import ab.util.model.ChoiceDate; import ab.view.OnWheelChangedListener; import ab.view.WheelView; import ab.view.wheel.adapters.ArrayWheelAdapter; import spfworld.spfworld.R; import spfworld.spfworld.entity.User.CityBean; import spfworld.spfworld.widget.percent.LoadingDialog; import spfworld.spfworld.widget.percent.weelutils.OptionsPickerView; // TODO: Auto-generated Javadoc /** * 2012 amsoft.cn ??AbDialogUtil.java ??Dialog. * * @author * @version v1.0 * @date2014-07-02 ?11:52:13 */ @SuppressLint("NewApi") public class AbDialogUtil { /** dialog tag */ private static String mDialogTag = "dialog"; /** * ?????View * * @param view * @return */ public static AbSampleDialogFragment showTipsDialog(View view) { FragmentActivity activity = (FragmentActivity) view.getContext(); // Create and show the dialog. AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light); newFragment.setContentView(view); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); // ?,content?fragment,Activity ft.add(android.R.id.content, newFragment, mDialogTag).addToBackStack(null).commit(); return newFragment; } /** * ?? * * @param view * @return */ public static AbSampleDialogFragment showFullScreenDialog(View view) { FragmentActivity activity = (FragmentActivity) view.getContext(); // Create and show the dialog. AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen); newFragment.setContentView(view); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?() * * @param view */ public static AbSampleDialogFragment showDialog(View view) { return showDialog(view, Gravity.CENTER); } /** * * ???(). * * @param view * @param gravity * ? * @return */ public static AbSampleDialogFragment showDialog(View view, int gravity) { FragmentActivity activity = (FragmentActivity) view.getContext(); // Create and show the dialog. AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog, gravity); newFragment.setContentView(view); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?() * * @param view * @param animEnter * @param animExit * @param animPopEnter * @param animPopExit * @return */ public static AbSampleDialogFragment showDialog(View view, int animEnter, int animExit, int animPopEnter, int animPopExit) { return showDialog(view, animEnter, animExit, animPopEnter, animPopExit, Gravity.CENTER); } /** * * ???(). * * @param view * @param animEnter * @param animExit * @param animPopEnter * @param animPopExit * @param gravity * ? * @return */ public static AbSampleDialogFragment showDialog(View view, int animEnter, int animExit, int animPopEnter, int animPopExit, int gravity) { FragmentActivity activity = (FragmentActivity) view.getContext(); // Create and show the dialog. AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog, gravity); newFragment.setContentView(view); // FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); ft.setCustomAnimations(animEnter, animExit, animPopEnter, animPopExit); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?() * * @param view * @param onCancelListener * @return */ public static AbSampleDialogFragment showDialog(View view, DialogInterface.OnCancelListener onCancelListener) { return showDialog(view, Gravity.CENTER, onCancelListener); } /** * * ???(). * * @param view * @param gravity * ? * @param onCancelListener * ? * @return */ public static AbSampleDialogFragment showDialog(View view, int gravity, DialogInterface.OnCancelListener onCancelListener) { FragmentActivity activity = (FragmentActivity) view.getContext(); // Create and show the dialog. AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog, gravity); newFragment.setContentView(view); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.setOnCancelListener(onCancelListener); newFragment.show(ft, mDialogTag); return newFragment; } /** * * ???(). * * @param view * @param animEnter * @param animExit * @param animPopEnter * @param animPopExit * @param onCancelListener * @return */ public static AbSampleDialogFragment showDialog(View view, int animEnter, int animExit, int animPopEnter, int animPopExit, DialogInterface.OnCancelListener onCancelListener) { return showDialog(view, animEnter, animExit, animPopEnter, animPopExit, Gravity.CENTER, onCancelListener); } /** * * ???(). * * @param view * @param animEnter * @param animExit * @param animPopEnter * @param animPopExit * @param gravity * @param onCancelListener * @return */ public static AbSampleDialogFragment showDialog(View view, int animEnter, int animExit, int animPopEnter, int animPopExit, int gravity, DialogInterface.OnCancelListener onCancelListener) { FragmentActivity activity = (FragmentActivity) view.getContext(); // Create and show the dialog. AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog, gravity); newFragment.setContentView(view); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); ft.setCustomAnimations(animEnter, animExit, animPopEnter, animPopExit); newFragment.setOnCancelListener(onCancelListener); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?() * * @param view */ public static AbSampleDialogFragment showPanel(View view) { return showPanel(view, Gravity.CENTER); } /** * * ???(). * * @param view * @param gravity * @return */ public static AbSampleDialogFragment showPanel(View view, int gravity) { FragmentActivity activity = (FragmentActivity) view.getContext(); // Create and show the dialog. AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Light_Panel, gravity); newFragment.setContentView(view); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?() * * @param view * @param onCancelListener * @return */ public static AbSampleDialogFragment showPanel(View view, DialogInterface.OnCancelListener onCancelListener) { return showPanel(view, Gravity.CENTER, onCancelListener); } /** * ?() * * @param view * @param onCancelListener * @return */ public static AbSampleDialogFragment showPanel(View view, int gravity, DialogInterface.OnCancelListener onCancelListener) { FragmentActivity activity = (FragmentActivity) view.getContext(); // Create and show the dialog. AbSampleDialogFragment newFragment = AbSampleDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Light_Panel, gravity); newFragment.setContentView(view); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.setOnCancelListener(onCancelListener); newFragment.show(ft, mDialogTag); return newFragment; } /** * ???dialog String. * * @param context * @param icon * @param title * ? * @param * */ public static AbAlertDialogFragment showAlertDialog(Context context, int icon, String title, String message) { FragmentActivity activity = (FragmentActivity) context; AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(icon, title, message, null, null); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?string?. * * @param context * @param icon * @param title * ? * @param message * ??? * @param onClickListener * ? */ public static AbAlertDialogFragment showAlertDialog(Context context, int icon, String title, String message, AbDialogOnClickListener onClickListener) { FragmentActivity activity = (FragmentActivity) context; AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(icon, title, message, null, onClickListener); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?String?. * * @param context * @param title * ? * @param message * ??? * @param onClickListener * ? */ public static AbAlertDialogFragment showAlertDialog(Context context, String title, String message, AbDialogOnClickListener onClickListener) { FragmentActivity activity = (FragmentActivity) context; AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(0, title, message, null, onClickListener); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?View. * * @param view * ? */ public static AbAlertDialogFragment showAlertDialog(View view) { FragmentActivity activity = (FragmentActivity) view.getContext(); AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(0, null, null, view, null); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?String. * * @param context * @param * */ public static AbAlertDialogFragment showAlertDialog(Context context, String message) { FragmentActivity activity = (FragmentActivity) context; AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(0, null, message, null, null); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ???dialog View. * * @param icon * @param title * ? * @param view * ??? */ public static AbAlertDialogFragment showAlertDialog(int icon, String title, View view) { FragmentActivity activity = (FragmentActivity) view.getContext(); AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(icon, title, null, view, null); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?View?. * * @param icon * @param title * ? * @param view * ??? * @param onClickListener * ? */ public static AbAlertDialogFragment showAlertDialog(int icon, String title, View view, AbDialogOnClickListener onClickListener) { FragmentActivity activity = (FragmentActivity) view.getContext(); AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(icon, title, null, view, onClickListener); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ???dialog View. * * @param title * ? * @param view * ??? */ public static AbAlertDialogFragment showAlertDialog(String title, View view) { FragmentActivity activity = (FragmentActivity) view.getContext(); AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(0, title, null, view, null); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ?View?. * * @param title * ? * @param view * ??? * @param onClickListener * ? */ public static AbAlertDialogFragment showAlertDialog(String title, View view, AbDialogOnClickListener onClickListener) { FragmentActivity activity = (FragmentActivity) view.getContext(); AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(0, title, null, view, onClickListener); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ???dialog String. * * @param context * @param title * ? * @param * */ public static AbAlertDialogFragment showAlertDialog(Context context, String title, String message) { FragmentActivity activity = (FragmentActivity) context; AbAlertDialogFragment newFragment = AbAlertDialogFragment.newInstance(0, title, message, null, null); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??.zz * * @param context * the context * @param indeterminateDrawable * 0 * @param message * the message */ public static AbProgressDialogFragment showProgressDialog(Context context, int indeterminateDrawable, String message) { FragmentActivity activity = (FragmentActivity) context; AbProgressDialogFragment newFragment = AbProgressDialogFragment.newInstance(indeterminateDrawable, message); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??. * * @param context * the context * @param indeterminateDrawable * 0 * @param message * the message */ public static AbProgressDialogFragment2 showProgressDialog2(Context context, int indeterminateDrawable, String message) { FragmentActivity activity = (FragmentActivity) context; AbProgressDialogFragment2 newFragment = AbProgressDialogFragment2.newInstance(indeterminateDrawable, message); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??. * * @param context * the context * @param indeterminateDrawable * @param message * the message */ public static AbLoadDialogFragment showLoadDialog(Context context, int indeterminateDrawable, String message) { FragmentActivity activity = (FragmentActivity) context; AbLoadDialogFragment newFragment = AbLoadDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog); newFragment.setIndeterminateDrawable(indeterminateDrawable); newFragment.setMessage(message); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??. * * @param context * the context * @param indeterminateDrawable * @param message * the message */ public static AbLoadDialogFragment showLoadDialog(Context context, int indeterminateDrawable, String message, AbDialogOnLoadListener abDialogOnLoadListener) { FragmentActivity activity = (FragmentActivity) context; AbLoadDialogFragment newFragment = AbLoadDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog); newFragment.setIndeterminateDrawable(indeterminateDrawable); newFragment.setMessage(message); newFragment.setAbDialogOnLoadListener(abDialogOnLoadListener); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??. * * @param context * the context * @param indeterminateDrawable * @param message * the message */ public static AbLoadDialogFragment showLoadPanel(Context context, int indeterminateDrawable, String message) { FragmentActivity activity = (FragmentActivity) context; AbLoadDialogFragment newFragment = AbLoadDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Light_Panel); newFragment.setIndeterminateDrawable(indeterminateDrawable); newFragment.setMessage(message); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??. * * @param context * the context * @param indeterminateDrawable * @param message * the message * @param */ public static AbLoadDialogFragment showLoadPanel(Context context, int indeterminateDrawable, String message, AbDialogOnLoadListener abDialogOnLoadListener) { FragmentActivity activity = (FragmentActivity) context; AbLoadDialogFragment newFragment = AbLoadDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Light_Panel); newFragment.setIndeterminateDrawable(indeterminateDrawable); newFragment.setMessage(message); newFragment.setAbDialogOnLoadListener(abDialogOnLoadListener); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??. * * @param context * the context * @param indeterminateDrawable * @param message * the message * @param */ public static AbRefreshDialogFragment showRefreshDialog(Context context, int indeterminateDrawable, String message) { FragmentActivity activity = (FragmentActivity) context; AbRefreshDialogFragment newFragment = AbRefreshDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog); newFragment.setIndeterminateDrawable(indeterminateDrawable); newFragment.setMessage(message); newFragment.setAbDialogOnLoadListener(null); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??. * * @param context * @param indeterminateDrawable * @param message * @param * @return */ public static AbRefreshDialogFragment showRefreshDialog(Context context, int indeterminateDrawable, String message, AbDialogOnLoadListener abDialogOnLoadListener) { FragmentActivity activity = (FragmentActivity) context; AbRefreshDialogFragment newFragment = AbRefreshDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog); newFragment.setIndeterminateDrawable(indeterminateDrawable); newFragment.setMessage(message); newFragment.setAbDialogOnLoadListener(abDialogOnLoadListener); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??. * * @param context * the context * @param indeterminateDrawable * @param message * the message */ public static AbRefreshDialogFragment showRefreshPanel(Context context, int indeterminateDrawable, String message) { FragmentActivity activity = (FragmentActivity) context; AbRefreshDialogFragment newFragment = AbRefreshDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Light_Panel); newFragment.setIndeterminateDrawable(indeterminateDrawable); newFragment.setMessage(message); newFragment.setAbDialogOnLoadListener(null); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??. * * @param context * @param indeterminateDrawable * @param message * @param * @return */ public static AbRefreshDialogFragment showRefreshPanel(Context context, int indeterminateDrawable, String message, AbDialogOnLoadListener abDialogOnLoadListener) { FragmentActivity activity = (FragmentActivity) context; AbRefreshDialogFragment newFragment = AbRefreshDialogFragment.newInstance(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Light_Panel); newFragment.setIndeterminateDrawable(indeterminateDrawable); newFragment.setMessage(message); newFragment.setAbDialogOnLoadListener(abDialogOnLoadListener); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); newFragment.show(ft, mDialogTag); return newFragment; } /** * ??Fragment. * * @param context * the context */ public static void removeDialog(Context context) { try { FragmentActivity activity = (FragmentActivity) context; FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE); Fragment prev = activity.getFragmentManager().findFragmentByTag(mDialogTag); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); if (context != null) { ft.commit(); } } catch (Exception e) { // ?Activity?? e.printStackTrace(); } } /** * ??FragmentView * * @param view */ public static void removeDialog(View view) { removeDialog(view.getContext()); AbViewUtil.removeSelfFromParent(view); } /** * ? * * @param content * * @param * * @param * * @return sweetAlertDialog */ public static SweetAlertDialog showBasicDialog(Context context, String content) { SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(context); sweetAlertDialog.setContentText(content); sweetAlertDialog.show(); return sweetAlertDialog; } /** * ?dialog * * @param title * * @param content * * @param butText * button * @return */ public static SweetAlertDialog showErroDialog(Context context, String title, String content, String butText, OnSweetClickListener onSweetClickListener) { SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(context, SweetAlertDialog.ERROR_TYPE); sweetAlertDialog.setContentText(AbStrUtil.parseEmpty(content)); sweetAlertDialog.setTitleText(AbStrUtil.parseEmpty(title)); sweetAlertDialog.setConfirmText(AbStrUtil.parseEmpty(butText)); sweetAlertDialog.setConfirmClickListener(onSweetClickListener); sweetAlertDialog.show(); return sweetAlertDialog; } /** * ??dialog * * @param title * @param content * @param butText * @return */ public static SweetAlertDialog showSuccessDialog(Context context, String title, String content, String butText) { SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(context, SweetAlertDialog.SUCCESS_TYPE); sweetAlertDialog.setContentText(AbStrUtil.parseEmpty(content)); sweetAlertDialog.setTitleText(AbStrUtil.parseEmpty(title)); sweetAlertDialog.setConfirmText(AbStrUtil.parseEmpty(butText)); sweetAlertDialog.show(); return sweetAlertDialog; } /** * ??dialog * * @param title * @param content * @param butText * @return */ public SweetAlertDialog showSuccessDialog2(Context context, String title, String content, String butText, OnSweetClickListener onClickListener) { SweetAlertDialog showSuccessDialog = showSuccessDialog(context, title, content, butText); showSuccessDialog.setConfirmClickListener(onClickListener); return showSuccessDialog; } /** * ?? * * @param title * @param content * @param * @return */ public SweetAlertDialog showWarningDialog(Context context, String title, String content, String confirmButText, OnSweetClickListener onSweetClickListener) { SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE); sweetAlertDialog.setContentText(AbStrUtil.parseEmpty(content)); sweetAlertDialog.setTitleText(AbStrUtil.parseEmpty(title)); sweetAlertDialog.setConfirmText(AbStrUtil.parseEmpty(confirmButText)); sweetAlertDialog.setConfirmClickListener(onSweetClickListener); sweetAlertDialog.show(); return sweetAlertDialog; } /** * ??2 * * @param title * * @param content * * @param confirmButText * * @param onConfirmListener * ? * @param onCancleListener * ?? * @return */ public static SweetAlertDialog showWarningDialog2(Context context, String title, String content, String confirmButText, OnSweetClickListener onConfirmListener, String cancelConent, OnSweetClickListener onCancleListener) { SweetAlertDialog sweetAlertDialog = new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE); sweetAlertDialog.setContentText(AbStrUtil.parseEmpty(content)); sweetAlertDialog.setTitleText(AbStrUtil.parseEmpty(title)); sweetAlertDialog.setConfirmText(AbStrUtil.parseEmpty(confirmButText)); sweetAlertDialog.setConfirmClickListener(onConfirmListener); sweetAlertDialog.showCancelButton(true); sweetAlertDialog.setCancelText(AbStrUtil.parseEmpty(cancelConent)); sweetAlertDialog.setCancelClickListener(onCancleListener); sweetAlertDialog.show(); return sweetAlertDialog; } /** * progressDialog * * @param context * @param msg * @return */ public static Dialog createLoadingDialog(Context context, String msg) { LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(R.layout.herily_alertex_dialog_custom_frame_layout, null);// view ProgressWheel spaceshipImage = (ProgressWheel) v.findViewById(R.id.customFrameLoadImg); spaceshipImage.stopSpinning(); spaceshipImage.startSpinning(); TextView tipTextView = (TextView) v.findViewById(R.id.customFrameMsg);// ?? tipTextView.setText(msg);// ? Dialog loadingDialog = new Dialog(context, R.style.loading_dialog);// ?dialog loadingDialog.setCancelable(false);// ???? loadingDialog.setContentView(v, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));// return loadingDialog; } /** * popupwindow */ public static PopupWindow showPopWindow(Context context, View targetView, View contentView, Integer width) { PopupWindow popupWindow = null; popupWindow = new PopupWindow(contentView, -2, -2); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE)); if (width != null) { popupWindow.setWidth(width); } popupWindow.setOutsideTouchable(true); popupWindow.showAsDropDown(targetView); return popupWindow; } /** * popupwindow */ public static PopupWindow showPopWindow2(Context context, View targetView, View contentView, Integer width) { PopupWindow popupWindow = null; popupWindow = new PopupWindow(contentView, -2, -2); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE)); if (width != null) { popupWindow.setWidth(width); } popupWindow.setOutsideTouchable(true); popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0); return popupWindow; } /** * popupwindow */ public static PopupWindow showPopWindow3(Context context, View targetView, View contentView, Integer width) { PopupWindow popupWindow = null; popupWindow = new PopupWindow(contentView, -2, -2); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE)); if (width != null) { popupWindow.setWidth(width); } popupWindow.setOutsideTouchable(true); popupWindow.showAtLocation(targetView, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0); return popupWindow; } /** * popup */ // ? public static String[] yearArrayString = null; public static String[] dayArrayString = null; public static String[] monthArrayString = null; public static String[] hourArrayString = null; public static String[] minuteArrayString = null; public static Calendar c = null; private static WheelView yearWV = null; private static WheelView monthWV = null; private static WheelView dayWV = null; private static WheelView hourWV = null; private static WheelView minuteWV = null; public static MyPop showDatePopWindow(Context context, View contentView, View targetView) { // yearArrayString = getYEARArray(2016, 30); monthArrayString = getDayArray(12); hourArrayString = getHMArray(24); minuteArrayString = getHMArray(60); // ?? c = Calendar.getInstance(); PopupWindow popupWindow = new PopupWindow(contentView, -2, -2); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE)); popupWindow.setWidth(context.getResources().getDisplayMetrics().widthPixels); popupWindow.setOutsideTouchable(true); popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0); yearWV = (WheelView) contentView.findViewById(R.id.time_year); monthWV = (WheelView) contentView.findViewById(R.id.time_month); dayWV = (WheelView) contentView.findViewById(R.id.time_day); hourWV = (WheelView) contentView.findViewById(R.id.time_hour); minuteWV = (WheelView) contentView.findViewById(R.id.time_minute); // ? yearWV.setVisibleItems(5); monthWV.setVisibleItems(5); dayWV.setVisibleItems(5); hourWV.setVisibleItems(5); minuteWV.setVisibleItems(5); // yearWV.setLabel(""); monthWV.setLabel(""); dayWV.setLabel(""); hourWV.setLabel(""); minuteWV.setLabel(""); yearWV.setCyclic(true); monthWV.setCyclic(true); dayWV.setCyclic(true); hourWV.setCyclic(true); minuteWV.setCyclic(true); setData(); return new MyPop(popupWindow, yearWV, monthWV, dayWV, hourWV, minuteWV); } /** * */ public static MyPop showDatePopWindowDate(Context context, View contentView, View targetView) { // yearArrayString = getYEARArray(2016, 36); monthArrayString = getDayArray(12); hourArrayString = getHMArray(24); minuteArrayString = getHMArray(60); // ?? c = Calendar.getInstance(); PopupWindow popupWindow = new PopupWindow(contentView, -2, -2); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.BLACK)); popupWindow.setWidth(context.getResources().getDisplayMetrics().widthPixels); popupWindow.setOutsideTouchable(true); popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0); yearWV = (WheelView) contentView.findViewById(R.id.time_year); monthWV = (WheelView) contentView.findViewById(R.id.time_month); dayWV = (WheelView) contentView.findViewById(R.id.time_day); hourWV = (WheelView) contentView.findViewById(R.id.time_hour); minuteWV = (WheelView) contentView.findViewById(R.id.time_minute); hourWV.setVisibility(View.GONE); minuteWV.setVisibility(View.GONE); // ? yearWV.setVisibleItems(5); monthWV.setVisibleItems(5); dayWV.setVisibleItems(5); hourWV.setVisibleItems(5); minuteWV.setVisibleItems(5); // yearWV.setLabel(""); monthWV.setLabel(""); dayWV.setLabel(""); hourWV.setLabel(""); minuteWV.setLabel(""); yearWV.setCyclic(true); monthWV.setCyclic(true); dayWV.setCyclic(true); hourWV.setCyclic(true); minuteWV.setCyclic(true); setData(); return new MyPop(popupWindow, yearWV, monthWV, dayWV, hourWV, minuteWV); } /** * */ public static MyPop showDatePopWindowHour(Context context, View contentView, View targetView) { // hourArrayString = getHMArray(24); // ?? c = Calendar.getInstance(); PopupWindow popupWindow = new PopupWindow(contentView, -2, -2); popupWindow.setBackgroundDrawable(new ColorDrawable(Color.BLACK)); popupWindow.setWidth(context.getResources().getDisplayMetrics().widthPixels); popupWindow.setOutsideTouchable(true); popupWindow.showAtLocation(targetView, Gravity.BOTTOM, 0, 0); hourWV = (WheelView) contentView.findViewById(R.id.time_hour); // ? hourWV.setVisibleItems(5); // hourWV.setLabel(":00"); hourWV.setCyclic(true); setHourData(); return new MyPop(popupWindow, yearWV, monthWV, dayWV, hourWV, minuteWV); } /** * ??? */ private static void setHourData() { // ??? hourWV.setAdapter(new ArrayWheelAdapter<String>(hourArrayString)); // ? setOriHourTime(); } /** * ??? */ private static void setData() { // ??? yearWV.setAdapter(new ArrayWheelAdapter<String>(yearArrayString)); monthWV.setAdapter(new ArrayWheelAdapter<String>(monthArrayString)); hourWV.setAdapter(new ArrayWheelAdapter<String>(hourArrayString)); minuteWV.setAdapter(new ArrayWheelAdapter<String>(minuteArrayString)); yearWV.addChangingListener(new OnWheelChangedListener() { @Override public void onChanged(WheelView wheel, int oldValue, int newValue) { // TODO Auto-generated method stub // ? int year = Integer.parseInt(yearArrayString[yearWV.getCurrentItem()]); int month = Integer.parseInt(monthArrayString[monthWV.getCurrentItem()]); // ?? dayArrayString = getDayArray(getDay(year, month)); // ? dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString)); // if (dayWV.getCurrentItem() >= dayArrayString.length) { dayWV.setCurrentItem(dayArrayString.length - 1); } } }); // ? monthWV.addChangingListener(new OnWheelChangedListener() { @Override public void onChanged(WheelView wheel, int oldValue, int newValue) { // TODO Auto-generated method stub // ? int year = Integer.parseInt(yearArrayString[yearWV.getCurrentItem()]); int month = Integer.parseInt(monthArrayString[monthWV.getCurrentItem()]); // ?? dayArrayString = getDayArray(getDay(year, month)); // ? dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString)); // if (dayWV.getCurrentItem() >= dayArrayString.length) { dayWV.setCurrentItem(dayArrayString.length - 1); } } }); // ? setOriTime(); } public static ChoiceDate date; // public static ChoiceDate showDate() { ChoiceDate choiceDate = new ChoiceDate(yearArrayString[yearWV.getCurrentItem()], monthArrayString[monthWV.getCurrentItem()], dayArrayString[dayWV.getCurrentItem()], hourArrayString[hourWV.getCurrentItem()], minuteArrayString[minuteWV.getCurrentItem()]); return choiceDate; } // public static ChoiceDate showDateHour() { ChoiceDate choiceDate = new ChoiceDate("", "", "", hourArrayString[hourWV.getCurrentItem()], ""); return choiceDate; } // ? public static void setOriTime() { yearWV.setCurrentItem(getNumData(c.get(Calendar.YEAR) + "", yearArrayString)); int month = c.get(Calendar.MONTH) + 1; String strMonth = ""; if (month < 10) { strMonth = "0" + month; } else { strMonth = "" + month; } monthWV.setCurrentItem(getNumData(strMonth, monthArrayString) + 0); int hour = c.get(Calendar.HOUR_OF_DAY); String strHour; if (hour < 10) { strHour = "0" + hour; } else { strHour = "" + hour; } hourWV.setCurrentItem(getNumData(strHour, hourArrayString)); int minute = c.get(Calendar.MINUTE); String strMinute; if (minute < 10) { strMinute = "0" + minute; } else { strMinute = "" + minute; } minuteWV.setCurrentItem(getNumData(strMinute, minuteArrayString)); dayArrayString = getDayArray(getDay(c.get(Calendar.YEAR), c.get(Calendar.MONTH))); dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString)); int day = c.get(Calendar.DAY_OF_MONTH); String strDay = ""; if (day < 10) { strDay = "0" + day; } else { strDay = "" + day; } dayWV.setCurrentItem(getNumData(strDay, dayArrayString)); } // ? public static void setOriHourTime() { hourWV.setCurrentItem(getNumData(c.get(Calendar.HOUR_OF_DAY) + "", hourArrayString)); } // Array[]s? public static int getNumData(String s, String[] Array) { int num = 0; for (int i = 0; i < Array.length; i++) { if (s.equals(Array[i])) { num = i; break; } } return num; } // ?? public static int getDay(int year, int month) { int day; if (year % 4 == 0 && year % 100 != 0) { // if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { day = 31; } else if (month == 2) { day = 29; } else { day = 30; } } else { // if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { day = 31; } else if (month == 2) { day = 28; } else { day = 30; } } return day; } // ?? public static String[] getDayArray(int day) { String[] dayArr = new String[day]; for (int i = 0; i < day; i++) { int flag = i + 1; if (flag < 10) { dayArr[i] = "0" + (i + 1); } else { dayArr[i] = "" + (i + 1); } } return dayArr; } // ?? public static String[] getHMArray(int day) { String[] dayArr = new String[day]; for (int i = 0; i < day; i++) { if (i < 10) { dayArr[i] = "0" + (i); } else { dayArr[i] = "" + (i); } } return dayArr; } // ??startstepstartstart+step-1 public static String[] getYEARArray(int start, int step) { String[] dayArr = new String[step]; for (int i = 0; i < step; i++) { dayArr[i] = start + i + ""; } return dayArr; } public static class MyPop { private WheelView yearWV; private WheelView monthWV; private WheelView dayWV; private WheelView hourWV; private WheelView minuteWV; private PopupWindow popupWindow; public MyPop(PopupWindow popupWindow, WheelView yearWV, WheelView monthWV, WheelView dayWV, WheelView hourWV, WheelView minuteWV) { super(); this.yearWV = yearWV; this.monthWV = monthWV; this.dayWV = dayWV; this.hourWV = hourWV; this.minuteWV = minuteWV; this.popupWindow = popupWindow; } public WheelView getYearWV() { return yearWV; } public void setYearWV(WheelView yearWV) { this.yearWV = yearWV; } public WheelView getMonthWV() { return monthWV; } public void setMonthWV(WheelView monthWV) { this.monthWV = monthWV; } public WheelView getDayWV() { return dayWV; } public void setDayWV(WheelView dayWV) { this.dayWV = dayWV; } public WheelView getHourWV() { return hourWV; } public void setHourWV(WheelView hourWV) { this.hourWV = hourWV; } public WheelView getMinuteWV() { return minuteWV; } public void setMinuteWV(WheelView minuteWV) { this.minuteWV = minuteWV; } public PopupWindow getPopupWindow() { return popupWindow; } public void setPopupWindow(PopupWindow popupWindow) { this.popupWindow = popupWindow; } } /** * AlertDialog ?? */ public static AlertDialog getAlertDialogWithoutRemove(Context mContext, int layout, double showWidth) { final AlertDialog alerDialog = new AlertDialog.Builder(mContext).create(); alerDialog.show(); alerDialog.setCanceledOnTouchOutside(true); Window window = alerDialog.getWindow(); // ?? int height = ScreenUtils.getScreenHeight(mContext); int width = ScreenUtils.getScreenWidth(mContext); WindowManager.LayoutParams params = window.getAttributes(); params.width = (int) (width * showWidth); params.gravity = Gravity.CENTER_HORIZONTAL; alerDialog.onWindowAttributesChanged(params); window.setContentView(layout); return alerDialog; } public static LoadingDialog showLodingDialog(Context mContext) { LoadingDialog LoadingDialog = new LoadingDialog(mContext, R.style.AlertDialogStyle); return LoadingDialog; } /** * ? */ public static OptionsPickerView getCityOptionsPicker(Context context, List<CityBean> mCitys) { OptionsPickerView mAdressOptions = new OptionsPickerView(context); mAdressOptions.setCancelable(true); ArrayList<String> province = new ArrayList<String>(mCitys.size());// ? ArrayList<ArrayList<String>> cityList = new ArrayList<ArrayList<String>>();// ArrayList<ArrayList<ArrayList<String>>> areaList = new ArrayList<ArrayList<ArrayList<String>>>();// for (int i = 0; i < mCitys.size(); i++) { if (mCitys.get(i).getN().length() > 4) { province.add(mCitys.get(i).getN().substring(0, 3) + "..");// ? } else { province.add(mCitys.get(i).getN());// ? } ArrayList<String> list = new ArrayList<String>();// ? ArrayList<ArrayList<String>> list2 = new ArrayList<ArrayList<String>>();// for (int j = 0; j < mCitys.get(i).getC().size(); j++) { if (mCitys.get(i).getC().get(j).getN().length() > 4) { list.add(mCitys.get(i).getC().get(j).getN().substring(0, 3) + ".."); } else { list.add(mCitys.get(i).getC().get(j).getN()); } ArrayList<String> list3 = new ArrayList<String>(); for (int j2 = 0; j2 < mCitys.get(i).getC().get(j).getD().size(); j2++) { if (mCitys.get(i).getC().get(j).getD().get(j2).getN().length() > 4) { list3.add(mCitys.get(i).getC().get(j).getD().get(j2).getN().substring(0, 3) + ".."); } else { list3.add(mCitys.get(i).getC().get(j).getD().get(j2).getN()); } } list2.add(list3); } areaList.add(list2); cityList.add(list); } mAdressOptions.setPicker(province, cityList, areaList, true); mAdressOptions.setTitle("?"); mAdressOptions.setCyclic(false, false, false); mAdressOptions.setSelectOptions(0); return mAdressOptions; } }