Java Code Examples for android.content.res.Resources#getFraction()
The following examples show how to use
android.content.res.Resources#getFraction() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmojiLayoutParams.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
public EmojiLayoutParams(final Resources res) { final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); final int defaultKeyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); mKeyVerticalGap = (int) res.getFraction(R.fraction.config_key_vertical_gap_holo, defaultKeyboardHeight, defaultKeyboardHeight); mBottomPadding = (int) res.getFraction(R.fraction.config_keyboard_bottom_padding_holo, defaultKeyboardHeight, defaultKeyboardHeight); mTopPadding = (int) res.getFraction(R.fraction.config_keyboard_top_padding_holo, defaultKeyboardHeight, defaultKeyboardHeight); mKeyHorizontalGap = (int) (res.getFraction(R.fraction.config_key_horizontal_gap_holo, defaultKeyboardWidth, defaultKeyboardWidth)); mEmojiCategoryPageIdViewHeight = (int) (res.getDimension(R.dimen.config_emoji_category_page_id_height)); final int baseheight = defaultKeyboardHeight - mBottomPadding - mTopPadding + mKeyVerticalGap; mEmojiActionBarHeight = baseheight / DEFAULT_KEYBOARD_ROWS - (mKeyVerticalGap - mBottomPadding) / 2; mEmojiPagerHeight = defaultKeyboardHeight - mEmojiActionBarHeight - mEmojiCategoryPageIdViewHeight; mEmojiPagerBottomMargin = 0; mEmojiKeyboardHeight = mEmojiPagerHeight - mEmojiPagerBottomMargin - 1; }
Example 2
Source File: ResourceUtils.java From openboard with GNU General Public License v3.0 | 6 votes |
public static int getDefaultKeyboardHeight(final Resources res) { final DisplayMetrics dm = res.getDisplayMetrics(); final String keyboardHeightInDp = getDeviceOverrideValue( res, R.array.keyboard_heights, null /* defaultValue */); final float keyboardHeight; if (TextUtils.isEmpty(keyboardHeightInDp)) { keyboardHeight = res.getDimension(R.dimen.config_default_keyboard_height); } else { keyboardHeight = Float.parseFloat(keyboardHeightInDp) * dm.density; } final float maxKeyboardHeight = res.getFraction( R.fraction.config_max_keyboard_height, dm.heightPixels, dm.heightPixels); float minKeyboardHeight = res.getFraction( R.fraction.config_min_keyboard_height, dm.heightPixels, dm.heightPixels); if (minKeyboardHeight < 0.0f) { // Specified fraction was negative, so it should be calculated against display // width. minKeyboardHeight = -res.getFraction( R.fraction.config_min_keyboard_height, dm.widthPixels, dm.widthPixels); } // Keyboard height will not exceed maxKeyboardHeight and will not be less than // minKeyboardHeight. return (int)Math.max(Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight); }
Example 3
Source File: ResourceUtils.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
public static int getDefaultKeyboardHeight(final Resources res) { final DisplayMetrics dm = res.getDisplayMetrics(); final String keyboardHeightInDp = getDeviceOverrideValue( res, R.array.keyboard_heights, null /* defaultValue */); final float keyboardHeight; if (TextUtils.isEmpty(keyboardHeightInDp)) { keyboardHeight = res.getDimension(R.dimen.config_default_keyboard_height); } else { keyboardHeight = Float.parseFloat(keyboardHeightInDp) * dm.density; } final float maxKeyboardHeight = res.getFraction( R.fraction.config_max_keyboard_height, dm.heightPixels, dm.heightPixels); float minKeyboardHeight = res.getFraction( R.fraction.config_min_keyboard_height, dm.heightPixels, dm.heightPixels); if (minKeyboardHeight < 0.0f) { // Specified fraction was negative, so it should be calculated against display // width. minKeyboardHeight = -res.getFraction( R.fraction.config_min_keyboard_height, dm.widthPixels, dm.widthPixels); } // Keyboard height will not exceed maxKeyboardHeight and will not be less than // minKeyboardHeight. return (int)Math.max(Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight); }
Example 4
Source File: EmojiLayoutParams.java From openboard with GNU General Public License v3.0 | 6 votes |
public EmojiLayoutParams(final Resources res) { final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); final int defaultKeyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); mKeyVerticalGap = (int) res.getFraction(R.fraction.config_key_vertical_gap_holo, defaultKeyboardHeight, defaultKeyboardHeight); mBottomPadding = (int) res.getFraction(R.fraction.config_keyboard_bottom_padding_holo, defaultKeyboardHeight, defaultKeyboardHeight); mTopPadding = (int) res.getFraction(R.fraction.config_keyboard_top_padding_holo, defaultKeyboardHeight, defaultKeyboardHeight); mKeyHorizontalGap = (int) (res.getFraction(R.fraction.config_key_horizontal_gap_holo, defaultKeyboardWidth, defaultKeyboardWidth)); mEmojiCategoryPageIdViewHeight = (int) (res.getDimension(R.dimen.config_emoji_category_page_id_height)); final int baseheight = defaultKeyboardHeight - mBottomPadding - mTopPadding + mKeyVerticalGap; mEmojiActionBarHeight = baseheight / DEFAULT_KEYBOARD_ROWS - (mKeyVerticalGap - mBottomPadding) / 2; mEmojiPagerHeight = defaultKeyboardHeight - mEmojiActionBarHeight - mEmojiCategoryPageIdViewHeight; mEmojiPagerBottomMargin = 0; mEmojiKeyboardHeight = mEmojiPagerHeight - mEmojiPagerBottomMargin - 1; }
Example 5
Source File: ResourceUtils.java From LokiBoard-Android-Keylogger with Apache License 2.0 | 6 votes |
public static int getDefaultKeyboardHeight(final Resources res) { final DisplayMetrics dm = res.getDisplayMetrics(); final float keyboardHeight = res.getDimension(R.dimen.config_default_keyboard_height); final float maxKeyboardHeight = res.getFraction( R.fraction.config_max_keyboard_height, dm.heightPixels, dm.heightPixels); float minKeyboardHeight = res.getFraction( R.fraction.config_min_keyboard_height, dm.heightPixels, dm.heightPixels); if (minKeyboardHeight < 0.0f) { // Specified fraction was negative, so it should be calculated against display // width. minKeyboardHeight = -res.getFraction( R.fraction.config_min_keyboard_height, dm.widthPixels, dm.widthPixels); } // Keyboard height will not exceed maxKeyboardHeight and will not be less than // minKeyboardHeight. return (int)Math.max(Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight); }
Example 6
Source File: ResourceUtils.java From simple-keyboard with Apache License 2.0 | 6 votes |
public static int getDefaultKeyboardHeight(final Resources res) { final DisplayMetrics dm = res.getDisplayMetrics(); final float keyboardHeight = res.getDimension(R.dimen.config_default_keyboard_height); final float maxKeyboardHeight = res.getFraction( R.fraction.config_max_keyboard_height, dm.heightPixels, dm.heightPixels); float minKeyboardHeight = res.getFraction( R.fraction.config_min_keyboard_height, dm.heightPixels, dm.heightPixels); if (minKeyboardHeight < 0.0f) { // Specified fraction was negative, so it should be calculated against display // width. minKeyboardHeight = -res.getFraction( R.fraction.config_min_keyboard_height, dm.widthPixels, dm.widthPixels); } // Keyboard height will not exceed maxKeyboardHeight and will not be less than // minKeyboardHeight. return (int)Math.max(Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight); }
Example 7
Source File: ResourceUtils.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
public static int getDefaultKeyboardHeight(final Resources res) { final DisplayMetrics dm = res.getDisplayMetrics(); final String keyboardHeightInDp = getDeviceOverrideValue( res, R.array.keyboard_heights, null /* defaultValue */); final float keyboardHeight; if (TextUtils.isEmpty(keyboardHeightInDp)) { keyboardHeight = res.getDimension(R.dimen.config_default_keyboard_height); } else { keyboardHeight = Float.parseFloat(keyboardHeightInDp) * dm.density; } final float maxKeyboardHeight = res.getFraction( R.fraction.config_max_keyboard_height, dm.heightPixels, dm.heightPixels); float minKeyboardHeight = res.getFraction( R.fraction.config_min_keyboard_height, dm.heightPixels, dm.heightPixels); if (minKeyboardHeight < 0.0f) { // Specified fraction was negative, so it should be calculated against display // width. minKeyboardHeight = -res.getFraction( R.fraction.config_min_keyboard_height, dm.widthPixels, dm.widthPixels); } // Keyboard height will not exceed maxKeyboardHeight and will not be less than // minKeyboardHeight. return (int)Math.max(Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight); }
Example 8
Source File: SpeechOrbView.java From adt-leanback-support with Apache License 2.0 | 6 votes |
public SpeechOrbView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); Resources resources = context.getResources(); mSoundLevelMaxZoom = resources.getFraction(R.fraction.lb_search_bar_speech_orb_max_level_zoom, 1, 1); mNotListeningOrbColors = new Colors(resources.getColor(R.color.lb_speech_orb_not_recording), resources.getColor(R.color.lb_speech_orb_not_recording_pulsed), resources.getColor(R.color.lb_speech_orb_not_recording_icon)); mListeningOrbColors = new Colors(resources.getColor(R.color.lb_speech_orb_recording), resources.getColor(R.color.lb_speech_orb_recording), Color.TRANSPARENT); showNotListening(); }
Example 9
Source File: EmojiLayoutParams.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
public EmojiLayoutParams(final Resources res) { final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); final int defaultKeyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); mKeyVerticalGap = (int) res.getFraction(R.fraction.config_key_vertical_gap_holo, defaultKeyboardHeight, defaultKeyboardHeight); mBottomPadding = (int) res.getFraction(R.fraction.config_keyboard_bottom_padding_holo, defaultKeyboardHeight, defaultKeyboardHeight); mTopPadding = (int) res.getFraction(R.fraction.config_keyboard_top_padding_holo, defaultKeyboardHeight, defaultKeyboardHeight); mKeyHorizontalGap = (int) (res.getFraction(R.fraction.config_key_horizontal_gap_holo, defaultKeyboardWidth, defaultKeyboardWidth)); mEmojiCategoryPageIdViewHeight = (int) (res.getDimension(R.dimen.config_emoji_category_page_id_height)); final int baseheight = defaultKeyboardHeight - mBottomPadding - mTopPadding + mKeyVerticalGap; mEmojiActionBarHeight = baseheight / DEFAULT_KEYBOARD_ROWS - (mKeyVerticalGap - mBottomPadding) / 2; mEmojiPagerHeight = defaultKeyboardHeight - mEmojiActionBarHeight - mEmojiCategoryPageIdViewHeight; mEmojiPagerBottomMargin = 0; mEmojiKeyboardHeight = mEmojiPagerHeight - mEmojiPagerBottomMargin - 1; }
Example 10
Source File: PowerManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void readConfigurationLocked() { final Resources resources = mContext.getResources(); mDecoupleHalAutoSuspendModeFromDisplayConfig = resources.getBoolean( com.android.internal.R.bool.config_powerDecoupleAutoSuspendModeFromDisplay); mDecoupleHalInteractiveModeFromDisplayConfig = resources.getBoolean( com.android.internal.R.bool.config_powerDecoupleInteractiveModeFromDisplay); mWakeUpWhenPluggedOrUnpluggedConfig = resources.getBoolean( com.android.internal.R.bool.config_unplugTurnsOnScreen); mWakeUpWhenPluggedOrUnpluggedInTheaterModeConfig = resources.getBoolean( com.android.internal.R.bool.config_allowTheaterModeWakeFromUnplug); mSuspendWhenScreenOffDueToProximityConfig = resources.getBoolean( com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity); mDreamsSupportedConfig = resources.getBoolean( com.android.internal.R.bool.config_dreamsSupported); mDreamsEnabledByDefaultConfig = resources.getBoolean( com.android.internal.R.bool.config_dreamsEnabledByDefault); mDreamsActivatedOnSleepByDefaultConfig = resources.getBoolean( com.android.internal.R.bool.config_dreamsActivatedOnSleepByDefault); mDreamsActivatedOnDockByDefaultConfig = resources.getBoolean( com.android.internal.R.bool.config_dreamsActivatedOnDockByDefault); mDreamsEnabledOnBatteryConfig = resources.getBoolean( com.android.internal.R.bool.config_dreamsEnabledOnBattery); mDreamsBatteryLevelMinimumWhenPoweredConfig = resources.getInteger( com.android.internal.R.integer.config_dreamsBatteryLevelMinimumWhenPowered); mDreamsBatteryLevelMinimumWhenNotPoweredConfig = resources.getInteger( com.android.internal.R.integer.config_dreamsBatteryLevelMinimumWhenNotPowered); mDreamsBatteryLevelDrainCutoffConfig = resources.getInteger( com.android.internal.R.integer.config_dreamsBatteryLevelDrainCutoff); mDozeAfterScreenOff = resources.getBoolean( com.android.internal.R.bool.config_dozeAfterScreenOffByDefault); mMinimumScreenOffTimeoutConfig = resources.getInteger( com.android.internal.R.integer.config_minimumScreenOffTimeout); mMaximumScreenDimDurationConfig = resources.getInteger( com.android.internal.R.integer.config_maximumScreenDimDuration); mMaximumScreenDimRatioConfig = resources.getFraction( com.android.internal.R.fraction.config_maximumScreenDimRatio, 1, 1); mSupportsDoubleTapWakeConfig = resources.getBoolean( com.android.internal.R.bool.config_supportDoubleTapWake); }
Example 11
Source File: FocusHighlightHelper.java From adt-leanback-support with Apache License 2.0 | 5 votes |
private static void lazyInit(Resources resources) { if (sScaleFactor[ZOOM_FACTOR_NONE] == 0f) { sScaleFactor[ZOOM_FACTOR_NONE] = 1f; sScaleFactor[ZOOM_FACTOR_SMALL] = resources.getFraction(R.fraction.lb_focus_zoom_factor_small, 1, 1); sScaleFactor[ZOOM_FACTOR_MEDIUM] = resources.getFraction(R.fraction.lb_focus_zoom_factor_medium, 1, 1); sScaleFactor[ZOOM_FACTOR_LARGE] = resources.getFraction(R.fraction.lb_focus_zoom_factor_large, 1, 1); } }
Example 12
Source File: TrainActionActivity.java From shortrain with MIT License | 5 votes |
@NonNull private TrainView addTrain(Rect trainRect, int trainType, FrameLayout frameLayout) { final int size = Math.min(trainRect.width(), trainRect.height()); final TrainView trainView = new TrainView(this); Resources res = getResources(); int trainWidth = (int) (trainRect.width() * 0.70); int trainHeight = (int) res.getFraction(R.fraction.rail_height_width_fraction, trainWidth, trainWidth); trainView.setType(trainType); trainView.setTrainHeight(trainHeight); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(trainWidth, trainHeight); frameLayout.addView(trainView, lp); trainView.setX(trainRect.left + (size - trainWidth) / 2); trainView.setY(trainRect.top + (size - trainHeight) / 2); return trainView; }
Example 13
Source File: BrightnessMappingStrategy.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Nullable public static BrightnessMappingStrategy create(Resources resources) { float[] luxLevels = getLuxLevels(resources.getIntArray( com.android.internal.R.array.config_autoBrightnessLevels)); int[] brightnessLevelsBacklight = resources.getIntArray( com.android.internal.R.array.config_autoBrightnessLcdBacklightValues); float[] brightnessLevelsNits = getFloatArray(resources.obtainTypedArray( com.android.internal.R.array.config_autoBrightnessDisplayValuesNits)); float autoBrightnessAdjustmentMaxGamma = resources.getFraction( com.android.internal.R.fraction.config_autoBrightnessAdjustmentMaxGamma, 1, 1); float[] nitsRange = getFloatArray(resources.obtainTypedArray( com.android.internal.R.array.config_screenBrightnessNits)); int[] backlightRange = resources.getIntArray( com.android.internal.R.array.config_screenBrightnessBacklight); if (isValidMapping(nitsRange, backlightRange) && isValidMapping(luxLevels, brightnessLevelsNits)) { int minimumBacklight = resources.getInteger( com.android.internal.R.integer.config_screenBrightnessSettingMinimum); int maximumBacklight = resources.getInteger( com.android.internal.R.integer.config_screenBrightnessSettingMaximum); if (backlightRange[0] > minimumBacklight || backlightRange[backlightRange.length - 1] < maximumBacklight) { Slog.w(TAG, "Screen brightness mapping does not cover whole range of available " + "backlight values, autobrightness functionality may be impaired."); } BrightnessConfiguration.Builder builder = new BrightnessConfiguration.Builder(); builder.setCurve(luxLevels, brightnessLevelsNits); return new PhysicalMappingStrategy(builder.build(), nitsRange, backlightRange, autoBrightnessAdjustmentMaxGamma); } else if (isValidMapping(luxLevels, brightnessLevelsBacklight)) { return new SimpleMappingStrategy(luxLevels, brightnessLevelsBacklight, autoBrightnessAdjustmentMaxGamma); } else { return null; } }
Example 14
Source File: FocusHighlightHelper.java From TvRecyclerView with Apache License 2.0 | 4 votes |
private float getScale(Resources res) { return mScaleIndex == ZOOM_FACTOR_NONE ? 1f : res.getFraction(getResId(mScaleIndex), 1, 1); }
Example 15
Source File: ResourceUtils.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 4 votes |
public static float getFloatFromFraction(final Resources res, final int fractionResId) { return res.getFraction(fractionResId, 1, 1); }
Example 16
Source File: MyFocusHighlightHelper.java From LeanbackTvSample with MIT License | 4 votes |
private float getScale(Resources res) { return mScaleIndex == ZOOM_FACTOR_NONE ? 1f : res.getFraction(getResId(mScaleIndex), 1, 1); }
Example 17
Source File: ResourceUtils.java From openboard with GNU General Public License v3.0 | 4 votes |
public static float getFloatFromFraction(final Resources res, final int fractionResId) { return res.getFraction(fractionResId, 1, 1); }
Example 18
Source File: ResourceUtils.java From Indic-Keyboard with Apache License 2.0 | 4 votes |
public static float getFloatFromFraction(final Resources res, final int fractionResId) { return res.getFraction(fractionResId, 1, 1); }