Example usage for android.widget LinearLayout setGravity

List of usage examples for android.widget LinearLayout setGravity

Introduction

In this page you can find the example usage for android.widget LinearLayout setGravity.

Prototype

@android.view.RemotableViewMethod
public void setGravity(int gravity) 

Source Link

Document

Describes how the child views are positioned.

Usage

From source file:net.opendasharchive.openarchive.ReviewMediaActivity.java

private void deleteMedia() {
    final Switch swDeleteLocal = new Switch(this);
    final Switch swDeleteRemote = new Switch(this);

    LinearLayout linearLayoutGroup = new LinearLayout(this);
    linearLayoutGroup.setOrientation(LinearLayout.VERTICAL);
    linearLayoutGroup.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    swDeleteLocal.setTextOn(getString(R.string.answer_yes));
    swDeleteLocal.setTextOff(getString(R.string.answer_no));

    TextView tvLocal = new TextView(this);
    tvLocal.setText(R.string.delete_local);

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);
    linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);

    linearLayout.addView(tvLocal);/*from   w ww  .  j  a  va  2 s .  c  om*/
    linearLayout.addView(swDeleteLocal);

    linearLayoutGroup.addView(linearLayout);

    if (mMedia.getServerUrl() != null) {
        swDeleteRemote.setTextOn(getString(R.string.answer_yes));
        swDeleteRemote.setTextOff(getString(R.string.answer_no));

        TextView tvRemote = new TextView(this);
        tvRemote.setText(R.string.delete_remote);

        LinearLayout linearLayoutRemote = new LinearLayout(this);
        linearLayoutRemote.setOrientation(LinearLayout.HORIZONTAL);
        linearLayoutRemote.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        linearLayoutRemote.setGravity(Gravity.CENTER_HORIZONTAL);

        linearLayoutRemote.addView(tvRemote);
        linearLayoutRemote.addView(swDeleteRemote);
        linearLayoutGroup.addView(linearLayoutRemote);

    }

    AlertDialog.Builder build = new AlertDialog.Builder(ReviewMediaActivity.this).setTitle(R.string.menu_delete)
            .setMessage(R.string.alert_delete_media).setView(linearLayoutGroup).setCancelable(true)
            .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    //do nothing
                }
            })

            .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    deleteMedia(swDeleteLocal.isChecked(), swDeleteRemote.isChecked());
                    finish();

                }
            });

    build.create().show();
}

From source file:self.philbrown.droidQuery.Example.ExampleActivity.java

/**
 * Refreshes the list of cells containing App.net messages. This <em>ListView</em> is actually
 * a <em>scrollable LinearLayout</em>, and is assembled in much the same way a layout would be
 * made using <em>JavaScript</em>, with the <em>CSS3</em> attribute <em>overscroll-y: scroll</em>.
 * <br>/*from w  ww .  j  ava2s.  c  o m*/
 * For this example, the public stream is retrieved using <em>ajax</em>, and for each message
 * received, a new cell is created. For each cell, a new <em>ajax</em> request is started to
 * retrieve the thumbnail image for the user. As all these events occur on a background thread, the
 * main ScrollView is populated with cells and displayed to the user.
 * <br>
 * The stream <em>JSON</em> request is performed in a <em>global ajax</em> request, which will
 * trigger the global start and stop events (which show a progress indicator, using a droidQuery
 * extension). The image get requests are not global, so they will not trigger global events.
 */
