AppOpsSummary.java revision 55eaa96fe44ab473975fd2d9b3d97836935752fe
1/**
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy
6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16
17package com.android.settings.applications;
18
19import android.app.Fragment;
20import android.app.FragmentManager;
21import android.content.res.TypedArray;
22import android.os.Bundle;
23import android.preference.PreferenceFrameLayout;
24import android.support.v13.app.FragmentPagerAdapter;
25import android.support.v4.view.PagerTabStrip;
26import android.support.v4.view.ViewPager;
27import android.view.LayoutInflater;
28import android.view.View;
29import android.view.ViewGroup;
30
31import com.android.settings.R;
32
33public class AppOpsSummary extends Fragment {
34    // layout inflater object used to inflate views
35    private LayoutInflater mInflater;
36
37    private ViewGroup mContentContainer;
38    private View mRootView;
39    private ViewPager mViewPager;
40
41    CharSequence[] mPageNames;
42    static AppOpsState.OpsTemplate[] sPageTemplates = new AppOpsState.OpsTemplate[] {
43        AppOpsState.LOCATION_TEMPLATE,
44        AppOpsState.PERSONAL_TEMPLATE,
45        AppOpsState.MESSAGING_TEMPLATE,
46        AppOpsState.MEDIA_TEMPLATE,
47        AppOpsState.DEVICE_TEMPLATE
48    };
49
50    int mCurPos;
51
52    class MyPagerAdapter extends FragmentPagerAdapter implements ViewPager.OnPageChangeListener {
53
54        public MyPagerAdapter(FragmentManager fm) {
55            super(fm);
56        }
57
58        @Override
59        public Fragment getItem(int position) {
60            return new AppOpsCategory(sPageTemplates[position]);
61        }
62
63        @Override
64        public int getCount() {
65            return sPageTemplates.length;
66        }
67
68        @Override
69        public CharSequence getPageTitle(int position) {
70            return mPageNames[position];
71        }
72
73        @Override
74        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
75        }
76
77        @Override
78        public void onPageSelected(int position) {
79            mCurPos = position;
80        }
81
82        @Override
83        public void onPageScrollStateChanged(int state) {
84            if (state == ViewPager.SCROLL_STATE_IDLE) {
85                //updateCurrentTab(mCurPos);
86            }
87        }
88    }
89
90    @Override
91    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
92        // initialize the inflater
93        mInflater = inflater;
94
95        View rootView = mInflater.inflate(R.layout.app_ops_summary,
96                container, false);
97        mContentContainer = container;
98        mRootView = rootView;
99
100        mPageNames = getResources().getTextArray(R.array.app_ops_categories);
101
102        mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
103        MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
104        mViewPager.setAdapter(adapter);
105        mViewPager.setOnPageChangeListener(adapter);
106        PagerTabStrip tabs = (PagerTabStrip) rootView.findViewById(R.id.tabs);
107
108        // This should be set in the XML layout, but PagerTabStrip lives in
109        // support-v4 and doesn't have styleable attributes.
110        final TypedArray ta = tabs.getContext().obtainStyledAttributes(
111                new int[] { android.R.attr.colorAccent });
112        final int colorAccent = ta.getColor(0, 0);
113        ta.recycle();
114
115        tabs.setTabIndicatorColorResource(colorAccent);
116
117        // We have to do this now because PreferenceFrameLayout looks at it
118        // only when the view is added.
119        if (container instanceof PreferenceFrameLayout) {
120            ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true;
121        }
122
123        return rootView;
124    }
125}
126