List of usage examples for android.graphics Paint setColor
public void setColor(@ColorInt int color)
From source file:com.almalence.opencam.SavingService.java
protected void addTimestamp(File file, int exif_orientation) { try {/*from w w w . j a v a2s . c o m*/ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); int dateFormat = Integer.parseInt(prefs.getString(ApplicationScreen.sTimestampDate, "0")); boolean abbreviation = prefs.getBoolean(ApplicationScreen.sTimestampAbbreviation, false); int saveGeo = Integer.parseInt(prefs.getString(ApplicationScreen.sTimestampGeo, "0")); int timeFormat = Integer.parseInt(prefs.getString(ApplicationScreen.sTimestampTime, "0")); int separator = Integer.parseInt(prefs.getString(ApplicationScreen.sTimestampSeparator, "0")); String customText = prefs.getString(ApplicationScreen.sTimestampCustomText, ""); int color = Integer.parseInt(prefs.getString(ApplicationScreen.sTimestampColor, "1")); int fontSizeC = Integer.parseInt(prefs.getString(ApplicationScreen.sTimestampFontSize, "80")); String formattedCurrentDate = ""; if (dateFormat == 0 && timeFormat == 0 && customText.equals("") && saveGeo == 0) return; String geoText = ""; // show geo data on time stamp if (saveGeo != 0) { Location l = MLocation.getLocation(getApplicationContext()); if (l != null) { if (saveGeo == 2) { Geocoder geocoder = new Geocoder(MainScreen.getMainContext(), Locale.getDefault()); List<Address> list = geocoder.getFromLocation(l.getLatitude(), l.getLongitude(), 1); if (!list.isEmpty()) { String country = list.get(0).getCountryName(); String locality = list.get(0).getLocality(); String adminArea = list.get(0).getSubAdminArea();// city // localized String street = list.get(0).getThoroughfare();// street // localized String address = list.get(0).getAddressLine(0); // replace street and city with localized name if (street != null) address = street; if (adminArea != null) locality = adminArea; geoText = (country != null ? country : "") + (locality != null ? (", " + locality) : "") + (address != null ? (", \n" + address) : ""); if (geoText.equals("")) geoText = "lat:" + l.getLatitude() + "\nlng:" + l.getLongitude(); } } else geoText = "lat:" + l.getLatitude() + "\nlng:" + l.getLongitude(); } } String dateFormatString = ""; String timeFormatString = ""; String separatorString = "."; String monthString = abbreviation ? "MMMM" : "MM"; switch (separator) { case 0: separatorString = "/"; break; case 1: separatorString = "."; break; case 2: separatorString = "-"; break; case 3: separatorString = " "; break; default: separatorString = " "; } switch (dateFormat) { case 1: dateFormatString = "yyyy" + separatorString + monthString + separatorString + "dd"; break; case 2: dateFormatString = "dd" + separatorString + monthString + separatorString + "yyyy"; break; case 3: dateFormatString = monthString + separatorString + "dd" + separatorString + "yyyy"; break; default: } switch (timeFormat) { case 1: timeFormatString = " hh:mm:ss a"; break; case 2: timeFormatString = " HH:mm:ss"; break; default: } Date currentDate = Calendar.getInstance().getTime(); java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat( dateFormatString + timeFormatString); formattedCurrentDate = simpleDateFormat.format(currentDate); formattedCurrentDate += (customText.isEmpty() ? "" : ("\n" + customText)) + (geoText.isEmpty() ? "" : ("\n" + geoText)); if (formattedCurrentDate.equals("")) return; Bitmap sourceBitmap; Bitmap bitmap; int rotation = 0; Matrix matrix = new Matrix(); if (exif_orientation == ExifInterface.ORIENTATION_ROTATE_90) { rotation = 90; } else if (exif_orientation == ExifInterface.ORIENTATION_ROTATE_180) { rotation = 180; } else if (exif_orientation == ExifInterface.ORIENTATION_ROTATE_270) { rotation = 270; } matrix.postRotate(rotation); BitmapFactory.Options options = new BitmapFactory.Options(); options.inMutable = true; sourceBitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options); bitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, false); sourceBitmap.recycle(); int width = bitmap.getWidth(); int height = bitmap.getHeight(); Paint p = new Paint(); Canvas canvas = new Canvas(bitmap); final float scale = getResources().getDisplayMetrics().density; p.setColor(Color.WHITE); switch (color) { case 0: color = Color.BLACK; p.setColor(Color.BLACK); break; case 1: color = Color.WHITE; p.setColor(Color.WHITE); break; case 2: color = Color.YELLOW; p.setColor(Color.YELLOW); break; } if (width > height) { p.setTextSize(height / fontSizeC * scale + 0.5f); // convert dps // to pixels } else { p.setTextSize(width / fontSizeC * scale + 0.5f); // convert dps // to pixels } p.setTextAlign(Align.RIGHT); drawTextWithBackground(canvas, p, formattedCurrentDate, color, Color.BLACK, width, height); Matrix matrix2 = new Matrix(); matrix2.postRotate(360 - rotation); sourceBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix2, false); bitmap.recycle(); FileOutputStream outStream; outStream = new FileOutputStream(file); sourceBitmap.compress(Bitmap.CompressFormat.JPEG, jpegQuality, outStream); sourceBitmap.recycle(); outStream.flush(); outStream.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
public static Bitmap graphics_addWaterMarkToImage(Bitmap src, String watermark, Point location, int size, boolean underline) { Bitmap result = null;//from w w w.j av a 2 s . c o m try { int w = src.getWidth(); int h = src.getHeight(); result = Bitmap.createBitmap(w, h, src.getConfig()); Canvas canvas = new Canvas(result); canvas.drawBitmap(src, 0, 0, null); Paint paint = new Paint(); paint.setColor(Color.RED); //paint.setAlpha(alpha); paint.setTextSize(size); paint.setAntiAlias(true); paint.setUnderlineText(underline); canvas.drawText(watermark, location.x, location.y, paint); } catch (Exception e) { result = null; if (LOG_ENABLE) Log.e(TAG, "ERROR: graphics_addWaterMarkToImage() [" + e.getMessage() + "]", e); } return result; }
From source file:com.cssweb.android.view.PriceView.java
public void drawIndex(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/*from www .j a va2s .co m*/ tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1); this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY * 7 + DY / 2, endX, DY * 7 + DY / 2, tPaint); canvas.drawLine(startX, DY * 18 + DY / 4, endX, DY * 18 + DY / 4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); double zrsp = jo.getDouble("zrsp"); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY * 2); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("???", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY * 1.5f); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width, -DY * 15.5f); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x - tips, y, paint); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.translate(0, DY * 1.5f); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorLabelName); canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangdie = Utils.dataFormation(zhangd, stockdigit); if (zhangdie.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangdie, x - tips, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit); if (zhangfu.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangfu + "%", x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit), x - tips, y, paint); canvas.translate(-width, DY * 1.7f); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(width / 2, 0); canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(width / 2, 0); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java
/** * Draw the 12 text values at the positions specified by the textGrid parameters. *///from ww w . j av a 2s .c om private void drawTextElements(Canvas canvas, float textSize, Typeface typeface, ColorStateList textColor, String[] texts, float[] textX, float[] textY, Paint paint, int alpha, boolean showActivated, int activatedDegrees, boolean activatedOnly) { paint.setTextSize(textSize); paint.setTypeface(typeface); // The activated index can touch a range of elements. final float activatedIndex = activatedDegrees / (360.0f / NUM_POSITIONS); final int activatedFloor = (int) activatedIndex; final int activatedCeil = ((int) Math.ceil(activatedIndex)) % NUM_POSITIONS; for (int i = 0; i < 12; i++) { final boolean activated = (activatedFloor == i || activatedCeil == i); if (activatedOnly && !activated) { continue; } final int stateMask = SUtils.STATE_ENABLED | (showActivated && activated ? SUtils.STATE_ACTIVATED : 0); final int color = textColor.getColorForState(SUtils.resolveStateSet(stateMask), 0); paint.setColor(color); paint.setAlpha(getMultipliedAlpha(color, alpha)); canvas.drawText(texts[i], textX[i], textY[i], paint); } }
From source file:me.tb.player.SkeletonActivity.java
@Override public Bitmap getCircleBitmap(Bitmap bitmap) { final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(output); final int color = Color.RED; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true);// w ww .j a v a2 s. co m canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawOval(rectF, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); bitmap.recycle(); return output; }
From source file:com.cssweb.android.view.PriceView.java
public void drawHKIndex(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/*from w w w. j a v a 2 s . c o m*/ tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1); this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY * 5 + DY / 2, endX, DY * 5 + DY / 2, tPaint); canvas.drawLine(startX, DY * 11 + DY / 8, endX, DY * 11 + DY / 8, tPaint); //canvas.drawLine(startX, DY*16+DY/4, endX, DY*16+DY/4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); double zrsp = jo.getDouble("zrsp"); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY * 2); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY * 1.5f); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); // canvas.translate(0, DY); // canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY * 1.5f); // canvas.drawText("?", x + tips, y, paint); // canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width, -DY * 13f); paint.setTextAlign(Paint.Align.RIGHT); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x - tips, y, paint); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangdie = Utils.dataFormation(zhangd, stockdigit); if (zhangdie.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangdie, x - tips, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit); if (zhangfu.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangfu + "%", x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x - tips, y, paint); canvas.translate(0, DY * 1.5f); paint.setColor(GlobalColor.colorLabelName); canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); //canvas.translate(0, DY); //canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint); canvas.translate(0, DY * 1.5f); //canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1), x - tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); //canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("zj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceEqual); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.tr4android.support.extension.picker.time.RadialTimePickerView.java
/** * Draw the 12 text values at the positions specified by the textGrid parameters. *///from w ww . j a v a2s . c o m private void drawTextElements(Canvas canvas, float textSize, Typeface typeface, ColorStateList textColor, String[] texts, float[] textX, float[] textY, Paint paint, int alpha, boolean showActivated, int activatedDegrees, boolean activatedOnly) { paint.setTextSize(textSize); paint.setTypeface(typeface); // The activated index can touch a range of elements. final float activatedIndex = activatedDegrees / (360.0f / NUM_POSITIONS); final int activatedFloor = (int) activatedIndex; final int activatedCeil = ((int) Math.ceil(activatedIndex)) % NUM_POSITIONS; for (int i = 0; i < 12; i++) { final boolean activated = (activatedFloor == i || activatedCeil == i); if (activatedOnly && !activated) { continue; } final int[] stateMask = new int[] { android.R.attr.state_enabled, (showActivated && activated ? android.R.attr.state_selected : 0) }; final int color = textColor.getColorForState(stateMask, 0); paint.setColor(color); paint.setAlpha(getMultipliedAlpha(color, alpha)); canvas.drawText(texts[i], textX[i], textY[i], paint); } }
From source file:com.dwdesign.tweetings.util.Utils.java
public static Bitmap getColorPreviewBitmap(final Context context, final int color) { if (context == null) return null; final float density = context.getResources().getDisplayMetrics().density; final int width = (int) (32 * density), height = (int) (32 * density); final Bitmap bm = Bitmap.createBitmap(width, height, Config.ARGB_8888); final Canvas canvas = new Canvas(bm); final int rectrangle_size = (int) (density * 5); final int numRectanglesHorizontal = (int) Math.ceil(width / rectrangle_size); final int numRectanglesVertical = (int) Math.ceil(height / rectrangle_size); final Rect r = new Rect(); boolean verticalStartWhite = true; for (int i = 0; i <= numRectanglesVertical; i++) { boolean isWhite = verticalStartWhite; for (int j = 0; j <= numRectanglesHorizontal; j++) { r.top = i * rectrangle_size; r.left = j * rectrangle_size; r.bottom = r.top + rectrangle_size; r.right = r.left + rectrangle_size; final Paint paint = new Paint(); paint.setColor(isWhite ? Color.WHITE : Color.GRAY); canvas.drawRect(r, paint);//from w w w. ja va 2 s.co m isWhite = !isWhite; } verticalStartWhite = !verticalStartWhite; } canvas.drawColor(color); final Paint paint = new Paint(); paint.setColor(Color.WHITE); paint.setStrokeWidth(2.0f); final float[] points = new float[] { 0, 0, width, 0, 0, 0, 0, height, width, 0, width, height, 0, height, width, height }; canvas.drawLines(points, paint); return bm; }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { int userId = Util.getUserId(Process.myUid()); boolean mounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); boolean updates = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingUpdates, false); menu.findItem(R.id.menu_export).setEnabled(mounted); menu.findItem(R.id.menu_import).setEnabled(mounted); menu.findItem(R.id.menu_submit).setEnabled(Util.hasValidFingerPrint(this)); menu.findItem(R.id.menu_pro).setVisible(!Util.isProEnabled() && Util.hasProLicense(this) == null); menu.findItem(R.id.menu_dump).setVisible(Util.isDebuggable(this)); menu.findItem(R.id.menu_update).setVisible(updates); menu.findItem(R.id.menu_update).setEnabled(mounted); // Update filter count // Get settings boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false); boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false); boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false); boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true); boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false); boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true); boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false); // Count number of active filters int numberOfFilters = 0; if (fUsed)//www .j av a2 s.c o m numberOfFilters++; if (fInternet) numberOfFilters++; if (fRestriction) numberOfFilters++; if (fPermission) numberOfFilters++; if (fOnDemand) numberOfFilters++; if (fUser) numberOfFilters++; if (fSystem) numberOfFilters++; if (numberOfFilters > 0) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_filter) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.GRAY); paint.setTextSize(bitmap.getWidth() / 3); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String text = Integer.toString(numberOfFilters); Canvas canvas = new Canvas(bitmap); canvas.drawText(text, bitmap.getWidth() - paint.measureText(text), bitmap.getHeight(), paint); MenuItem fMenu = menu.findItem(R.id.menu_filter); fMenu.setIcon(new BitmapDrawable(getResources(), bitmap)); } return super.onPrepareOptionsMenu(menu); }