| /* |
| * Copyright (C) 2014 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License |
| */ |
| |
| package com.android.systemui.statusbar.phone; |
| |
| import android.content.Context; |
| import android.graphics.drawable.Drawable; |
| import android.util.AttributeSet; |
| import android.view.View; |
| import android.widget.ImageView; |
| import android.widget.RelativeLayout; |
| import android.widget.TextView; |
| |
| import com.android.systemui.R; |
| import com.android.systemui.statusbar.policy.BatteryController; |
| import com.android.systemui.statusbar.policy.KeyguardUserSwitcher; |
| import com.android.systemui.statusbar.policy.UserInfoController; |
| |
| /** |
| * The header group on Keyguard. |
| */ |
| public class KeyguardStatusBarView extends RelativeLayout |
| implements BatteryController.BatteryStateChangeCallback { |
| |
| private boolean mBatteryCharging; |
| private boolean mKeyguardUserSwitcherShowing; |
| private boolean mBatteryListening; |
| |
| private View mSystemIconsSuperContainer; |
| private MultiUserSwitch mMultiUserSwitch; |
| private ImageView mMultiUserAvatar; |
| private TextView mBatteryLevel; |
| |
| private BatteryController mBatteryController; |
| private KeyguardUserSwitcher mKeyguardUserSwitcher; |
| |
| private int mSystemIconsSwitcherHiddenExpandedMargin; |
| |
| public KeyguardStatusBarView(Context context, AttributeSet attrs) { |
| super(context, attrs); |
| } |
| |
| @Override |
| protected void onFinishInflate() { |
| super.onFinishInflate(); |
| mSystemIconsSuperContainer = findViewById(R.id.system_icons_super_container); |
| mMultiUserSwitch = (MultiUserSwitch) findViewById(R.id.multi_user_switch); |
| mMultiUserAvatar = (ImageView) findViewById(R.id.multi_user_avatar); |
| mBatteryLevel = (TextView) findViewById(R.id.battery_level); |
| loadDimens(); |
| updateUserSwitcher(); |
| } |
| |
| private void loadDimens() { |
| mSystemIconsSwitcherHiddenExpandedMargin = getResources().getDimensionPixelSize( |
| R.dimen.system_icons_switcher_hidden_expanded_margin); |
| } |
| |
| private void updateVisibilities() { |
| mMultiUserSwitch.setVisibility(!mKeyguardUserSwitcherShowing ? VISIBLE : GONE); |
| mBatteryLevel.setVisibility(mBatteryCharging ? View.VISIBLE : View.GONE); |
| } |
| |
| private void updateSystemIconsLayoutParams() { |
| RelativeLayout.LayoutParams lp = |
| (LayoutParams) mSystemIconsSuperContainer.getLayoutParams(); |
| int marginEnd = mKeyguardUserSwitcherShowing ? mSystemIconsSwitcherHiddenExpandedMargin : 0; |
| if (marginEnd != lp.getMarginEnd()) { |
| lp.setMarginEnd(marginEnd); |
| mSystemIconsSuperContainer.setLayoutParams(lp); |
| } |
| } |
| |
| public void setListening(boolean listening) { |
| if (listening == mBatteryListening) { |
| return; |
| } |
| mBatteryListening = listening; |
| if (mBatteryListening) { |
| mBatteryController.addStateChangedCallback(this); |
| } else { |
| mBatteryController.removeStateChangedCallback(this); |
| } |
| } |
| |
| private void updateUserSwitcher() { |
| boolean keyguardSwitcherAvailable = mKeyguardUserSwitcher != null; |
| mMultiUserSwitch.setClickable(keyguardSwitcherAvailable); |
| mMultiUserSwitch.setFocusable(keyguardSwitcherAvailable); |
| mMultiUserSwitch.setKeyguardMode(keyguardSwitcherAvailable); |
| } |
| |
| public void setBatteryController(BatteryController batteryController) { |
| mBatteryController = batteryController; |
| } |
| |
| public void setUserInfoController(UserInfoController userInfoController) { |
| userInfoController.addListener(new UserInfoController.OnUserInfoChangedListener() { |
| @Override |
| public void onUserInfoChanged(String name, Drawable picture) { |
| mMultiUserAvatar.setImageDrawable(picture); |
| } |
| }); |
| } |
| |
| @Override |
| public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { |
| mBatteryLevel.setText(getResources().getString(R.string.battery_level_template, level)); |
| boolean changed = mBatteryCharging != charging; |
| mBatteryCharging = charging; |
| if (changed) { |
| updateVisibilities(); |
| } |
| } |
| |
| @Override |
| public void onPowerSaveChanged() { |
| // could not care less |
| } |
| |
| public void setKeyguardUserSwitcher(KeyguardUserSwitcher keyguardUserSwitcher) { |
| mKeyguardUserSwitcher = keyguardUserSwitcher; |
| mMultiUserSwitch.setKeyguardUserSwitcher(keyguardUserSwitcher); |
| updateUserSwitcher(); |
| } |
| |
| public void setKeyguardUserSwitcherShowing(boolean showing) { |
| mKeyguardUserSwitcherShowing = showing; |
| updateVisibilities(); |
| updateSystemIconsLayoutParams(); |
| } |
| |
| @Override |
| public boolean hasOverlappingRendering() { |
| return false; |
| } |
| } |