• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.tv.settings.dialog;
18 
19 import android.app.Activity;
20 import android.app.FragmentManager;
21 import android.os.Bundle;
22 import android.view.View;
23 
24 import com.android.tv.settings.R;
25 import com.android.tv.settings.dialog.Layout.Action;
26 
27 /**
28  * Activity to present settings menus and options.
29  */
30 public abstract class SettingsLayoutActivity extends Activity implements
31         SettingsLayoutFragment.Listener, SettingsLayoutAdapter.OnFocusListener {
32 
33     private SettingsLayoutFragment mSettingsLayoutFragment;
34 
35     @Override
onCreate(Bundle savedInstanceState)36     protected void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38         final Layout layout = createLayout();
39         layout.navigateToRoot();
40         final FragmentManager fm = getFragmentManager();
41         mSettingsLayoutFragment = (SettingsLayoutFragment) fm.findFragmentByTag(
42                 SettingsLayoutFragment.TAG_LEAN_BACK_DIALOG_FRAGMENT);
43         if (mSettingsLayoutFragment == null) {
44             mSettingsLayoutFragment = new SettingsLayoutFragment.Builder()
45                     .title(layout.getTitle())
46                     .description(layout.getDescription())
47                     .breadcrumb(layout.getBreadcrumb())
48                     .icon(layout.getIcon())
49                     .iconBackgroundColor(getResources().getColor(R.color.icon_background))
50                     .build();
51             SettingsLayoutFragment.add(fm, mSettingsLayoutFragment);
52         }
53         mSettingsLayoutFragment.setLayout(layout);
54     }
55 
56     @Override
onBackPressed()57     public void onBackPressed() {
58         if (!mSettingsLayoutFragment.isVisible() || !mSettingsLayoutFragment.onBackPressed()) {
59             super.onBackPressed();
60         }
61     }
62 
createLayout()63     public abstract Layout createLayout();
64 
65     @Override
onActionFocused(Layout.LayoutRow item)66     public void onActionFocused(Layout.LayoutRow item) {
67     }
68 
69     @Override
onActionClicked(Action action)70     public void onActionClicked(Action action) {
71     }
72 
goBackToTitle(String title)73     protected void goBackToTitle (String title) {
74         mSettingsLayoutFragment.goBackToTitle (title);
75     }
76 
setIcon(int resId)77     protected void setIcon(int resId) {
78         mSettingsLayoutFragment.setIcon(resId);
79     }
80 }
81