List of usage examples for android.graphics.drawable Drawable getMinimumWidth
public int getMinimumWidth()
From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerViewPager.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //populate(); // Use reflection callPopulate();//from w w w. ja v a 2 s. c o m // Everything below is mostly copied from FrameLayout. int count = getChildCount(); final boolean measureMatchParentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; int maxHeight = 0; int maxWidth = 0; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { measureChild(child, widthMeasureSpec, heightMeasureSpec); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); maxWidth = Math.max(maxWidth, child.getMeasuredWidth()); maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); childState = combineMeasuredStates(childState, child.getMeasuredState()); if (measureMatchParentChildren) { if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) { mMatchParentChildren.add(child); } } } } // Account for padding too maxWidth += getPaddingLeft() + getPaddingRight(); maxHeight += getPaddingTop() + getPaddingBottom(); // Check against our minimum height and width maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); // Check against our foreground's minimum height and width if (SUtils.isApi_23_OrHigher()) { final Drawable drawable = getForeground(); if (drawable != null) { maxHeight = Math.max(maxHeight, drawable.getMinimumHeight()); maxWidth = Math.max(maxWidth, drawable.getMinimumWidth()); } } setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT)); count = mMatchParentChildren.size(); if (count > 1) { for (int i = 0; i < count; i++) { final View child = mMatchParentChildren.get(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childWidthMeasureSpec; final int childHeightMeasureSpec; if (lp.width == LayoutParams.MATCH_PARENT) { childWidthMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), MeasureSpec.EXACTLY); } else { childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width); } if (lp.height == LayoutParams.MATCH_PARENT) { childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY); } else { childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom(), lp.height); } child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } } mMatchParentChildren.clear(); }
From source file:com.example.ysh.myapplication.view.readview.TocListAdapter.java
@Override public void convert(EasyLVHolder holder, int position, BookMixAToc.mixToc.Chapters chapters) { TextView tvTocItem = holder.getView(R.id.tvTocItem); tvTocItem.setText(chapters.title);/* ww w . ja v a2 s.com*/ Drawable drawable; if (currentChapter == position + 1) { tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.light_red)); drawable = ContextCompat.getDrawable(mContext, R.drawable.ic_toc_item_activated); } else if (isEpub || FileUtils.getChapterFile(bookId, position + 1).length() > 10) { tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.light_black)); drawable = ContextCompat.getDrawable(mContext, R.drawable.ic_toc_item_download); } else { tvTocItem.setTextColor(ContextCompat.getColor(mContext, R.color.light_black)); drawable = ContextCompat.getDrawable(mContext, R.drawable.ic_toc_item_normal); } drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); tvTocItem.setCompoundDrawables(drawable, null, null, null); }
From source file:moe.johnny.tombstone.ui.PreventFragment.java
private void setHeaderIcon(ContextMenu menu, Drawable icon) { int width = getHeaderIconWidth(); if (icon.getMinimumWidth() <= width) { menu.setHeaderIcon(icon);/* www . j a va 2 s.c o m*/ } else if (icon instanceof BitmapDrawable) { Bitmap bitmap = Bitmap.createScaledBitmap(((BitmapDrawable) icon).getBitmap(), width, width, false); menu.setHeaderIcon(new BitmapDrawable(getResources(), bitmap)); } }
From source file:com.h6ah4i.android.materialshadowninepatch.MaterialShadowContainerView.java
private void onMeasureCompat(int widthMeasureSpec, int heightMeasureSpec) { int count = Math.min(1, getChildCount()); final boolean measureMatchParentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY; View matchParentChildren = null; int maxHeight = 0; int maxWidth = 0; int childState = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); maxWidth = Math.max(maxWidth, child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin); maxHeight = Math.max(maxHeight, child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin); childState |= ViewCompat.getMeasuredState(child); if (measureMatchParentChildren) { if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) { matchParentChildren = child; }//from w ww . j ava 2 s .co m } } } final int paddingH = getPaddingLeft() + getPaddingRight(); final int paddingV = getPaddingTop() + getPaddingBottom(); maxWidth += paddingH; maxHeight += paddingV; maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); final Drawable drawable = getForeground(); if (drawable != null) { maxHeight = Math.max(maxHeight, drawable.getMinimumHeight()); maxWidth = Math.max(maxWidth, drawable.getMinimumWidth()); } setMeasuredDimension(ViewCompat.resolveSizeAndState(maxWidth, widthMeasureSpec, childState), ViewCompat.resolveSizeAndState(maxHeight, heightMeasureSpec, childState << ViewCompat.MEASURED_HEIGHT_STATE_SHIFT)); if (matchParentChildren != null) { final View child = matchParentChildren; final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int childWidthMeasureSpec; int childHeightMeasureSpec; if (lp.width == LayoutParams.MATCH_PARENT) { childWidthMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredWidth() - paddingH - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY); } else { childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, paddingH + lp.leftMargin + lp.rightMargin, lp.width); } if (lp.height == LayoutParams.MATCH_PARENT) { childHeightMeasureSpec = MeasureSpec.makeMeasureSpec( getMeasuredHeight() - paddingV - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY); } else { childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, paddingV + lp.topMargin + lp.bottomMargin, lp.height); } child.measure(childWidthMeasureSpec, childHeightMeasureSpec); } }
From source file:com.labs.okey.commonride.utils.DrawableManager.java
public Drawable fetchDrawable(String urlString) { if (drawableMap.containsKey(urlString)) { return drawableMap.get(urlString); }//from ww w . j a v a 2 s . c o m Log.d(this.getClass().getSimpleName(), "image url:" + urlString); try { InputStream is = fetch(urlString); Drawable drawable = Drawable.createFromStream(is, "src"); if (isRounded) { drawable = RoundedDrawable.fromDrawable(drawable); if (drawable instanceof RoundedDrawable) { ((RoundedDrawable) drawable).setCornerRadius(cornerRadius).setBorderColor(borderColor) .setBorderWidth(4).setOval(true); } } if (drawable != null) { drawableMap.put(urlString, drawable); Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth()); } else { Log.w(this.getClass().getSimpleName(), "could not get thumbnail"); } return drawable; } catch (MalformedURLException e) { Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e); return null; } catch (IOException e) { Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e); return null; } catch (Exception e) { Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e); return null; } }
From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java
/** * // w w w. j av a2s.c o m * * @param canvas */ private void drawTag(Canvas canvas) { // TODO if (mTagAdapter != null) { canvas.save(); float canvasOffset = 0; int x = getPaddingLeft(); int y = getPaddingTop(); float textTop = 0; mTextPaint.setColor(Color.WHITE); mTextPaint.setTextAlign(Align.LEFT); for (int position = 0; position < tabs.size(); position++) { canvas.translate(canvasOffset, 0); canvasOffset = itemWidth + intervalWidth; canvas.save(); if (mTagAdapter.isEnable(position)) { int textWidth; int textHeight; mTextPaint.setTextSize(mTagAdapter.getTextSize(position)); String tag = mTagAdapter.getTag(position) == null ? "" : mTagAdapter.getTag(position); textWidth = (int) Math.ceil(mTextPaint.measureText(tag)); FontMetrics fontMetrics = mTextPaint.getFontMetrics(); textHeight = (int) Math.ceil(fontMetrics.descent - fontMetrics.ascent); textTop = textHeight - (-fontMetrics.ascent - fontMetrics.descent + (fontMetrics.bottom - fontMetrics.descent) * density); textHeight += textTop; if ("".equals(tag)) { textHeight = 0; } final Drawable drawable = mTagAdapter.getBackground(position); int drawableWidth = drawable == null ? 0 : drawable.getMinimumWidth(); int drawableHeight = drawable == null ? 0 : drawable.getMinimumHeight(); float offsetX = Math.max(textWidth + mTagAdapter.getPaddingLeft(position) + mTagAdapter.getPaddingRight(position), drawableWidth); float offsetTextX = (offsetX - (textWidth + mTagAdapter.getPaddingLeft(position) + mTagAdapter.getPaddingRight(position))) * 0.5f; float offsetY = Math.max(textHeight + mTagAdapter.getPaddingBottom(position) + mTagAdapter.getPaddingTop(position), drawableHeight); float offsetTextY = (offsetY - (textHeight + mTagAdapter.getPaddingBottom(position) + mTagAdapter.getPaddingTop(position))) * 0.5f; mTextPaint.setTextSize(showTextScale ? textSize * (1 + magnification) : textSize); float myTextWidth = mTextPaint.measureText(tabs.get(position)); TagAlign ta = mTagAdapter.getTagAlign(position); switch (ta) { default: case LEFTTOP: canvas.translate(mTagAdapter.getMarginLeft(position), mTagAdapter.getMarginTop(position)); break; case LEFTCENTER: canvas.translate(mTagAdapter.getMarginLeft(position), (getHeight() - underLineHeight - offsetY) / 2); break; case LEFTBOTTOM: canvas.translate(mTagAdapter.getMarginLeft(position), getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position)); break; case RIGHTTOP: canvas.translate(itemWidth - offsetX - mTagAdapter.getMarginRight(position), mTagAdapter.getMarginTop(position)); break; case RIGHTCENTER: canvas.translate(itemWidth - offsetX - mTagAdapter.getMarginRight(position), (getHeight() - underLineHeight - offsetY) / 2); break; case RIGHTBOTTOM: canvas.translate(itemWidth - offsetX - mTagAdapter.getMarginRight(position), getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position)); break; case LEFTTOPTEXT: canvas.translate( (itemWidth - myTextWidth) / 2 - offsetX - mTagAdapter.getMarginRight(position), mTagAdapter.getMarginTop(position)); break; case LEFTCENTERTEXT: canvas.translate( (itemWidth - myTextWidth) / 2 - offsetX - mTagAdapter.getMarginRight(position), (getHeight() - underLineHeight - offsetY) / 2); break; case LEFTBOTTOMTEXT: canvas.translate( (itemWidth - myTextWidth) / 2 - offsetX - mTagAdapter.getMarginRight(position), getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position)); break; case RIGHTTOPTEXT: canvas.translate((itemWidth + myTextWidth) / 2 + mTagAdapter.getMarginLeft(position), mTagAdapter.getMarginTop(position)); break; case RIGHTCENTERTEXT: canvas.translate((itemWidth + myTextWidth) / 2 + mTagAdapter.getMarginLeft(position), (getHeight() - underLineHeight - offsetY) / 2); break; case RIGHTBOTTOMTEXT: canvas.translate((itemWidth + myTextWidth) / 2 + mTagAdapter.getMarginLeft(position), getHeight() - offsetY - underLineHeight - mTagAdapter.getMarginBottom(position)); break; } mTextPaint.setTextSize(mTagAdapter.getTextSize(position)); if (drawable != null) { drawable.setBounds(x, y, (int) (x + offsetX), (int) (y + offsetY)); drawable.draw(canvas); } canvas.drawText(tag, x + offsetTextX + mTagAdapter.getPaddingLeft(position), y + offsetY - textTop - offsetTextY - mTagAdapter.getPaddingTop(position), mTextPaint); } canvas.restore(); } canvas.restore(); } }
From source file:cn.longchou.wholesale.activity.VehicleDetailActivity.java
private void setAttention() { isAttention = cars.isFollow;/*from www . j a va 2s . c o m*/ if (!isAttention) { mAttention.setText(""); Drawable drawable = getResources().getDrawable(R.drawable.car_detail_attention_no); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); mAttention.setCompoundDrawables(null, drawable, null, null); } else { mAttention.setText("?"); Drawable drawable = getResources().getDrawable(R.drawable.car_detail_attention); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); mAttention.setCompoundDrawables(null, drawable, null, null); } }
From source file:cn.longchou.wholesale.activity.VehicleDetailActivity.java
private void showAttention() { //,?/*from www .j a v a 2s. c om*/ if (isAttention) { isAttention = false; mAttention.setText(""); Drawable drawable = getResources().getDrawable(R.drawable.car_detail_attention_no); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); mAttention.setCompoundDrawables(null, drawable, null, null); //? deleteAttention(); } // else { isAttention = true; mAttention.setText("?"); Drawable drawable = getResources().getDrawable(R.drawable.car_detail_attention); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); mAttention.setCompoundDrawables(null, drawable, null, null); // addAttention(); } }
From source file:com.fullteem.yueba.app.ui.MainActivity.java
@Override public void initData() { LogUtil.LogDebug("?", "Fragment:" + System.currentTimeMillis(), null); mListener = new MyListener(); // for fragent mFragments = new ArrayList<Fragment>(PAGE_TOATAL); mFragments.add(NearbyMainFragment.getInstance()); mFragments.add(MessageMainFragment.getInstance()); mFragments.add(DiscoverMainFragment.getInstance()); mFragments.add(PersonalMainFragment.getInstance()); for (int i = 0; i < mFragments.size(); i++) { getSupportFragmentManager().beginTransaction().add(R.id.ll_fragmentcontainer, mFragments.get(i)) .commit();/*from ww w. j a va 2s . c o m*/ } ((NearbyMainFragment) mFragments.get(0)).onLuckyMeet(); // for show image int[] imgId = { R.drawable.img_main_nearby, R.drawable.img_main_message, R.drawable.img_main_discover, R.drawable.img_main_personal, R.drawable.img_main_nearby_selected, R.drawable.img_main_message_selected, R.drawable.img_main_discover_selected, R.drawable.img_main_personal_selected }; mImgUnSelected = new ArrayList<Drawable>(PAGE_TOATAL); for (int i = 0; i < PAGE_TOATAL; i++) { Drawable drawable = getResources().getDrawable(imgId[i]); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); mImgUnSelected.add(drawable); } mImgSelected = new ArrayList<Drawable>(PAGE_TOATAL); for (int i = 4; i < imgId.length; i++) { Drawable drawable = getResources().getDrawable(imgId[i]); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); mImgSelected.add(drawable); } // ?? inviteMessgeDao = new InviteMessgeDao(this); userDao = new UserDao(this); // ?BroadcastReceiver msgReceiver = new NewYBMessageBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(EMChatManager.getInstance().getNewMessageBroadcastAction()); intentFilter.setPriority(3); registerReceiver(msgReceiver, intentFilter); // ack?BroadcastReceiver IntentFilter ackMessageIntentFilter = new IntentFilter( EMChatManager.getInstance().getAckMessageBroadcastAction()); ackMessageIntentFilter.setPriority(3); registerReceiver(ackMessageReceiver, ackMessageIntentFilter); // ??BroadcastReceiver IntentFilter cmdMessageIntentFilter = new IntentFilter( EMChatManager.getInstance().getCmdMessageBroadcastAction()); cmdMessageIntentFilter.setPriority(3); registerReceiver(cmdMessageReceiver, cmdMessageIntentFilter); // setContactListener??? EMContactManager.getInstance().setContactListener(new MyContactListener()); // ??listener EMChatManager.getInstance().addConnectionListener(new MyConnectionListener()); // ?listener EMGroupManager.getInstance().addGroupChangeListener(new MyGroupChangeListener()); // sdkUI ??receiverlistener, ??broadcast EMChat.getInstance().setAppInited(); LogUtil.LogDebug("?", "MainActivity ??:" + System.currentTimeMillis(), null); }
From source file:com.zhenlaidian.ui.InputCarNumberActivity.java
private void initPopWindow(final ArrayList<CarTypeItem> car_type) { View cartypeView = getLayoutInflater().inflate(R.layout.cartype_layout, null, false); pow = new PopupWindow(cartypeView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true); // ??BackPopupWindow pow.setOutsideTouchable(true);/* w w w . j av a 2 s . c o m*/ pow.setBackgroundDrawable(new BitmapDrawable()); cartypeView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (pow != null && pow.isShowing()) { pow.dismiss(); pow = null; } return false; } }); pow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { Drawable d = getResources().getDrawable(R.drawable.set_collect_on); d.setBounds(0, 0, d.getMinimumWidth(), d.getMinimumHeight()); // cartype.setCompoundDrawables(null, null, d, null); } }); listtype = ((ListView) cartypeView.findViewById(R.id.cartype_lv_popview)); if (car_type.size() > 9) { ViewGroup.LayoutParams params = listtype.getLayoutParams(); params.height = CommontUtils.getScreenWidth(this); listtype.setLayoutParams(params); } cartypeAdapter = new CartypeAdapter(car_type, context); listtype.setAdapter(cartypeAdapter); listtype.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { cartypecode = car_type.get(position).getId(); cartype.setText(car_type.get(position).getName()); pow.dismiss(); } }); }