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