List of usage examples for android.widget ImageView getMeasuredWidth
public final int getMeasuredWidth()
From source file:Main.java
private static void updateImageViewAfterScaleTypeChange(ImageView imageView) { // enforcing imageView to update its internal bounds/matrix immediately imageView.measure(MeasureSpec.makeMeasureSpec(imageView.getMeasuredWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(imageView.getMeasuredHeight(), MeasureSpec.EXACTLY)); imageView.layout(imageView.getLeft(), imageView.getTop(), imageView.getRight(), imageView.getBottom()); }
From source file:com.yanzhenjie.album.task.LocalImageLoader.java
/** * According to the ImageView obtains appropriate width and height of compression. * * @param imageView {@link ImageView}./*from w ww .j a v a2 s. com*/ * @param viewSizes ViewSize. */ public static void measureSize(ImageView imageView, int[] viewSizes) { final DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics(); final LayoutParams params = imageView.getLayoutParams(); if (params == null) { viewSizes[0] = displayMetrics.widthPixels; viewSizes[1] = displayMetrics.heightPixels; } else { viewSizes[0] = params.width == LayoutParams.WRAP_CONTENT ? 0 : imageView.getMeasuredWidth(); // Get actual image width viewSizes[1] = params.height == LayoutParams.WRAP_CONTENT ? 0 : imageView.getMeasuredWidth(); // Get actual image // height if (viewSizes[0] <= 0) viewSizes[0] = displayMetrics.widthPixels; // Get layout width parameter if (viewSizes[1] <= 0) viewSizes[1] = displayMetrics.heightPixels; // Get layout height parameter } }
From source file:com.tigerpenguin.places.model.Photo.java
public void loadImage(Context context, ImageView imageView) { int width = imageView.getLayoutParams().width; if (width <= 0) { width = imageView.getMeasuredWidth(); }/*from w w w.ja v a 2 s.c o m*/ int height = imageView.getLayoutParams().height; if (height <= 0) { height = imageView.getMeasuredHeight(); } Picasso.with(context).load(getUrl(context, width, height)).into(imageView); }
From source file:net.naonedbus.card.impl.MapCard.java
private void fillView(final ImageView imageView) { final String url; if (mCurrentLocation == null) { url = String.format(Locale.ENGLISH, MAP_URL, imageView.getMeasuredWidth(), imageView.getMeasuredHeight(), mLatitude, mLongitude); } else {//from ww w. j a v a 2 s. c om url = String.format(Locale.ENGLISH, MAP_URL_CURRENT_LOCATION, imageView.getMeasuredWidth(), imageView.getMeasuredHeight(), mLatitude, mLongitude, mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()); } final Bundle bundle = new Bundle(); bundle.putString(PARAM_URL, url); initLoader(bundle, this).forceLoad(); }
From source file:ru.tlrs.vincent.LightBox.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "onCreateView: "); inflateView(inflater, container);// w w w . j av a2s. c om final ImageView fullImage = (ImageView) view.findViewById(R.id.fullImage); fullImage.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { fullImage.getViewTreeObserver().removeOnPreDrawListener(this); int height = fullImage.getMeasuredHeight(); int width = fullImage.getMeasuredWidth(); Log.d(TAG, "onPreDraw: " + String.format("height: %s, width: %s", height, width)); //Rect view = new Rect(0,0,width, height); Drawable drawable = ((ImageView) getActivity().findViewById(parentId)).getDrawable(); /*drawable = drawable.mutate(); //Rect draw = drawable.getBounds(); int h = drawable.getIntrinsicHeight(); int w = drawable.getIntrinsicWidth(); //drawable.setBounds(0,0,w,h); drawable.setBounds(new Rect(0,0,width,height)); //ScaleDrawable sd = new ScaleDrawable(drawable, 0, 1.0f ,1.0f );*/ //fullImage.setImageDrawable(drawable); //fullImage.setImageURI(null); Log.d(TAG, "onPreDraw: mSrc = " + mSrc); fullImage.setImageURI(Uri.parse("android.resource://com.example.vincent/" + mSrc)); //give "More than two path segments", instead of NullPointer return false; } }); //((ImageView) view.findViewById(R.id.fullImage)).setImageDrawable(((ImageView) getActivity().findViewById(parentId)).getDrawable()); ((TextView) view.findViewById(R.id.description)).setText(mDesc); return view; }
From source file:com.yanzhenjie.album.task.ImageLocalLoader.java
/** * According to the ImageView obtains appropriate width and height of compression. * * @param imageView {@link ImageView}.//from www.ja va 2 s . c om * @param viewSizes ViewSize. */ private void measureSize(ImageView imageView, int[] viewSizes) { final DisplayMetrics displayMetrics = imageView.getContext().getResources().getDisplayMetrics(); final LayoutParams params = imageView.getLayoutParams(); if (params == null) { viewSizes[0] = displayMetrics.widthPixels; viewSizes[1] = displayMetrics.heightPixels; } else { viewSizes[0] = params.width == LayoutParams.WRAP_CONTENT ? 0 : imageView.getMeasuredWidth(); // Get actual image width viewSizes[1] = params.height == LayoutParams.WRAP_CONTENT ? 0 : imageView.getMeasuredWidth(); // Get actual image height if (viewSizes[0] <= 0) viewSizes[0] = displayMetrics.widthPixels; // Get layout width parameter if (viewSizes[1] <= 0) viewSizes[1] = displayMetrics.heightPixels; // Get layout height parameter } }
From source file:com.keylesspalace.tusky.activity.MainActivity.java
private void fetchUserInfo() { SharedPreferences preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE); final String domain = preferences.getString("domain", null); String id = preferences.getString("loggedInAccountId", null); String username = preferences.getString("loggedInAccountUsername", null); if (id != null && username != null) { loggedInAccountId = id;/*w w w . j a va 2 s . com*/ loggedInAccountUsername = username; } mastodonAPI.accountVerifyCredentials().enqueue(new Callback<Account>() { @Override public void onResponse(Call<Account> call, Response<Account> response) { if (!response.isSuccessful()) { onFetchUserInfoFailure(new Exception(response.message())); return; } Account me = response.body(); ImageView background = headerResult.getHeaderBackgroundView(); int backgroundWidth = background.getWidth(); int backgroundHeight = background.getHeight(); if (backgroundWidth == 0 || backgroundHeight == 0) { /* The header ImageView may not be layed out when the verify credentials call * returns so measure the dimensions and use those. */ background.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY); backgroundWidth = background.getMeasuredWidth(); backgroundHeight = background.getMeasuredHeight(); } Picasso.with(MainActivity.this).load(me.header).placeholder(R.drawable.account_header_missing) .resize(backgroundWidth, backgroundHeight).centerCrop().into(background); headerResult.addProfiles(new ProfileDrawerItem().withName(me.getDisplayName()) .withEmail(String.format("%s@%s", me.username, domain)).withIcon(me.avatar)); onFetchUserInfoSuccess(me.id, me.username); } @Override public void onFailure(Call<Account> call, Throwable t) { onFetchUserInfoFailure((Exception) t); } }); }
From source file:com.squareup.picasso.RequestCreator.java
/** * Asynchronously fulfills the request into the specified {@link ImageView} and invokes the * target {@link Callback} if it's not {@code null}. * <p/>//from ww w.ja v a 2s . c o m * <em>Note:</em> The {@link Callback} param is a strong reference and will prevent your * {@link android.app.Activity} or {@link android.app.Fragment} from being garbage collected. If * you use this method, it is <b>strongly</b> recommended you invoke an adjacent * {@link Picasso#cancelRequest(android.widget.ImageView)} call to prevent temporary leaking. */ public void into(ImageView target, Callback callback) { if (target == null) { throw new IllegalArgumentException("Target must not be null."); } if (!data.hasImage()) { picasso.cancelRequest(target); PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable); return; } if (deferred) { if (data.hasSize()) { throw new IllegalStateException("Fit cannot be used with resize."); } int measuredWidth = target.getMeasuredWidth(); int measuredHeight = target.getMeasuredHeight(); if (maxWidth != -1 && measuredWidth > maxWidth) measuredWidth = maxWidth; if (maxHeight != -1 && measuredHeight > maxHeight) measuredHeight = maxHeight; if (measuredWidth == 0 && measuredHeight == 0) { PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable); picasso.defer(target, new DeferredRequestCreator(this, target, callback)); return; } data.resize(measuredWidth, measuredHeight, false); } Request finalData = picasso.transformRequest(data.build()); String requestKey = createKey(finalData); if (!skipMemoryCache) { Bitmap bitmap = picasso.quickMemoryCacheCheck( data.getCache() != null ? data.getCache() : picasso.getCache(), requestKey); if (bitmap != null) { picasso.cancelRequest(target); PicassoDrawable.setBitmap(target, picasso.context, bitmap, MEMORY, fadeTime, picasso.debugging); if (callback != null) { callback.onSuccess(); } return; } } PicassoDrawable.setPlaceholder(target, placeholderResId, placeholderDrawable); Action<ImageView> action = new ImageViewAction(picasso, target, finalData, skipMemoryCache, fadeTime, errorResId, errorDrawable, requestKey, callback); picasso.enqueueAndSubmit(action, delayMillis); }
From source file:net.maa123.tatuky.MainActivity.java
private void onFetchUserInfoSuccess(Account me, String domain) { // Add the header image and avatar from the account, into the navigation drawer header. headerResult.clear();/*from ww w . j av a 2s. c o m*/ ImageView background = headerResult.getHeaderBackgroundView(); int backgroundWidth = background.getWidth(); int backgroundHeight = background.getHeight(); if (backgroundWidth == 0 || backgroundHeight == 0) { /* The header ImageView may not be layed out when the verify credentials call returns so * measure the dimensions and use those. */ background.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY); backgroundWidth = background.getMeasuredWidth(); backgroundHeight = background.getMeasuredHeight(); } background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark)); Picasso.with(MainActivity.this).load(me.header).placeholder(R.drawable.account_header_default) .resize(backgroundWidth, backgroundHeight).centerCrop().into(background); headerResult.addProfiles(new ProfileDrawerItem().withName(me.getDisplayName()) .withEmail(String.format("%s@%s", me.username, domain)).withIcon(me.avatar)); // Show follow requests in the menu, if this is a locked account. if (me.locked) { PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem().withIdentifier(6) .withName(R.string.action_view_follow_requests).withSelectable(false) .withIcon(GoogleMaterial.Icon.gmd_person_add); drawer.addItemAtPosition(followRequestsItem, 3); } // Update the current login information. loggedInAccountId = me.id; loggedInAccountUsername = me.username; getPrivatePreferences().edit().putString("loggedInAccountId", loggedInAccountId) .putString("loggedInAccountUsername", loggedInAccountUsername) .putBoolean("loggedInAccountLocked", me.locked).apply(); }
From source file:com.fa.mastodon.activity.MainActivity.java
private void onFetchUserInfoSuccess(Account me, String domain) { // Add the header image and avatar from the account, into the navigation drawer header. headerResult.clear();/*from w w w . j av a 2s .c o m*/ ImageView background = headerResult.getHeaderBackgroundView(); int backgroundWidth = background.getWidth(); int backgroundHeight = background.getHeight(); if (backgroundWidth == 0 || backgroundHeight == 0) { /* The header ImageView may not be layed out when the verify credentials call returns so * measure the dimensions and use those. */ background.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY); backgroundWidth = background.getMeasuredWidth(); backgroundHeight = background.getMeasuredHeight(); } background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark)); if (backgroundWidth == 0 || backgroundHeight == 0) { } else { Picasso.with(MainActivity.this).load(me.header).placeholder(R.drawable.account_header_default) .resize(backgroundWidth, backgroundHeight).centerCrop().into(background); } headerResult.addProfiles(new ProfileDrawerItem().withName(me.getDisplayName()) .withEmail(String.format("%s@%s", me.username, domain)).withIcon(me.avatar)); // Show follow requests in the menu, if this is a locked account. if (me.locked) { PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem().withIdentifier(6) .withName(R.string.action_view_follow_requests).withSelectable(false) .withIcon(GoogleMaterial.Icon.gmd_person_add); drawer.addItemAtPosition(followRequestsItem, 3); } // Update the current login information. loggedInAccountId = me.id; loggedInAccountUsername = me.username; getPrivatePreferences().edit().putString("loggedInAccountId", loggedInAccountId) .putString("loggedInAccountUsername", loggedInAccountUsername) .putBoolean("loggedInAccountLocked", me.locked).apply(); }