Esempio n. 1
0
  /**
   * @param context Context.
   * @param title The title of this AlertDialog can be null .
   * @param items button name list.
   * @param alertDo methods call Id:Button + cancel_Button.
   * @param exit Name can be null.It will be Red Color
   * @return A AlertDialog
   */
  public static Dialog showAlert(
      final Context context,
      final String title,
      final String[] items,
      String exit,
      final OnAlertSelectId alertDo,
      OnCancelListener cancelListener) {
    String cancel = context.getString(R.string.app_cancel);
    final Dialog dlg = new Dialog(context, R.style.MMTheme_DataSheet);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.alert_dialog_menu_layout, null);
    final int cFullFillWidth = 10000;
    layout.setMinimumWidth(cFullFillWidth);
    final ListView list = (ListView) layout.findViewById(R.id.content_list);
    AlertAdapter adapter = new AlertAdapter(context, title, items, exit, cancel);
    list.setAdapter(adapter);
    list.setDividerHeight(0);

    list.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!(title == null || title.equals("")) && position - 1 >= 0) {
              alertDo.onClick(position - 1);
              dlg.dismiss();
              list.requestFocus();
            } else {
              alertDo.onClick(position);
              dlg.dismiss();
              list.requestFocus();
            }
          }
        });
    // set a large value put it in bottom
    Window w = dlg.getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    lp.x = 0;
    final int cMakeBottom = -1000;
    lp.y = cMakeBottom;
    lp.gravity = Gravity.BOTTOM;
    dlg.onWindowAttributesChanged(lp);
    dlg.setCanceledOnTouchOutside(true);
    if (cancelListener != null) {
      dlg.setOnCancelListener(cancelListener);
    }
    dlg.setContentView(layout);
    dlg.show();
    return dlg;
  }
  public static Dialog createCustomDialog(
      Context context, List<IphoneDialogItem> items, int style) {
    LinearLayout dialogView =
        (LinearLayout) LayoutInflater.from(context).inflate(R.layout.iphone_dialog_layout, null);
    final Dialog customDialog = new Dialog(context, style);
    LinearLayout itemView;
    TextView textView;
    for (IphoneDialogItem item : items) {
      itemView = (LinearLayout) LayoutInflater.from(context).inflate(item.getViewId(), null);
      textView = (TextView) itemView.findViewById(R.id.popup_text);
      //			textView.setTypeface(CommonTypeface.getInstance(context));
      textView.setText(item.getText());
      textView.setOnClickListener(new IphoneDialogOnItemClick(item, customDialog));
      dialogView.addView(itemView);
    }

    WindowManager.LayoutParams localLayoutParams = customDialog.getWindow().getAttributes();
    localLayoutParams.x = 0;
    localLayoutParams.y = -1000;
    localLayoutParams.gravity = 80;
    dialogView.setMinimumWidth(10000);

    customDialog.onWindowAttributesChanged(localLayoutParams);
    customDialog.setCanceledOnTouchOutside(true);
    customDialog.setCancelable(true);
    customDialog.setContentView(dialogView);

    if (context instanceof Activity) {
      Activity activity = (Activity) context;
      if (!activity.isFinishing()) {
        customDialog.show();
      }
    }

    return customDialog;
  }
Esempio n. 3
0
  /** 底部弹出的九宫格 */
  public static Dialog showNiceAler(
      final Context context,
      final String buttonTitle,
      final List<GridViewMenuItem> list,
      final int width,
      final OnAlertSelectId alertDo,
      OnCancelListener cancelListener) {
    final Dialog dlg = new Dialog(context, R.style.MMThem_DataSheet);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final LinearLayout layout =
        (LinearLayout) inflater.inflate(R.layout.bottom_gridview_menu, null);
    LinearLayout parentLayout = (LinearLayout) layout.findViewById(R.id.control);

    final int cFullFillWidth = 10000;
    layout.setMinimumWidth(cFullFillWidth);

    int count = list.size() % 3 == 0 ? list.size() / 3 : list.size() / 3 + 1;
    int index = 0;
    for (int i = 0; i < count; i++) {
      LinearLayout childLayout = new LinearLayout(context);
      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
      childLayout.setLayoutParams(params);
      childLayout.setOrientation(LinearLayout.HORIZONTAL);

      for (int j = index; j < list.size(); j++) {
        LinearLayout view = (LinearLayout) inflater.inflate(R.layout.gridview_menu_item, null);
        LinearLayout.LayoutParams itemParams = new LayoutParams(width, LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(itemParams);

        ImageView menuIcon = (ImageView) view.findViewById(R.id.menu_icon);
        menuIcon.setImageResource(list.get(j).resource_id);
        TextView menuText = (TextView) view.findViewById(R.id.menu_text);
        menuText.setText(list.get(j).menu_name);
        childLayout.addView(view);

        final int id = j;
        view.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                alertDo.onClick(id);
                dlg.dismiss();
                layout.requestFocus();
              }
            });

        if ((j + 1) % 3 == 0) {
          index = j;
          break;
        }
      }
      parentLayout.addView(childLayout);
    }

    final TextView cancleBtn = (TextView) layout.findViewById(R.id.popup_text);
    cancleBtn.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // alertDo.onClick(v.getId());
            dlg.dismiss();
            cancleBtn.requestFocus();
          }
        });

    // set a large value put it in bottom
    Window w = dlg.getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    lp.x = 0;
    final int cMakeBottom = -100 /*0*/;
    lp.y = cMakeBottom;
    lp.gravity = Gravity.BOTTOM;
    dlg.onWindowAttributesChanged(lp);
    dlg.setCanceledOnTouchOutside(true);
    if (cancelListener != null) dlg.setOnCancelListener(cancelListener);

    dlg.setContentView(layout);
    dlg.show();

    return dlg;
  }
  /**
   * @param context
   * @param actionSheetSelected
   * @param cancelListener
   * @param type 1.上传照片 2.预览下载
   * @return
   */
  public static Dialog showSheet(
      Context context,
      final OnActionSheetSelected actionSheetSelected,
      OnCancelListener cancelListener,
      String type) {
    final Dialog dlg = new Dialog(context, R.style.ActionSheet);
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.actionsharesheet, null);
    final int cFullFillWidth = 10000;
    layout.setMinimumWidth(cFullFillWidth);

    final TextView savepic_tv = (TextView) layout.findViewById(R.id.savepic_tv);
    final TextView share_tv = (TextView) layout.findViewById(R.id.share_tv);
    final TextView cancel = (TextView) layout.findViewById(R.id.cancel);
    savepic_tv.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            // 拍照
            actionSheetSelected.onClick(1);
            dlg.dismiss();
          }
        });

    share_tv.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            // 选择本地照片
            actionSheetSelected.onClick(2);
            dlg.dismiss();
          }
        });

    cancel.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            dlg.dismiss();
          }
        });

    Window w = dlg.getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    lp.x = 0;
    final int cMakeBottom = -1000;
    lp.y = cMakeBottom;
    lp.gravity = Gravity.BOTTOM;
    dlg.onWindowAttributesChanged(lp);
    dlg.setCanceledOnTouchOutside(true);
    if (cancelListener != null) dlg.setOnCancelListener(cancelListener);

    dlg.setContentView(layout);
    dlg.show();

    return dlg;
  }