@Test public void getFraction() { final int myself = 300; final int myParent = 600; assertThat(resources.getFraction(R.fraction.half, myself, myParent)).isEqualTo(150f); assertThat(resources.getFraction(R.fraction.half_of_parent, myself, myParent)).isEqualTo(300f); assertThat(resources.getFraction(R.fraction.quarter_as_item, myself, myParent)).isEqualTo(75f); assertThat(resources.getFraction(R.fraction.quarter_of_parent_as_item, myself, myParent)).isEqualTo(150f); assertThat(resources.getFraction(R.fraction.fifth_as_reference, myself, myParent)).isWithin(0.01f).of(60f); assertThat(resources.getFraction(R.fraction.fifth_of_parent_as_reference, myself, myParent)).isWithin(0.01f).of(120f); }
@Override public float getFraction(int id, int base, int pbase) { try { return super.getFraction(id, base, pbase); } catch (NotFoundException e) { return mHostResources.getFraction(id, base, pbase); } }
@Override public float getFraction(int id, int base, int pbase) { try { return super.getFraction(id, base, pbase); } catch (NotFoundException e) { return mHostResources.getFraction(id, base, pbase); } }
public static float getFloatFromFraction(final Resources res, final int fractionResId) { return res.getFraction(fractionResId, 1, 1); }
public static float getFloatFromFraction(final Resources res, final int fractionResId) { return res.getFraction(fractionResId, 1, 1); }
public float getFocusedScaleFactor() { return this.mTargetView.getResources().getFraction(R.fraction.lb_focus_zoom_factor_medium, 1, 1); }
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); }
public BatteryMeterView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mButtonHeightFraction = context.getResources().getFraction(R.fraction.battery_button_height_fraction, 1, 1); mSubpixelSmoothingLeft = context.getResources().getFraction(R.fraction.battery_subpixel_smoothing_left, 1, 1); mSubpixelSmoothingRight = context.getResources().getFraction(R.fraction.battery_subpixel_smoothing_right, 1, 1); mFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG); mFramePaint.setColor(getResources().getColor(R.color.batterymeter_frame_color)); mFramePaint.setDither(true); mFramePaint.setStrokeWidth(0); mFramePaint.setStyle(Paint.Style.FILL_AND_STROKE); mBatteryPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mBatteryPaint.setDither(true); mBatteryPaint.setStrokeWidth(0); mBatteryPaint.setStyle(Paint.Style.FILL_AND_STROKE); }
public PhoneFavoriteSquareTileView(Context context, AttributeSet attrs) { super(context, attrs); mHeightToWidthRatio = getResources().getFraction( R.dimen.contact_tile_height_to_width_ratio, 1, 1); }
NowPlayCardListener(Context context, boolean isTestRunning) { this.mMediaSessionCallback = new MediaControllerCallback(this); this.mContext = context; this.mIsTestRunning = isTestRunning; Resources res = this.mContext.getResources(); this.mCardMaxWidth = res.getDimensionPixelOffset(R.dimen.notif_card_img_max_width); this.mCardMaxHeight = res.getDimensionPixelOffset(R.dimen.notif_card_img_height); this.mBannerMaxWidth = res.getDimensionPixelOffset(R.dimen.banner_width); this.mBannerMaxHeight = res.getDimensionPixelOffset(R.dimen.banner_height); this.mNowPlayingDefaultDarkening = res.getFraction(R.fraction.now_playing_icon_color_darkening, 1, 1); }
@Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup) { mUnselectedAlpha = viewGroup.getResources() .getFraction(R.fraction.lb_browse_header_unselect_alpha, 1, 1); LayoutInflater inflater = (LayoutInflater) viewGroup.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.item_icon_header, null); return new ViewHolder(view); }
@Override public ViewHolder onCreateViewHolder(ViewGroup parent) { mUnselectedAlpha = parent.getResources() .getFraction(R.fraction.lb_browse_header_unselect_alpha, 1, 1); LayoutInflater inflater = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.tv_header_item, null); view.setAlpha(mUnselectedAlpha); return new ViewHolder(view); }
public NotificationCardView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.mAnimationsEnabled = true; Resources res = getResources(); this.mImageMinWidth = res.getDimensionPixelOffset(R.dimen.notif_card_img_min_width); this.mImageMaxWidth = res.getDimensionPixelOffset(R.dimen.notif_card_img_max_width); this.mImageHeight = res.getDimensionPixelOffset(R.dimen.notif_card_img_height); this.mFocusAnimDuration = res.getInteger(R.integer.notif_card_metadata_animation_duration); this.mMetaUnselectedHeight = res.getDimensionPixelOffset(R.dimen.notif_card_info_height); this.mBadgeImageAlpha = res.getFraction(R.fraction.badge_icon_alpha, 1, 1); this.mDimmer = new ViewDimmer(this); this.mFocusAnimator = createNewFocusAnimator(); }
public LauncherWallpaper(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.mInShyMode = true; this.mWallpaperInstaller = WallpaperInstaller.getInstance(context); Resources resources = getContext().getResources(); this.mDownloader = new WallpaperDownloader(context, resources.getInteger(R.integer.wallpaper_update_delay), resources.getInteger(R.integer.wallpaper_fetch_timeout), this); this.mScrollDarkeningOffset = (float) resources.getDimensionPixelOffset(R.dimen.home_scroll_size_search); this.mScrollDarkeningAmount = getResources().getFraction(R.fraction.wallpaper_scroll_darkening_amount, 1, 1); this.mWallpaperScrollScale = getResources().getFraction(R.fraction.wallpaper_to_launcher_scroll_scale, 1, 1); this.mZoom = getResources().getFraction(R.fraction.wallpaper_zoom_amount, 1, 1); this.mZoomThreshold = this.mScrollDarkeningOffset / getResources().getFraction(R.fraction.wallpaper_zoom_to_darkening_scale, 1, 1); this.mDimmer = ColorFilterDimmer.create(ColorFilterCache.getColorFilterCache(ContextCompat.getColor(context, R.color.launcher_background_color)), 0.0f, this.mScrollDarkeningAmount); }
public ViewFocusAnimator(View view) { this.mEnabled = true; this.mTargetView = view; Resources res = view.getResources(); this.mTargetView.setOnFocusChangeListener(this); TypedValue out = new TypedValue(); res.getValue(R.raw.unselected_scale, out, true); this.mUnselectedScale = out.getFloat(); this.mSelectedScaleDelta = res.getFraction(R.fraction.lb_focus_zoom_factor_medium, 1, 1) - this.mUnselectedScale; this.mUnselectedZ = (float) res.getDimensionPixelOffset(R.dimen.unselected_item_z); this.mSelectedZDelta = (float) res.getDimensionPixelOffset(R.dimen.selected_item_z_delta); this.mFocusAnimation = ObjectAnimator.ofFloat(this, "focusProgress", new float[]{0.0f}); this.mFocusAnimation.setDuration((long) res.getInteger(R.integer.item_scale_anim_duration)); this.mFocusAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); setFocusProgress(0.0f); this.mFocusAnimation.addListener(new C01801()); }
@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; }
@SmallTest public void testFraction() { assertEquals(res.getFraction(R.fraction.fraction, 2, 2), testView.testFractionBase); assertEquals(res.getFraction(R.fraction.parent_fraction, 2, 2), testView.testFracionPBase); assertEquals(res.getFraction(R.fraction.fraction, 2, 2), defaultsTestView.testFractionBase); assertEquals(res.getFraction(R.fraction.parent_fraction, 2, 2), defaultsTestView.testFracionPBase); }
protected void onFinishInflate() { super.onFinishInflate(); setClipChildren(false); this.mScaleFactor = getResources().getFraction(R.fraction.lb_focus_zoom_factor_medium, 1, 1); this.mContent = getChildAt(0); this.mContent.setPivotX(0.0f); this.mContent.setPivotY(0.0f); this.mContent.setScaleX(1.0f / this.mScaleFactor); this.mContent.setScaleY(1.0f / this.mScaleFactor); }
public ActiveFrame(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.mDimState = ViewDimmer.DimState.INACTIVE; this.mScalesWhenUnfocused = false; this.mExpanded = 1.0f; this.mHeaderVisible = true; setDescendantFocusability(262144); this.mHeaderHeight = getResources().getDimensionPixelSize(R.dimen.header_height); this.mActiveTextMargin = getResources().getDimension(R.dimen.header_text_active_margin_extra); this.mAnimDuration = getResources().getInteger(R.integer.item_scale_anim_duration); this.mBottomPadding = getResources().getDimensionPixelSize(R.dimen.group_vertical_spacing); this.mRowPadding = getResources().getDimension(R.dimen.row_padding); this.mCardSpacing = getResources().getDimension(R.dimen.card_spacing); this.mDownscaleFactor = getResources().getFraction(R.fraction.inactive_banner_scale_down_amount, 1, 1); if (this.mDownscaleFactor < 0.0f || this.mDownscaleFactor >= 1.0f) { this.mDownscaleFactor = 0.0f; } this.mRowMinSpacing = (int) ((1.0f - this.mDownscaleFactor) * getResources().getDimension(R.dimen.inter_card_spacing)); this.mAccessibilityManager = (AccessibilityManager) context.getSystemService("accessibility"); }
protected void onFinishInflate() { super.onFinishInflate(); setClipChildren(false); this.mScaleFactor = getResources().getFraction(R.fraction.lb_focus_zoom_factor_medium, 1, 1); this.mContent = getChildAt(0); this.mContent.setPivotX(0.0f); this.mContent.setPivotY(0.0f); this.mContent.setScaleX(1.0f / this.mScaleFactor); this.mContent.setScaleY(1.0f / this.mScaleFactor); }