public void refresh() {
    $.ajax(new AjaxOptions().url("https://alpha-api.app.net/stream/0/posts/stream/global").dataType("json")
            .type("GET").error(new Function() {
                @Override
                public void invoke($ droidQuery, Object... params) {
                    //Object error, int status, String reason
                    Object error = params[0];
                    int status = (Integer) params[1];
                    String reason = (String) params[2];
                    Log.w("app.net Client", "Could not complete request: " + reason);
                }
            }).success(new Function() {
                @Override
                public void invoke($ droidQuery, Object... params) {
                    //Object, reason
                    JSONObject json = (JSONObject) params[0];
                    String reason = (String) params[1];
                    try {
                        Map<String, ?> map = $.map(json);
                        JSONArray datas = (JSONArray) map.get("data");

                        if (datas.length() != 0) {
                            //clear old subviews in layout
                            $.with(ExampleActivity.this, R.id.example_layout).selectChildren().remove();

                            //get each message infos and create a cell
                            for (int i = 0; i < datas.length(); i++) {
                                JSONObject jdata = (JSONObject) datas.get(i);
                                Map<String, ?> data = $.map(jdata);

                                String text = data.get("text").toString();

                                Map<String, ?> user = $.map((JSONObject) data.get("user"));

                                String username = user.get("username").toString();
                                String avatarURL = ((JSONObject) user.get("avatar_image")).getString("url");

                                //get Avatar image in a new task (but go ahead and create the cell for now)
                                LinearLayout cell = new LinearLayout(ExampleActivity.this);
                                LinearLayout.LayoutParams cell_params = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                cell_params.bottomMargin = 5;
                                cell.setLayoutParams(cell_params);
                                cell.setOrientation(LinearLayout.HORIZONTAL);
                                cell.setWeightSum(8);
                                cell.setPadding(5, 5, 5, 5);
                                cell.setBackgroundColor(Color.parseColor("#333333"));
                                final LinearLayout fcell = cell;

                                //contains the image location
                                ImageView image = new ImageView(ExampleActivity.this);
                                image.setId(99);
                                LinearLayout.LayoutParams ip_params = new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                ip_params.weight = 2;
                                image.setLayoutParams(ip_params);
                                image.setPadding(0, 0, 5, 0);
                                $.with(image).attr("alpha", 0.0f);
                                cell.addView(image);
                                final ImageView fimage = image;

                                //the text location in the cell
                                LinearLayout body = new LinearLayout(ExampleActivity.this);
                                LinearLayout.LayoutParams body_params = new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                body_params.weight = 5;
                                body.setLayoutParams(body_params);
                                body.setOrientation(LinearLayout.VERTICAL);
                                body.setGravity(Gravity.CENTER_VERTICAL);
                                cell.addView(body);

                                //the username
                                TextView name = new TextView(ExampleActivity.this);
                                LinearLayout.LayoutParams name_params = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.WRAP_CONTENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                name.setLayoutParams(name_params);
                                name.setTextColor(Color.GRAY);
                                name.setText(username);
                                body.addView(name);

                                //the message
                                TextView message = new TextView(ExampleActivity.this);
                                LinearLayout.LayoutParams msg_params = new LinearLayout.LayoutParams(
                                        LinearLayout.LayoutParams.WRAP_CONTENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                message.setLayoutParams(msg_params);
                                message.setTextColor(Color.WHITE);
                                message.setTextSize(18);
                                message.setText(text);
                                body.addView(message);

                                CheckBox checkbox = new CheckBox(ExampleActivity.this);
                                LinearLayout.LayoutParams box_params = new LinearLayout.LayoutParams(0,
                                        LinearLayout.LayoutParams.WRAP_CONTENT);
                                box_params.weight = 1;
                                checkbox.setLayoutParams(box_params);

                                cell.addView(checkbox);

                                $.with(ExampleActivity.this, R.id.example_layout).add(cell);
                                //$.with(fimage).image(avatarURL, 200, 200, $.noop());
                                $.ajax(new AjaxOptions(avatarURL).type("GET").dataType("image").imageHeight(200)
                                        .imageWidth(200).global(false).success(new Function() {
                                            @Override
                                            public void invoke($ droidQuery, Object... params) {
                                                //Object, reason
                                                Bitmap src = (Bitmap) params[0];
                                                String reason = (String) params[1];
                                                $.with(fimage).val(src);
                                                try {
                                                    $.with(fimage)
                                                            .fadeIn(new AnimationOptions("{ duration: 400 }"));
                                                } catch (Throwable e) {
                                                    e.printStackTrace();
                                                }
                                                LinearLayout.LayoutParams lparams = (LinearLayout.LayoutParams) fcell
                                                        .getLayoutParams();
                                                try {
                                                    lparams.height = Math.min(src.getWidth(),
                                                            fimage.getWidth());
                                                } catch (Throwable t) {
                                                    //ignore NPE
                                                }

                                                fcell.setLayoutParams(lparams);
                                            }
                                        }).error(new Function() {
                                            @Override
                                            public void invoke($ droidQuery, Object... params) {
                                                //Object error, int status, String reason
                                                Object error = params[0];
                                                int status = (Integer) params[1];
                                                String reason = (String) params[2];
                                                Log.w("app.net Client",
                                                        "Could not complete image request: " + reason);
                                            }
                                        }));

                            }
                        } else {
                            Log.w("app.net client", "could not update data");
                        }
                    } catch (Throwable t) {
                        t.printStackTrace();
                    }
                }
            }));
}

From source file:brostore.maquillage.custom.PagerSlidingTabStrip.java

private void addCustomTextTab(final int position, String title) {
    LinearLayout conteneur = new LinearLayout(getContext());
    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    conteneur.setOrientation(LinearLayout.HORIZONTAL);
    conteneur.setGravity(Gravity.CENTER);
    TextView tab = new TextView(getContext());
    TextView tabCust = new TextView(getContext());
    //tabCust.setBackgroundResource(R.drawable.live_nombre);
    tabCust.setGravity(Gravity.CENTER);// w  w  w .  j  av  a 2s. co  m
    tabCust.setTextColor(Color.WHITE);
    tabCust.setTypeface(tabTypeface);
    tabCust.setTextSize(11);
    tabCust.setVisibility(View.GONE);
    int fiveDip = Utils.convertDpToPixel(5, getResources());
    tabCust.setPadding(fiveDip, 0, fiveDip, 0);
    tabCust.setText("0");
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    conteneur.addView(tab, param);
    param.leftMargin = Utils.convertDpToPixel(10, getResources());
    conteneur.addView(tabCust, param);
    addTab(position, conteneur);
}

From source file:com.example.fragmentdemo.views.PagerSlidingTabStrip.java

private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId,
        int iIconLocation) {
    // final View tabView = ((Activity) getContext()).getLayoutInflater()
    // .inflate(iLayoutResId, null);
    // TextView tab_text_textview = (TextView)
    // tabView.findViewById(iTextId);
    // tab_text_textview.setText(title);
    LinearLayout tabView = new LinearLayout(getContext());
    tabView.setGravity(Gravity.CENTER);
    TextView tab_text_textview = new TextView(getContext());
    tab_text_textview.setId(position);//from  w  w w  .ja  v a  2  s.com
    tab_text_textview.setText(title);
    tab_text_textview.setGravity(Gravity.CENTER_VERTICAL);
    tab_text_textview.setSingleLine();
    // tab_text_textview.setTextColor(tabTextColor);
    // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color));
    XmlPullParser xrp = getResources().getXml(tabTextColor);
    try {
        ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);

        if (tab_text_textview != null) {
            tab_text_textview.setTextColor(csl);
        }
    } catch (Exception e) {

    }
    tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
    tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle);
    LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    if (iconResId != 0) {
        // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds(
        // iconResId, 0, 0, 0);
        // Drawable mDrawable = ((Activity) getContext()).getResources()
        // .getDrawable(iconResId);
        // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(),
        // mDrawable.getMinimumHeight());
        int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding);
        ImageView icon = new ImageView(getContext());
        icon.setImageResource(iconResId);
        icon.setScaleType(ScaleType.CENTER_INSIDE);
        LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                iIconHeight);

        switch (iIconLocation) {
        case 1:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);

            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 2:
            // tab_text_textview.setCompoundDrawables(null, mDrawable, null,
            // null);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(icon, lpImage);
            lpText.topMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 3:
            // tab_text_textview.setCompoundDrawables(null, null, mDrawable,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.leftMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        case 4:
            // tab_text_textview.setCompoundDrawables(null, null, null,
            // mDrawable);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.topMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        default:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        }

        // tab_text_textview
        // .setCompoundDrawablePadding((int) ((Activity) getContext())
        // .getResources()
        // .getDimension(R.dimen.common_padding));

    } else {
        tabView.addView(tab_text_textview, lpText);
    }

    tabView.setFocusable(true);
    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.wangbb.naruto.app.view.PagerSlidingTabStrip.java

