Example usage for android.widget RelativeLayout BELOW

List of usage examples for android.widget RelativeLayout BELOW

Introduction

In this page you can find the example usage for android.widget RelativeLayout BELOW.

Prototype

int BELOW

To view the source code for android.widget RelativeLayout BELOW.

Click Source Link

Document

Rule that aligns a child's top edge with another child's bottom edge.

Usage

From source file:com.landenlabs.all_devtool.ConsoleFragment.java

private TextView addTextView(RelativeLayout relLayout, int belowId, int rightId, int widthDp, int heightDp,
        int padLeft) {
    float scale = Resources.getSystem().getDisplayMetrics().density;

    int widthParam = (widthDp != 0) ? dpToPx(widthDp) : RelativeLayout.LayoutParams.WRAP_CONTENT;
    int heightParam = (heightDp != 0) ? dpToPx(heightDp) : RelativeLayout.LayoutParams.WRAP_CONTENT;
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(widthParam, heightParam);

    // params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    if (belowId != 0)
        params.addRule(RelativeLayout.BELOW, belowId);
    if (rightId != 0) {
        if (rightId > 0)
            params.addRule(RelativeLayout.ALIGN_RIGHT, rightId);
        else/*from  w w w.jav  a  2  s . c o  m*/
            params.addRule(RelativeLayout.RIGHT_OF, -rightId);
    }

    // relLayout.setPadding(padLeft,  0,  0,  0);
    params.setMargins(padLeft, 0, 0, 0);

    TextView textView = new TextView(relLayout.getContext());
    textView.setLines(1);
    if (widthDp > 0)
        textView.setMaxWidth(dpToPx(widthDp));

    if (Build.VERSION.SDK_INT >= 17) {
        textView.setId(View.generateViewId());
    } else {
        textView.setId(sNextId++);
    }

    relLayout.addView(textView, params);
    return textView;
}

From source file:fr.cph.stock.android.activity.AccountActivity.java

@Override
public void displayError(JSONObject json) {
    boolean sessionError = ((StockTrackerApp) getApplication()).isSessionError(json);
    if (sessionError) {
        ((StockTrackerApp) getApplication()).loadErrorActivity(this, json);
    } else {//from w ww.  j a v  a2s  .  c  om
        errorView.setText(json.optString("error"));
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) LayoutParams.WRAP_CONTENT,
                (int) LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.BELOW, errorView.getId());
        params.addRule(RelativeLayout.CENTER_HORIZONTAL);
        totalValueView.setLayoutParams(params);
        menuItem.collapseActionView();
        menuItem.setActionView(null);
    }
}

From source file:com.nextgis.mobile.MapFragment.java

