Home | History | Annotate | Download | only in applications
      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.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         tabs.setTabIndicatorColorResource(android.R.color.holo_blue_light);
    108 
    109         // We have to do this now because PreferenceFrameLayout looks at it
    110         // only when the view is added.
    111         if (container instanceof PreferenceFrameLayout) {
    112             ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true;
    113         }
    114 
    115         return rootView;
    116     }
    117 }
    118