List of usage examples for android.graphics.drawable Drawable getIntrinsicWidth
public int getIntrinsicWidth()
From source file:com.github.jobs.ui.activity.JobDetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.job_details_activity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (getIntent() == null || getIntent().getExtras() == null) { finish();/* w w w . j a v a 2 s . c om*/ return; } // get the selected job and the list of ids Bundle extras = getIntent().getExtras(); String jobId = extras.getString(EXTRA_CURRENT_JOB_ID); mJobsIds = extras.getStringArrayList(EXTRA_JOBS_IDS); mCurrentJobPosition = mJobsIds.indexOf(jobId); // prepare the view pager to show current job mJobsPager = (ViewPager) findViewById(R.id.jobs_pager); mJobsPager.setAdapter(new JobsDetailsAdapter(getSupportFragmentManager(), mJobsIds)); mJobsPager.setCurrentItem(mCurrentJobPosition); mJobsPager.setOnPageChangeListener(this); Drawable drawable = getResources().getDrawable(R.drawable.view_pager_separator); mJobsPager.setPageMargin(drawable.getIntrinsicWidth()); mJobsPager.setPageMarginDrawable(drawable); getTracker(this).trackPageView(NAME_DETAILS + "?id=" + jobId); }
From source file:com.hippo.gl.glrenderer.XmlResourceTexture.java
@Override protected Bitmap onGetBitmap() { Drawable drawable = ContextCompat.getDrawable(mContext, mResId); int width = mWidth; int height = mHeight; if (width <= 0) { width = drawable.getIntrinsicWidth(); }/* w ww . j av a 2 s . c o m*/ if (height <= 0) { height = drawable.getIntrinsicHeight(); } if (width <= 0) { width = 1; } if (height <= 0) { height = 1; } drawable.setBounds(0, 0, width, height); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.draw(canvas); return bitmap; }
From source file:android.support.v7.widget.AppCompatCompoundButtonHelper.java
int getCompoundPaddingLeft(int superValue) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { // Before JB-MR1 the button drawable wasn't taken into account for padding. We'll // workaround that here Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView); if (buttonDrawable != null) { superValue += buttonDrawable.getIntrinsicWidth(); }//from w ww. j a v a 2 s.co m } return superValue; }
From source file:com.silentcircle.contacts.calllognew.CallTypeIconsView.java
public void add(int callType) { mCallTypes.add(callType);//w ww.j a va 2s. c o m final Drawable drawable = getCallTypeDrawable(callType); mWidth += drawable.getIntrinsicWidth() + mResources.iconMargin; mHeight = Math.max(mHeight, drawable.getIntrinsicHeight()); invalidate(); }
From source file:com.google.android.gms.samples.wallet.CartDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_cart_detail, container, false); ItemInfo itemInfo = Constants.ITEMS_FOR_SALE[mItemId]; TextView itemName = (TextView) view.findViewById(R.id.text_item_name); itemName.setText(itemInfo.name);//from w w w . j a va 2 s . c o m Drawable itemImage = getResources().getDrawable(itemInfo.imageResourceId); int imageSize = getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size); int actualWidth = itemImage.getIntrinsicWidth(); int actualHeight = itemImage.getIntrinsicHeight(); int scaledHeight = imageSize; int scaledWidth = (int) (((float) actualWidth / actualHeight) * scaledHeight); itemImage.setBounds(0, 0, scaledWidth, scaledHeight); itemName.setCompoundDrawables(itemImage, null, null, null); TextView itemPrice = (TextView) view.findViewById(R.id.text_item_price); itemPrice.setText(Util.formatPrice(getActivity(), itemInfo.priceMicros)); TextView shippingCost = (TextView) view.findViewById(R.id.text_shipping_price); TextView tax = (TextView) view.findViewById(R.id.text_tax_price); TextView total = (TextView) view.findViewById(R.id.text_total_price); if ((mItemId == Constants.PROMOTION_ITEM) && getApplication().isAddressValidForPromo()) { shippingCost.setText(Util.formatPrice(getActivity(), 0L)); } else { shippingCost.setText(Util.formatPrice(getActivity(), itemInfo.shippingPriceMicros)); } tax.setText(Util.formatPrice(getActivity(), itemInfo.taxMicros)); total.setText(Util.formatPrice(getActivity(), itemInfo.getTotalPrice())); return view; }
From source file:com.sareen.squarelabs.techrumors.HTMLParser.HtmlLocalImageGetter.java
private float getScale(Drawable drawable) { if (!matchParentWidth || container == null) { return 1f; }/*from ww w. j a va 2 s . c o m*/ float maxWidth = container.getWidth(); float originalDrawableWidth = drawable.getIntrinsicWidth(); return maxWidth / originalDrawableWidth; }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void startImg(SpannableStringBuilder text, Attributes attributes, HtmlParser.ImageGetter img) { String src = attributes.getValue("", "src"); Drawable d = null; if (img != null) { d = img.getDrawable(src);//from ww w . ja va2s .co m } if (d == null) { d = ResourcesCompat.getDrawable(Resources.getSystem(), android.R.drawable.ic_menu_report_image, null); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
From source file:org.opensourcetlapp.tl.CustomImageGetter.java
@Override public Drawable getDrawable(String url) { try {// w ww .j a v a 2s .com // get name of image String name = url.substring(url.lastIndexOf("/") + 1); InputStream is; try { try { is = assetManager.open("images/" + name); } catch (IOException e) { is = context.openFileInput(name); } } catch (FileNotFoundException e) { is = getImageInputStream(url); if (!name.contains("draw.php?poll_id")) { FileOutputStream out = context.openFileOutput(name, Context.MODE_PRIVATE); byte[] buffer = new byte[1024]; int totalLength = 0; int length; while ((length = is.read(buffer)) >= 0) { totalLength += length; out.write(buffer, 0, length); } is.close(); out.close(); is = context.openFileInput(name); } } // cache dir + name of image + the image save format Drawable d = Drawable.createFromStream(is, name); //Drawable d = Drawable.createFromPath(f.getAbsolutePath()); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());// make it the size of the image return d; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:edu.mit.mobile.android.imagecache.test.ImageCacheJunitTest.java
private void assertBitmapMaxSize(int maxExpectedWidth, int maxExpectedHeight, Drawable actual) { assertTrue(maxExpectedWidth >= actual.getIntrinsicWidth()); assertTrue(maxExpectedHeight >= actual.getIntrinsicHeight()); }
From source file:edu.mit.mobile.android.imagecache.test.ImageCacheJunitTest.java
private void assertBitmapMinSize(int minExpectedWidth, int minExpectedHeight, Drawable actual) { assertTrue(minExpectedWidth <= actual.getIntrinsicWidth()); assertTrue(minExpectedHeight <= actual.getIntrinsicHeight()); }