protected void addMapButtons(RelativeLayout rl) {
    mivZoomIn = new ImageView(getActivity());
    mivZoomIn.setImageResource(R.drawable.ic_plus);
    //mivZoomIn.setId(R.drawable.ic_plus);

    mivZoomOut = new ImageView(getActivity());
    mivZoomOut.setImageResource(R.drawable.ic_minus);
    //mivZoomOut.setId(R.drawable.ic_minus);

    final ImageView ivMark = new ImageView(getActivity());
    ivMark.setImageResource(R.drawable.ic_mark);
    //ivMark.setId(R.drawable.ic_mark);

    //show zoom level between plus and minus
    mivZoomLevel = new TextView(getActivity());
    //ivZoomLevel.setAlpha(150);
    mivZoomLevel.setId(R.drawable.ic_zoomlevel);

    final float scale = getResources().getDisplayMetrics().density;
    int pixels = (int) (48 * scale + 0.5f);

    mivZoomLevel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    //ivZoomLevel.setTextAppearance(this, android.R.attr.textAppearanceLarge);

    mivZoomLevel.setWidth(pixels);//from  w ww  .j a  v a 2s  .  c om
    mivZoomLevel.setHeight(pixels);
    mivZoomLevel.setTextColor(Color.DKGRAY);
    mivZoomLevel.setBackgroundColor(Color.argb(50, 128, 128, 128)); //Color.LTGRAY R.drawable.ic_zoomlevel);
    mivZoomLevel.setGravity(Gravity.CENTER);
    mivZoomLevel.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    mivZoomLevel.setText("" + (int) Math.floor(mMap.getZoomLevel()));

    mivZoomIn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mMap.zoomIn();
        }
    });

    mivZoomOut.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mMap.zoomOut();
        }
    });

    ivMark.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            //TODO: onMark();
        }
    });

    final RelativeLayout.LayoutParams RightParams1 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RightParams1.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5);
    RightParams1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    RightParams1.addRule(RelativeLayout.CENTER_IN_PARENT);//ALIGN_PARENT_TOP
    rl.addView(mivZoomLevel, RightParams1);

    final RelativeLayout.LayoutParams RightParams4 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RightParams4.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5);
    RightParams4.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    RightParams4.addRule(RelativeLayout.ABOVE, R.drawable.ic_zoomlevel);//ALIGN_PARENT_TOP
    rl.addView(mivZoomIn, RightParams4);

    final RelativeLayout.LayoutParams RightParams3 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RightParams3.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5);
    RightParams3.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    RightParams3.addRule(RelativeLayout.CENTER_IN_PARENT);//ALIGN_PARENT_TOP
    rl.addView(ivMark, RightParams3);

    final RelativeLayout.LayoutParams RightParams2 = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    RightParams2.setMargins(mMargings + 5, mMargings - 5, mMargings + 5, mMargings - 5);
    RightParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    RightParams2.addRule(RelativeLayout.BELOW, R.drawable.ic_zoomlevel);//R.drawable.ic_plus);
    rl.addView(mivZoomOut, RightParams2);

    setZoomInEnabled(mMap.canZoomIn());
    setZoomOutEnabled(mMap.canZoomOut());
}

From source file:org.mozilla.gecko.AboutHomeContent.java

private void updateSyncLayout(boolean isFirstRun, boolean hasTopSites) {
    RelativeLayout syncContainer = (RelativeLayout) findViewById(R.id.sync_box_container);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) syncContainer.getLayoutParams();

    int below = R.id.all_top_sites_text;
    if (isFirstRun && !hasTopSites)
        below = R.id.top_sites_top;// w ww. j  a  va2 s. c om
    else if (!hasTopSites)
        below = R.id.no_top_sites_text;

    int background = R.drawable.abouthome_bg_repeat;
    if (isFirstRun && !hasTopSites)
        background = 0;

    params.addRule(RelativeLayout.BELOW, below);
    syncContainer.setLayoutParams(params);

    syncContainer.setBackgroundResource(background);
}

From source file:org.odk.collect.android.widgets.QuestionWidget.java

/**
 * Default place to put the answer/*  w w  w  .  ja  v  a 2  s.  c om*/
 * (below the help text or question text if there is no help text)
 * If you have many elements, use this first
 * and use the standard addView(view, params) to place the rest
 */
