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 */ 27class MediaRowFocusView extends View { 28 29 private final Paint mPaint; 30 private final RectF mRoundRectF = new RectF(); 31 private int mRoundRectRadius; 32 33 public MediaRowFocusView(Context context) { 34 super(context); 35 mPaint = createPaint(context); 36 } 37 38 public MediaRowFocusView(Context context, AttributeSet attrs) { 39 super(context, attrs); 40 mPaint = createPaint(context); 41 } 42 43 public MediaRowFocusView(Context context, AttributeSet attrs, int defStyleAttr) { 44 super(context, attrs, defStyleAttr); 45 mPaint = createPaint(context); 46 } 47 48 @Override 49 protected void onDraw(Canvas canvas) { 50 super.onDraw(canvas); 51 mRoundRectRadius = getHeight() / 2; 52 int drawHeight = 2 * mRoundRectRadius; 53 int drawOffset = (drawHeight - getHeight()) / 2; 54 mRoundRectF.set(0, -drawOffset, getWidth(), getHeight() + drawOffset); 55 canvas.drawRoundRect(mRoundRectF, mRoundRectRadius, mRoundRectRadius, mPaint); 56 } 57 58 private Paint createPaint(Context context) { 59 Paint paint = new Paint(); 60 paint.setColor(context.getResources().getColor( 61 R.color.lb_playback_media_row_highlight_color)); 62 return paint; 63 } 64 65 public int getRoundRectRadius() { 66 return mRoundRectRadius; 67 } 68}