Home | History | Annotate | Download | only in tiles
      1 /*
      2  * Copyright (C) 2014 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.systemui.qs.tiles;
     18 
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import android.util.AttributeSet;
     22 import android.view.LayoutInflater;
     23 import android.view.View;
     24 import android.view.ViewGroup;
     25 
     26 import com.android.internal.logging.MetricsLogger;
     27 import com.android.internal.logging.MetricsProto.MetricsEvent;
     28 import com.android.settingslib.RestrictedLockUtils;
     29 import com.android.systemui.R;
     30 import com.android.systemui.qs.PseudoGridView;
     31 import com.android.systemui.statusbar.policy.UserSwitcherController;
     32 /**
     33  * Quick settings detail view for user switching.
     34  */
     35 public class UserDetailView extends PseudoGridView {
     36 
     37     private Adapter mAdapter;
     38 
     39     public UserDetailView(Context context, AttributeSet attrs) {
     40         super(context, attrs);
     41     }
     42 
     43     public static UserDetailView inflate(Context context, ViewGroup parent, boolean attach) {
     44         return (UserDetailView) LayoutInflater.from(context).inflate(
     45                 R.layout.qs_user_detail, parent, attach);
     46     }
     47 
     48     public void createAndSetAdapter(UserSwitcherController controller) {
     49         mAdapter = new Adapter(mContext, controller);
     50         ViewGroupAdapterBridge.link(this, mAdapter);
     51     }
     52 
     53     public void refreshAdapter() {
     54         mAdapter.refresh();
     55     }
     56 
     57     public static class Adapter extends UserSwitcherController.BaseUserAdapter
     58             implements OnClickListener {
     59 
     60         private final Context mContext;
     61         private final UserSwitcherController mController;
     62 
     63         public Adapter(Context context, UserSwitcherController controller) {
     64             super(controller);
     65             mContext = context;
     66             mController = controller;
     67         }
     68 
     69         @Override
     70         public View getView(int position, View convertView, ViewGroup parent) {
     71             UserSwitcherController.UserRecord item = getItem(position);
     72             UserDetailItemView v = UserDetailItemView.convertOrInflate(
     73                     mContext, convertView, parent);
     74             if (v != convertView) {
     75                 v.setOnClickListener(this);
     76             }
     77             String name = getName(mContext, item);
     78             if (item.picture == null) {
     79                 v.bind(name, getDrawable(mContext, item), item.resolveId());
     80             } else {
     81                 v.bind(name, item.picture, item.info.id);
     82             }
     83             v.setActivated(item.isCurrent);
     84             v.setDisabledByAdmin(item.isDisabledByAdmin);
     85             if (!item.isSwitchToEnabled) {
     86                 v.setEnabled(false);
     87             }
     88             v.setTag(item);
     89             return v;
     90         }
     91 
     92         @Override
     93         public void onClick(View view) {
     94             UserSwitcherController.UserRecord tag =
     95                     (UserSwitcherController.UserRecord) view.getTag();
     96             if (tag.isDisabledByAdmin) {
     97                 final Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(
     98                         mContext, tag.enforcedAdmin);
     99                 mController.startActivity(intent);
    100             } else if (tag.isSwitchToEnabled) {
    101                 MetricsLogger.action(mContext, MetricsEvent.QS_SWITCH_USER);
    102                 switchTo(tag);
    103             }
    104         }
    105     }
    106 }
    107