public static void a(LinearLayout paramLinearLayout) {
   Display localDisplay =
       ((WindowManager) paramLinearLayout.getContext().getSystemService("window"))
           .getDefaultDisplay();
   paramLinearLayout.setMinimumWidth(localDisplay.getWidth() - 30);
   paramLinearLayout.setMinimumHeight(localDisplay.getHeight() - 40);
 }
Example #2
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;
  }
  private void resizeLayout() {
    // This sets the minimum width of the activity to a minimum of 80% of the screen
    // size only needed because the theme of this activity is "dialog" so it looks
    // like it's floating and doesn't seem to fill_parent like a regular activity
    if (mainLL == null) {
      mainLL = (LinearLayout) findViewById(R.id.MainLinearLayout);
    }
    Display d = getWindowManager().getDefaultDisplay();

    int width = d.getWidth() > MAX_WIDTH ? MAX_WIDTH : (int) (d.getWidth() * WIDTH);

    mainLL.setMinimumWidth(width);
    mainLL.invalidate();
  }
Example #4
0
 @Override
 protected void onPrepareDialogBuilder(Builder builder) {
   LinearLayout layout = new LinearLayout(context);
   layout.setLayoutParams(
       new LinearLayout.LayoutParams(
           LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
   layout.setMinimumWidth(200);
   TextView tv = new TextView(context);
   tv.setText("Press a key!");
   layout.addView(tv);
   builder.setView(layout);
   builder.setOnKeyListener(this);
   super.onPrepareDialogBuilder(builder);
 }
  public MaterialDialogAlert(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    this.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    contentView = new LinearLayout(this.getContext());
    contentView.setMinimumWidth(DIALOG_MIN_WIDTH);
    contentView.setBackgroundResource(R.drawable.rectangle_rounded_angle_white_bg);
    contentView.setGravity(Gravity.TOP | Gravity.CENTER);
    contentView.setOrientation(LinearLayout.VERTICAL);
    // contentView.setPadding(UnitConversion.dip2px(context, 1), UnitConversion.dip2px(context, 1),
    // UnitConversion.dip2px(context, 1), UnitConversion.dip2px(context, 1));
    createView();
  }
  private void setPreviewColor(int Color, int Width, int ColorShadow, double ShadowRadius) {
    if (mView == null) return;

    ImageView iView = new ImageView(getContext());
    LinearLayout widgetFrameView = ((LinearLayout) mView.findViewById(android.R.id.widget_frame));
    if (widgetFrameView == null) return;
    widgetFrameView.setVisibility(View.VISIBLE);
    int count = widgetFrameView.getChildCount();
    if (count > 0) {
      widgetFrameView.removeViews(0, count);
    }
    widgetFrameView.addView(iView);
    widgetFrameView.setMinimumWidth(0);

    final Drawable dr = new TrackStyleDrawable(Color, Width, ColorShadow, ShadowRadius);
    final Drawable[] d = {getContext().getResources().getDrawable(R.drawable.track_background), dr};
    LayerDrawable ld = new LayerDrawable(d);
    iView.setBackgroundDrawable(ld);
  }
  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;
  }
Example #8
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;
  }
  @SuppressWarnings("deprecation")
  private View generateView() {
    LinearLayout rootLayout = new LinearLayout(getContext());
    rootLayout.setOrientation(LinearLayout.VERTICAL);
    rootLayout.setMinimumWidth(DimensionUtility.dp2px(260));

    GradientDrawable gradientDrawable =
        new GradientDrawable(
            GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] {Color.argb(0xCC, 0xFF, 0xFF, 0xFF), Color.argb(0xCC, 0xFF, 0xFF, 0xFF)});
    gradientDrawable.setCornerRadius(DimensionUtility.dp2px(6));
    gradientDrawable.setStroke(1, Color.parseColor("#CFFFFFFF"));

    rootLayout.setBackgroundDrawable(gradientDrawable);
    int padding = DimensionUtility.dp2px(8);
    rootLayout.setPadding(padding, padding, padding, padding);

    titleLabel = new TextView(getContext());
    titleLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    titleLabel.setGravity(Gravity.CENTER);
    titleLabel.setTextColor(Color.parseColor("#333333"));

    LinearLayout.LayoutParams titleParams =
        new LinearLayout.LayoutParams(fillParent(), wrapContent());
    rootLayout.addView(titleLabel, titleParams);

    messageLabel = new TextView(getContext());
    messageLabel.setTextColor(Color.parseColor("#333333"));
    messageLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    messageLabel.setGravity(Gravity.CENTER);
    LinearLayout.LayoutParams messageParams =
        new LinearLayout.LayoutParams(fillParent(), wrapContent());
    messageParams.topMargin = DimensionUtility.dp2px(10);
    rootLayout.addView(messageLabel, messageParams);

    text = new EditText(getContext());
    text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    text.setInputType(InputType.TYPE_CLASS_TEXT);
    LinearLayout.LayoutParams textParams =
        new LinearLayout.LayoutParams(fillParent(), wrapContent());
    textParams.topMargin = DimensionUtility.dp2px(8);
    rootLayout.addView(text, textParams);

    LinearLayout container = new LinearLayout(getContext());
    container.setOrientation(LinearLayout.HORIZONTAL);
    container.setWeightSum(2);

    positiveButton = new Button(getContext());
    LinearLayout.LayoutParams positiveParams =
        new LinearLayout.LayoutParams(fillParent(), wrapContent());
    positiveParams.weight = 1;
    container.addView(positiveButton, positiveParams);

    negativeButton = new Button(getContext());
    LinearLayout.LayoutParams negativeParams =
        new LinearLayout.LayoutParams(fillParent(), wrapContent());
    negativeParams.weight = 1;
    container.addView(negativeButton, negativeParams);

    positiveButton.setOnClickListener(this);
    negativeButton.setOnClickListener(this);

    LinearLayout.LayoutParams ctrParams =
        new LinearLayout.LayoutParams(fillParent(), wrapContent());
    ctrParams.topMargin = DimensionUtility.dp2px(8);
    rootLayout.addView(container, ctrParams);

    return rootLayout;
  }
  private View setCurrentUserRow() {
    View header1 = getLayoutInflater().inflate(R.layout.leaderboarditem, null, false);
    header1
        .findViewById(R.id.alliance)
        .setVisibility(View.GONE); // alliance in user not implemented now

    TextView p = (TextView) header1.findViewById(R.id.position);
    p.setTextColor(Color.WHITE);
    p.setText(currentUser.position);
    TextView nickname = (TextView) header1.findViewById(R.id.nickname);
    nickname.setText(currentUser.name);
    TextView score = (TextView) header1.findViewById(R.id.score);

    NumberFormat nf = NumberFormat.getInstance(Locale.getDefault());
    String formattedScore = nf.format(Double.parseDouble(currentUser.score));

    if (currentUser.feed == null)
      score.setText(currentContext.getString(R.string.leadScore) + "\n" + formattedScore);
    else score.setText(currentUser.feed + ":\n" + formattedScore);

    header1.findViewById(R.id.image).setVisibility(LinearLayout.GONE);
    header1.findViewById(R.id.whiteline).setVisibility(LinearLayout.GONE);
    try {
      if (currentUser.imageUrl != null) {
        ImageView imageView = new ImageView(currentContext);
        imageView.setTag(currentUser.imageUrl);
        int size = (int) (50 * currentContext.getResources().getDisplayMetrics().density + 0.5f);
        imageView.setLayoutParams(new LinearLayout.LayoutParams(size, size));
        imageManager.displayImage(currentUser.imageUrl, currentContext, imageView);

        LinearLayout a = (LinearLayout) header1.findViewById(R.id.item);
        a.addView(imageView, 0);
      } else {
        header1
            .findViewById(R.id.item)
            .setPadding((int) (ratio * 5), (int) (ratio * 5), 0, (int) (ratio * 5));
      }
    } catch (Exception e) {
    }

    LinearLayout positionView = (LinearLayout) header1.findViewById(R.id.post);
    LinearLayout.LayoutParams params =
        new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, (int) (ratio * 35));
    params.setMargins(0, 0, (int) (ratio * 10), 0);
    positionView.setLayoutParams(params);
    positionView.setPadding((int) (ratio * 5), 0, (int) (ratio * 5), 0);
    positionView.setMinimumHeight((int) (ratio * 35));
    positionView.setMinimumWidth((int) (ratio * 35));

    positionView.setBackgroundDrawable(
        new BDrawableGradient(0, (int) (ratio * 35), BDrawableGradient.HIGH_GRAY_GRADIENT));
    header1
        .findViewById(R.id.item)
        .setBackgroundDrawable(
            new BDrawableGradient(0, (int) (ratio * 60), BDrawableGradient.LIGHT_GRAY_GRADIENT));

    LinearLayout spacer = (LinearLayout) header1.findViewById(R.id.space);
    spacer.setVisibility(LinearLayout.VISIBLE);

    return header1;
  }