List of usage examples for android.graphics.drawable Drawable setBounds
public void setBounds(int left, int top, int right, int bottom)
From source file:kr.wdream.storyshop.AndroidUtilities.java
private static Intent createShortcutIntent(long did, boolean forDelete) { Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class); int lower_id = (int) did; int high_id = (int) (did >> 32); TLRPC.User user = null;/*w w w . j a va 2s.c o m*/ TLRPC.Chat chat = null; if (lower_id == 0) { shortcutIntent.putExtra("encId", high_id); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id); if (encryptedChat == null) { return null; } user = MessagesController.getInstance().getUser(encryptedChat.user_id); } else if (lower_id > 0) { shortcutIntent.putExtra("userId", lower_id); user = MessagesController.getInstance().getUser(lower_id); } else if (lower_id < 0) { chat = MessagesController.getInstance().getChat(-lower_id); shortcutIntent.putExtra("chatId", -lower_id); } else { return null; } if (user == null && chat == null) { return null; } String name; TLRPC.FileLocation photo = null; if (user != null) { name = ContactsController.formatName(user.first_name, user.last_name); if (user.photo != null) { photo = user.photo.photo_small; } } else { name = chat.title; if (chat.photo != null) { photo = chat.photo.photo_small; } } shortcutIntent.setAction("com.tmessages.openchat" + did); shortcutIntent.addFlags(0x4000000); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); addIntent.putExtra("duplicate", false); if (!forDelete) { Bitmap bitmap = null; if (photo != null) { try { File path = FileLoader.getPathToAttach(photo, true); bitmap = BitmapFactory.decodeFile(path.toString()); if (bitmap != null) { int size = AndroidUtilities.dp(58); Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(result); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); if (roundPaint == null) { roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmapRect = new RectF(); } float scale = size / (float) bitmap.getWidth(); canvas.save(); canvas.scale(scale, scale); roundPaint.setShader(shader); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint); canvas.restore(); Drawable drawable = ApplicationLoader.applicationContext.getResources() .getDrawable(R.drawable.book_logo); int w = AndroidUtilities.dp(15); int left = size - w - AndroidUtilities.dp(2); int top = size - w - AndroidUtilities.dp(2); drawable.setBounds(left, top, left + w, top + w); drawable.draw(canvas); try { canvas.setBitmap(null); } catch (Exception e) { //don't promt, this will crash on 2.x } bitmap = result; } } catch (Throwable e) { FileLog.e("tmessages", e); } } if (bitmap != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); } else { if (user != null) { if (user.bot) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_bot)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_user)); } } else if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_channel)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_group)); } } } } return addIntent; }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw cards with big single center suite * @param r application resources reference *///from www . ja va 2 s . co m private void drawBigCards(final Resources r) { final Bitmap[] bigSuit = new Bitmap[4]; final Bitmap[] suit = new Bitmap[4]; Canvas canvas; final String[] card_values = mResources.getStringArray(R.array.card_values); final Paint cardFrontPaint = new Paint(); final Paint cardBorderPaint = new Paint(); final Paint textPaintLeft = getTextPaint(mSuitsSize, Paint.Align.LEFT); Drawable drawable = ResourcesCompat.getDrawable(r, R.drawable.cardback, null); mCardHidden = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardHidden); drawable.setBounds(0, 0, Card.WIDTH, Card.HEIGHT); drawable.draw(canvas); for (int i = 0; i < 4; i++) { suit[i] = Bitmap.createBitmap((int) mSuitsSizeHalf, (int) mSuitsSizeHalf, Bitmap.Config.ARGB_8888); canvas = new Canvas(suit[i]); drawSuit(i, canvas, mSuitsSizeHalf); } for (int i = 0; i < 4; i++) { bigSuit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888); canvas = new Canvas(bigSuit[i]); drawSuit(i, canvas, mSuitsSize); } cardBorderPaint.setARGB(255, 0, 0, 0); cardFrontPaint.setARGB(255, 255, 255, 255); RectF rectf = new RectF(); for (int suitIdx = 0; suitIdx < 4; suitIdx++) { for (int valueIdx = 0; valueIdx < 13; valueIdx++) { mCardBitmap[suitIdx * 13 + valueIdx] = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardBitmap[suitIdx * 13 + valueIdx]); drawCardBackground(rectf, canvas, cardBorderPaint, cardFrontPaint); drawCardValue(textPaintLeft, canvas, card_values[valueIdx], suit[suitIdx], suitIdx); // Middle canvas.drawBitmap(bigSuit[suitIdx], Card.WIDTH / 2 - mSuitsSizeHalf, Card.HEIGHT / 2 - mSuitsSizeHalf, mSuitPaint); } } }
From source file:cn.longchou.wholesale.activity.VehicleDetailActivity.java
private void showAttention() { //,?//from w w w. java2s.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.hirebuddy.util.CircleImageView.java
private Bitmap getBitmapFromDrawable(Drawable drawable) { if (drawable == null) { return null; }//from w w w . j a va 2 s . co m if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } try { Bitmap bitmap; if (drawable instanceof ColorDrawable) { bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:net.cloudpath.xpressconnect.screens.ScreenBase.java
private void setIcon(int paramInt, TextView paramTextView) { switch (paramInt) { default://from ww w .ja va 2 s.c o m Drawable localDrawable3 = getResources().getDrawable(this.mParcelHelper.getDrawableId("xpc_blank")); localDrawable3.setBounds(0, 0, 20, 20); paramTextView.setCompoundDrawables(localDrawable3, null, null, null); return; case 1: Drawable localDrawable2 = getResources() .getDrawable(this.mParcelHelper.getDrawableId("xpc_applicationtabarrow")); localDrawable2.setBounds(0, 0, 20, 20); paramTextView.setCompoundDrawables(localDrawable2, null, null, null); return; case 2: } Drawable localDrawable1 = getResources() .getDrawable(this.mParcelHelper.getDrawableId("xpc_applicationtabcheck")); localDrawable1.setBounds(0, 0, 20, 20); paramTextView.setCompoundDrawables(localDrawable1, null, null, null); }
From source file:com.userhook.view.UHMessageView.java
protected void loadMessage(Map<String, Object> params) { if (meta.getDisplayType().equals(UHMessageMeta.TYPE_IMAGE)) { if (meta.getButton1() != null && meta.getButton1().getImage() != null && meta.getButton1().getImage().getUrl() != null) { AsyncTask task = new AsyncTask<Object, Void, Drawable>() { @Override/* w w w.j a va2 s .c o m*/ protected Drawable doInBackground(Object... params) { Drawable drawable = null; try { URL url = new URL((String) params[0]); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream is = conn.getInputStream(); drawable = Drawable.createFromStream(is, "src"); int height = drawable.getIntrinsicHeight(); int width = drawable.getIntrinsicWidth(); drawable.setBounds(0, 0, width, height); } catch (Exception e) { Log.e(UserHook.TAG, "error download message image", e); } return drawable; } @Override protected void onPostExecute(Drawable result) { if (result != null) { // size image to fit inside the view int screenHeight = getResources().getDisplayMetrics().heightPixels; int screenWidth = getResources().getDisplayMetrics().widthPixels; int heightGutter = 40; int widthGutter = 40; int screenSpaceHeight = screenHeight - heightGutter * 2; int screenSpaceWidth = screenWidth - widthGutter * 2; float height = result.getIntrinsicHeight(); float width = result.getIntrinsicWidth(); float aspect = height / width; if (height > screenSpaceHeight) { height = screenHeight; width = height / aspect; } if (width > screenSpaceWidth) { width = screenSpaceWidth; height = width * aspect; } ImageView imageView = new ImageView(getContext()); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageView.setImageDrawable(result); LayoutParams layoutParams = new LayoutParams((int) width, (int) height); layoutParams.addRule(CENTER_IN_PARENT); addView(imageView, layoutParams); // add click handler to image imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (meta.getButton1() != null) { clickedButton(meta.getButton1()); } } }); contentLoaded = true; if (showAfterLoad) { showDialog(); } } } }; task.execute(meta.getButton1().getImage().getUrl()); } } else if (UHMessageTemplate.getInstance().hasTemplate(meta.getDisplayType())) { String html = UHMessageTemplate.getInstance().renderTemplate(meta); loadWebViewContent(html); if (showAfterLoad) { showDialog(); } } else { UHPostAsyncTask asyncTask = new UHPostAsyncTask(params, new UHAsyncTask.UHAsyncTaskListener() { @Override public void onSuccess(String result) { if (result != null) { loadWebViewContent(result); } if (showAfterLoad) { showDialog(); } } }); asyncTask.execute(UserHook.UH_HOST_URL + UH_MESSAGE_PATH); } }
From source file:com.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java
private Drawable getDrawable(RenderOptions renderOptions) { validateCacheWidthHeight(renderOptions.getWidth(), renderOptions.getHeight()); Drawable drawable; if (renderOptions.getRenderStyle() == RenderStyles.BlackWhite) { if (m_cachedBlackWhiteDrawable == null) { m_cachedBlackWhiteDrawable = createDrawable(renderOptions); }// w w w. jav a2 s . c om drawable = m_cachedBlackWhiteDrawable; } else { if (m_cachedDrawable == null) { m_cachedDrawable = createDrawable(renderOptions); } drawable = m_cachedDrawable; } drawable.setBounds(renderOptions.getLeft(), renderOptions.getTop(), renderOptions.getRight(), renderOptions.getBottom()); return drawable; }
From source file:com.justwayward.reader.view.RVPIndicator.java
public RVPIndicator(Context context, AttributeSet attrs) { super(context, attrs); // /*ww w .j a v a 2s. c o m*/ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RVPIndicator); mTabVisibleCount = a.getInt(R.styleable.RVPIndicator_item_count, D_TAB_COUNT); mTextColorNormal = a.getColor(R.styleable.RVPIndicator_text_color_normal, D_TEXT_COLOR_NORMAL); mTextColorHighlight = a.getColor(R.styleable.RVPIndicator_text_color_hightlight, D_TEXT_COLOR_HIGHLIGHT); mTextSize = a.getDimensionPixelSize(R.styleable.RVPIndicator_text_size, 16); mIndicatorColor = a.getColor(R.styleable.RVPIndicator_indicator_color, D_INDICATOR_COLOR); mIndicatorStyle = a.getInt(R.styleable.RVPIndicator_indicator_style, STYLE_LINE); Drawable drawable = a.getDrawable(R.styleable.RVPIndicator_indicator_src); if (drawable != null) { if (drawable instanceof BitmapDrawable) { mBitmap = ((BitmapDrawable) drawable).getBitmap(); } else if (drawable instanceof NinePatchDrawable) { // .9? Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); mBitmap = bitmap; } } else { mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.heart_love); } a.recycle(); /** * */ mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(mIndicatorColor); mPaint.setStyle(Style.FILL); }
From source file:org.gateshipone.malp.application.background.NotificationManager.java
public synchronized void updateNotification(MPDTrack track, MPDCurrentStatus.MPD_PLAYBACK_STATE state) { if (track != null) { mNotificationBuilder = new NotificationCompat.Builder(mService); // Open application intent Intent contentIntent = new Intent(mService, MainActivity.class); contentIntent.putExtra(MainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW, MainActivity.MAINACTIVITY_INTENT_EXTRA_REQUESTEDVIEW_NOWPLAYINGVIEW); contentIntent.addFlags(//from w w w . jav a 2 s .c om Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY); PendingIntent contentPendingIntent = PendingIntent.getActivity(mService, INTENT_OPENGUI, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.setContentIntent(contentPendingIntent); // Set pendingintents // Previous song action Intent prevIntent = new Intent(BackgroundService.ACTION_PREVIOUS); PendingIntent prevPendingIntent = PendingIntent.getBroadcast(mService, INTENT_PREVIOUS, prevIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action prevAction = new NotificationCompat.Action.Builder( R.drawable.ic_skip_previous_48dp, "Previous", prevPendingIntent).build(); // Pause/Play action PendingIntent playPauseIntent; int playPauseIcon; if (state == MPDCurrentStatus.MPD_PLAYBACK_STATE.MPD_PLAYING) { Intent pauseIntent = new Intent(BackgroundService.ACTION_PAUSE); playPauseIntent = PendingIntent.getBroadcast(mService, INTENT_PLAYPAUSE, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT); playPauseIcon = R.drawable.ic_pause_48dp; } else { Intent playIntent = new Intent(BackgroundService.ACTION_PLAY); playPauseIntent = PendingIntent.getBroadcast(mService, INTENT_PLAYPAUSE, playIntent, PendingIntent.FLAG_UPDATE_CURRENT); playPauseIcon = R.drawable.ic_play_arrow_48dp; } NotificationCompat.Action playPauseAction = new NotificationCompat.Action.Builder(playPauseIcon, "PlayPause", playPauseIntent).build(); // Stop action Intent stopIntent = new Intent(BackgroundService.ACTION_STOP); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(mService, INTENT_STOP, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action stopActon = new NotificationCompat.Action.Builder( R.drawable.ic_stop_black_48dp, "Stop", stopPendingIntent).build(); // Next song action Intent nextIntent = new Intent(BackgroundService.ACTION_NEXT); PendingIntent nextPendingIntent = PendingIntent.getBroadcast(mService, INTENT_NEXT, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action nextAction = new NotificationCompat.Action.Builder( R.drawable.ic_skip_next_48dp, "Next", nextPendingIntent).build(); // Quit action Intent quitIntent = new Intent(BackgroundService.ACTION_QUIT_BACKGROUND_SERVICE); PendingIntent quitPendingIntent = PendingIntent.getBroadcast(mService, INTENT_QUIT, quitIntent, PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.setDeleteIntent(quitPendingIntent); mNotificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); mNotificationBuilder.setSmallIcon(R.drawable.ic_notification_24dp); mNotificationBuilder.addAction(prevAction); mNotificationBuilder.addAction(playPauseAction); mNotificationBuilder.addAction(stopActon); mNotificationBuilder.addAction(nextAction); NotificationCompat.MediaStyle notificationStyle = new NotificationCompat.MediaStyle(); notificationStyle.setShowActionsInCompactView(1, 2); mNotificationBuilder.setStyle(notificationStyle); String title; if (track.getTrackTitle().isEmpty()) { title = FormatHelper.getFilenameFromPath(track.getPath()); } else { title = track.getTrackTitle(); } mNotificationBuilder.setContentTitle(title); String secondRow; if (!track.getTrackArtist().isEmpty() && !track.getTrackAlbum().isEmpty()) { secondRow = track.getTrackArtist() + mService.getString(R.string.track_item_separator) + track.getTrackAlbum(); } else if (track.getTrackArtist().isEmpty() && !track.getTrackAlbum().isEmpty()) { secondRow = track.getTrackAlbum(); } else if (track.getTrackAlbum().isEmpty() && !track.getTrackArtist().isEmpty()) { secondRow = track.getTrackArtist(); } else { secondRow = track.getPath(); } // Set the media session metadata updateMetadata(track, state); mNotificationBuilder.setContentText(secondRow); // Remove unnecessary time info mNotificationBuilder.setWhen(0); // Cover but only if changed if (mNotification == null || !track.getTrackAlbum().equals(mLastTrack.getTrackAlbum())) { mLastTrack = track; mLastBitmap = null; mCoverLoader.getImage(mLastTrack, true); } // Only set image if an saved one is available if (mLastBitmap != null) { mNotificationBuilder.setLargeIcon(mLastBitmap); } else { /** * Create a dummy placeholder image for versions greater android 7 because it * does not automatically show the application icon anymore in mediastyle notifications. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Drawable icon = mService.getDrawable(R.drawable.notification_placeholder_256dp); Bitmap iconBitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(iconBitmap); DrawFilter filter = new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG, 1); canvas.setDrawFilter(filter); icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); icon.setFilterBitmap(true); icon.draw(canvas); mNotificationBuilder.setLargeIcon(iconBitmap); } else { /** * For older android versions set the null icon which will result in a dummy icon * generated from the application icon. */ mNotificationBuilder.setLargeIcon(null); } } // Build the notification mNotification = mNotificationBuilder.build(); // Send the notification away mNotificationManager.notify(NOTIFICATION_ID, mNotification); } }
From source file:br.com.cast.treinamento.tabs.SlidingTabLayout.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;/*from w w w . java 2 s . c om*/ TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate // it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } CharSequence pageTitle = adapter.getPageTitle(i); int drawableId; Drawable drawable = null; int density = (int) getResources().getDisplayMetrics().density; try { drawableId = Integer.parseInt(pageTitle.toString().trim()); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable = getResources().getDrawable(drawableId); } else { drawable = getResources().getDrawable(drawableId, null); } } catch (NumberFormatException e) { // e.printStackTrace(); } if (drawable == null) { tabTitleView.setText(pageTitle); } else { drawable.setBounds(0, 0, 24 * density, 24 * density); tabTitleView.setCompoundDrawables(drawable, null, null, null); tabTitleView.setText(""); } tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }