1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package androidx.leanback.widget; 15 16 import android.content.Context; 17 import android.graphics.Canvas; 18 import android.graphics.Paint; 19 import android.graphics.RectF; 20 import android.util.AttributeSet; 21 import android.view.View; 22 23 import androidx.annotation.RestrictTo; 24 import androidx.leanback.R; 25 26 /** 27 * Creates a view for a media item row in a playlist 28 * @hide 29 */ 30 @RestrictTo(RestrictTo.Scope.LIBRARY) 31 class MediaRowFocusView extends View { 32 33 private final Paint mPaint; 34 private final RectF mRoundRectF = new RectF(); 35 private int mRoundRectRadius; 36 37 public MediaRowFocusView(Context context) { 38 super(context); 39 mPaint = createPaint(context); 40 } 41 42 public MediaRowFocusView(Context context, AttributeSet attrs) { 43 super(context, attrs); 44 mPaint = createPaint(context); 45 } 46 47 public MediaRowFocusView(Context context, AttributeSet attrs, int defStyleAttr) { 48 super(context, attrs, defStyleAttr); 49 mPaint = createPaint(context); 50 } 51 52 @Override 53 protected void onDraw(Canvas canvas) { 54 super.onDraw(canvas); 55 mRoundRectRadius = getHeight() / 2; 56 int drawHeight = 2 * mRoundRectRadius; 57 int drawOffset = (drawHeight - getHeight()) / 2; 58 mRoundRectF.set(0, -drawOffset, getWidth(), getHeight() + drawOffset); 59 canvas.drawRoundRect(mRoundRectF, mRoundRectRadius, mRoundRectRadius, mPaint); 60 } 61 62 private Paint createPaint(Context context) { 63 Paint paint = new Paint(); 64 paint.setColor(context.getResources().getColor( 65 R.color.lb_playback_media_row_highlight_color)); 66 return paint; 67 } 68 69 public int getRoundRectRadius() { 70 return mRoundRectRadius; 71 } 72 }