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 */ 14package android.support.v17.leanback.widget; 15 16import android.content.Context; 17import android.graphics.Canvas; 18import android.graphics.Paint; 19import android.graphics.RectF; 20import android.util.AttributeSet; 21import android.view.View; 22import android.support.v17.leanback.R; 23 24/** 25 * Creates a view for a media item row in a playlist 26 * @hide 27 */ 28class MediaRowFocusView extends View { 29 30 private final Paint mPaint; 31 private final RectF mRoundRectF = new RectF(); 32 private int mRoundRectRadius; 33 34 public MediaRowFocusView(Context context) { 35 super(context); 36 mPaint = createPaint(context); 37 } 38 39 public MediaRowFocusView(Context context, AttributeSet attrs) { 40 super(context, attrs); 41 mPaint = createPaint(context); 42 } 43 44 public MediaRowFocusView(Context context, AttributeSet attrs, int defStyleAttr) { 45 super(context, attrs, defStyleAttr); 46 mPaint = createPaint(context); 47 } 48 49 @Override 50 protected void onDraw(Canvas canvas) { 51 super.onDraw(canvas); 52 mRoundRectRadius = getHeight() / 2; 53 int drawHeight = 2 * mRoundRectRadius; 54 int drawOffset = (drawHeight - getHeight()) / 2; 55 mRoundRectF.set(0, -drawOffset, getWidth(), getHeight() + drawOffset); 56 canvas.drawRoundRect(mRoundRectF, mRoundRectRadius, mRoundRectRadius, mPaint); 57 } 58 59 private Paint createPaint(Context context) { 60 Paint paint = new Paint(); 61 paint.setColor(context.getResources().getColor( 62 R.color.lb_playback_media_row_highlight_color)); 63 return paint; 64 } 65 66 public int getRoundRectRadius() { 67 return mRoundRectRadius; 68 } 69}