Example usage for android.widget LinearLayout getMeasuredWidth

List of usage examples for android.widget LinearLayout getMeasuredWidth

Introduction

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

Prototype

public final int getMeasuredWidth() 

Source Link

Document

Like #getMeasuredWidthAndState() , but only returns the raw width component (that is the result is masked by #MEASURED_SIZE_MASK ).

Usage

From source file:rosmi.acagild.alarmclock.ringing.ShareFragment.java

private static void drawStamp(Context context, Bitmap bitmap, String question) {
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);

    float opacity = 0.7f;
    int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int textSize = 16; // defined in SP
    int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16,
            context.getResources().getDisplayMetrics());

    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setBackgroundResource(R.drawable.rounded_corners);
    layout.getBackground().setAlpha((int) (opacity * 255));
    layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

    ImageView logo = new ImageView(context);
    logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher));
    layout.addView(logo);//  w ww. j a v a2  s. co m

    TextView textView = new TextView(context);
    textView.setVisibility(View.VISIBLE);
    if (question != null) {
        textView.setText(question);
    } else {
        textView.setText("Mimicker");
    }
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
    textView.setPadding(horizontalPadding, 0, 0, 0);

    LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    centerInParent.gravity = Gravity.CENTER_VERTICAL;
    layout.addView(textView, centerInParent);

    layout.measure(canvas.getWidth(), height);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height));
    float scale = Math.min(1.0f, canvas.getWidth() / 1080f);
    canvas.scale(scale, scale);
    layout.draw(canvas);
}

From source file:com.microsoft.mimickeralarm.ringing.ShareFragment.java

private static void drawStamp(Context context, Bitmap bitmap, String question) {
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);

    float opacity = 0.7f;
    int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int textSize = 16; // defined in SP
    int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16,
            context.getResources().getDisplayMetrics());

    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setBackgroundResource(R.drawable.rounded_corners);
    layout.getBackground().setAlpha((int) (opacity * 255));
    layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

    ImageView logo = new ImageView(context);
    logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher_no_bg));
    layout.addView(logo);//w  ww .j  a  va 2s. c  o  m

    TextView textView = new TextView(context);
    textView.setVisibility(View.VISIBLE);
    if (question != null) {
        textView.setText(question);
    } else {
        textView.setText("Mimicker");
    }
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
    textView.setPadding(horizontalPadding, 0, 0, 0);

    LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    centerInParent.gravity = Gravity.CENTER_VERTICAL;
    layout.addView(textView, centerInParent);

    layout.measure(canvas.getWidth(), height);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height));
    float scale = Math.min(1.0f, canvas.getWidth() / 1080f);
    canvas.scale(scale, scale);
    layout.draw(canvas);
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java

private void correctNameAndPriceWidth(final View v, final AdvancedOrderCategoryItemRow row) {
    mActivity.getMainService().postOnUIHandler(new SafeRunnable() {
        @Override//from ww  w .j  a v  a2  s.c o  m
        protected void safeRun() throws Exception {
            TextView nameLbl = (TextView) v.findViewById(R.id.name);
            if (!row.name.equals(nameLbl.getText())) {
                return;
            }
            LinearLayout txtContainer = (LinearLayout) v.findViewById(R.id.text_container);
            txtContainer.measure(0, 0);
            int currentWidth = txtContainer.getMeasuredWidth();
            int maxWidth = txtContainer.getWidth() - UIUtils.convertDipToPixels(mActivity, 35);

            nameLbl.measure(0, 0);
            int nameWidth = nameLbl.getMeasuredWidth();
            int priceWidth = 0;
            if (row.hasPrice) {
                TextView priceLbl = (TextView) v.findViewById(R.id.price);
                priceLbl.measure(0, 0);
                priceWidth = priceLbl.getMeasuredWidth();
                ViewGroup.LayoutParams lpPrice = priceLbl.getLayoutParams();
                lpPrice.width = priceWidth;
                priceLbl.setLayoutParams(lpPrice);
                priceLbl.requestLayout();
            }

            ViewGroup.LayoutParams lpName = nameLbl.getLayoutParams();
            if (maxWidth > 0 && currentWidth < maxWidth) {
                if (maxWidth - priceWidth > nameWidth) {
                    lpName.width = nameWidth;
                } else {
                    lpName.width = maxWidth - priceWidth;
                }
            } else {
                lpName.width = maxWidth - priceWidth;
            }

            nameLbl.setLayoutParams(lpName);
            nameLbl.requestLayout();
        }
    });
}

