Home | History | Annotate | Download | only in settings
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy 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,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.packageinstaller.permission.ui.wear.settings;
     18 
     19 import android.content.Context;
     20 import android.content.res.Resources;
     21 import android.support.wearable.view.WearableListView;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 import android.widget.TextView;
     25 
     26 import com.android.packageinstaller.R;
     27 import com.android.packageinstaller.permission.model.AppPermissionGroup;
     28 
     29 public final class PermissionsSettingsAdapter extends SettingsAdapter<AppPermissionGroup> {
     30     private Resources mRes;
     31 
     32     public PermissionsSettingsAdapter(Context context) {
     33         super(context, R.layout.permissions_settings_item);
     34         mRes = context.getResources();
     35     }
     36 
     37     @Override
     38     public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
     39         return new PermissionsViewHolder(new PermissionsSettingsItem(parent.getContext()));
     40     }
     41 
     42     @Override
     43     public void onBindViewHolder(WearableListView.ViewHolder holder, int position) {
     44         super.onBindViewHolder(holder, position);
     45         PermissionsViewHolder viewHolder = (PermissionsViewHolder) holder;
     46         AppPermissionGroup group = get(position).data;
     47 
     48         if (group.isPolicyFixed()) {
     49             viewHolder.imageView.setEnabled(false);
     50             viewHolder.textView.setEnabled(false);
     51             viewHolder.state.setEnabled(false);
     52             viewHolder.state.setText(
     53                     mRes.getString(R.string.permission_summary_enforced_by_policy));
     54         } else {
     55             viewHolder.imageView.setEnabled(true);
     56             viewHolder.textView.setEnabled(true);
     57             viewHolder.state.setEnabled(true);
     58 
     59             if (group.areRuntimePermissionsGranted()) {
     60                 viewHolder.state.setText(R.string.generic_enabled);
     61             } else {
     62                 viewHolder.state.setText(R.string.generic_disabled);
     63             }
     64         }
     65     }
     66 
     67     private static final class PermissionsViewHolder extends SettingsAdapter.SettingsItemHolder {
     68         public final TextView state;
     69 
     70         public PermissionsViewHolder(View view) {
     71             super(view);
     72             state = (TextView) view.findViewById(R.id.state);
     73         }
     74     }
     75 
     76     private class PermissionsSettingsItem extends SettingsItem {
     77         private final TextView mState;
     78         private final float mCenteredAlpha = 1.0f;
     79         private final float mNonCenteredAlpha = 0.5f;
     80 
     81         public PermissionsSettingsItem (Context context) {
     82             super(context);
     83             mState = (TextView) findViewById(R.id.state);
     84         }
     85 
     86         @Override
     87         public void onCenterPosition(boolean animate) {
     88             mImage.setAlpha(mImage.isEnabled() ? mCenteredAlpha : mNonCenteredAlpha);
     89             mText.setAlpha(mText.isEnabled() ? mCenteredAlpha : mNonCenteredAlpha);
     90             mState.setAlpha(mState.isEnabled() ? mCenteredAlpha : mNonCenteredAlpha);
     91         }
     92 
     93         @Override
     94         public void onNonCenterPosition(boolean animate) {
     95             mImage.setAlpha(mNonCenteredAlpha);
     96             mText.setAlpha(mNonCenteredAlpha);
     97             mState.setAlpha(mNonCenteredAlpha);
     98         }
     99     }
    100 }
    101 
    102