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 17 package com.android.settings.applications; 18 19 import android.app.AppOpsManager; 20 import android.app.Fragment; 21 import android.app.FragmentManager; 22 import android.os.Bundle; 23 import android.preference.PreferenceFrameLayout; 24 import android.support.v13.app.FragmentPagerAdapter; 25 import android.support.v4.view.PagerTabStrip; 26 import android.support.v4.view.ViewPager; 27 import android.view.LayoutInflater; 28 import android.view.View; 29 import android.view.ViewGroup; 30 31 import com.android.settings.R; 32 33 public 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.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(android.R.color.holo_blue_light); 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