165fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko/* 265fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * Copyright (C) 2016 The Android Open Source Project 365fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * 465fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * Licensed under the Apache License, Version 2.0 (the "License"); 565fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * you may not use this file except in compliance with the License. 665fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * You may obtain a copy of the License at 765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * 865fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * http://www.apache.org/licenses/LICENSE-2.0 965fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * 1065fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * Unless required by applicable law or agreed to in writing, software 1165fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * distributed under the License is distributed on an "AS IS" BASIS, 1265fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * See the License for the specific language governing permissions and 1465fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * limitations under the License 1565fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko */ 1665fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 1765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkopackage com.android.tv.dvr.ui.list; 1865fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 1965fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkoimport android.content.Context; 2065fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkoimport android.graphics.Canvas; 2165fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkoimport android.graphics.Paint; 2265fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkoimport android.graphics.RectF; 2365fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkoimport android.text.TextUtils; 2465fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkoimport android.util.AttributeSet; 2565fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkoimport android.view.View; 2665fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 2765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkoimport com.android.tv.R; 2865fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 2965fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko/** 3065fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko * A view used for focus in schedules list. 3165fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko */ 3265fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalkopublic class DvrSchedulesFocusView extends View { 3365fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko private final Paint mPaint; 3465fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko private final RectF mRoundRectF = new RectF(); 3565fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko private final int mRoundRectRadius; 3665fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 3765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko private final String mViewTag; 3865fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko private final String mHeaderFocusViewTag; 3965fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko private final String mItemFocusViewTag; 4065fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 4165fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko public DvrSchedulesFocusView(Context context) { 4265fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko this(context, null, 0); 4365fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } 4465fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 4565fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko public DvrSchedulesFocusView(Context context, AttributeSet attrs) { 4665fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko this(context, attrs, 0); 4765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } 4865fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 4965fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko public DvrSchedulesFocusView(Context context, AttributeSet attrs, int defStyleAttr) { 5065fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko super(context, attrs, defStyleAttr); 5165fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko mHeaderFocusViewTag = getContext().getString(R.string.dvr_schedules_header_focus_view); 5265fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko mItemFocusViewTag = getContext().getString(R.string.dvr_schedules_item_focus_view); 5365fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko mViewTag = (String) getTag(); 5465fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko mPaint = createPaint(context); 5565fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko mRoundRectRadius = getRoundRectRadius(); 5665fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } 5765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 5865fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko @Override 5965fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko protected void onDraw(Canvas canvas) { 6065fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko super.onDraw(canvas); 6165fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko if (TextUtils.equals(mViewTag, mHeaderFocusViewTag)) { 6265fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko mRoundRectF.set(0, 0, getWidth(), getHeight()); 6365fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } else if (TextUtils.equals(mViewTag, mItemFocusViewTag)) { 6465fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko int drawHeight = 2 * mRoundRectRadius; 6565fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko int drawOffset = (drawHeight - getHeight()) / 2; 6665fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko mRoundRectF.set(0, -drawOffset, getWidth(), getHeight() + drawOffset); 6765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } 6865fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko canvas.drawRoundRect(mRoundRectF, mRoundRectRadius, mRoundRectRadius, mPaint); 6965fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } 7065fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 7165fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko private Paint createPaint(Context context) { 7265fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko Paint paint = new Paint(); 7365fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko paint.setColor(context.getColor(R.color.dvr_schedules_list_item_selector)); 7465fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko return paint; 7565fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } 7665fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 7765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko private int getRoundRectRadius() { 7865fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko if (TextUtils.equals(mViewTag, mHeaderFocusViewTag)) { 7965fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko return getResources().getDimensionPixelSize( 8065fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko R.dimen.dvr_schedules_header_selector_radius); 8165fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } else if (TextUtils.equals(mViewTag, mItemFocusViewTag)) { 8265fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko return getResources().getDimensionPixelSize(R.dimen.dvr_schedules_selector_radius); 8365fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } 8465fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko return 0; 8565fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko } 8665fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko} 8765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 8865fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko 89