List of usage examples for android.graphics.drawable Drawable setBounds
public void setBounds(int left, int top, int right, int bottom)
From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java
private CharSequence getDecoratedHint(CharSequence hintText) { // If the field is always expanded, then don't add the search icon to the hint if (!mIconifiedByDefault) return hintText; SpannableStringBuilder ssb = new SpannableStringBuilder(" "); // for the icon ssb.append(hintText);/* w ww . ja va2 s. co m*/ Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId()); int textSize = (int) (mQueryTextView.getTextSize() * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return ssb; }
From source file:com.hippo.ehviewer.ui.scene.GalleryListScene.java
private void setSearchBarHint(Context context, SearchBar searchBar) { Resources resources = context.getResources(); Drawable searchImage = DrawableManager.getDrawable(context, R.drawable.v_magnify_x24); SpannableStringBuilder ssb = new SpannableStringBuilder(" "); ssb.append(resources.getString(//from w w w .java 2s . com EhUrl.SITE_EX == Settings.getGallerySite() ? R.string.gallery_list_search_bar_hint_exhentai : R.string.gallery_list_search_bar_hint_e_hentai)); int textSize = (int) (searchBar.getEditTextTextSize() * 1.25); if (searchImage != null) { searchImage.setBounds(0, 0, textSize, textSize); ssb.setSpan(new ImageSpan(searchImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } searchBar.setEditTextHint(ssb); }
From source file:org.mariotaku.twidere.fragment.support.UserFragment.java
private void showRelationship(ParcelableUser user, Relationship relationship) { mRelationship = relationship;/*from ww w. j a v a 2s .c o m*/ if (user == null) return; invalidateOptionsMenu(); final boolean isMyself = user.account_id == user.id; if (isMyself) { mFollowButton.setText(R.string.edit); mFollowButton.setVisibility(View.VISIBLE); } else if (relationship != null) { final int drawableRes; mFollowButton.setEnabled(!relationship.isSourceBlockedByTarget()); if (relationship.isSourceBlockedByTarget()) { mPagesErrorContainer.setVisibility(View.VISIBLE); final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); mPagesErrorText.setText(getString(R.string.blocked_by_user_summary, displayName)); mPagesErrorIcon.setImageResource(R.drawable.ic_info_error_generic); mPagesContent.setVisibility(View.GONE); } else if (!relationship.isSourceFollowingTarget() && user.is_protected) { mPagesErrorContainer.setVisibility(View.VISIBLE); final String displayName = mUserColorNameManager.getDisplayName(user, mNameFirst, true); mPagesErrorText.setText(getString(R.string.user_protected_summary, displayName)); mPagesErrorIcon.setImageResource(R.drawable.ic_info_locked); mPagesContent.setVisibility(View.GONE); } else { mPagesErrorContainer.setVisibility(View.GONE); mPagesErrorText.setText(null); mPagesContent.setVisibility(View.VISIBLE); } if (relationship.isSourceBlockingTarget()) { mFollowButton.setText(R.string.unblock); drawableRes = R.drawable.ic_follow_blocked; } else if (relationship.isSourceFollowingTarget()) { mFollowButton.setText(R.string.unfollow); if (relationship.isTargetFollowingSource()) { drawableRes = R.drawable.ic_follow_bidirectional; } else { drawableRes = R.drawable.ic_follow_outgoing; } } else if (user.is_follow_request_sent) { mFollowButton.setText(R.string.requested); if (relationship.isTargetFollowingSource()) { drawableRes = R.drawable.ic_follow_incoming; } else { drawableRes = R.drawable.ic_follow_pending; } } else { mFollowButton.setText(R.string.follow); if (relationship.isTargetFollowingSource()) { drawableRes = R.drawable.ic_follow_incoming; } else { drawableRes = R.drawable.ic_follow_none; } } final Drawable icon = ResourcesCompat.getDrawable(getResources(), drawableRes, null); final int iconSize = Math.round(mFollowButton.getTextSize() * 1.4f); icon.setBounds(0, 0, iconSize, iconSize); icon.setColorFilter(mFollowButton.getCurrentTextColor(), Mode.SRC_ATOP); mFollowButton.setCompoundDrawables(icon, null, null, null); mFollowButton.setCompoundDrawablePadding(Math.round(mFollowButton.getTextSize() * 0.25f)); final ContentResolver resolver = getContentResolver(); final ContentValues cachedValues = ParcelableUser.makeCachedUserContentValues(user); resolver.insert(CachedUsers.CONTENT_URI, cachedValues); mFollowButton.setVisibility(View.VISIBLE); } else { mFollowButton.setText(null); mFollowButton.setVisibility(View.GONE); mPagesErrorContainer.setVisibility(View.GONE); mPagesContent.setVisibility(View.VISIBLE); } }
From source file:com.hippo.ehviewer.ui.scene.GalleryDetailScene.java
@Nullable @Override/*w w w . j av a 2 s .co m*/ public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // Get download state long gid = getGid(); if (gid != -1) { Context context = getContext2(); Assert.assertNotNull(context); mDownloadState = EhApplication.getDownloadManager(context).getDownloadState(gid); } else { mDownloadState = DownloadInfo.STATE_INVALID; } View view = inflater.inflate(R.layout.scene_gallery_detail, container, false); ViewGroup main = (ViewGroup) ViewUtils.$$(view, R.id.main); View mainView = ViewUtils.$$(main, R.id.scroll_view); View progressView = ViewUtils.$$(main, R.id.progress_view); mTip = (TextView) ViewUtils.$$(main, R.id.tip); mViewTransition = new ViewTransition(mainView, progressView, mTip); Context context = getContext2(); Assert.assertNotNull(context); Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_weird_face); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); mTip.setCompoundDrawables(null, drawable, null, null); mTip.setOnClickListener(this); mHeader = ViewUtils.$$(mainView, R.id.header); mColorBg = ViewUtils.$$(mHeader, R.id.color_bg); mThumb = (LoadImageView) ViewUtils.$$(mHeader, R.id.thumb); mTitle = (TextView) ViewUtils.$$(mHeader, R.id.title); mUploader = (TextView) ViewUtils.$$(mHeader, R.id.uploader); mCategory = (TextView) ViewUtils.$$(mHeader, R.id.category); mOtherActions = (ImageView) ViewUtils.$$(mHeader, R.id.other_actions); mActionGroup = (ViewGroup) ViewUtils.$$(mHeader, R.id.action_card); mDownload = (TextView) ViewUtils.$$(mActionGroup, R.id.download); mRead = ViewUtils.$$(mActionGroup, R.id.read); Ripple.addRipple(mOtherActions, false); Ripple.addRipple(mDownload, false); Ripple.addRipple(mRead, false); mUploader.setOnClickListener(this); mCategory.setOnClickListener(this); mOtherActions.setOnClickListener(this); mDownload.setOnClickListener(this); mDownload.setOnLongClickListener(this); mRead.setOnClickListener(this); mUploader.setOnLongClickListener(this); mBelowHeader = mainView.findViewById(R.id.below_header); View belowHeader = mBelowHeader; mInfo = ViewUtils.$$(belowHeader, R.id.info); mLanguage = (TextView) ViewUtils.$$(mInfo, R.id.language); mPages = (TextView) ViewUtils.$$(mInfo, R.id.pages); mSize = (TextView) ViewUtils.$$(mInfo, R.id.size); mPosted = (TextView) ViewUtils.$$(mInfo, R.id.posted); mFavoredTimes = (TextView) ViewUtils.$$(mInfo, R.id.favoredTimes); Ripple.addRipple(mInfo, false); mInfo.setOnClickListener(this); mActions = ViewUtils.$$(belowHeader, R.id.actions); mRatingText = (TextView) ViewUtils.$$(mActions, R.id.rating_text); mRating = (RatingBar) ViewUtils.$$(mActions, R.id.rating); mHeartGroup = ViewUtils.$$(mActions, R.id.heart_group); mHeart = (TextView) ViewUtils.$$(mHeartGroup, R.id.heart); mHeartOutline = (TextView) ViewUtils.$$(mHeartGroup, R.id.heart_outline); mTorrent = (TextView) ViewUtils.$$(mActions, R.id.torrent); mShare = (TextView) ViewUtils.$$(mActions, R.id.share); mRate = (TextView) ViewUtils.$$(mActions, R.id.rate); mSimilar = (TextView) ViewUtils.$$(mActions, R.id.similar); mSearchCover = (TextView) ViewUtils.$$(mActions, R.id.search_cover); Ripple.addRipple(mHeartGroup, false); Ripple.addRipple(mTorrent, false); Ripple.addRipple(mShare, false); Ripple.addRipple(mRate, false); Ripple.addRipple(mSimilar, false); Ripple.addRipple(mSearchCover, false); mHeartGroup.setOnClickListener(this); mTorrent.setOnClickListener(this); mShare.setOnClickListener(this); mRate.setOnClickListener(this); mSimilar.setOnClickListener(this); mSearchCover.setOnClickListener(this); ensureActionDrawable(context); mTags = (LinearLayout) ViewUtils.$$(belowHeader, R.id.tags); mNoTags = (TextView) ViewUtils.$$(mTags, R.id.no_tags); mComments = (LinearLayout) ViewUtils.$$(belowHeader, R.id.comments); mCommentsText = (TextView) ViewUtils.$$(mComments, R.id.comments_text); Ripple.addRipple(mComments, false); mComments.setOnClickListener(this); mPreviews = ViewUtils.$$(belowHeader, R.id.previews); mGridLayout = (SimpleGridAutoSpanLayout) ViewUtils.$$(mPreviews, R.id.grid_layout); mPreviewText = (TextView) ViewUtils.$$(mPreviews, R.id.preview_text); Ripple.addRipple(mPreviews, false); mPreviews.setOnClickListener(this); mProgress = ViewUtils.$$(mainView, R.id.progress); mViewTransition2 = new ViewTransition(mBelowHeader, mProgress); if (prepareData()) { if (mGalleryDetail != null) { bindViewSecond(); setTransitionName(); adjustViewVisibility(STATE_NORMAL, false); } else if (mGalleryInfo != null) { bindViewFirst(); setTransitionName(); adjustViewVisibility(STATE_REFRESH_HEADER, false); } else { adjustViewVisibility(STATE_REFRESH, false); } } else { mTip.setText(R.string.error_cannot_find_gallery); adjustViewVisibility(STATE_FAILED, false); } EhApplication.getDownloadManager(context).addDownloadInfoListener(this); return view; }
From source file:com.android.launcher2.AsyncTaskCallback.java
private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h, float scale) { if (bitmap != null) { Canvas c = new Canvas(bitmap); c.scale(scale, scale);//from w w w . j av a2s.co m Rect oldBounds = d.copyBounds(); d.setBounds(x, y, x + w, y + h); d.draw(c); d.setBounds(oldBounds); // Restore the bounds c.setBitmap(null); } }
From source file:com.waz.zclient.pages.main.conversationpager.SlidingPaneLayout.java
@Override public void draw(Canvas c) { super.draw(c); final boolean isLayoutRtl = isLayoutRtlSupport(); Drawable shadowDrawable; if (isLayoutRtl) { shadowDrawable = shadowDrawableRight; } else {// w ww. j a v a2s. c o m shadowDrawable = shadowDrawableLeft; } final View shadowView = getChildCount() > 1 ? getChildAt(1) : null; if (shadowView == null || shadowDrawable == null) { // No need to draw a shadow if we don't have one. return; } final int top = shadowView.getTop(); final int bottom = shadowView.getBottom(); final int shadowWidth = shadowDrawable.getIntrinsicWidth(); final int left; final int right; if (isLayoutRtlSupport()) { left = shadowView.getRight(); right = left + shadowWidth; } else { right = shadowView.getLeft(); left = right - shadowWidth; } shadowDrawable.setBounds(left, top, right, bottom); shadowDrawable.draw(c); }
From source file:io.apptik.widget.MultiSlider.java
/** * @param gap If set to {@link Integer#MIN_VALUE}, this will be ignored and *///from w w w . ja v a 2s.c om private void setThumbPos(int w, int h, Drawable thumb, Drawable prevThumb, Drawable range, float scale, int gap, int thumbOffset, int optThumbOffset) { final int available = getAvailable(); int thumbWidth = thumb.getIntrinsicWidth(); int thumbHeight = thumb.getIntrinsicHeight(); //todo change available before also float scaleOffset = getScaleSize() > 0 ? (float) mScaleMin / (float) getScaleSize() : 0; int thumbPos = (int) (scale * available - scaleOffset * available + 0.5f); int topBound, bottomBound; if (gap == Integer.MIN_VALUE) { Rect oldBounds = thumb.getBounds(); topBound = oldBounds.top; bottomBound = oldBounds.bottom; } else { topBound = gap; bottomBound = gap + thumbHeight; } // Canvas will be translated, so 0,0 is where we start drawing final int left = (isLayoutRtl() && mMirrorForRtl) ? available - thumbPos - optThumbOffset : thumbPos + optThumbOffset; thumb.setBounds(left, topBound, left + thumbWidth, bottomBound); w -= getPaddingRight() + getPaddingLeft(); h -= getPaddingTop() + getPaddingBottom(); int right = w; int bottom = h; int leftRange = 0; if (prevThumb != null) { leftRange = prevThumb.getBounds().left; } if (range != null) { range.setBounds(leftRange, 0, left, bottom); } invalidate(); }
From source file:org.chromium.chrome.browser.toolbar.ToolbarPhone.java
/** * When entering and exiting the TabSwitcher mode, we fade out or fade in the browsing * mode of the toolbar on top of the TabSwitcher mode version of it. We do this by * drawing all of the browsing mode views on top of the android view. *///from w w w . j av a 2 s .co m private void drawTabSwitcherAnimationOverlay(Canvas canvas, float animationProgress) { if (!isNativeLibraryReady()) return; float floatAlpha = 1 - animationProgress; int rgbAlpha = (int) (255 * floatAlpha); canvas.save(); canvas.translate(0, -animationProgress * mBackgroundOverlayBounds.height()); canvas.clipRect(mBackgroundOverlayBounds); float previousAlpha = 0.f; if (mHomeButton.getVisibility() != View.GONE) { // Draw the New Tab button used in the URL view. previousAlpha = mHomeButton.getAlpha(); mHomeButton.setAlpha(previousAlpha * floatAlpha); drawChild(canvas, mHomeButton, SystemClock.uptimeMillis()); mHomeButton.setAlpha(previousAlpha); } // Draw the location/URL bar. previousAlpha = mLocationBar.getAlpha(); mLocationBar.setAlpha(previousAlpha * floatAlpha); // If the location bar is now fully transparent, do not bother drawing it. if (mLocationBar.getAlpha() != 0) { drawChild(canvas, mLocationBar, SystemClock.uptimeMillis()); } mLocationBar.setAlpha(previousAlpha); // Draw the tab stack button and associated text. translateCanvasToView(this, mToolbarButtonsContainer, canvas); if (mTabSwitcherAnimationTabStackDrawable != null && mToggleTabStackButton != null && mUrlExpansionPercent != 1f) { // Draw the tab stack button image. canvas.save(); translateCanvasToView(mToolbarButtonsContainer, mToggleTabStackButton, canvas); int backgroundWidth = mToggleTabStackButton.getDrawable().getIntrinsicWidth(); int backgroundHeight = mToggleTabStackButton.getDrawable().getIntrinsicHeight(); int backgroundLeft = (mToggleTabStackButton.getWidth() - mToggleTabStackButton.getPaddingLeft() - mToggleTabStackButton.getPaddingRight() - backgroundWidth) / 2; backgroundLeft += mToggleTabStackButton.getPaddingLeft(); int backgroundTop = (mToggleTabStackButton.getHeight() - mToggleTabStackButton.getPaddingTop() - mToggleTabStackButton.getPaddingBottom() - backgroundHeight) / 2; backgroundTop += mToggleTabStackButton.getPaddingTop(); canvas.translate(backgroundLeft, backgroundTop); mTabSwitcherAnimationTabStackDrawable.setAlpha(rgbAlpha); mTabSwitcherAnimationTabStackDrawable.draw(canvas); canvas.restore(); } // Draw the menu button if necessary. if (!mShowMenuBadge && mTabSwitcherAnimationMenuDrawable != null && mUrlExpansionPercent != 1f) { mTabSwitcherAnimationMenuDrawable.setBounds(mMenuButton.getPaddingLeft(), mMenuButton.getPaddingTop(), mMenuButton.getWidth() - mMenuButton.getPaddingRight(), mMenuButton.getHeight() - mMenuButton.getPaddingBottom()); translateCanvasToView(mToolbarButtonsContainer, mMenuButton, canvas); mTabSwitcherAnimationMenuDrawable.setAlpha(rgbAlpha); int color = mUseLightDrawablesForTextureCapture ? mLightModeDefaultColor : mDarkModeDefaultColor; mTabSwitcherAnimationMenuDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); mTabSwitcherAnimationMenuDrawable.draw(canvas); } // Draw the menu badge if necessary. Drawable badgeDrawable = mUseLightDrawablesForTextureCapture ? mTabSwitcherAnimationMenuBadgeLightDrawable : mTabSwitcherAnimationMenuBadgeDarkDrawable; if (mShowMenuBadge && badgeDrawable != null && mUrlExpansionPercent != 1f) { badgeDrawable.setBounds(mMenuBadge.getPaddingLeft(), mMenuBadge.getPaddingTop(), mMenuBadge.getWidth() - mMenuBadge.getPaddingRight(), mMenuBadge.getHeight() - mMenuBadge.getPaddingBottom()); translateCanvasToView(mToolbarButtonsContainer, mMenuBadge, canvas); badgeDrawable.setAlpha(rgbAlpha); badgeDrawable.draw(canvas); } mLightDrawablesUsedForLastTextureCapture = mUseLightDrawablesForTextureCapture; canvas.restore(); }
From source file:com.tandong.sa.sherlock.widget.SearchView.java
private CharSequence getDecoratedHint(CharSequence hintText) { // If the field is always expanded, then don't add the search icon to // the hint/*from ww w . j a v a 2s . c o m*/ if (!mIconifiedByDefault) return hintText; SpannableStringBuilder ssb = new SpannableStringBuilder(" "); // for // the // icon ssb.append(hintText); Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId()); int textSize = (int) (mQueryTextView.getTextSize() * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return ssb; }
From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java
/** * Helper function to add links from mVoteTargetThing to the button * @param linkButton Button that should open list of links *//*from www .j a v a 2 s . c o m*/ private void linkToEmbeddedURLs(Button linkButton) { final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<MarkdownURL> vtUrls = mVoteTargetThing.getUrls(); int urlsCount = vtUrls.size(); for (int i = 0; i < urlsCount; i++) { urls.add(vtUrls.get(i).url); } if (urlsCount == 0) { linkButton.setEnabled(false); } else { linkButton.setEnabled(true); linkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { removeDialog(Constants.DIALOG_COMMENT_CLICK); ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(CommentsListActivity.this, android.R.layout.select_dialog_item, vtUrls) { public View getView(int position, View convertView, ViewGroup parent) { TextView tv; if (convertView == null) { tv = (TextView) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(android.R.layout.select_dialog_item, null); } else { tv = (TextView) convertView; } String url = getItem(position).url; String anchorText = getItem(position).anchorText; if (Constants.LOGGING) Log.d(TAG, "links url=" + url + " anchorText=" + anchorText); Drawable d = null; try { d = getPackageManager() .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (NameNotFoundException ignore) { } if (d != null) { d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight()); tv.setCompoundDrawablePadding(10); tv.setCompoundDrawables(d, null, null, null); } final String telPrefix = "tel:"; if (url.startsWith(telPrefix)) { url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length())); } if (anchorText != null) tv.setText(Html.fromHtml( "<span>" + anchorText + "</span><br /><small>" + url + "</small>")); else tv.setText(Html.fromHtml(url)); return tv; } }; AlertDialog.Builder b = new AlertDialog.Builder( new ContextThemeWrapper(CommentsListActivity.this, mSettings.getDialogTheme())); DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { if (which >= 0) { Common.launchBrowser(CommentsListActivity.this, urls.get(which), Util.createThreadUri(getOpThingInfo()).toString(), false, false, mSettings.isUseExternalBrowser(), mSettings.isSaveHistory()); } } }; b.setTitle(R.string.select_link_title); b.setCancelable(true); b.setAdapter(adapter, click); b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); b.show(); } }); } }