AppOpsSummary.java revision cc22af08117a2f90d879cc360f76de48fd234e0d
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.os.Bundle;
22import android.preference.PreferenceFrameLayout;
23import android.support.v13.app.FragmentPagerAdapter;
24import android.support.v4.view.PagerTabStrip;
25import android.support.v4.view.ViewPager;
26import android.view.LayoutInflater;
27import android.view.View;
28import android.view.ViewGroup;
29
30import com.android.settings.R;
31
32public class AppOpsSummary extends Fragment {
33    // layout inflater object used to inflate views
34    private LayoutInflater mInflater;
35
36    private ViewGroup mContentContainer;
37    private View mRootView;
38    private ViewPager mViewPager;
39
40    CharSequence[] mPageNames;
41    static AppOpsState.OpsTemplate[] sPageTemplates = new AppOpsState.OpsTemplate[] {
42        AppOpsState.LOCATION_TEMPLATE,
43        AppOpsState.PERSONAL_TEMPLATE,
44        AppOpsState.MESSAGING_TEMPLATE,
45        AppOpsState.MEDIA_TEMPLATE,
46        AppOpsState.DEVICE_TEMPLATE
47    };
48
49    int mCurPos;
50
51    class MyPagerAdapter extends FragmentPagerAdapter implements ViewPager.OnPageChangeListener {
52
53        public MyPagerAdapter(FragmentManager fm) {
54            super(fm);
55        }
56
57        @Override
58        public Fragment getItem(int position) {
59            return new AppOpsCategory(sPageTemplates[position]);
60        }
61
62        @Override
63        public int getCount() {
64            return sPageTemplates.length;
65        }
66
67        @Override
68        public CharSequence getPageTitle(int position) {
69            return mPageNames[position];
70        }
71
72        @Override
73        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
74        }
75
76        @Override
77        public void onPageSelected(int position) {
78            mCurPos = position;
79        }
80
81        @Override
82        public void onPageScrollStateChanged(int state) {
83            if (state == ViewPager.SCROLL_STATE_IDLE) {
84                //updateCurrentTab(mCurPos);
85            }
86        }
87    }
88
89    @Override
90    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
91        // initialize the inflater
92        mInflater = inflater;
93
94        View rootView = mInflater.inflate(R.layout.app_ops_summary,
95                container, false);
96        mContentContainer = container;
97        mRootView = rootView;
98
99        mPageNames = getResources().getTextArray(R.array.app_ops_categories);
100
101        mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
102        MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
103        mViewPager.setAdapter(adapter);
104        mViewPager.setOnPageChangeListener(adapter);
105        PagerTabStrip tabs = (PagerTabStrip) rootView.findViewById(R.id.tabs);
106        tabs.setTabIndicatorColorResource(R.color.theme_accent);
107
108        // We have to do this now because PreferenceFrameLayout looks at it
109        // only when the view is added.
110        if (container instanceof PreferenceFrameLayout) {
111            ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true;
112        }
113
114        return rootView;
115    }
116}
117