protected void addAnswerView(View v) {
    if (v == null) {
        Timber.e("cannot add a null view as an answerView");
        return;
    }
    // default place to add answer
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    if (helpTextView.getVisibility() == View.VISIBLE) {
        params.addRule(RelativeLayout.BELOW, helpTextView.getId());
    } else {
        params.addRule(RelativeLayout.BELOW, questionMediaLayout.getId());
    }
    params.setMargins(10, 0, 10, 0);
    addView(v, params);
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

@SuppressLint("NewApi")
private static void applyAttributes(View view, Map<String, String> attrs, ViewGroup parent) {
    if (viewRunnables == null)
        createViewRunnables();//from ww w  .ja v  a2s  .  com
    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    int layoutRule;
    int marginLeft = 0, marginRight = 0, marginTop = 0, marginBottom = 0, paddingLeft = 0, paddingRight = 0,
            paddingTop = 0, paddingBottom = 0;
    boolean hasCornerRadius = false, hasCornerRadii = false;
    for (Map.Entry<String, String> entry : attrs.entrySet()) {
        String attr = entry.getKey();
        if (viewRunnables.containsKey(attr)) {
            viewRunnables.get(attr).apply(view, entry.getValue(), parent, attrs);
            continue;
        }
        if (attr.startsWith("cornerRadius")) {
            hasCornerRadius = true;
            hasCornerRadii = !attr.equals("cornerRadius");
            continue;
        }
        layoutRule = NO_LAYOUT_RULE;
        boolean layoutTarget = false;
        switch (attr) {
        case "id":
            String idValue = parseId(entry.getValue());
            if (parent != null) {
                DynamicLayoutInfo info = getDynamicLayoutInfo(parent);
                int newId = highestIdNumberUsed++;
                view.setId(newId);
                info.nameToIdNumber.put(idValue, newId);
            }
            break;
        case "width":
        case "layout_width":
            switch (entry.getValue()) {
            case "wrap_content":
                layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
                break;
            case "fill_parent":
            case "match_parent":
                layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
                break;
            default:
                layoutParams.width = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                        view.getResources().getDisplayMetrics(), parent, true);
                break;
            }
            break;
        case "height":
        case "layout_height":
            switch (entry.getValue()) {
            case "wrap_content":
                layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                break;
            case "fill_parent":
            case "match_parent":
                layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
                break;
            default:
                layoutParams.height = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                        view.getResources().getDisplayMetrics(), parent, false);
                break;
            }
            break;
        case "layout_gravity":
            if (parent != null && parent instanceof LinearLayout) {
                ((LinearLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue());
            } else if (parent != null && parent instanceof FrameLayout) {
                ((FrameLayout.LayoutParams) layoutParams).gravity = parseGravity(entry.getValue());
            }
            break;
        case "layout_weight":
            if (parent != null && parent instanceof LinearLayout) {
                ((LinearLayout.LayoutParams) layoutParams).weight = Float.parseFloat(entry.getValue());
            }
            break;
        case "layout_below":
            layoutRule = RelativeLayout.BELOW;
            layoutTarget = true;
            break;
        case "layout_above":
            layoutRule = RelativeLayout.ABOVE;
            layoutTarget = true;
            break;
        case "layout_toLeftOf":
            layoutRule = RelativeLayout.LEFT_OF;
            layoutTarget = true;
            break;
        case "layout_toRightOf":
            layoutRule = RelativeLayout.RIGHT_OF;
            layoutTarget = true;
            break;
        case "layout_alignBottom":
            layoutRule = RelativeLayout.ALIGN_BOTTOM;
            layoutTarget = true;
            break;
        case "layout_alignTop":
            layoutRule = RelativeLayout.ALIGN_TOP;
            layoutTarget = true;
            break;
        case "layout_alignLeft":
        case "layout_alignStart":
            layoutRule = RelativeLayout.ALIGN_LEFT;
            layoutTarget = true;
            break;
        case "layout_alignRight":
        case "layout_alignEnd":
            layoutRule = RelativeLayout.ALIGN_RIGHT;
            layoutTarget = true;
            break;
        case "layout_alignParentBottom":
            layoutRule = RelativeLayout.ALIGN_PARENT_BOTTOM;
            break;
        case "layout_alignParentTop":
            layoutRule = RelativeLayout.ALIGN_PARENT_TOP;
            break;
        case "layout_alignParentLeft":
        case "layout_alignParentStart":
            layoutRule = RelativeLayout.ALIGN_PARENT_LEFT;
            break;
        case "layout_alignParentRight":
        case "layout_alignParentEnd":
            layoutRule = RelativeLayout.ALIGN_PARENT_RIGHT;
            break;
        case "layout_centerHorizontal":
            layoutRule = RelativeLayout.CENTER_HORIZONTAL;
            break;
        case "layout_centerVertical":
            layoutRule = RelativeLayout.CENTER_VERTICAL;
            break;
        case "layout_centerInParent":
            layoutRule = RelativeLayout.CENTER_IN_PARENT;
            break;
        case "layout_margin":
            marginLeft = marginRight = marginTop = marginBottom = DimensionConverter
                    .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics());
            break;
        case "layout_marginLeft":
            marginLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, true);
            break;
        case "layout_marginTop":
            marginTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, false);
            break;
        case "layout_marginRight":
            marginRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, true);
            break;
        case "layout_marginBottom":
            marginBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics(), parent, false);
            break;
        case "padding":
            paddingBottom = paddingLeft = paddingRight = paddingTop = DimensionConverter
                    .stringToDimensionPixelSize(entry.getValue(), view.getResources().getDisplayMetrics());
            break;
        case "paddingLeft":
            paddingLeft = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingTop":
            paddingTop = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingRight":
            paddingRight = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;
        case "paddingBottom":
            paddingBottom = DimensionConverter.stringToDimensionPixelSize(entry.getValue(),
                    view.getResources().getDisplayMetrics());
            break;

        }
        if (layoutRule != NO_LAYOUT_RULE && parent instanceof RelativeLayout) {
            if (layoutTarget) {
                int anchor = idNumFromIdString(parent, parseId(entry.getValue()));
                ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule, anchor);
            } else if (entry.getValue().equals("true")) {
                ((RelativeLayout.LayoutParams) layoutParams).addRule(layoutRule);
            }
        }
    }
    // TODO: this is a giant mess; come up with a simpler way of deciding what to draw for the background
    if (attrs.containsKey("background") || attrs.containsKey("borderColor")) {
        String bgValue = attrs.containsKey("background") ? attrs.get("background") : null;
        if (bgValue != null && bgValue.startsWith("@drawable/")) {
            view.setBackground(getDrawableByName(view, bgValue));
        } else if (bgValue == null || bgValue.startsWith("#") || bgValue.startsWith("@color")) {
            if (view instanceof Button || attrs.containsKey("pressedColor")) {
                int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue);
                int pressedColor;
                if (attrs.containsKey("pressedColor")) {
                    pressedColor = parseColor(view, attrs.get("pressedColor"));
                } else {
                    pressedColor = adjustBrightness(bgColor, 0.9f);
                }
                GradientDrawable gd = new GradientDrawable();
                gd.setColor(bgColor);
                GradientDrawable pressedGd = new GradientDrawable();
                pressedGd.setColor(pressedColor);
                if (hasCornerRadii) {
                    float radii[] = new float[8];
                    for (int i = 0; i < CORNERS.length; i++) {
                        String corner = CORNERS[i];
                        if (attrs.containsKey("cornerRadius" + corner)) {
                            radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension(
                                    attrs.get("cornerRadius" + corner),
                                    view.getResources().getDisplayMetrics());
                        }
                        gd.setCornerRadii(radii);
                        pressedGd.setCornerRadii(radii);
                    }
                } else if (hasCornerRadius) {
                    float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"),
                            view.getResources().getDisplayMetrics());
                    gd.setCornerRadius(cornerRadius);
                    pressedGd.setCornerRadius(cornerRadius);
                }
                if (attrs.containsKey("borderColor")) {
                    String borderWidth = "1dp";
                    if (attrs.containsKey("borderWidth")) {
                        borderWidth = attrs.get("borderWidth");
                    }
                    int borderWidthPx = DimensionConverter.stringToDimensionPixelSize(borderWidth,
                            view.getResources().getDisplayMetrics());
                    gd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor")));
                    pressedGd.setStroke(borderWidthPx, parseColor(view, attrs.get("borderColor")));
                }
                StateListDrawable selector = new StateListDrawable();
                selector.addState(new int[] { android.R.attr.state_pressed }, pressedGd);
                selector.addState(new int[] {}, gd);
                view.setBackground(selector);
                getDynamicLayoutInfo(view).bgDrawable = gd;
            } else if (hasCornerRadius || attrs.containsKey("borderColor")) {
                GradientDrawable gd = new GradientDrawable();
                int bgColor = parseColor(view, bgValue == null ? "#00000000" : bgValue);
                gd.setColor(bgColor);
                if (hasCornerRadii) {
                    float radii[] = new float[8];
                    for (int i = 0; i < CORNERS.length; i++) {
                        String corner = CORNERS[i];
                        if (attrs.containsKey("cornerRadius" + corner)) {
                            radii[i * 2] = radii[i * 2 + 1] = DimensionConverter.stringToDimension(
                                    attrs.get("cornerRadius" + corner),
                                    view.getResources().getDisplayMetrics());
                        }
                        gd.setCornerRadii(radii);
                    }
                } else if (hasCornerRadius) {
                    float cornerRadius = DimensionConverter.stringToDimension(attrs.get("cornerRadius"),
                            view.getResources().getDisplayMetrics());
                    gd.setCornerRadius(cornerRadius);
                }
                if (attrs.containsKey("borderColor")) {
                    String borderWidth = "1dp";
                    if (attrs.containsKey("borderWidth")) {
                        borderWidth = attrs.get("borderWidth");
                    }
                    gd.setStroke(
                            DimensionConverter.stringToDimensionPixelSize(borderWidth,
                                    view.getResources().getDisplayMetrics()),
                            parseColor(view, attrs.get("borderColor")));
                }
                view.setBackground(gd);
                getDynamicLayoutInfo(view).bgDrawable = gd;
            } else {
                view.setBackgroundColor(parseColor(view, bgValue));
            }
        }
    }

    if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
        ((ViewGroup.MarginLayoutParams) layoutParams).setMargins(marginLeft, marginTop, marginRight,
                marginBottom);
    }
    view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
    view.setLayoutParams(layoutParams);
}

