List of usage examples for android.widget LinearLayout measure
public final void measure(int widthMeasureSpec, int heightMeasureSpec)
This is called to find out how big a view should be.
From source file:com.layer.atlas.AtlasMessageComposer.java
/** * Prepares this AtlasMessageComposer for use. * * @return this AtlasMessageComposer.//from ww w . j ava 2 s. c om */ public AtlasMessageComposer init(LayerClient layerClient, ParticipantProvider participantProvider) { LayoutInflater.from(getContext()).inflate(R.layout.atlas_message_composer, this); mLayerClient = layerClient; mParticipantProvider = participantProvider; mAttachButton = (ImageView) findViewById(R.id.attachment); mAttachButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (mAttachmentMenu.isShowing()) { mAttachmentMenu.dismiss(); } else { LinearLayout menu = (LinearLayout) mAttachmentMenu.getContentView(); menu.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mAttachmentMenu.showAsDropDown(v, 0, -menu.getMeasuredHeight() - v.getHeight()); } } }); mMessageEditText = (EditText) findViewById(R.id.message_edit_text); mMessageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (mConversation == null || mConversation.isDeleted()) return; if (s.length() > 0) { mSendButton.setEnabled(isEnabled()); mConversation.send(LayerTypingIndicatorListener.TypingIndicator.STARTED); } else { mSendButton.setEnabled(false); mConversation.send(LayerTypingIndicatorListener.TypingIndicator.FINISHED); } } }); mSendButton = (Button) findViewById(R.id.send_button); mSendButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (!mTextSender.requestSend(mMessageEditText.getText().toString())) return; mMessageEditText.setText(""); mSendButton.setEnabled(false); } }); applyStyle(); return this; }
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);/*from w w w . j av a 2 s .com*/ 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.layer.messenger.makemoji.MakeMojiAtlasComposer.java
/** * Prepares this AtlasMessageComposer for use. * * @return this AtlasMessageComposer./* w w w . j av a 2s . c o m*/ */ public MakeMojiAtlasComposer init(LayerClient layerClient, ParticipantProvider participantProvider) { LayoutInflater.from(getContext()).inflate(com.layer.atlas.R.layout.atlas_message_composer, this); mLayerClient = layerClient; mParticipantProvider = participantProvider; mAttachButton = (ImageView) findViewById(com.layer.atlas.R.id.attachment); mAttachButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { LinearLayout menu = (LinearLayout) mAttachmentMenu.getContentView(); menu.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mAttachmentMenu.showAsDropDown(v, 0, -menu.getMeasuredHeight() - v.getHeight()); } }); mMessageEditText = (EditText) findViewById(com.layer.atlas.R.id.message_edit_text); mMessageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (mConversation == null || mConversation.isDeleted()) return; if (s.length() > 0) { mSendButton.setEnabled(isEnabled()); mConversation.send(LayerTypingIndicatorListener.TypingIndicator.STARTED); } else { mSendButton.setEnabled(false); mConversation.send(LayerTypingIndicatorListener.TypingIndicator.FINISHED); } } }); mSendButton = (Button) findViewById(com.layer.atlas.R.id.send_button); final MojiInputLayout analytics = new MojiInputLayout(getContext()); mSendButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (!mTextSender.requestSend(Moji.toHtml(mMessageEditText.getText()))) return; analytics.setInputText(mMessageEditText.getText()); analytics.manualSaveInputToRecentsAndBackend(); mMessageEditText.setText(""); mSendButton.setEnabled(false); } }); applyStyle(); return this; }
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 w w. j a va 2 s . 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.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.j a 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.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void correctNameAndPriceWidth(final View v, final AdvancedOrderCategoryItemRow row) { mActivity.getMainService().postOnUIHandler(new SafeRunnable() { @Override// w w w. ja v a 2 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 w ww. j a va2 s .co 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.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void setBasketListViewHeight() { final Point displaySize = UIUtils.getDisplaySize(mActivity); final TextView nameLbl = (TextView) mBasketDialog.findViewById(R.id.name); final ListView listView = (ListView) mBasketDialog.findViewById(R.id.list_view); final LinearLayout buttonContainer = (LinearLayout) mBasketDialog.findViewById(R.id.button_container); int maxPopupHeight = (int) Math.floor(displaySize.y * 0.75); nameLbl.measure(0, 0);/*from w w w . ja v a2s. com*/ int nameLblHeight = nameLbl.getMeasuredHeight(); buttonContainer.measure(0, 0); int buttonContainerHeight = buttonContainer.getMeasuredHeight(); UIUtils.setListViewHeightBasedOnItems(listView, maxPopupHeight - nameLblHeight - buttonContainerHeight); }
From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void setDetailScrollViewHeight() { final Point displaySize = UIUtils.getDisplaySize(mActivity); final TextView nameLbl = (TextView) mDetailDialog.findViewById(R.id.name); final TextView priceLbl = (TextView) mDetailDialog.findViewById(R.id.price); final ScrollView scrollView = (ScrollView) mDetailDialog.findViewById(R.id.scroll_view); final LinearLayout valueContainer = (LinearLayout) mDetailDialog.findViewById(R.id.value_container); final Button dismissBtn = (Button) mDetailDialog.findViewById(R.id.dismiss); int maxPopupHeight = (int) Math.floor(displaySize.y * 0.75); int desiredWidth = MeasureSpec.makeMeasureSpec(nameLbl.getWidth(), MeasureSpec.AT_MOST); nameLbl.measure(desiredWidth, 0);/*from w w w . ja v a 2s . c o m*/ int nameLblHeight = nameLbl.getMeasuredHeight(); int priceLblHeight = 0; if (priceLbl.getVisibility() == View.VISIBLE) { priceLbl.measure(desiredWidth, 0); priceLblHeight = priceLbl.getMeasuredHeight(); } valueContainer.measure(desiredWidth, 0); int valueContainerHeight = valueContainer.getMeasuredHeight(); dismissBtn.measure(desiredWidth, 0); int dismissBtnHeight = dismissBtn.getMeasuredHeight(); int maxScrollViewHeight = maxPopupHeight - nameLblHeight - priceLblHeight - valueContainerHeight - dismissBtnHeight; ViewGroup.LayoutParams params = scrollView.getLayoutParams(); scrollView.measure(desiredWidth, 0); params.height = scrollView.getMeasuredHeight(); if (maxScrollViewHeight > 0 && params.height > maxScrollViewHeight) { params.height = maxScrollViewHeight; } scrollView.setLayoutParams(params); scrollView.requestLayout(); }
From source file:com.example.SmartBoard.DrawingView.java
public Bitmap textToBitmap(String text, int color, float posX, float posY, int size) { TextView textView = new TextView(getContext()); textView.setVisibility(View.VISIBLE); textView.setTextColor(color);/* www. j a v a 2 s .c o m*/ textView.setMaxWidth(500); textView.setMaxHeight(500); textView.setMaxLines(4); textView.setX(posX); textView.setY(posY); textView.setText(text); textView.setTextSize(size); LinearLayout layout = new LinearLayout(getContext()); layout.addView(textView); layout.measure(500, 500); layout.layout(0, 0, 500, 500); textView.setDrawingCacheEnabled(true); textView.buildDrawingCache(); Bitmap bm = textView.getDrawingCache(); return bm; }