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
17package com.android.tv.settings.dialog;
18
19import android.app.Activity;
20import android.content.ContentResolver;
21import android.content.Context;
22import android.content.Intent;
23import android.content.res.Resources;
24import android.net.Uri;
25import android.os.Bundle;
26import android.provider.Settings;
27import android.util.Log;
28
29import com.android.tv.settings.dialog.SettingsLayoutFragment;
30import com.android.tv.settings.dialog.Layout;
31import com.android.tv.settings.dialog.Layout.Action;
32import com.android.tv.settings.dialog.Layout.LayoutRow;
33
34import com.android.tv.settings.R;
35
36import java.util.ArrayList;
37
38/**
39 * Activity to present settings menus and options.
40 */
41public 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