From source file:com.microsoft.mimickeralarm.mimics.MimicTongueTwisterFragment.java

private void createSharableBitmap() {
    Bitmap sharableBitmap = Bitmap.createBitmap(getView().getWidth(), getView().getHeight(),
            Bitmap.Config.ARGB_8888);/*from ww w  .  java2 s  .c  o m*/
    Canvas canvas = new Canvas(sharableBitmap);
    canvas.drawColor(ContextCompat.getColor(getContext(), R.color.white));

    // Load the view for the sharable. This will be drawn to the bitmap
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.fragment_sharable_tongue_twister, null);

    TextView textView = (TextView) layout.findViewById(R.id.twister_sharable_tongue_twister);
    textView.setText(mQuestion);

    textView = (TextView) layout.findViewById(R.id.twister_sharable_i_said);
    textView.setText(mUnderstoodText);

    textView = (TextView) layout.findViewById(R.id.mimic_twister_share_success);
    textView.setText(mSuccessMessage);

    // Perform the layout using the dimension of the bitmap
    int widthSpec = View.MeasureSpec.makeMeasureSpec(canvas.getWidth(), View.MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(canvas.getHeight(), View.MeasureSpec.EXACTLY);
    layout.measure(widthSpec, heightSpec);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    // Draw the generated view to canvas
    layout.draw(canvas);

    String title = getString(R.string.app_short_name) + ": " + getString(R.string.mimic_twister_name);
    mSharableUri = ShareFragment.saveShareableBitmap(getActivity(), sharableBitmap, title);
}

From source file:com.thingsee.tracker.MainActivity.java

public static void refreshTrackerMarker(String serial) {
    TrackerModel trackerModel = trackers.get(serial);
    if (trackerModel != null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout tv = (LinearLayout) inflater.inflate(R.layout.tracker_map_marker, null, false);
        ImageView image2 = (ImageView) tv.findViewById(R.id.tracker_marker_icon);
        TextView name = (TextView) tv.findViewById(R.id.tracker_name);
        name.setText(trackerModel.getName());
        ImageView trackerBg = (ImageView) trackerModel.getView().findViewById(R.id.tracker_image_bg);
        if (trackerModel.isLocationTimeoutAlarmOn()) {
            image2.setColorFilter(mResources.getColor(R.color.red));
            trackerBg.setColorFilter(mResources.getColor(R.color.red));
            name.setTextColor(mResources.getColor(R.color.white_effect));
        } else {/*from w w  w. ja  v a 2 s.  c o m*/
            image2.clearColorFilter();
            trackerBg.setColorFilter(mResources.getColor(R.color.green));
            name.setTextColor(mResources.getColor(R.color.black_effect));
        }
        tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
        tv.setDrawingCacheEnabled(true);
        tv.buildDrawingCache();
        Bitmap bm = tv.getDrawingCache();
        tv = null;
        if (trackerModel.getMarker() != null) {
            trackerModel.getMarker().setIcon(BitmapDescriptorFactory.fromBitmap(bm));
        }
        if (trackerModelWithMarker != null) {
            if (onChildOnMapView) {
                trackerModelWithMarker.getMarker().showInfoWindow();
            }
        }
    }
}

From source file:com.sdspikes.fireworks.FireworksActivity.java

private void displayInitialState() {
    switchToScreen(R.id.screen_game);/*w ww . j  av  a  2 s . co  m*/
    GameState.HandNode currentNode = mTurnData.state.hands.get(mMyId);
    FragmentManager fm = getFragmentManager();
    fragments = new HashMap<>();

    if (fm.findFragmentById(R.id.my_hand) == null) {
        if (currentNode != null) {
            addHandFragment(fm, currentNode, mMyId, mIdToName.get(mMyId), R.id.my_hand);
        } else {
            Log.d(TAG, mMyId);
        }
    }

    if (fm.findFragmentById(R.id.other_hands) == null) {
        while (true) {
            String currentId = currentNode.nextPlayerId;
            if (currentId.equals(mMyId)) {
                break;
            }
            currentNode = mTurnData.state.hands.get(currentId);
            addHandFragment(fm, currentNode, currentId, mIdToName.get(currentId), R.id.other_hands);
        }
    }

    LinearLayout played = (LinearLayout) findViewById(R.id.played_pile);

    played.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            LinearLayout played = (LinearLayout) findViewById(R.id.played_pile);
            mDiscardWidthR2 = played.getMeasuredWidth();

            if (mDiscardWidthR2 != 0) {
                int usableWidth = mDiscardWidthR2 - findViewById(R.id.played_label).getMeasuredWidth();
                mDiscardWidthR1 = mDiscardWidthR2 - findViewById(R.id.discarded_label).getMeasuredWidth();
                for (int i = 1; i < played.getChildCount(); i++) {
                    ViewGroup.LayoutParams params = played.getChildAt(i).getLayoutParams();
                    params.width = usableWidth / 5;
                    played.getChildAt(i).setLayoutParams(params);
                }
                played.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                LinearLayout chooseAttribute = (LinearLayout) findViewById(R.id.chooseAttribute);
                for (int i = 1; i <= 5; i++) {
                    chooseAttribute.addView(makeAttributeTextView(i, null));
                }
                for (GameState.CardColor color : GameState.CardColor.values()) {
                    chooseAttribute.addView(makeAttributeTextView(-1, color));
                }

                // In case all the data is ready already and was just waiting on this.
                updateDisplay();
            }
        }
    });

    createInitialLog();
    ((TextView) findViewById(R.id.log)).setMovementMethod(new ScrollingMovementMethod());
}

