• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.radio;
18 
19 import android.hardware.radio.RadioManager.ProgramInfo;
20 import android.os.Bundle;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.view.ViewGroup;
24 
25 import androidx.fragment.app.Fragment;
26 
27 import com.android.car.radio.bands.ProgramType;
28 
29 /**
30  * Fragment that allows tuning to a specific frequency using a keypad
31  */
32 public class ManualTunerFragment extends Fragment {
33 
34     private ManualTunerController mController;
35     private RadioController mRadioController;
36 
37     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)38     public View onCreateView(LayoutInflater inflater, ViewGroup container,
39             Bundle savedInstanceState) {
40         View view = inflater.inflate(R.layout.tuner_fragment, container, false);
41         mController = new ManualTunerController(getContext(), view,
42                 mRadioController.getRegionConfig(), mRadioController::tune);
43 
44         return view;
45     }
46 
47     @Override
setUserVisibleHint(boolean isVisibleToUser)48     public void setUserVisibleHint(boolean isVisibleToUser) {
49         super.setUserVisibleHint(isVisibleToUser);
50 
51         if (!isVisibleToUser) return;
52         ProgramInfo current = mRadioController.getCurrentProgram().getValue();
53         if (current == null) return;
54         mController.switchProgramType(ProgramType.fromSelector(current.getSelector()));
55     }
56 
newInstance(RadioController radioController)57     static ManualTunerFragment newInstance(RadioController radioController) {
58         ManualTunerFragment fragment = new ManualTunerFragment();
59         fragment.mRadioController = radioController;
60         return fragment;
61     }
62 }
63