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.content.ContentResolver; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.res.Resources; 24 import android.net.Uri; 25 import android.os.Bundle; 26 import android.provider.Settings; 27 import android.util.Log; 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 private Layout mLayout; 46 47 @Override 48 protected void onCreate(Bundle savedInstanceState) { 49 super.onCreate(savedInstanceState); 50 51 mLayout = createLayout(); 52 mLayout.navigateToRoot(); 53 mSettingsLayoutFragment = new SettingsLayoutFragment.Builder() 54 .title(mLayout.getTitle()) 55 .breadcrumb(mLayout.getBreadcrumb()) 56 .icon(mLayout.getIcon()) 57 .iconBackgroundColor(getResources().getColor(R.color.icon_background)) 58 .layout(mLayout).build(); 59 SettingsLayoutFragment.add(getFragmentManager(), mSettingsLayoutFragment); 60 } 61 62 @Override 63 public void onBackPressed() { 64 if (! mSettingsLayoutFragment.onBackPressed()) { 65 super.onBackPressed(); 66 } 67 } 68 69 public abstract Layout createLayout(); 70 71 @Override 72 public void onActionFocused(Layout.LayoutRow item) { 73 } 74 75 @Override 76 public void onActionClicked(Action action) { 77 } 78 79 protected void goBackToTitle (String title) { 80 mSettingsLayoutFragment.goBackToTitle (title); 81 } 82 83 /** 84 * Return true if the display view is rendered right to left. 85 */ 86 protected boolean isLayoutRtl() { 87 return mSettingsLayoutFragment.getView().isLayoutRtl(); 88 } 89 90 protected void setIcon(int resId) { 91 mSettingsLayoutFragment.setIcon(resId); 92 } 93 } 94