List of usage examples for android.graphics Typeface defaultFromStyle
public static Typeface defaultFromStyle(@Style int style)
From source file:com.andexert.calendarlistview.library.SimpleMonthView.java
protected void drawMonthNums(Canvas canvas) { int y = (mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2 - DAY_SEPARATOR_WIDTH + MONTH_HEADER_SIZE; int paddingDay = (mWidth - 2 * mPadding) / (2 * mNumDays); int dayOffset = findDayOffset(); int day = 1;//from www.j av a 2 s . c o m String toDayRes = getResources().getString(R.string.today); while (day <= mNumCells) { boolean isShowTrain = true; int x = paddingDay * (1 + dayOffset * 2) + mPadding; if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) { if (mDrawRect) { RectF rectF = new RectF(x - DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) - DAY_SELECTED_CIRCLE_SIZE, x + DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) + DAY_SELECTED_CIRCLE_SIZE); canvas.drawRoundRect(rectF, 10.0f, 10.0f, mSelectedCirclePaint); } else { canvas.drawCircle(x, y - MINI_DAY_NUMBER_TEXT_SIZE / 3, DAY_SELECTED_CIRCLE_SIZE, mSelectedCirclePaint); } isShowTrain = false; } if (mHasToday && (mToday == day)) { mMonthNumPaint.setColor(mCurrentDayTextColor); } else { mMonthNumPaint.setColor(mDayNumColor); mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); } if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) mMonthNumPaint.setColor(mMonthTitleBGColor); if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mSelectedBeginMonth == mSelectedLastMonth && mSelectedBeginDay == mSelectedLastDay && day == mSelectedBeginDay && mMonth == mSelectedBeginMonth && mYear == mSelectedBeginYear)) { mMonthNumPaint.setColor(mSelectedDaysColor); } //? if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mSelectedBeginYear == mYear) && (((mMonth == mSelectedBeginMonth && mSelectedLastMonth == mSelectedBeginMonth) && ((mSelectedBeginDay < mSelectedLastDay && day > mSelectedBeginDay && day < mSelectedLastDay) || (mSelectedBeginDay > mSelectedLastDay && day < mSelectedBeginDay && day > mSelectedLastDay))) || ((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay)) || ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)))) { mMonthNumPaint.setColor(mSelectedDaysColor); } if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear && ((mSelectedBeginYear == mYear && mMonth == mSelectedBeginMonth) || (mSelectedLastYear == mYear && mMonth == mSelectedLastMonth)) && (((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)) || ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay))))) { mMonthNumPaint.setColor(mSelectedDaysColor); } if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mYear == mSelectedBeginYear) && ((mMonth > mSelectedBeginMonth && mMonth < mSelectedLastMonth && mSelectedBeginMonth < mSelectedLastMonth) || (mMonth < mSelectedBeginMonth && mMonth > mSelectedLastMonth && mSelectedBeginMonth > mSelectedLastMonth))) { mMonthNumPaint.setColor(mSelectedDaysColor); } if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear) && ((mSelectedBeginYear < mSelectedLastYear && ((mMonth > mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth < mSelectedLastMonth && mYear == mSelectedLastYear))) || (mSelectedBeginYear > mSelectedLastYear && ((mMonth < mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth > mSelectedLastMonth && mYear == mSelectedLastYear))))) { mMonthNumPaint.setColor(mSelectedDaysColor); } if ((!isPrevDayEnabled && prevDay(day, today)) || nextDay(day)) { mMonthNumPaint.setColor(mPreviousDayColor); } if (mHasToday && (mToday == day)) { canvas.drawText(toDayRes, x, y, mMonthNumPaint); } else { canvas.drawText(String.format("%d", day), x, y, mMonthNumPaint); } dayOffset++; if (dayOffset == mNumDays) { dayOffset = 0; y += mRowHeight; } day++; } }
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)//from w w w. j a va 2 s. co 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); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewBase.java
protected boolean setValueFromTheme(TypedArray remoteTypedArray, final int[] padding, final int localAttrId, final int remoteTypedArrayIndex) { try {// www . jav a 2s .c o m switch (localAttrId) { case android.R.attr.background: Drawable keyboardBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); if (keyboardBackground == null) return false; CompatUtils.setViewBackgroundDrawable(this, keyboardBackground); break; case android.R.attr.paddingLeft: padding[0] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[0] == -1) return false; break; case android.R.attr.paddingTop: padding[1] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[1] == -1) return false; break; case android.R.attr.paddingRight: padding[2] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[2] == -1) return false; break; case android.R.attr.paddingBottom: padding[3] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (padding[3] == -1) return false; break; case R.attr.keyBackground: mKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); if (mKeyBackground == null) return false; break; case R.attr.keyHysteresisDistance: mKeyHysteresisDistance = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (mKeyHysteresisDistance == -1) return false; break; case R.attr.verticalCorrection: mOriginalVerticalCorrection = mVerticalCorrection = remoteTypedArray .getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (mOriginalVerticalCorrection == -1) return false; break; case R.attr.keyTextSize: mKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mKeyTextSize == -1) return false; // you might ask yourself "why did Menny sqrt root the factor?" // I'll tell you; the factor is mostly for the height, not the // font size, // but I also factorize the font size because I want the text to // be a little like // the key size. // the whole factor maybe too much, so I ease that a bit. if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mKeyTextSize = (float) (mKeyTextSize * Math.sqrt(AnyApplication.getConfig().getKeysHeightFactorInLandscape())); else mKeyTextSize = (float) (mKeyTextSize * Math.sqrt(AnyApplication.getConfig().getKeysHeightFactorInPortrait())); Logger.d(TAG, "AnySoftKeyboardTheme_keyTextSize " + mKeyTextSize); break; case R.attr.keyTextColor: mKeyTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex); if (mKeyTextColor == null) { mKeyTextColor = new ColorStateList(new int[][] { { 0 } }, new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) }); } break; case R.attr.labelTextSize: mLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mLabelTextSize == -1) return false; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); break; case R.attr.keyboardNameTextSize: mKeyboardNameTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mKeyboardNameTextSize == -1) return false; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mKeyboardNameTextSize = mKeyboardNameTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mKeyboardNameTextSize = mKeyboardNameTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); break; case R.attr.keyboardNameTextColor: mKeyboardNameTextColor = remoteTypedArray.getColor(remoteTypedArrayIndex, Color.WHITE); break; case R.attr.shadowColor: mShadowColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0); break; case R.attr.shadowRadius: mShadowRadius = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); break; case R.attr.shadowOffsetX: mShadowOffsetX = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); break; case R.attr.shadowOffsetY: mShadowOffsetY = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); break; case R.attr.backgroundDimAmount: mBackgroundDimAmount = remoteTypedArray.getFloat(remoteTypedArrayIndex, -1f); if (mBackgroundDimAmount == -1f) return false; break; case R.attr.keyPreviewBackground: Drawable keyPreviewBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); if (keyPreviewBackground == null) return false; mPreviewPopupTheme.setPreviewKeyBackground(keyPreviewBackground); break; case R.attr.keyPreviewTextColor: mPreviewPopupTheme.setPreviewKeyTextColor(remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFF)); break; case R.attr.keyPreviewTextSize: mPreviewPopupTheme .setPreviewKeyTextSize(remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0)); break; case R.attr.keyPreviewLabelTextSize: mPreviewPopupTheme .setPreviewLabelTextSize(remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0)); break; case R.attr.keyPreviewOffset: mPreviewPopupTheme .setVerticalOffset(remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0)); break; case R.attr.previewAnimationType: int previewAnimationType = remoteTypedArray.getInteger(remoteTypedArrayIndex, -1); if (previewAnimationType == -1) return false; mPreviewPopupTheme.setPreviewAnimationType(previewAnimationType); break; case R.attr.keyTextStyle: int textStyle = remoteTypedArray.getInt(remoteTypedArrayIndex, 0); switch (textStyle) { case 0: mKeyTextStyle = Typeface.DEFAULT; break; case 1: mKeyTextStyle = Typeface.DEFAULT_BOLD; break; case 2: mKeyTextStyle = Typeface.defaultFromStyle(Typeface.ITALIC); break; default: mKeyTextStyle = Typeface.defaultFromStyle(textStyle); break; } mPreviewPopupTheme.setKeyStyle(mKeyTextStyle); break; case R.attr.keyHorizontalGap: float themeHorizontalKeyGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeHorizontalKeyGap == -1) return false; mKeyboardDimens.setHorizontalKeyGap(themeHorizontalKeyGap); break; case R.attr.keyVerticalGap: float themeVerticalRowGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeVerticalRowGap == -1) return false; mKeyboardDimens.setVerticalRowGap(themeVerticalRowGap); break; case R.attr.keyNormalHeight: int themeNormalKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeNormalKeyHeight == -1) return false; mKeyboardDimens.setNormalKeyHeight(themeNormalKeyHeight); break; case R.attr.keyLargeHeight: int themeLargeKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeLargeKeyHeight == -1) return false; mKeyboardDimens.setLargeKeyHeight(themeLargeKeyHeight); break; case R.attr.keySmallHeight: int themeSmallKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, -1); if (themeSmallKeyHeight == -1) return false; mKeyboardDimens.setSmallKeyHeight(themeSmallKeyHeight); break; case R.attr.hintTextSize: mHintTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, -1); if (mHintTextSize == -1) return false; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); break; case R.attr.hintTextColor: mHintTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex); if (mHintTextColor == null) { mHintTextColor = new ColorStateList(new int[][] { { 0 } }, new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) }); } break; case R.attr.hintLabelVAlign: mHintLabelVAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.BOTTOM); break; case R.attr.hintLabelAlign: mHintLabelAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.RIGHT); break; case R.attr.hintOverflowLabel: mHintOverflowLabel = remoteTypedArray.getString(remoteTypedArrayIndex); break; } return true; } catch (Exception e) { // on API changes, so the incompatible themes wont crash me.. e.printStackTrace(); return false; } }
From source file:com.example.psumaps.MapView.java
private void drawMarker(LatLng point, String str) { // Creating an instance of MarkerOptions MarkerOptions markerOptions = new MarkerOptions(); //IconGenerator tc = new IconGenerator(this); //Bitmap bmp = tc.makeIcon("hello"); Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.bubble_white);// get the image same as your EditText int h = bitmap.getHeight() * 2; int w = bitmap.getWidth() * 2; bitmap = convertToMutable(bitmap);// converting the bitmap to mutable Bitmap incrsize = Bitmap.createScaledBitmap(bitmap, w, h, false); Canvas cs = new Canvas(incrsize); Paint pt = new Paint(); pt.setColor(Color.BLACK);/*from www. j a v a2 s . com*/ //Typeface tf = Typeface.create("Helvetica",Typeface.BOLD); pt.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String iam = str.toUpperCase(Locale.getDefault()); pt.setTextSize(25); cs.drawText(iam, 0, iam.length(), (h / 2) + 10, (w / 2) / 2, pt); //pt.setColor(Color.RED); //cs.drawText("this is praki", 0, 13, h / 2, w / 3, pt); // Setting latitude and longitude for the marker markerOptions.position(point).title(str).icon(BitmapDescriptorFactory.fromBitmap(incrsize)); // Adding marker on the Google Map map.addMarker(markerOptions); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java
public boolean setValueFromTheme(TypedArray remoteTypedArray, final int[] padding, final int localAttrId, final int remoteTypedArrayIndex) { try {/* w w w. j a va2 s. c o m*/ if (localAttrId == android.R.attr.background) { Drawable keyboardBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); Log.d(TAG, "AnySoftKeyboardTheme_android_background " + (keyboardBackground != null)); super.setBackgroundDrawable(keyboardBackground); } else if (localAttrId == android.R.attr.paddingLeft) { padding[0] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_android_paddingLeft " + padding[0]); } else if (localAttrId == android.R.attr.paddingTop) { padding[1] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_android_paddingTop " + padding[1]); } else if (localAttrId == android.R.attr.paddingRight) { padding[2] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_android_paddingRight " + padding[2]); } else if (localAttrId == android.R.attr.paddingBottom) { padding[3] = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_android_paddingBottom " + padding[3]); } else if (localAttrId == R.attr.keyBackground) { mKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); Log.d(TAG, "AnySoftKeyboardTheme_keyBackground " + (mKeyBackground != null)); } else if (localAttrId == R.attr.keyHysteresisDistance) { mKeyHysteresisDistance = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_keyHysteresisDistance " + mKeyHysteresisDistance); } else if (localAttrId == R.attr.verticalCorrection) { mVerticalCorrection = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_verticalCorrection " + mVerticalCorrection); } else if (localAttrId == R.attr.keyPreviewBackground) { mPreviewKeyBackground = remoteTypedArray.getDrawable(remoteTypedArrayIndex); Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewBackground " + (mPreviewKeyBackground != null)); } else if (localAttrId == R.attr.keyPreviewTextColor) { mPreviewKeyTextColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFF); Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewTextColor " + mPreviewKeyTextColor); } else if (localAttrId == R.attr.keyPreviewTextSize) { mPreviewKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewTextSize " + mPreviewKeyTextSize); } else if (localAttrId == R.attr.keyPreviewLabelTextSize) { mPreviewLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewLabelTextSize " + mPreviewLabelTextSize); } else if (localAttrId == R.attr.keyPreviewOffset) { mPreviewOffset = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_keyPreviewOffset " + mPreviewOffset); } else if (localAttrId == R.attr.keyTextSize) { mKeyTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 18); // you might ask yourself "why did Menny sqrt root the factor?" // I'll tell you; the factor is mostly for the height, not the // font size, // but I also factorize the font size because I want the text to // be a little like // the key size. // the whole factor maybe too much, so I ease that a bit. if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mKeyTextSize = mKeyTextSize * FloatMath.sqrt(AnyApplication.getConfig().getKeysHeightFactorInLandscape()); else mKeyTextSize = mKeyTextSize * FloatMath.sqrt(AnyApplication.getConfig().getKeysHeightFactorInPortrait()); Log.d(TAG, "AnySoftKeyboardTheme_keyTextSize " + mKeyTextSize); } else if (localAttrId == R.attr.keyTextColor) { mKeyTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex); if (mKeyTextColor == null) { Log.d(TAG, "Creating an empty ColorStateList for mKeyTextColor"); mKeyTextColor = new ColorStateList(new int[][] { { 0 } }, new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) }); } Log.d(TAG, "AnySoftKeyboardTheme_keyTextColor " + mKeyTextColor); } else if (localAttrId == R.attr.labelTextSize) { mLabelTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 14); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mLabelTextSize = mLabelTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); Log.d(TAG, "AnySoftKeyboardTheme_labelTextSize " + mLabelTextSize); } else if (localAttrId == R.attr.keyboardNameTextSize) { mKeyboardNameTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 10); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mKeyboardNameTextSize = mKeyboardNameTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mKeyboardNameTextSize = mKeyboardNameTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); Log.d(TAG, "AnySoftKeyboardTheme_keyboardNameTextSize " + mKeyboardNameTextSize); } else if (localAttrId == R.attr.keyboardNameTextColor) { mKeyboardNameTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex); if (mKeyboardNameTextColor == null) { Log.d(TAG, "Creating an empty ColorStateList for mKeyboardNameTextColor"); mKeyboardNameTextColor = new ColorStateList(new int[][] { { 0 } }, new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFFAAAAAA) }); } Log.d(TAG, "AnySoftKeyboardTheme_keyboardNameTextColor " + mKeyboardNameTextColor); } else if (localAttrId == R.attr.shadowColor) { mShadowColor = remoteTypedArray.getColor(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_shadowColor " + mShadowColor); } else if (localAttrId == R.attr.shadowRadius) { mShadowRadius = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_shadowRadius " + mShadowRadius); } else if (localAttrId == R.attr.shadowOffsetX) { mShadowOffsetX = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_shadowOffsetX " + mShadowOffsetX); } else if (localAttrId == R.attr.shadowOffsetY) { mShadowOffsetY = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_shadowOffsetY " + mShadowOffsetY); } else if (localAttrId == R.attr.backgroundDimAmount) { mBackgroundDimAmount = remoteTypedArray.getFloat(remoteTypedArrayIndex, 0.5f); Log.d(TAG, "AnySoftKeyboardTheme_backgroundDimAmount " + mBackgroundDimAmount); } else if (localAttrId == R.attr.keyTextStyle) { int textStyle = remoteTypedArray.getInt(remoteTypedArrayIndex, 0); switch (textStyle) { case 0: mKeyTextStyle = Typeface.DEFAULT; break; case 1: mKeyTextStyle = Typeface.DEFAULT_BOLD; break; case 2: mKeyTextStyle = Typeface.defaultFromStyle(Typeface.ITALIC); break; default: mKeyTextStyle = Typeface.defaultFromStyle(textStyle); break; } Log.d(TAG, "AnySoftKeyboardTheme_keyTextStyle " + mKeyTextStyle); } else if (localAttrId == R.attr.symbolColorScheme) { mSymbolColorScheme = remoteTypedArray.getInt(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_symbolColorScheme " + mSymbolColorScheme); } else if (localAttrId == R.attr.keyHorizontalGap) { float themeHorizotalKeyGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); mKeyboardDimens.setHorizontalKeyGap(themeHorizotalKeyGap); Log.d(TAG, "AnySoftKeyboardTheme_keyHorizontalGap " + themeHorizotalKeyGap); } else if (localAttrId == R.attr.keyVerticalGap) { float themeVerticalRowGap = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); mKeyboardDimens.setVerticalRowGap(themeVerticalRowGap); Log.d(TAG, "AnySoftKeyboardTheme_keyVerticalGap " + themeVerticalRowGap); } else if (localAttrId == R.attr.keyNormalHeight) { float themeNormalKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); mKeyboardDimens.setNormalKeyHeight(themeNormalKeyHeight); Log.d(TAG, "AnySoftKeyboardTheme_keyNormalHeight " + themeNormalKeyHeight); } else if (localAttrId == R.attr.keyLargeHeight) { float themeLargeKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); mKeyboardDimens.setLargeKeyHeight(themeLargeKeyHeight); Log.d(TAG, "AnySoftKeyboardTheme_keyLargeHeight " + themeLargeKeyHeight); } else if (localAttrId == R.attr.keySmallHeight) { float themeSmallKeyHeight = remoteTypedArray.getDimensionPixelOffset(remoteTypedArrayIndex, 0); mKeyboardDimens.setSmallKeyHeight(themeSmallKeyHeight); Log.d(TAG, "AnySoftKeyboardTheme_keySmallHeight " + themeSmallKeyHeight); } else if (localAttrId == R.attr.hintTextSize) { mHintTextSize = remoteTypedArray.getDimensionPixelSize(remoteTypedArrayIndex, 0); Log.d(TAG, "AnySoftKeyboardTheme_hintTextSize " + mHintTextSize); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInLandscape(); else mHintTextSize = mHintTextSize * AnyApplication.getConfig().getKeysHeightFactorInPortrait(); Log.d(TAG, "AnySoftKeyboardTheme_hintTextSize with factor " + mHintTextSize); } else if (localAttrId == R.attr.hintTextColor) { mHintTextColor = remoteTypedArray.getColorStateList(remoteTypedArrayIndex); if (mHintTextColor == null) { Log.d(TAG, "Creating an empty ColorStateList for mHintTextColor"); mHintTextColor = new ColorStateList(new int[][] { { 0 } }, new int[] { remoteTypedArray.getColor(remoteTypedArrayIndex, 0xFF000000) }); } Log.d(TAG, "AnySoftKeyboardTheme_hintTextColor " + mHintTextColor); } else if (localAttrId == R.attr.hintLabelVAlign) { mHintLabelVAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.BOTTOM); Log.d(TAG, "AnySoftKeyboardTheme_hintLabelVAlign " + mHintLabelVAlign); } else if (localAttrId == R.attr.hintLabelAlign) { mHintLabelAlign = remoteTypedArray.getInt(remoteTypedArrayIndex, Gravity.RIGHT); Log.d(TAG, "AnySoftKeyboardTheme_hintLabelAlign " + mHintLabelAlign); } else if (localAttrId == R.attr.hintOverflowLabel) { mHintOverflowLabel = remoteTypedArray.getString(remoteTypedArrayIndex); Log.d(TAG, "AnySoftKeyboardTheme_hintOverflowLabel " + mHintOverflowLabel); } return true; } catch (Exception e) { // on API changes, so the incompatible themes wont crash me.. e.printStackTrace(); return false; } }
From source file:com.edible.ocr.CaptureActivity.java
/** * Displays information relating to the result of OCR, and requests a translation if necessary. * /* ww w.ja v a 2s. com*/ * @param ocrResult Object representing successful OCR results * @return True if a non-null result was received for OCR */ boolean handleOcrDecode(OcrResult ocrResult) { lastResult = ocrResult; // Test whether the result is null if (ocrResult.getText() == null || ocrResult.getText().equals("")) { Toast toast = Toast.makeText(this, "OCR failed. Please try again.", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); return false; } // Turn off capture-related UI elements shutterButton.setVisibility(View.GONE); statusViewBottom.setVisibility(View.GONE); statusViewTop.setVisibility(View.GONE); cameraButtonView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView bitmapImageView = (ImageView) findViewById(R.id.image_view); lastBitmap = ocrResult.getBitmap(); if (lastBitmap == null) { bitmapImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)); } else { bitmapImageView.setImageBitmap(lastBitmap); } // Display the recognized text TextView sourceLanguageTextView = (TextView) findViewById(R.id.source_language_text_view); sourceLanguageTextView.setText(sourceLanguageReadable); TextView ocrResultTextView = (TextView) findViewById(R.id.ocr_result_text_view); ocrResultTextView.setText(stripNoise(ocrResult.getText())); // Crudely scale betweeen 22 and 32 -- bigger font for shorter text int scaledSize = Math.max(22, 32 - ocrResult.getText().length() / 4); ocrResultTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView translationLanguageLabelTextView = (TextView) findViewById( R.id.translation_language_label_text_view); TextView translationLanguageTextView = (TextView) findViewById(R.id.translation_language_text_view); TextView translationTextView = (TextView) findViewById(R.id.translation_text_view); if (isTranslationActive) { // Handle translation text fields translationLanguageLabelTextView.setVisibility(View.VISIBLE); translationLanguageTextView.setText(targetLanguageReadable); translationLanguageTextView.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL); translationLanguageTextView.setVisibility(View.VISIBLE); // Activate/re-activate the indeterminate progress indicator translationTextView.setVisibility(View.GONE); progressView.setVisibility(View.VISIBLE); setProgressBarVisibility(true); // Get the translation asynchronously new TranslateAsyncTask(this, sourceLanguageCodeTranslation, targetLanguageCodeTranslation, stripNoise(ocrResult.getText())).execute(); } else { translationLanguageLabelTextView.setVisibility(View.GONE); translationLanguageTextView.setVisibility(View.GONE); translationTextView.setVisibility(View.GONE); progressView.setVisibility(View.GONE); setProgressBarVisibility(false); } return true; }