• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.car.settings.common.rotary;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.View;
22 
23 /**
24  * A transparent {@link View} that can take focus. It is used as a view that can invisibly
25  * take rotary focus when another view is unable to take this focus.
26  *
27  * Adapted from {@link com.android.car.ui.FocusParkingView} for finer control over focus in
28  * dual-pane layouts. This separate class is also needed to allow a second "FocusParkingView"
29  * element within an activity, since only one {@link com.android.car.ui.FocusParkingView} is
30  * allowed per activity.
31  */
32 public class SettingsFocusParkingView extends View {
SettingsFocusParkingView(Context context)33     public SettingsFocusParkingView(Context context) {
34         super(context);
35         init();
36     }
37 
SettingsFocusParkingView(Context context, AttributeSet attrs)38     public SettingsFocusParkingView(Context context, AttributeSet attrs) {
39         super(context, attrs);
40         init();
41     }
42 
SettingsFocusParkingView(Context context, AttributeSet attrs, int defStyleAttr)43     public SettingsFocusParkingView(Context context, AttributeSet attrs, int defStyleAttr) {
44         super(context, attrs, defStyleAttr);
45         init();
46     }
47 
SettingsFocusParkingView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)48     public SettingsFocusParkingView(Context context, AttributeSet attrs, int defStyleAttr,
49             int defStyleRes) {
50         super(context, attrs, defStyleAttr, defStyleRes);
51         init();
52     }
53 
init()54     private void init() {
55         // This view is focusable, visible and enabled so it can take focus.
56         setFocusable(View.FOCUSABLE);
57         setVisibility(VISIBLE);
58         setEnabled(true);
59 
60         // This view is not clickable so it won't affect the app's behavior when the user clicks on
61         // it by accident.
62         setClickable(false);
63 
64         // This view is always transparent.
65         setAlpha(0f);
66 
67         // Prevent Android from drawing the default focus highlight for this view when it's focused.
68         setDefaultFocusHighlightEnabled(false);
69     }
70 }
71