private void addTab(final int position, CharSequence title, int iconResId, int iLayoutResId, int iTextId,
        int iIconLocation) {
    // final View tabView = ((Activity) getContext()).getLayoutInflater()
    // .inflate(iLayoutResId, null);
    // TextView tab_text_textview = (TextView)
    // tabView.findViewById(iTextId);
    // tab_text_textview.setText(title);
    LinearLayout tabView = new LinearLayout(getContext());
    tabView.setGravity(Gravity.CENTER);
    TextView tab_text_textview = new TextView(getContext());
    tab_text_textview.setId(position);/* www  .  j av  a 2 s  .co  m*/
    tab_text_textview.setText(title);
    tab_text_textview.setGravity(Gravity.CENTER_VERTICAL);
    tab_text_textview.setSingleLine();
    // tab_text_textview.setTextColor(tabTextColor);
    // tab_text_textview.setTextColor(getResources().getColor(R.color.indicator_tab_main_text_color));
    //      XmlPullParser xrp = getResources().getXml(tabTextColor);
    //      try {
    //         ColorStateList csl = ColorStateList.createFromXml(getResources(),
    //               xrp);

    //         if (tab_text_textview != null) {
    tab_text_textview.setTextColor(tabTextColor);
    //         }
    //      } catch (Exception e) {
    //
    //      }
    tab_text_textview.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
    tab_text_textview.setTypeface(tabTypeface, tabTypefaceStyle);
    LinearLayout.LayoutParams lpText = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    if (iconResId != 0) {
        // tab_text_textview.setCompoundDrawablesWithIntrinsicBounds(
        // iconResId, 0, 0, 0);
        // Drawable mDrawable = ((Activity) getContext()).getResources()
        // .getDrawable(iconResId);
        // mDrawable.setBounds(0, 0, mDrawable.getMinimumWidth(),
        // mDrawable.getMinimumHeight());
        int iPandding = (int) ((Activity) getContext()).getResources().getDimension(R.dimen.common_padding);
        ImageView icon = new ImageView(getContext());
        icon.setImageResource(iconResId);
        icon.setScaleType(ScaleType.CENTER_INSIDE);
        LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                iIconHeight);

        switch (iIconLocation) {
        case 1:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);

            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 2:
            // tab_text_textview.setCompoundDrawables(null, mDrawable, null,
            // null);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(icon, lpImage);
            lpText.topMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        case 3:
            // tab_text_textview.setCompoundDrawables(null, null, mDrawable,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.leftMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        case 4:
            // tab_text_textview.setCompoundDrawables(null, null, null,
            // mDrawable);
            tabView.setOrientation(LinearLayout.VERTICAL);
            // tabView.setGravity(Gravity.CENTER_HORIZONTAL);
            tabView.addView(tab_text_textview, lpText);
            lpImage.topMargin = iPandding;
            tabView.addView(icon, lpImage);
            break;
        default:
            // tab_text_textview.setCompoundDrawables(mDrawable, null, null,
            // null);
            tabView.setOrientation(LinearLayout.HORIZONTAL);
            // tabView.setGravity(Gravity.CENTER_VERTICAL);
            tabView.addView(icon, lpImage);
            lpText.leftMargin = iPandding;
            tabView.addView(tab_text_textview, lpText);
            break;
        }

        // tab_text_textview
        // .setCompoundDrawablePadding((int) ((Activity) getContext())
        // .getResources()
        // .getDimension(R.dimen.common_padding));

    } else {
        tabView.addView(tab_text_textview, lpText);
    }

    tabView.setFocusable(true);
    tabView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    // tab_text_textview.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tabView, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:edu.ptu.navpattern.tooltip.Tooltip.java

