List of usage examples for android.graphics.drawable Drawable getIntrinsicWidth
public int getIntrinsicWidth()
From source file:cnedu.ustcjd.widget.MultiSlider.java
/** * @param gap If set to {@link Integer#MIN_VALUE}, this will be ignored and *//* ww w. ja v a 2 s.c o m*/ 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(); int prevLeft = thumb.getBounds().left; //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: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 {// ww w. j a va2s . 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:com.android.launcher3.Utilities.java
/** * @param scale the scale to apply before drawing {@param icon} on the canvas *//*from w ww . ja va2 s . c om*/ public static Bitmap createIconBitmap(Drawable icon, Context context, float scale) { synchronized (sCanvas) { final int iconBitmapSize = getIconBitmapSize(); int width = iconBitmapSize; int height = iconBitmapSize; if (icon instanceof PaintDrawable) { PaintDrawable painter = (PaintDrawable) icon; painter.setIntrinsicWidth(width); painter.setIntrinsicHeight(height); } else if (icon instanceof BitmapDrawable) { // Ensure the bitmap has a density. BitmapDrawable bitmapDrawable = (BitmapDrawable) icon; Bitmap bitmap = bitmapDrawable.getBitmap(); if (bitmap != null && bitmap.getDensity() == Bitmap.DENSITY_NONE) { bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics()); } } int sourceWidth = icon.getIntrinsicWidth(); int sourceHeight = icon.getIntrinsicHeight(); if (sourceWidth > 0 && sourceHeight > 0) { // Scale the icon proportionally to the icon dimensions final float ratio = (float) sourceWidth / sourceHeight; if (sourceWidth > sourceHeight) { height = (int) (width / ratio); } else if (sourceHeight > sourceWidth) { width = (int) (height * ratio); } } // no intrinsic size --> use default size int textureWidth = iconBitmapSize; int textureHeight = iconBitmapSize; final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888); final Canvas canvas = sCanvas; canvas.setBitmap(bitmap); final int left = (textureWidth - width) / 2; final int top = (textureHeight - height) / 2; @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; if (debug) { // draw a big box for the icon for debugging canvas.drawColor(sColors[sColorIndex]); if (++sColorIndex >= sColors.length) sColorIndex = 0; Paint debugPaint = new Paint(); debugPaint.setColor(0xffcccc00); canvas.drawRect(left, top, left + width, top + height, debugPaint); } sOldBounds.set(icon.getBounds()); icon.setBounds(left, top, left + width, top + height); canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.scale(scale, scale, textureWidth / 2, textureHeight / 2); icon.draw(canvas); canvas.restore(); icon.setBounds(sOldBounds); canvas.setBitmap(null); return bitmap; } }
From source file:cnedu.ustcjd.widget.MultiSlider.java
private void setThumbDrawable(Thumb thumb, Drawable thumbDrawable, int thumbColor) { requireNonNull(thumbDrawable);//www. j av a2 s . com Drawable nThumbDrawable = getTintedDrawable(thumbDrawable.getConstantState().newDrawable(), thumbColor); nThumbDrawable.setCallback(this); // Assuming the thumb drawable is symmetric, set the thumb offset // such that the thumb will hang halfway off either edge of the // progress bar. thumb.setThumbOffset(thumbDrawable.getIntrinsicWidth() / 2); // If we're updating get the new states if (thumb.getThumb() != null && (nThumbDrawable.getIntrinsicWidth() != thumb.getThumb().getIntrinsicWidth() || nThumbDrawable.getIntrinsicHeight() != thumb.getThumb().getIntrinsicHeight())) { requestLayout(); } thumb.setThumb(nThumbDrawable); invalidate(); if (nThumbDrawable != null && nThumbDrawable.isStateful()) { // Note that if the states are different this won't work. // For now, let's consider that an app bug. int[] state = getDrawableState(); nThumbDrawable.setState(state); } }
From source file:com.phonemetra.turbo.launcher.AsyncTaskCallback.java
private boolean beginDraggingWidget(View v) { mDraggingWidget = true;//from w ww . j a va 2 s .co m // Get the widget preview as the drag representation ImageView image = (ImageView) v.findViewById(R.id.widget_preview); PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag(); // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and // we abort the drag. if (image.getDrawable() == null) { mDraggingWidget = false; return false; } // Compose the drag image Bitmap preview; Bitmap outline; float scale = 1f; Point previewPadding = null; if (createItemInfo instanceof PendingAddWidgetInfo) { // This can happen in some weird cases involving multi-touch. We can't start dragging // the widget if this is null, so we break out. if (mCreateWidgetInfo == null) { return false; } PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo; createItemInfo = createWidgetInfo; int spanX = createItemInfo.spanX; int spanY = createItemInfo.spanY; int[] size = mLauncher.getWorkspace().estimateItemSize(spanX, spanY, createWidgetInfo, true); FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable(); float minScale = 1.25f; int maxWidth, maxHeight; maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]); maxHeight = Math.min((int) (previewDrawable.getIntrinsicHeight() * minScale), size[1]); int[] previewSizeBeforeScale = new int[1]; preview = getWidgetPreviewLoader().generateWidgetPreview(createWidgetInfo.componentName, createWidgetInfo.previewImage, createWidgetInfo.icon, spanX, spanY, maxWidth, maxHeight, null, previewSizeBeforeScale); // Compare the size of the drag preview to the preview in the AppsCustomize tray int previewWidthInAppsCustomize = Math.min(previewSizeBeforeScale[0], getWidgetPreviewLoader().maxWidthForWidgetPreview(spanX)); scale = previewWidthInAppsCustomize / (float) preview.getWidth(); // The bitmap in the AppsCustomize tray is always the the same size, so there // might be extra pixels around the preview itself - this accounts for that if (previewWidthInAppsCustomize < previewDrawable.getIntrinsicWidth()) { int padding = (previewDrawable.getIntrinsicWidth() - previewWidthInAppsCustomize) / 2; previewPadding = new Point(padding, 0); } } else { PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag(); Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo); preview = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); mCanvas.setBitmap(preview); mCanvas.save(); WidgetPreviewLoader.renderDrawableToBitmap(icon, preview, 0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); mCanvas.restore(); mCanvas.setBitmap(null); createItemInfo.spanX = createItemInfo.spanY = 1; } // Don't clip alpha values for the drag outline if we're using the default widget preview boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo && (((PendingAddWidgetInfo) createItemInfo).previewImage == 0)); // Save the preview for the outline generation, then dim the preview outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), false); // Start the drag mLauncher.lockScreenOrientation(); mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha); mDragController.startDrag(image, preview, this, createItemInfo, DragController.DRAG_ACTION_COPY, previewPadding, scale); outline.recycle(); preview.recycle(); return true; }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java
@Override public void draw(Canvas c) { super.draw(c); final boolean isLayoutRtl = isLayoutRtlSupport(); Drawable shadowDrawable; if (isLayoutRtl) { shadowDrawable = mShadowDrawableRight; } else {//w w w . j a va2 s . c o m shadowDrawable = mShadowDrawableLeft; } 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
public MultiSlider(Context context, AttributeSet attrs, int defStyle, int styleRes) { super(context, attrs, defStyle); mUiThreadId = Thread.currentThread().getId(); a = context.obtainStyledAttributes(attrs, io.apptik.widget.R.styleable.MultiSlider, defStyle, styleRes); mNoInvalidate = true;// ww w . java2s .c o m int numThumbs = a.getInt(io.apptik.widget.R.styleable.MultiSlider_thumbNumber, 2); initMultiSlider(numThumbs); Drawable trackDrawable = a.getDrawable(io.apptik.widget.R.styleable.MultiSlider_android_track); if (trackDrawable == null) { trackDrawable = ContextCompat.getDrawable(getContext(), io.apptik.widget.R.drawable.multislider_scrubber_track_holo_light); } setTrackDrawable(getTintedDrawable(trackDrawable, a.getColor(io.apptik.widget.R.styleable.MultiSlider_trackColor, 0))); //TODO // mMinWidth = a.getDimensionPixelSize(R.styleable.MultiSlider_minWidth, mMinWidth); // mMaxWidth = a.getDimensionPixelSize(R.styleable.MultiSlider_maxWidth, mMaxWidth); // mMinHeight = a.getDimensionPixelSize(R.styleable.MultiSlider_minHeight, mMinHeight); // mMaxHeight = a.getDimensionPixelSize(R.styleable.MultiSlider_maxHeight, mMaxHeight); setStep(a.getInt(io.apptik.widget.R.styleable.MultiSlider_scaleStep, mStep)); setStepsThumbsApart(a.getInt(io.apptik.widget.R.styleable.MultiSlider_stepsThumbsApart, mStepsThumbsApart)); setDrawThumbsApart( a.getBoolean(io.apptik.widget.R.styleable.MultiSlider_drawThumbsApart, mDrawThumbsApart)); setMax(a.getInt(io.apptik.widget.R.styleable.MultiSlider_scaleMax, mScaleMax), true); setMin(a.getInt(io.apptik.widget.R.styleable.MultiSlider_scaleMin, mScaleMin), true); mMirrorForRtl = a.getBoolean(io.apptik.widget.R.styleable.MultiSlider_mirrorForRTL, mMirrorForRtl); // --> now place thumbs Drawable thumbDrawable = a.getDrawable(io.apptik.widget.R.styleable.MultiSlider_android_thumb); if (thumbDrawable == null) { thumbDrawable = ContextCompat.getDrawable(getContext(), io.apptik.widget.R.drawable.multislider_scrubber_control_selector_holo_light); } Drawable range = a.getDrawable(io.apptik.widget.R.styleable.MultiSlider_range); if (range == null) { range = ContextCompat.getDrawable(getContext(), io.apptik.widget.R.drawable.multislider_scrubber_primary_holo); } Drawable range1 = a.getDrawable(io.apptik.widget.R.styleable.MultiSlider_range1); Drawable range2 = a.getDrawable(io.apptik.widget.R.styleable.MultiSlider_range2); setThumbDrawables(thumbDrawable, range, range1, range2); // will guess thumbOffset if thumb != null... // ...but allow layout to override this int thumbOffset = a.getDimensionPixelOffset(io.apptik.widget.R.styleable.MultiSlider_android_thumbOffset, thumbDrawable.getIntrinsicWidth() / 2); setThumbOffset(thumbOffset); positionThumbs(); mScaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mNoInvalidate = false; a.recycle(); }
From source file:com.android.launcher2.AsyncTaskCallback.java
private Bitmap getWidgetPreview(ComponentName provider, int previewImage, int iconId, int cellHSpan, int cellVSpan, int maxWidth, int maxHeight) { // Load the preview image if possible String packageName = provider.getPackageName(); if (maxWidth < 0) maxWidth = Integer.MAX_VALUE; if (maxHeight < 0) maxHeight = Integer.MAX_VALUE; Drawable drawable = null; if (previewImage != 0) { drawable = mPackageManager.getDrawable(packageName, previewImage, null); if (drawable == null) { Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(previewImage) + " for provider: " + provider); }/*www. ja va2 s . c o m*/ } int bitmapWidth; int bitmapHeight; Bitmap defaultPreview = null; boolean widgetPreviewExists = (drawable != null); if (widgetPreviewExists) { bitmapWidth = drawable.getIntrinsicWidth(); bitmapHeight = drawable.getIntrinsicHeight(); } else { // Generate a preview image if we couldn't load one if (cellHSpan < 1) cellHSpan = 1; if (cellVSpan < 1) cellVSpan = 1; BitmapDrawable previewDrawable = (BitmapDrawable) getResources() .getDrawable(R.drawable.widget_preview_tile); final int previewDrawableWidth = previewDrawable.getIntrinsicWidth(); final int previewDrawableHeight = previewDrawable.getIntrinsicHeight(); bitmapWidth = previewDrawableWidth * cellHSpan; // subtract 2 dips bitmapHeight = previewDrawableHeight * cellVSpan; defaultPreview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888); final Canvas c = mCachedAppWidgetPreviewCanvas.get(); c.setBitmap(defaultPreview); previewDrawable.setBounds(0, 0, bitmapWidth, bitmapHeight); previewDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); previewDrawable.draw(c); c.setBitmap(null); // Draw the icon in the top left corner int minOffset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage); int smallestSide = Math.min(bitmapWidth, bitmapHeight); float iconScale = Math.min((float) smallestSide / (mAppIconSize + 2 * minOffset), 1f); try { Drawable icon = null; int hoffset = (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2); int yoffset = (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2); if (iconId > 0) icon = mIconCache.getFullResIcon(packageName, iconId); if (icon != null) { renderDrawableToBitmap(icon, defaultPreview, hoffset, yoffset, (int) (mAppIconSize * iconScale), (int) (mAppIconSize * iconScale)); } } catch (Resources.NotFoundException e) { } } // Scale to fit width only - let the widget preview be clipped in the // vertical dimension float scale = 1f; if (bitmapWidth > maxWidth) { scale = maxWidth / (float) bitmapWidth; } if (scale != 1f) { bitmapWidth = (int) (scale * bitmapWidth); bitmapHeight = (int) (scale * bitmapHeight); } Bitmap preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888); // Draw the scaled preview into the final bitmap if (widgetPreviewExists) { renderDrawableToBitmap(drawable, preview, 0, 0, bitmapWidth, bitmapHeight); } else { final Canvas c = mCachedAppWidgetPreviewCanvas.get(); final Rect src = mCachedAppWidgetPreviewSrcRect.get(); final Rect dest = mCachedAppWidgetPreviewDestRect.get(); c.setBitmap(preview); src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight()); dest.set(0, 0, preview.getWidth(), preview.getHeight()); Paint p = mCachedAppWidgetPreviewPaint.get(); if (p == null) { p = new Paint(); p.setFilterBitmap(true); mCachedAppWidgetPreviewPaint.set(p); } c.drawBitmap(defaultPreview, src, dest, p); c.setBitmap(null); } return preview; }
From source file:cw.kop.autobackground.LiveWallpaperService.java
@SuppressLint("NewApi") private void startNotification(boolean useNotification) { if (useNotification) { normalView = new RemoteViews(getPackageName(), R.layout.notification_layout); normalView.setInt(R.id.notification_container, "setBackgroundColor", AppSettings.getNotificationColor()); normalView.setImageViewResource(R.id.notification_icon, R.drawable.app_icon); normalView.setTextViewText(R.id.notification_title, AppSettings.getNotificationTitle()); normalView.setInt(R.id.notification_title, "setTextColor", AppSettings.getNotificationTitleColor()); normalView.setTextViewText(R.id.notification_summary, AppSettings.getNotificationSummary()); normalView.setInt(R.id.notification_summary, "setTextColor", AppSettings.getNotificationSummaryColor()); Drawable coloredImageOne = LiveWallpaperService.this.getResources() .getDrawable(AppSettings.getNotificationOptionDrawable(0)); Drawable coloredImageTwo = LiveWallpaperService.this.getResources() .getDrawable(AppSettings.getNotificationOptionDrawable(1)); Drawable coloredImageThree = LiveWallpaperService.this.getResources() .getDrawable(AppSettings.getNotificationOptionDrawable(2)); coloredImageOne.mutate().setColorFilter(AppSettings.getNotificationOptionColor(0), PorterDuff.Mode.MULTIPLY); coloredImageTwo.mutate().setColorFilter(AppSettings.getNotificationOptionColor(1), PorterDuff.Mode.MULTIPLY); coloredImageThree.mutate().setColorFilter(AppSettings.getNotificationOptionColor(2), PorterDuff.Mode.MULTIPLY); Bitmap mutableBitmapOne = Bitmap.createBitmap(coloredImageOne.getIntrinsicWidth(), coloredImageOne.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvasOne = new Canvas(mutableBitmapOne); coloredImageOne.setBounds(0, 0, coloredImageOne.getIntrinsicWidth(), coloredImageOne.getIntrinsicHeight()); coloredImageOne.draw(canvasOne); Bitmap mutableBitmapTwo = Bitmap.createBitmap(coloredImageTwo.getIntrinsicWidth(), coloredImageTwo.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvasTwo = new Canvas(mutableBitmapTwo); coloredImageTwo.setBounds(0, 0, coloredImageTwo.getIntrinsicWidth(), coloredImageTwo.getIntrinsicHeight()); coloredImageTwo.draw(canvasTwo); Bitmap mutableBitmapThree = Bitmap.createBitmap(coloredImageThree.getIntrinsicWidth(), coloredImageThree.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvasThree = new Canvas(mutableBitmapThree); coloredImageThree.setBounds(0, 0, coloredImageThree.getIntrinsicWidth(), coloredImageThree.getIntrinsicHeight()); coloredImageThree.draw(canvasThree); if (AppSettings.useNotificationGame()) { if (setupGameTiles()) { bigView = new RemoteViews(getPackageName(), R.layout.notification_game); tileIds = new int[] { R.id.notification_game_tile_0, R.id.notification_game_tile_1, R.id.notification_game_tile_2, R.id.notification_game_tile_3, R.id.notification_game_tile_4, R.id.notification_game_tile_5, R.id.notification_game_tile_6, R.id.notification_game_tile_7, R.id.notification_game_tile_8, R.id.notification_game_tile_9 }; bigView.setOnClickPendingIntent(tileIds[0], pendingTile0); bigView.setOnClickPendingIntent(tileIds[1], pendingTile1); bigView.setOnClickPendingIntent(tileIds[2], pendingTile2); bigView.setOnClickPendingIntent(tileIds[3], pendingTile3); bigView.setOnClickPendingIntent(tileIds[4], pendingTile4); bigView.setOnClickPendingIntent(tileIds[5], pendingTile5); bigView.setOnClickPendingIntent(tileIds[6], pendingTile6); bigView.setOnClickPendingIntent(tileIds[7], pendingTile7); bigView.setOnClickPendingIntent(tileIds[8], pendingTile8); bigView.setOnClickPendingIntent(tileIds[9], pendingTile9); } else { bigView = new RemoteViews(getPackageName(), R.layout.notification_big_layout); closeNotificationDrawer(LiveWallpaperService.this); Toast.makeText(LiveWallpaperService.this, "Not enough images to create game", Toast.LENGTH_LONG) .show();// ww w . j av a2 s .co m AppSettings.setUseNotificationGame(false); } } else { bigView = new RemoteViews(getPackageName(), R.layout.notification_big_layout); } bigView.setInt(R.id.notification_big_container, "setBackgroundColor", AppSettings.getNotificationColor()); bigView.setImageViewResource(R.id.notification_big_icon, R.drawable.app_icon); bigView.setTextViewText(R.id.notification_big_title, AppSettings.getNotificationTitle()); bigView.setInt(R.id.notification_big_title, "setTextColor", AppSettings.getNotificationTitleColor()); bigView.setTextViewText(R.id.notification_big_summary, AppSettings.getNotificationSummary()); bigView.setInt(R.id.notification_big_summary, "setTextColor", AppSettings.getNotificationSummaryColor()); bigView.setImageViewBitmap(R.id.notification_button_one_image, mutableBitmapOne); bigView.setImageViewBitmap(R.id.notification_button_two_image, mutableBitmapTwo); bigView.setImageViewBitmap(R.id.notification_button_three_image, mutableBitmapThree); bigView.setTextViewText(R.id.notification_button_one_text, AppSettings.getNotificationOptionTitle(0)); bigView.setInt(R.id.notification_button_one_text, "setTextColor", AppSettings.getNotificationOptionColor(0)); bigView.setTextViewText(R.id.notification_button_two_text, AppSettings.getNotificationOptionTitle(1)); bigView.setInt(R.id.notification_button_two_text, "setTextColor", AppSettings.getNotificationOptionColor(1)); bigView.setTextViewText(R.id.notification_button_three_text, AppSettings.getNotificationOptionTitle(2)); bigView.setInt(R.id.notification_button_three_text, "setTextColor", AppSettings.getNotificationOptionColor(2)); if (getIntentForNotification(AppSettings.getNotificationIconAction()) != null) { normalView.setOnClickPendingIntent(R.id.notification_icon, getIntentForNotification(AppSettings.getNotificationIconAction())); bigView.setOnClickPendingIntent(R.id.notification_big_icon, getIntentForNotification(AppSettings.getNotificationIconAction())); } else { normalView.setOnClickPendingIntent(R.id.notification_icon, pendingAppIntent); bigView.setOnClickPendingIntent(R.id.notification_big_icon, pendingAppIntent); } notificationBuilder = new Notification.Builder(this).setContent(normalView) .setSmallIcon(R.drawable.notification_icon).setOngoing(true); if (Build.VERSION.SDK_INT >= 16) { if (AppSettings.useNotificationGame()) { notificationBuilder.setPriority(Notification.PRIORITY_MAX); } else { notificationBuilder.setPriority(Notification.PRIORITY_MIN); } if (getIntentForNotification(AppSettings.getNotificationOptionTitle(0)) != null) { bigView.setOnClickPendingIntent(R.id.notification_button_one, getIntentForNotification(AppSettings.getNotificationOptionTitle(0))); } if (getIntentForNotification(AppSettings.getNotificationOptionTitle(1)) != null) { bigView.setOnClickPendingIntent(R.id.notification_button_two, getIntentForNotification(AppSettings.getNotificationOptionTitle(1))); } if (getIntentForNotification(AppSettings.getNotificationOptionTitle(2)) != null) { bigView.setOnClickPendingIntent(R.id.notification_button_three, getIntentForNotification(AppSettings.getNotificationOptionTitle(2))); } } else { notificationBuilder.setContentTitle(AppSettings.getNotificationTitle()); notificationBuilder.setContentText(AppSettings.getNotificationSummary()); notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(0), AppSettings.getNotificationOptionTitle(0), getIntentForNotification(AppSettings.getNotificationOptionTitle(0))); notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(1), AppSettings.getNotificationOptionTitle(1), getIntentForNotification(AppSettings.getNotificationOptionTitle(1))); notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(2), AppSettings.getNotificationOptionTitle(2), getIntentForNotification(AppSettings.getNotificationOptionTitle(2))); } pushNotification(); if (FileHandler.getCurrentBitmapFile() != null) { notifyChangeImage(); } } else { notificationManager.cancel(NOTIFICATION_ID); } }
From source file:org.profeda.dictionary.SearchActivity.java
/** * Called when the activity is first created. *//* ww w .j a v a2 s. c o m*/ @Override public void onCreate(Bundle savedInstanceState) { final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(SearchActivity.this); if (pref.getBoolean("show_changelog", true) == true) { MessageBox.showChangeLog(this); } loadDictionaries(pref); if (pref.getBoolean("p_invert_colors", false) == true) { setTheme(R.style.Light); } else { setTheme(R.style.Dark); } super.onCreate(savedInstanceState); setContentView(R.layout.main); dict = new Dict(this, pref.getString("dictFile", null)); updateTitleBar(); readMRU(); final EditText searchbox = (EditText) findViewById(R.id.searchbox); final Button dictselectbutton = (Button) findViewById(R.id.dictselectbutton); final ListView listview = (ListView) findViewById(R.id.contentlist); listview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView l, View v, int position, long id) { ListAdapter la = ((ListView) l).getAdapter(); if (la instanceof GenericStringAdapter) { final String data = (String) la.getItem(position); if (data.startsWith("> ")) { searchbox.setText(data.substring(2)); doSearch(true); } } else if (la instanceof DictListAdapter) { final String[] data = (String[]) la.getItem(position); final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, null); String[] menu = new String[langs.size() + 1]; menu[0] = getString(R.string.copy_translation_to_clipboard); for (int i = 1; i < menu.length; i++) menu[i] = String.format(getString(R.string.search_translation_in_language), langs.get(i - 1).toLang); Matcher m = Pattern.compile("<b>(.*)<\\/b>.*").matcher(data[1]); if (!m.matches()) return; final String translation = m.group(1).trim(); new AlertDialog.Builder(SearchActivity.this).setIcon(android.R.drawable.ic_dialog_info) .setTitle(translation).setItems(menu, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { switch (arg1) { case 0: ClipboardManager cm = (ClipboardManager) getSystemService( CLIPBOARD_SERVICE); cm.setText(translation); break; default: dict = langs.get(arg1 - 1); readMRU(); updateTitleBar(); searchbox.setText(translation); doSearch(true); } } }).show(); } } }); searchbox.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { doSearch(true); return true; } else { return false; } } }); final Drawable deleteIcon = getResources().getDrawable(R.drawable.textbox_clear); //deleteIcon.setBounds(0, 0, deleteIcon.getIntrinsicWidth(), deleteIcon.getIntrinsicHeight()); deleteIcon.setBounds(0, 0, 51, 30); // wtf??? die Zahlen sind empirisch ermittelt... ab right>=52 springt die hhe des editText searchbox.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { searchbox.setCompoundDrawables(null, null, s.toString().equals("") ? null : deleteIcon, null); //searchbox.setCompoundDrawablesWithIntrinsicBounds(null, null, s.toString().equals("") ? null : deleteIcon, null); searchbox.setCompoundDrawablePadding(0); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (enableLivesearch && s.length() > 1 && dict.filePrefix != null && dictSearchInAction == false) { DictionarySearcher ds = new DictionarySearcher(); ds.targetList = (ListView) findViewById(R.id.contentlist); ds.execute(dict.filePrefix, s.toString()); } if (s.length() == 0) { displayMRU(); } } }); //searchbox.setCompoundDrawables(null, null, deleteIcon, null); searchbox.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (searchbox.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > searchbox.getWidth() - searchbox.getPaddingRight() - deleteIcon.getIntrinsicWidth()) { searchbox.setText(""); searchbox.setCompoundDrawables(null, null, null, null); } return false; } }); dictselectbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { selectDictionary(); } }); ((Button) findViewById(R.id.dictswapbutton)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final List<Dict> langs = Dict.searchForLanguage(SearchActivity.this, dict.toLang, dict.fromLang); if (langs.size() > 0) { dict = langs.get(0); readMRU(); updateTitleBar(); searchbox.setText(""); } else { MessageBox.alert(SearchActivity.this, getString(R.string.no_reverse_dict_found)); } } }); }