From source file:com.example.damerap_ver1.IntroVideoActivity.java

/**
* Create the view in which the video will be rendered.
*///from  w  w w .  j av  a  2 s.c om
private void setupView() {
    LinearLayout lLinLayout = new LinearLayout(this);
    lLinLayout.setId(1);
    lLinLayout.setOrientation(LinearLayout.VERTICAL);
    lLinLayout.setGravity(Gravity.CENTER);
    lLinLayout.setBackgroundColor(Color.BLACK);

    LayoutParams lLinLayoutParms = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT);
    lLinLayout.setLayoutParams(lLinLayoutParms);

    this.setContentView(lLinLayout);

    RelativeLayout lRelLayout = new RelativeLayout(this);
    lRelLayout.setId(2);
    lRelLayout.setGravity(Gravity.CENTER);
    lRelLayout.setBackgroundColor(Color.BLACK);
    android.widget.RelativeLayout.LayoutParams lRelLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
    lRelLayout.setLayoutParams(lRelLayoutParms);
    lLinLayout.addView(lRelLayout);

    mVideoView = new VideoView(this);
    mVideoView.setId(3);
    android.widget.RelativeLayout.LayoutParams lVidViewLayoutParams = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lVidViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    mVideoView.setLayoutParams(lVidViewLayoutParams);
    lRelLayout.addView(mVideoView);

    mProgressBar = new ProgressBar(this);
    mProgressBar.setId(4);
    android.widget.RelativeLayout.LayoutParams lProgressBarLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressBarLayoutParms.addRule(RelativeLayout.CENTER_IN_PARENT);
    mProgressBar.setLayoutParams(lProgressBarLayoutParms);
    lRelLayout.addView(mProgressBar);

    mProgressMessage = new TextView(this);
    mProgressMessage.setId(5);
    android.widget.RelativeLayout.LayoutParams lProgressMsgLayoutParms = new android.widget.RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lProgressMsgLayoutParms.addRule(RelativeLayout.CENTER_HORIZONTAL);
    lProgressMsgLayoutParms.addRule(RelativeLayout.BELOW, 4);
    mProgressMessage.setLayoutParams(lProgressMsgLayoutParms);
    mProgressMessage.setTextColor(Color.LTGRAY);
    mProgressMessage.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);
    mProgressMessage.setText("...");
    lRelLayout.addView(mProgressMessage);
}

