165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/*
265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project
365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License");
565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License.
665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at
765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *      http://www.apache.org/licenses/LICENSE-2.0
965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software
1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS,
1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and
1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License.
1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */
1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.dialog;
1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.app.Activity;
2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.ContentResolver;
2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Context;
2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Intent;
2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.res.Resources;
2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.net.Uri;
2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Bundle;
2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.provider.Settings;
2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.util.Log;
2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.dialog.SettingsLayoutFragment;
3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.dialog.Layout;
3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.dialog.Layout.Action;
3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.dialog.Layout.LayoutRow;
3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.R;
3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport java.util.ArrayList;
3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/**
3965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Activity to present settings menus and options.
4065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */
4165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepublic abstract class SettingsLayoutActivity extends Activity implements
4201a5b81394670c6c5c2011673ed48c4fee1cf77bbulic        SettingsLayoutFragment.Listener, SettingsLayoutAdapter.OnFocusListener {
4365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    private SettingsLayoutFragment mSettingsLayoutFragment;
4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    private Layout mLayout;
4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    protected void onCreate(Bundle savedInstanceState) {
4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        super.onCreate(savedInstanceState);
5065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        mLayout = createLayout();
5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        mLayout.navigateToRoot();
5365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        mSettingsLayoutFragment = new SettingsLayoutFragment.Builder()
5465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                .title(mLayout.getTitle())
5565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                .breadcrumb(mLayout.getBreadcrumb())
5665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                .icon(mLayout.getIcon())
5765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                .iconBackgroundColor(getResources().getColor(R.color.icon_background))
5865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane                .layout(mLayout).build();
5965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        SettingsLayoutFragment.add(getFragmentManager(), mSettingsLayoutFragment);
6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public void onBackPressed() {
6465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        if (! mSettingsLayoutFragment.onBackPressed()) {
6565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            super.onBackPressed();
6665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        }
6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
6865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public abstract Layout createLayout();
7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
7201a5b81394670c6c5c2011673ed48c4fee1cf77bbulic    public void onActionFocused(Layout.LayoutRow item) {
7301a5b81394670c6c5c2011673ed48c4fee1cf77bbulic    }
7401a5b81394670c6c5c2011673ed48c4fee1cf77bbulic
7501a5b81394670c6c5c2011673ed48c4fee1cf77bbulic    @Override
7665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public void onActionClicked(Action action) {
7765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
7865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
7965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    protected void goBackToTitle (String title) {
8065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        mSettingsLayoutFragment.goBackToTitle (title);
8165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
8265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
8365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    /**
8465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane     * Return true if the display view is rendered right to left.
8565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane     */
8665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    protected boolean isLayoutRtl() {
8765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        return mSettingsLayoutFragment.getView().isLayoutRtl();
8865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
8901a5b81394670c6c5c2011673ed48c4fee1cf77bbulic
9001a5b81394670c6c5c2011673ed48c4fee1cf77bbulic    protected void setIcon(int resId) {
9101a5b81394670c6c5c2011673ed48c4fee1cf77bbulic        mSettingsLayoutFragment.setIcon(resId);
9201a5b81394670c6c5c2011673ed48c4fee1cf77bbulic    }
9365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane}
94