private View getContentView(final Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);
    LinearLayout vgContent = new LinearLayout(builder.mContext);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        vgContent.setBackground(drawable);
    } else {//from w  w w.j  av  a 2s . co m
        //noinspection deprecation
        vgContent.setBackgroundDrawable(drawable);
    }
    int padding = (int) builder.mPadding;
    vgContent.setPadding(padding, padding, padding, padding);
    vgContent.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textViewParams.topMargin = 1;
    vgContent.setLayoutParams(textViewParams);
    vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line));
    vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

    if (builder.itemText != null && builder.itemText.length > 0) {
        for (int i = 0; i < builder.itemText.length; i++) {

            TextView textView = new TextView(builder.mContext);
            textView.setText(builder.itemText[i]);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44);
            textView.setTextColor(0xffffffff);
            textView.setGravity(Gravity.CENTER_VERTICAL);
            if (builder.itemLogo != null && builder.itemLogo.length > i) {
                Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]);
                /// ??,??.
                //                    drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                //                    textView.setCompoundDrawables(drawableLeft, null, null, null);
                //                    textView.setCompoundDrawablePadding(4);
                //                    textView.setBackgroundDrawable(drawableLeft);
                LinearLayout linearLayout = new LinearLayout(builder.mContext);
                linearLayout.setMinimumHeight((int) dpToPx(44f));
                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.setGravity(Gravity.CENTER_VERTICAL);
                ImageView icon = new ImageView(builder.mContext);
                icon.setImageDrawable(drawableLeft);
                linearLayout.addView(icon);
                linearLayout.addView(textView);
                vgContent.addView(linearLayout);
                final int position = i;
                linearLayout.setClickable(false);
                linearLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v,
                                MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                                        MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0));
                    }
                });
            } else {
                vgContent.addView(textView);
                final int position = i;
                textView.setClickable(false);
                textView.setMinimumHeight((int) dpToPx(44f));
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v, null);
                    }
                });
            }
        }

    }

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(vgContent);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(vgContent);
    }

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}