From source file:com.thingsee.tracker.MainActivity.java

@SuppressLint("InflateParams")
private Marker makeMarkerToMap(LatLng latLng, boolean visible, boolean alarmActive, String name,
        double timeStamp, double accuracy) {
    String snippet;/*from  ww  w. j a  v a2  s .  c o  m*/
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout tv = (LinearLayout) inflater.inflate(R.layout.tracker_map_marker, null, false);
    TextView trackerName = (TextView) tv.findViewById(R.id.tracker_name);
    trackerName.setText(name);
    ImageView image2 = (ImageView) tv.findViewById(R.id.tracker_marker_icon);
    if (alarmActive) {
        image2.setColorFilter(mResources.getColor(R.color.red));
        trackerName.setTextColor(mResources.getColor(R.color.white_effect));
    } else {
        image2.setColorFilter(mResources.getColor(R.color.dark_blue));
        trackerName.setTextColor(mResources.getColor(R.color.white_effect));
    }
    tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());
    tv.setDrawingCacheEnabled(true);
    tv.buildDrawingCache();
    Bitmap bm = tv.getDrawingCache();
    tv = null;

    if (accuracy != -1) {
        snippet = String.format(mResources.getString(R.string.tracker_accuracy), accuracy);
    } else {
        snippet = String.format(mResources.getString(R.string.tracker_accuracy), 0.0f);
    }
    if (timeStamp != 0) {
        String timeStampText = Utilities.getSmartTimeStampString(mContext, mResources, timeStamp);
        snippet = snippet + "\n" + mResources.getString(R.string.tracker_timestamp) + " " + timeStampText;
    } else {
        snippet = snippet + "\n" + mResources.getString(R.string.tracker_timestamp) + " - ";
    }
    return mMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(bm))
            .visible(visible).title(name).snippet(snippet));
}

From source file:com.forrestguice.suntimeswidget.SuntimesActivity.java

/**
 * Stretch the horizontal rule to match the actual table width.. this is a hack to work around
 * unwanted stretching of the GridLayout columns when setting the hr to match_parent or fill_parent.
 *//*from  www  .j  a v  a2  s.  c  o  m*/
private void stretchTableRule() {
    LinearLayout[] cards = new LinearLayout[2];
    cards[0] = (LinearLayout) findViewById(R.id.info_time_all_today);
    cards[1] = (LinearLayout) findViewById(R.id.info_time_all_tomorrow);
    for (LinearLayout card : cards) // for each card
    {
        View tableRule = card.findViewById(R.id.table_rule);
        if (tableRule != null) {
            LinearLayout[] cols = new LinearLayout[3];
            cols[0] = (LinearLayout) card.findViewById(R.id.table_head_date);
            cols[1] = (LinearLayout) card.findViewById(R.id.table_head_rise);
            cols[2] = (LinearLayout) card.findViewById(R.id.table_head_set);

            int tableWidth = 0;
            for (LinearLayout col : cols) // add up the measured column widths
            {
                if (col != null) {
                    col.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    tableWidth += col.getMeasuredWidth();
                }
            }

            ViewGroup.LayoutParams tableRuleParams = tableRule.getLayoutParams();
            tableRuleParams.width = tableWidth;
            tableRule.setLayoutParams(tableRuleParams); // and adjust the horizontal rule width
        }
    }
}