From source file:busradar.madison.StopDialog.java

StopDialog(final Context ctx, final int stopid, final int lat, final int lon) {
    super(ctx);//ww w . java 2 s .c o m
    this.stopid = stopid;

    // getWindow().requestFeature(Window.FEATURE_LEFT_ICON);
    getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

    final String name = DB.getStopName(stopid);
    setTitle(name);

    routes = get_time_urls(StopDialog.this.stopid);

    // getWindow().setLayout(LayoutParams.FILL_PARENT,
    // LayoutParams.FILL_PARENT);

    setContentView(new RelativeLayout(ctx) {
        {
            addView(new TextView(ctx) {
                {
                    setId(stop_num_id);
                    setText(Html.fromHtml(String.format(
                            "[<a href='http://www.cityofmadison.com/metro/BusStopDepartures/StopID/%04d.pdf'>%04d</a>]",
                            stopid, stopid)));
                    setPadding(0, 0, 5, 0);
                    this.setMovementMethod(LinkMovementMethod.getInstance());
                }
            }, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT) {
                {
                    addRule(ALIGN_PARENT_RIGHT);
                }
            });

            addView(new ImageView(ctx) {
                boolean enabled;

                @Override
                public void setEnabled(boolean e) {
                    enabled = e;

                    setImageResource(e ? R.drawable.love_enabled : R.drawable.love_disabled);
                    if (e) {
                        G.favorites.add_favorite_stop(stopid, name, lat, lon);
                        Toast.makeText(ctx, "Added stop to Favorites", Toast.LENGTH_SHORT).show();
                    } else {
                        G.favorites.remove_favorite_stop(stopid);
                        Toast.makeText(ctx, "Removed stop from Favorites", Toast.LENGTH_SHORT).show();
                    }
                }

                {
                    enabled = G.favorites.is_stop_favorite(stopid);
                    setImageResource(enabled ? R.drawable.love_enabled : R.drawable.love_disabled);

                    setPadding(0, 0, 10, 0);
                    setOnClickListener(new OnClickListener() {
                        public void onClick(View v) {
                            setEnabled(!enabled);
                        }
                    });
                }
            }, new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT) {
                {
                    addRule(LEFT_OF, stop_num_id);
                    setMargins(0, -3, 0, 0);
                }
            });

            addView(cur_loading_text = new TextView(ctx) {
                {
                    setText("Loading...");
                    setPadding(5, 0, 0, 0);
                }
            });
            addView(new HorizontalScrollView(ctx) {
                {
                    setId(route_list_id);
                    setHorizontalScrollBarEnabled(false);

                    addView(new LinearLayout(ctx) {
                        float text_size;
                        Button cur_button;
                        {
                            int last_route = -1;
                            for (int i = 0; i < routes.length; i++) {

                                final RouteURL route = routes[i];

                                if (route.route == last_route)
                                    continue;
                                last_route = route.route;

                                addView(new Button(ctx) {
                                    public void setEnabled(boolean e) {
                                        if (e) {
                                            setBackgroundColor(0xff000000 | G.route_points[route.route].color);
                                            setTextSize(TypedValue.COMPLEX_UNIT_PX, text_size * 1.5f);
                                        } else {
                                            setBackgroundColor(0x90000000 | G.route_points[route.route].color);
                                            setTextSize(TypedValue.COMPLEX_UNIT_PX, text_size);
                                        }
                                    }

                                    {
                                        setText(G.route_points[route.route].name);
                                        setTextColor(0xffffffff);
                                        setTypeface(Typeface.DEFAULT_BOLD);
                                        text_size = getTextSize();

                                        if (G.active_route == route.route) {
                                            setEnabled(true);
                                            cur_button = this;
                                        } else
                                            setEnabled(false);

                                        final Button b = this;

                                        setOnClickListener(new OnClickListener() {
                                            public void onClick(View v) {
                                                if (cur_button != null) {
                                                    cur_button.setEnabled(false);
                                                }

                                                if (cur_button == b) {
                                                    cur_button.setEnabled(false);
                                                    cur_button = null;

                                                    selected_route = null;
                                                    update_time_display();
                                                } else {
                                                    cur_button = b;
                                                    cur_button.setEnabled(true);

                                                    selected_route = route;
                                                    update_time_display();
                                                }
                                            }
                                        });

                                    }
                                });
                            }
                        }
                    });
                }
            }, new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) {
                {
                    addRule(RelativeLayout.BELOW, stop_num_id);
                    addRule(RelativeLayout.CENTER_HORIZONTAL);
                }
            });

            addView(status_text = new TextView(ctx) {
                {
                    setText("");
                }
            }, new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) {
                {
                    addRule(RelativeLayout.BELOW, route_list_id);
                    addRule(RelativeLayout.CENTER_HORIZONTAL);
                }
            });
            addView(list_view = new ListView(ctx) {
                {
                    setId(time_list_id);
                    setVerticalScrollBarEnabled(false);
                    setAdapter(times_adapter = new BaseAdapter() {

                        public View getView(final int position, View convertView, ViewGroup parent) {
                            CellView v;

                            if (convertView == null)
                                v = new CellView(ctx);
                            else
                                v = (CellView) convertView;

                            RouteTime rt = curr_times.get(position);
                            v.setBackgroundColor(G.route_points[rt.route].color | 0xff000000);
                            v.route_textview.setText(G.route_points[rt.route].name);
                            if (rt.dir != null)
                                v.dir_textview.setText("to " + rt.dir);
                            v.time_textview.setText(rt.time);

                            return v;

                        }

                        public int getCount() {
                            return curr_times.size();
                        }

                        public Object getItem(int position) {
                            return null;
                        }

                        public long getItemId(int position) {
                            return 0;
                        }

                    });
                }
            }, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT) {
                {
                    addRule(RelativeLayout.BELOW, route_list_id);
                }
            });
        }
    });

    TextView title = (TextView) findViewById(android.R.id.title);
    title.setEllipsize(TextUtils.TruncateAt.MARQUEE);
    title.setSelected(true);
    title.setTextColor(0xffffffff);
    title.setMarqueeRepeatLimit(-1);

    // getWindow().set, value)
    // getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
    // android.R.drawable.ic_dialog_info);

    // title.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);

    if (G.active_route >= 0)
        for (int i = 0; i < routes.length; i++)
            if (routes[i].route == G.active_route) {
                selected_route = routes[i];

                RouteURL[] rnew = new RouteURL[routes.length];
                rnew[0] = selected_route;

                for (int j = 0, k = 1; j < routes.length; j++)
                    if (j != i)
                        rnew[k++] = routes[j];

                routes = rnew;
                break;
            }
    update_time_display();
}

