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.Fragment;
     20 import android.app.FragmentManager;
     21 import android.content.res.TypedArray;
     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.internal.logging.MetricsProto.MetricsEvent;
     32 import com.android.settings.InstrumentedFragment;
     33 import com.android.settings.R;
     34 
     35 public class AppOpsSummary extends InstrumentedFragment {
     36     // layout inflater object used to inflate views
     37     private LayoutInflater mInflater;
     38 
     39     private ViewGroup mContentContainer;
     40     private View mRootView;
     41     private ViewPager mViewPager;
     42 
     43     CharSequence[] mPageNames;
     44     static AppOpsState.OpsTemplate[] sPageTemplates = new AppOpsState.OpsTemplate[] {
     45         AppOpsState.LOCATION_TEMPLATE,
     46         AppOpsState.PERSONAL_TEMPLATE,
     47         AppOpsState.MESSAGING_TEMPLATE,
     48         AppOpsState.MEDIA_TEMPLATE,
     49         AppOpsState.DEVICE_TEMPLATE
     50     };
     51 
     52     int mCurPos;
     53 
     54     @Override
     55     protected int getMetricsCategory() {
     56         return MetricsEvent.APP_OPS_SUMMARY;
     57     }
     58 
     59     class MyPagerAdapter extends FragmentPagerAdapter implements ViewPager.OnPageChangeListener {
     60 
     61         public MyPagerAdapter(FragmentManager fm) {
     62             super(fm);
     63         }
     64 
     65         @Override
     66         public Fragment getItem(int position) {
     67             return new AppOpsCategory(sPageTemplates[position]);
     68         }
     69 
     70         @Override
     71         public int getCount() {
     72             return sPageTemplates.length;
     73         }
     74 
     75         @Override
     76         public CharSequence getPageTitle(int position) {
     77             return mPageNames[position];
     78         }
     79 
     80         @Override
     81         public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
     82         }
     83 
     84         @Override
     85         public void onPageSelected(int position) {
     86             mCurPos = position;
     87         }
     88 
     89         @Override
     90         public void onPageScrollStateChanged(int state) {
     91             if (state == ViewPager.SCROLL_STATE_IDLE) {
     92                 //updateCurrentTab(mCurPos);
     93             }
     94         }
     95     }
     96 
     97     @Override
     98     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     99         // initialize the inflater
    100         mInflater = inflater;
    101 
    102         View rootView = mInflater.inflate(R.layout.app_ops_summary,
    103                 container, false);
    104         mContentContainer = container;
    105         mRootView = rootView;
    106 
    107         mPageNames = getResources().getTextArray(R.array.app_ops_categories);
    108 
    109         mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
    110         MyPagerAdapter adapter = new MyPagerAdapter(getChildFragmentManager());
    111         mViewPager.setAdapter(adapter);
    112         mViewPager.setOnPageChangeListener(adapter);
    113         PagerTabStrip tabs = (PagerTabStrip) rootView.findViewById(R.id.tabs);
    114 
    115         // This should be set in the XML layout, but PagerTabStrip lives in
    116         // support-v4 and doesn't have styleable attributes.
    117         final TypedArray ta = tabs.getContext().obtainStyledAttributes(
    118                 new int[] { android.R.attr.colorAccent });
    119         final int colorAccent = ta.getColor(0, 0);
    120         ta.recycle();
    121 
    122         tabs.setTabIndicatorColorResource(colorAccent);
    123 
    124         // We have to do this now because PreferenceFrameLayout looks at it
    125         // only when the view is added.
    126         if (container instanceof PreferenceFrameLayout) {
    127             ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true;
    128         }
    129 
    130         return rootView;
    131     }
    132 }
    133