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.content.ContentResolver; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.content.res.Resources; 25 import android.net.Uri; 26 import android.os.Bundle; 27 import android.provider.Settings; 28 29 import com.android.tv.settings.dialog.SettingsLayoutFragment; 30 import com.android.tv.settings.dialog.Layout; 31 import com.android.tv.settings.dialog.Layout.Action; 32 import com.android.tv.settings.dialog.Layout.LayoutRow; 33 34 import com.android.tv.settings.R; 35 36 import java.util.ArrayList; 37 38 /** 39 * Activity to present settings menus and options. 40 */ 41 public abstract class SettingsLayoutActivity extends Activity implements 42 SettingsLayoutFragment.Listener, SettingsLayoutAdapter.OnFocusListener { 43 44 private SettingsLayoutFragment mSettingsLayoutFragment; 45 46 @Override 47 protected void onCreate(Bundle savedInstanceState) { 48 super.onCreate(savedInstanceState); 49 final Layout layout = createLayout(); 50 layout.navigateToRoot(); 51 final FragmentManager fm = getFragmentManager(); 52 mSettingsLayoutFragment = (SettingsLayoutFragment) fm.findFragmentByTag( 53 SettingsLayoutFragment.TAG_LEAN_BACK_DIALOG_FRAGMENT); 54 if (mSettingsLayoutFragment == null) { 55 mSettingsLayoutFragment = new SettingsLayoutFragment.Builder() 56 .title(layout.getTitle()) 57 .breadcrumb(layout.getBreadcrumb()) 58 .icon(layout.getIcon()) 59 .iconBackgroundColor(getResources().getColor(R.color.icon_background)) 60 .build(); 61 SettingsLayoutFragment.add(fm, mSettingsLayoutFragment); 62 } 63 mSettingsLayoutFragment.setLayout(layout); 64 } 65 66 @Override 67 public void onBackPressed() { 68 if (! mSettingsLayoutFragment.onBackPressed()) { 69 super.onBackPressed(); 70 } 71 } 72 73 public abstract Layout createLayout(); 74 75 @Override 76 public void onActionFocused(Layout.LayoutRow item) { 77 } 78 79 @Override 80 public void onActionClicked(Action action) { 81 } 82 83 protected void goBackToTitle (String title) { 84 mSettingsLayoutFragment.goBackToTitle (title); 85 } 86 87 /** 88 * Return true if the display view is rendered right to left. 89 */ 90 protected boolean isLayoutRtl() { 91 return mSettingsLayoutFragment.getView().isLayoutRtl(); 92 } 93 94 protected void setIcon(int resId) { 95 mSettingsLayoutFragment.setIcon(resId); 96 } 97 } 98