From source file:com.facebook.GraphObjectListFragment.java

private void inflateTitleBar(ViewGroup view) {
    ViewStub stub = (ViewStub) view.findViewById(R.id.com_facebook_picker_title_bar_stub);
    if (stub != null) {
        View titleBar = stub.inflate();

        final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
        layoutParams.addRule(RelativeLayout.BELOW, R.id.com_facebook_picker_title_bar);
        listView.setLayoutParams(layoutParams);

        if (titleBarBackground != null) {
            titleBar.setBackgroundDrawable(titleBarBackground);
        }//from ww w .j a  va 2s . c o  m

        doneButton = (Button) view.findViewById(R.id.com_facebook_picker_done_button);
        if (doneButton != null) {
            doneButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onDoneButtonClickedListener != null) {
                        onDoneButtonClickedListener.onDoneButtonClicked();
                    }
                }
            });

            if (doneButtonText == null) {
                doneButtonText = getDefaultDoneButtonText();
            }
            if (doneButtonText != null) {
                doneButton.setText(doneButtonText);
            }

            if (doneButtonBackground != null) {
                doneButton.setBackgroundDrawable(doneButtonBackground);
            }
        }

        titleTextView = (TextView) view.findViewById(R.id.com_facebook_picker_title);
        if (titleTextView != null) {
            if (titleText == null) {
                titleText = getDefaultTitleText();
            }
            if (titleText != null) {
                titleTextView.setText(titleText);
            }
        }
    }
}

From source file:com.keepassdroid.PasswordActivity.java

private void setFingerPrintVisibilty(int vis) {
    ImageButton browse = (ImageButton) findViewById(R.id.browse_button);
    EditText fn = (EditText) findViewById(R.id.pass_keyfile);

    RelativeLayout.LayoutParams browseParams = (RelativeLayout.LayoutParams) browse.getLayoutParams();
    RelativeLayout.LayoutParams fnParams = (RelativeLayout.LayoutParams) fn.getLayoutParams();
    int layoutBelow;
    if (vis == View.GONE) {
        layoutBelow = R.id.password;/* w w w.  java  2s  .  co m*/
    } else {
        layoutBelow = R.id.fingerprint_label;
    }
    browseParams.addRule(RelativeLayout.BELOW, layoutBelow);
    fnParams.addRule(RelativeLayout.BELOW, layoutBelow);
    fingerprintView.setVisibility(vis);
    confirmationView.setVisibility(vis);
}