From source file:com.cssweb.android.quote.QuoteDetail.java

/**
 * ???//from  www  .  j  a v a  2 s .  c  om
 */
private void initLoading() {
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    ProgressBar progressBar = new ProgressBar(this);
    progressBar.setPadding(0, 0, 15, 0);
    LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.FILL_PARENT);
    layout.addView(progressBar, layoutParams);
    TextView textView = new TextView(this);
    textView.setText(getResources().getText(R.string.cjmx_loading));
    textView.setGravity(Gravity.CENTER_VERTICAL);
    layout.addView(textView, layoutParams2);
    layout.setGravity(Gravity.CENTER);
    loadingLayout = new LinearLayout(this);
    loadingLayout.addView(layout, layoutParams);
    loadingLayout.setGravity(Gravity.CENTER);
    table_1.addView(loadingLayout, 0);
}

From source file:com.nadmm.airports.ActivityBase.java

public View createContentView(View view) {
    FrameLayout root = new FrameLayout(this);
    int white = ContextCompat.getColor(this, android.R.color.white);
    root.setBackgroundColor(white);/*w  w  w .j  a va  2s .c  o  m*/
    root.setDrawingCacheBackgroundColor(white);
    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    LinearLayout pframe = new LinearLayout(this);
    pframe.setId(R.id.INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    FrameLayout lframe = new FrameLayout(this);
    lframe.setId(R.id.INTERNAL_FRAGMENT_CONTAINER_ID);
    lframe.setVisibility(View.GONE);

    lframe.addView(view, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:org.solovyev.android.messenger.BaseListFragment.java

@Nonnull
private View createListView() {
    final Context context = getThemeContext();

    final FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    final LinearLayout progressContainer = new LinearLayout(context);
    progressContainer.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    progressContainer.setOrientation(VERTICAL);
    progressContainer.setVisibility(GONE);
    progressContainer.setGravity(CENTER);

    final ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    progressContainer.addView(progress, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

    root.addView(progressContainer, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

    // ------------------------------------------------------------------

    final FrameLayout listViewContainer = new FrameLayout(context);
    listViewContainer.setId(INTERNAL_LIST_CONTAINER_ID);

    final TextView emptyListCaption = new TextView(context);
    emptyListCaption.setId(INTERNAL_EMPTY_ID);
    emptyListCaption.setGravity(CENTER);
    listViewContainer.addView(emptyListCaption, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

    final ListViewAwareOnRefreshListener topRefreshListener = getTopPullRefreshListener();
    final ListViewAwareOnRefreshListener bottomRefreshListener = getBottomPullRefreshListener();

    final View listView;

    if (topRefreshListener == null && bottomRefreshListener == null) {
        pullToRefreshMode = null;//  ww w  . j  a v  a 2s.  c  om
        listView = createListView(context);
    } else {
        listView = createPullToRefreshListView(context, topRefreshListener, bottomRefreshListener);
    }

    listViewContainer.addView(listView, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

    root.addView(listViewContainer, new LayoutParams(MATCH_PARENT, MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));

    return root;
}

From source file:dev.datvt.cloudtracks.sound_cloud.LocalTracksFragment.java

public void setUpListPlaylist() {
    menus = new ArrayList<>();
    mm.removeAllViews();/*  ww  w.j  av  a  2  s.  c  o  m*/
    LayoutInflater lf = LayoutInflater.from(ctx);

    if (true) {
        LinearLayout con;
        con = (LinearLayout) lf.inflate(R.layout.fragment_local_main, null);
        ImageView art = (ImageView) con.findViewById(R.id.artM);
        ImageView shuf = (ImageView) con.findViewById(R.id.shuffleM);
        ImageView del = (ImageView) con.findViewById(R.id.delM);
        TextView mn = (TextView) con.findViewById(R.id.nameM);
        TextView sn = (TextView) con.findViewById(R.id.noM);

        con.setGravity(Gravity.CENTER);
        art.setImageResource(R.drawable.icon_add_press);
        mn.setText(getString(R.string.create_new));

        art.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showChangeLangDialog();
            }
        });
        mm.addView(con);
    }

    final ArrayList<String> names = ToolsHelper.getListPlaylist();

    if (names.size() > 0) {
        for (int i = 0; i < ToolsHelper.getListPlaylist().size(); i++) {
            View con;

            con = lf.inflate(R.layout.fragment_local_main, null);
            ImageView art = (ImageView) con.findViewById(R.id.artM);
            ImageView shuf = (ImageView) con.findViewById(R.id.shuffleM);
            ImageView del = (ImageView) con.findViewById(R.id.delM);
            TextView mn = (TextView) con.findViewById(R.id.nameM);
            TextView sn = (TextView) con.findViewById(R.id.noM);

            Menu m;

            art.setImageResource(R.drawable.default_nhaccuatui);
            shuf.setImageResource(R.drawable.ic_shuffle);
            shuf.setVisibility(View.VISIBLE);
            del.setImageResource(R.drawable.ic_delete);
            del.setVisibility(View.VISIBLE);
            mn.setText(names.get(i).replace(".lst", ""));
            sn.setText(
                    "" + ToolsHelper.getPlayList(ctx, names.get(i)).size() + " " + getString(R.string.songs));
            sn.setVisibility(View.VISIBLE);

            final String playlistname = names.get(i);

            con.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mm.setVisibility(View.GONE);
                    lnBack.setVisibility(View.VISIBLE);
                    ref.setVisibility(View.VISIBLE);
                    ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {

                        @Override
                        public void doIt() {
                            baseLocal = ToolsHelper.getPlayList(ctx, playlistname);
                        }

                        @Override
                        public void doNe() {
                            setUpList(baseLocal);
                        }
                    };
                    ex.execute();
                }
            });

            del.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    File f = new File(MainActivity.folder + "/Playlist/" + playlistname);
                    f.delete();
                    setUpListPlaylist();
                }
            });

            shuf.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {
                        @Override
                        public void doIt() {
                            ArrayList<Track> tracks = ToolsHelper.getPlayList(ctx, playlistname);
                            localTracks = tracks;
                        }

                        @Override
                        public void doNe() {
                            ArrayList<Track> tracks = localTracks;
                            Collections.shuffle(tracks);
                            if (tracks.size() > 0) {
                                if (tracks.get(0).bpm == ToolsHelper.IS_LOCAL)
                                    mListener.onListFragmentInteraction(tracks, tracks.get(0), 0,
                                            ToolsHelper.IS_LOCAL);
                                else {
                                    mListener.onListFragmentInteraction(tracks, tracks.get(0), 0,
                                            ToolsHelper.DOWNLOAD_CODE);
                                }
                            } else {
                                ToolsHelper.toast(ctx, getString(R.string.empty_playlist));
                            }
                        }
                    };
                    ex.execute();
                }
            });

            m = new Menu(con, art, mn, sn);
            menus.add(m);
            mm.addView(con);
        }
    }
}