-
Notifications
You must be signed in to change notification settings - Fork 2
/
.merge_file_a05456
966 lines (825 loc) · 36.8 KB
/
.merge_file_a05456
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
/*
* Copyright (C) 2008 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.animation.LayoutTransition;
import android.animation.LayoutTransition.TransitionListener;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.app.ActivityManagerNative;
import android.app.StatusBarManager;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.android.internal.widget.LockPatternUtils;
import com.android.systemui.R;
import com.android.systemui.statusbar.BaseStatusBar;
import com.android.systemui.statusbar.DelegateViewHelper;
import com.android.systemui.statusbar.policy.DeadZone;
import com.android.systemui.statusbar.policy.KeyButtonView;
import java.io.FileDescriptor;
import java.io.PrintWriter;
public class NavigationBarView extends LinearLayout {
final static boolean DEBUG = false;
final static String TAG = "PhoneStatusBar/NavigationBarView";
final static boolean NAVBAR_ALWAYS_AT_RIGHT = true;
// slippery nav bar when everything is disabled, e.g. during setup
final static boolean SLIPPERY_WHEN_DISABLED = true;
final static String NAVBAR_EDIT_ACTION = "android.intent.action.NAVBAR_EDIT";
private boolean mInEditMode;
private NavbarEditor mEditBar;
private NavBarReceiver mNavBarReceiver;
private LockPatternUtils mLockUtils;
private OnClickListener mRecentsClickListener;
private OnTouchListener mRecentsPreloadListener;
private OnTouchListener mHomeSearchActionListener;
final Display mDisplay;
View mCurrentView = null;
View[] mRotatedViews = new View[4];
int mBarSize;
boolean mVertical;
boolean mScreenOn;
boolean mLeftInLandscape;
boolean mShowMenu;
int mDisabledFlags = 0;
int mNavigationIconHints = 0;
private Drawable mBackIcon, mBackLandIcon, mBackAltIcon, mBackAltLandIcon;
private Drawable mRecentIcon;
private Drawable mRecentLandIcon;
private Drawable mHomeIcon, mHomeLandIcon;
private DelegateViewHelper mDelegateHelper;
private DeadZone mDeadZone;
private final NavigationBarTransitions mBarTransitions;
private boolean mModLockDisabled = true;
private boolean mShowDpadArrowKeys = true;
private SettingsObserver mObserver;
// Visibility of R.id.one view prior to swapping it for a left arrow key
public int mSlotOneVisibility = -1;
// Visibility of R.id.six view prior to swapping it for a right arrow key
public int mSlotSixVisibility = -1;
// workaround for LayoutTransitions leaving the nav buttons in a weird state (bug 5549288)
final static boolean WORKAROUND_INVALID_LAYOUT = true;
final static int MSG_CHECK_INVALID_LAYOUT = 8686;
// used to disable the camera icon in navbar when disabled by DPM
private boolean mCameraDisabledByDpm;
// performs manual animation in sync with layout transitions
private final NavTransitionListener mTransitionListener = new NavTransitionListener();
private Resources mThemedResources;
private class NavTransitionListener implements TransitionListener {
private boolean mBackTransitioning;
private boolean mHomeAppearing;
private long mStartDelay;
private long mDuration;
private TimeInterpolator mInterpolator;
@Override
public void startTransition(LayoutTransition transition, ViewGroup container,
View view, int transitionType) {
if (view == findButton(NavbarEditor.NAVBAR_BACK)) {
mBackTransitioning = true;
} else if (view == findButton(NavbarEditor.NAVBAR_HOME)
&& transitionType == LayoutTransition.APPEARING) {
mHomeAppearing = true;
mStartDelay = transition.getStartDelay(transitionType);
mDuration = transition.getDuration(transitionType);
mInterpolator = transition.getInterpolator(transitionType);
}
}
@Override
public void endTransition(LayoutTransition transition, ViewGroup container,
View view, int transitionType) {
if (view == findButton(NavbarEditor.NAVBAR_BACK)) {
mBackTransitioning = false;
} else if (view == findButton(NavbarEditor.NAVBAR_HOME)
&& transitionType == LayoutTransition.APPEARING) {
mHomeAppearing = false;
}
}
public void onBackAltCleared() {
// When dismissing ime during unlock, force the back button to run the same appearance
// animation as home (if we catch this condition early enough).
View backView = findButton(NavbarEditor.NAVBAR_BACK);
View homeView = findButton(NavbarEditor.NAVBAR_HOME);
if (!mBackTransitioning && backView != null && backView.getVisibility() == VISIBLE
&& mHomeAppearing && homeView != null && homeView.getAlpha() == 0) {
backView.setAlpha(0);
ValueAnimator a = ObjectAnimator.ofFloat(backView, "alpha", 0, 1);
a.setStartDelay(mStartDelay);
a.setDuration(mDuration);
a.setInterpolator(mInterpolator);
a.start();
}
}
}
// simplified click handler to be used when device is in accessibility mode
private final OnClickListener mAccessibilityClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (v.getId() == R.id.camera_button) {
KeyguardTouchDelegate.getInstance(getContext()).launchCamera();
} else if (v.getId() == R.id.search_light) {
KeyguardTouchDelegate.getInstance(getContext()).showAssistant();
}
}
};
private final OnTouchListener mCameraTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View cameraButtonView, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// disable search gesture while interacting with camera
mDelegateHelper.setDisabled(true);
mBarTransitions.setContentVisible(false);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mDelegateHelper.setDisabled(false);
mBarTransitions.setContentVisible(true);
break;
}
return KeyguardTouchDelegate.getInstance(getContext()).dispatch(event);
}
};
private class H extends Handler {
public void handleMessage(Message m) {
switch (m.what) {
case MSG_CHECK_INVALID_LAYOUT:
final String how = "" + m.obj;
final int w = getWidth();
final int h = getHeight();
final int vw = mCurrentView.getWidth();
final int vh = mCurrentView.getHeight();
if (h != vh || w != vw) {
Log.w(TAG, String.format(
"*** Invalid layout in navigation bar (%s this=%dx%d cur=%dx%d)",
how, w, h, vw, vh));
if (WORKAROUND_INVALID_LAYOUT) {
requestLayout();
}
}
break;
}
}
}
public NavigationBarView(Context context, AttributeSet attrs) {
super(context, attrs);
mDisplay = ((WindowManager)context.getSystemService(
Context.WINDOW_SERVICE)).getDefaultDisplay();
final Resources res = mContext.getResources();
mBarSize = res.getDimensionPixelSize(R.dimen.navigation_bar_size);
mVertical = false;
mShowMenu = false;
mLeftInLandscape = false;
mDelegateHelper = new DelegateViewHelper(this);
getIcons(res);
mBarTransitions = new NavigationBarTransitions(this);
mCameraDisabledByDpm = isCameraDisabledByDpm();
watchForDevicePolicyChanges();
mNavBarReceiver = new NavBarReceiver();
mContext.registerReceiverAsUser(mNavBarReceiver, UserHandle.ALL,
new IntentFilter(NAVBAR_EDIT_ACTION), null, null);
mLockUtils = new LockPatternUtils(context);
mObserver = new SettingsObserver(new Handler());
}
private void watchForDevicePolicyChanges() {
final IntentFilter filter = new IntentFilter();
filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
mContext.registerReceiver(new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
post(new Runnable() {
@Override
public void run() {
mCameraDisabledByDpm = isCameraDisabledByDpm();
}
});
}
}, filter);
}
public BarTransitions getBarTransitions() {
return mBarTransitions;
}
public void setDelegateView(View view) {
mDelegateHelper.setDelegateView(view);
}
public void setBar(BaseStatusBar phoneStatusBar) {
mDelegateHelper.setBar(phoneStatusBar);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mDeadZone != null && event.getAction() == MotionEvent.ACTION_OUTSIDE) {
mDeadZone.poke(event);
}
if (mDelegateHelper != null) {
boolean ret = mDelegateHelper.onInterceptTouchEvent(event);
if (ret) return true;
}
return super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return mDelegateHelper.onInterceptTouchEvent(event);
}
private H mHandler = new H();
public View getCurrentView() {
return mCurrentView;
}
public boolean isInEditMode() {
return mInEditMode;
}
/* package */ void setListeners(OnClickListener recentsClickListener,
OnTouchListener recentsPreloadListener, OnTouchListener homeSearchActionListener) {
mRecentsClickListener = recentsClickListener;
mRecentsPreloadListener = recentsPreloadListener;
mHomeSearchActionListener = homeSearchActionListener;
updateButtonListeners();
}
private void removeButtonListeners() {
ViewGroup container = (ViewGroup) mCurrentView.findViewById(R.id.container);
int viewCount = container.getChildCount();
for (int i = 0; i < viewCount; i++) {
View button = container.getChildAt(i);
if (button instanceof KeyButtonView) {
button.setOnClickListener(null);
button.setOnTouchListener(null);
}
}
}
protected void updateButtonListeners() {
View recentView = findButton(NavbarEditor.NAVBAR_RECENT);
if (recentView != null) {
recentView.setOnClickListener(mRecentsClickListener);
recentView.setOnTouchListener(mRecentsPreloadListener);
}
View homeView = findButton(NavbarEditor.NAVBAR_HOME);
if (homeView != null) {
homeView.setOnTouchListener(mHomeSearchActionListener);
}
}
private void setButtonVisibility(NavbarEditor.ButtonInfo info, boolean visible) {
View findView = findButton(info);
if (findView != null) {
findView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
}
}
// for when home is disabled, but search isn't
public View getSearchLight() {
return mCurrentView.findViewById(R.id.search_light);
}
// shown when keyguard is visible and camera is available
public View getCameraButton() {
return mCurrentView.findViewById(R.id.camera_button);
}
private void getIcons(Resources res) {
mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back);
mBackLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_land);
mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
mBackAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime_land);
mRecentIcon = res.getDrawable(R.drawable.ic_sysbar_recent);
mRecentLandIcon = res.getDrawable(R.drawable.ic_sysbar_recent_land);
mHomeIcon = res.getDrawable(R.drawable.ic_sysbar_home);
mHomeLandIcon = res.getDrawable(R.drawable.ic_sysbar_home_land);
}
public void updateResources(Resources res) {
mThemedResources = res;
getIcons(mThemedResources);
for (int i = 0; i < mRotatedViews.length; i++) {
ViewGroup container = (ViewGroup) mRotatedViews[i];
if (container != null) {
updateKeyButtonViewResources(container);
updateLightsOutResources(container);
}
}
}
private void updateKeyButtonViewResources(ViewGroup container) {
ViewGroup midNavButtons = (ViewGroup) container.findViewById(R.id.mid_nav_buttons);
if (midNavButtons != null) {
final int nChildren = midNavButtons.getChildCount();
for (int i = 0; i < nChildren; i++) {
final View child = midNavButtons.getChildAt(i);
if (child instanceof KeyButtonView) {
((KeyButtonView) child).updateResources(mThemedResources);
}
}
}
KeyButtonView kbv = (KeyButtonView) findViewById(R.id.one);
if (kbv != null) {
kbv.updateResources(mThemedResources);
}
kbv = (KeyButtonView) findViewById(R.id.six);
if (kbv != null) {
kbv.updateResources(mThemedResources);
}
}
private void updateLightsOutResources(ViewGroup container) {
ViewGroup lightsOut = (ViewGroup) container.findViewById(R.id.lights_out);
if (lightsOut != null) {
final int nChildren = lightsOut.getChildCount();
for (int i = 0; i < nChildren; i++) {
final View child = lightsOut.getChildAt(i);
if (child instanceof ImageView) {
final ImageView iv = (ImageView) child;
// clear out the existing drawable, this is required since the
// ImageView keeps track of the resource ID and if it is the same
// it will not update the drawable.
iv.setImageDrawable(null);
iv.setImageDrawable(mThemedResources.getDrawable(
R.drawable.ic_sysbar_lights_out_dot_large));
}
}
}
}
@Override
public void setLayoutDirection(int layoutDirection) {
if (mThemedResources != null) getIcons(mThemedResources);
super.setLayoutDirection(layoutDirection);
}
public class NavBarReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
boolean edit = intent.getBooleanExtra("edit", false);
boolean save = intent.getBooleanExtra("save", false);
if (edit != mInEditMode) {
mInEditMode = edit;
if (edit) {
removeButtonListeners();
mEditBar.setEditMode(true);
} else {
if (save) {
mEditBar.saveKeys();
}
mEditBar.setEditMode(false);
updateSettings();
}
}
}
}
public void updateSettings() {
mEditBar.updateKeys();
removeButtonListeners();
updateButtonListeners();
setDisabledFlags(mDisabledFlags, true /* force */);
}
public void notifyScreenOn(boolean screenOn) {
mScreenOn = screenOn;
setDisabledFlags(mDisabledFlags, true);
}
public void setNavigationIconHints(int hints) {
setNavigationIconHints(hints, false);
}
public void setNavigationIconHints(int hints, boolean force) {
if (!force && hints == mNavigationIconHints) return;
final boolean backAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0;
if ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0 && !backAlt) {
mTransitionListener.onBackAltCleared();
}
if (DEBUG) {
android.widget.Toast.makeText(mContext,
"Navigation icon hints = " + hints,
500).show();
}
mNavigationIconHints = hints;
ImageView backView = (ImageView) findButton(NavbarEditor.NAVBAR_BACK);
ImageView recentView = (ImageView) findButton(NavbarEditor.NAVBAR_RECENT);
ImageView homeView = (ImageView) findButton(NavbarEditor.NAVBAR_HOME);
if (backView != null) {
backView.setImageDrawable(backAlt
? (mVertical ? mBackAltLandIcon : mBackAltIcon)
: (mVertical ? mBackLandIcon : mBackIcon));
}
if (recentView != null) {
recentView.setImageDrawable(mVertical ? mRecentLandIcon : mRecentIcon);
}
if (homeView != null) {
homeView.setImageDrawable(mVertical ? mHomeLandIcon : mHomeIcon);
}
setDisabledFlags(mDisabledFlags, true);
if (mShowDpadArrowKeys) {
final boolean showingIme = ((mNavigationIconHints
& StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0);
setVisibleOrGone(getCurrentView().findViewById(R.id.dpad_left), showingIme);
setVisibleOrGone(getCurrentView().findViewById(R.id.dpad_right), showingIme);
View one = getCurrentView().findViewById(mVertical ? R.id.six : R.id.one);
View six = getCurrentView().findViewById(mVertical ? R.id.one : R.id.six);
if (showingIme) {
mSlotOneVisibility = one.getVisibility();
mSlotSixVisibility = six.getVisibility();
setVisibleOrGone(one, false);
setVisibleOrGone(six, false);
} else {
if (mSlotOneVisibility != -1) {
one.setVisibility(mSlotOneVisibility);
}
if (mSlotSixVisibility != -1) {
six.setVisibility(mSlotSixVisibility);
}
}
}
}
public void setDisabledFlags(int disabledFlags) {
setDisabledFlags(disabledFlags, false);
}
public void setDisabledFlags(int disabledFlags, boolean force) {
if (!force && mDisabledFlags == disabledFlags) return;
mDisabledFlags = disabledFlags;
final boolean disableHome = ((disabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0);
final boolean disableRecent = ((disabledFlags & View.STATUS_BAR_DISABLE_RECENT) != 0);
final boolean disableBack = ((disabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0)
&& ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) == 0);
final boolean disableSearch = ((disabledFlags & View.STATUS_BAR_DISABLE_SEARCH) != 0);
if (SLIPPERY_WHEN_DISABLED) {
setSlippery(disableHome && disableRecent && disableBack && disableSearch);
}
ViewGroup navButtons = (ViewGroup) mCurrentView.findViewById(R.id.nav_buttons);
if (navButtons != null) {
LayoutTransition lt = navButtons.getLayoutTransition();
if (lt != null) {
if (!lt.getTransitionListeners().contains(mTransitionListener)) {
lt.addTransitionListener(mTransitionListener);
}
if (!mScreenOn && mCurrentView != null) {
lt.disableTransitionType(
LayoutTransition.CHANGE_APPEARING |
LayoutTransition.CHANGE_DISAPPEARING |
LayoutTransition.APPEARING |
LayoutTransition.DISAPPEARING);
}
}
}
setButtonVisibility(NavbarEditor.NAVBAR_BACK, !disableBack);
setButtonVisibility(NavbarEditor.NAVBAR_HOME, !disableHome);
setButtonVisibility(NavbarEditor.NAVBAR_RECENT, !disableRecent);
setButtonVisibility(NavbarEditor.NAVBAR_RECENT, !disableRecent);
setButtonVisibility(NavbarEditor.NAVBAR_ALWAYS_MENU, !disableRecent);
setButtonVisibility(NavbarEditor.NAVBAR_MENU_BIG, !disableRecent);
setButtonVisibility(NavbarEditor.NAVBAR_SEARCH, !disableRecent);
final boolean showSearch = disableHome && !disableSearch;
final boolean showCamera = showSearch && !mCameraDisabledByDpm
&& mLockUtils.getCameraEnabled();
setVisibleOrGone(getSearchLight(), showSearch && mModLockDisabled);
setVisibleOrGone(getCameraButton(), showCamera);
mBarTransitions.applyBackButtonQuiescentAlpha(mBarTransitions.getMode(), true /*animate*/);
}
private void setVisibleOrGone(View view, boolean visible) {
if (view != null) {
view.setVisibility(visible ? VISIBLE : GONE);
}
}
private boolean isCameraDisabledByDpm() {
final DevicePolicyManager dpm =
(DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
if (dpm != null) {
try {
final int userId = ActivityManagerNative.getDefault().getCurrentUser().id;
final int disabledFlags = dpm.getKeyguardDisabledFeatures(null, userId);
final boolean disabledBecauseKeyguardSecure =
(disabledFlags & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_CAMERA) != 0
&& KeyguardTouchDelegate.getInstance(getContext()).isSecure();
return dpm.getCameraDisabled(null) || disabledBecauseKeyguardSecure;
} catch (RemoteException e) {
Log.e(TAG, "Can't get userId", e);
}
}
return false;
}
public void setSlippery(boolean newSlippery) {
WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams();
if (lp != null) {
boolean oldSlippery = (lp.flags & WindowManager.LayoutParams.FLAG_SLIPPERY) != 0;
if (!oldSlippery && newSlippery) {
lp.flags |= WindowManager.LayoutParams.FLAG_SLIPPERY;
} else if (oldSlippery && !newSlippery) {
lp.flags &= ~WindowManager.LayoutParams.FLAG_SLIPPERY;
} else {
return;
}
WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
wm.updateViewLayout(this, lp);
}
}
public void setMenuVisibility(final boolean show) {
setMenuVisibility(show, false);
}
public void setMenuVisibility(final boolean show, final boolean force) {
if (!force && mShowMenu == show) return;
mShowMenu = show;
setButtonVisibility(NavbarEditor.NAVBAR_CONDITIONAL_MENU, mShowMenu);
}
@Override
public void onFinishInflate() {
mRotatedViews[Configuration.ORIENTATION_PORTRAIT] = findViewById(R.id.rot0);
mRotatedViews[Configuration.ORIENTATION_LANDSCAPE] = findViewById(R.id.rot90);
mCurrentView = mRotatedViews[mContext.getResources().getConfiguration().orientation];
watchForAccessibilityChanges();
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
final String keyguardPackage = mContext.getString(
com.android.internal.R.string.config_keyguardPackage);
final Bundle keyguard_metadata = NavigationBarView
.getApplicationMetadata(mContext, keyguardPackage);
if (null != keyguard_metadata &&
keyguard_metadata.getBoolean("com.cyanogenmod.keyguard", false)) {
mObserver.observe();
}
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
mObserver.unobserve();
}
private void watchForAccessibilityChanges() {
final AccessibilityManager am =
(AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
// Set the initial state
enableAccessibility(am.isTouchExplorationEnabled());
// Watch for changes
am.addTouchExplorationStateChangeListener(new TouchExplorationStateChangeListener() {
@Override
public void onTouchExplorationStateChanged(boolean enabled) {
enableAccessibility(enabled);
}
});
}
private void enableAccessibility(boolean touchEnabled) {
Log.v(TAG, "touchEnabled:" + touchEnabled);
// Add a touch handler or accessibility click listener for camera and search buttons
// for all view orientations.
final OnClickListener onClickListener = touchEnabled ? mAccessibilityClickListener : null;
final OnTouchListener onTouchListener = touchEnabled ? null : mCameraTouchListener;
boolean hasCamera = false;
for (int i = 0; i < mRotatedViews.length; i++) {
if (mRotatedViews[i] == null) {
continue;
}
final View cameraButton = mRotatedViews[i].findViewById(R.id.camera_button);
final View searchLight = mRotatedViews[i].findViewById(R.id.search_light);
if (cameraButton != null) {
hasCamera = true;
cameraButton.setOnTouchListener(onTouchListener);
cameraButton.setOnClickListener(onClickListener);
}
if (searchLight != null) {
searchLight.setOnClickListener(onClickListener);
}
}
if (hasCamera) {
// Warm up KeyguardTouchDelegate so it's ready by the time the camera button is touched.
// This will connect to KeyguardService so that touch events are processed.
KeyguardTouchDelegate.getInstance(mContext);
}
}
public boolean isVertical() {
return mVertical;
}
public void setLeftInLandscape(boolean leftInLandscape) {
mLeftInLandscape = leftInLandscape;
mDeadZone.setStartFromRight(leftInLandscape);
}
public void reorient() {
int orientation = mContext.getResources().getConfiguration().orientation;
mRotatedViews[Configuration.ORIENTATION_PORTRAIT].setVisibility(View.GONE);
mRotatedViews[Configuration.ORIENTATION_LANDSCAPE].setVisibility(View.GONE);
mCurrentView = mRotatedViews[orientation];
mCurrentView.setVisibility(View.VISIBLE);
if (NavbarEditor.isDevicePhone(mContext)) {
int rotation = mDisplay.getRotation();
mVertical = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270;
mDelegateHelper.setSwapXY(mVertical);
} else {
mVertical = getWidth() > 0 && getHeight() > getWidth();
}
mEditBar = new NavbarEditor(mCurrentView, mVertical);
updateSettings();
mDeadZone = (DeadZone) mCurrentView.findViewById(R.id.deadzone);
mDeadZone.setStartFromRight(mLeftInLandscape);
// force the low profile & disabled states into compliance
mBarTransitions.init(mVertical);
setDisabledFlags(mDisabledFlags, true /* force */);
setMenuVisibility(mShowMenu, true /* force */);
if (DEBUG) {
Log.d(TAG, "reorient(): rot=" + mDisplay.getRotation());
}
setNavigationIconHints(mNavigationIconHints, true);
}
View findButton(NavbarEditor.ButtonInfo info) {
return mCurrentView.findViewWithTag(info);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
ViewGroup midNavButtons = (ViewGroup) mCurrentView.findViewById(R.id.mid_nav_buttons);
int count = midNavButtons.getChildCount();
View buttons[] = new View[count];
for (int i = 0; i < count; i++) {
buttons[i] = midNavButtons.getChildAt(i);
}
mDelegateHelper.setInitialTouchRegion(buttons);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (DEBUG) Log.d(TAG, String.format(
"onSizeChanged: (%dx%d) old: (%dx%d)", w, h, oldw, oldh));
final boolean newVertical = w > 0 && h > w;
if (newVertical != mVertical) {
mVertical = newVertical;
//Log.v(TAG, String.format("onSizeChanged: h=%d, w=%d, vert=%s", h, w, mVertical?"y":"n"));
reorient();
}
postCheckForInvalidLayout("sizeChanged");
super.onSizeChanged(w, h, oldw, oldh);
}
/*
@Override
protected void onLayout (boolean changed, int left, int top, int right, int bottom) {
if (DEBUG) Log.d(TAG, String.format(
"onLayout: %s (%d,%d,%d,%d)",
changed?"changed":"notchanged", left, top, right, bottom));
super.onLayout(changed, left, top, right, bottom);
}
// uncomment this for extra defensiveness in WORKAROUND_INVALID_LAYOUT situations: if all else
// fails, any touch on the display will fix the layout.
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (DEBUG) Log.d(TAG, "onInterceptTouchEvent: " + ev.toString());
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
postCheckForInvalidLayout("touch");
}
return super.onInterceptTouchEvent(ev);
}
*/
private String getResourceName(int resId) {
if (resId != 0) {
final android.content.res.Resources res = mContext.getResources();
try {
return res.getResourceName(resId);
} catch (android.content.res.Resources.NotFoundException ex) {
return "(unknown)";
}
} else {
return "(null)";
}
}
private void postCheckForInvalidLayout(final String how) {
mHandler.obtainMessage(MSG_CHECK_INVALID_LAYOUT, 0, 0, how).sendToTarget();
}
private static String visibilityToString(int vis) {
switch (vis) {
case View.INVISIBLE:
return "INVISIBLE";
case View.GONE:
return "GONE";
default:
return "VISIBLE";
}
}
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("NavigationBarView {");
final Rect r = new Rect();
final Point size = new Point();
mDisplay.getRealSize(size);
pw.println(String.format(" this: " + PhoneStatusBar.viewInfo(this)
+ " " + visibilityToString(getVisibility())));
getWindowVisibleDisplayFrame(r);
final boolean offscreen = r.right > size.x || r.bottom > size.y;
pw.println(" window: "
+ r.toShortString()
+ " " + visibilityToString(getWindowVisibility())
+ (offscreen ? " OFFSCREEN!" : ""));
pw.println(String.format(" mCurrentView: id=%s (%dx%d) %s",
getResourceName(mCurrentView.getId()),
mCurrentView.getWidth(), mCurrentView.getHeight(),
visibilityToString(mCurrentView.getVisibility())));
pw.println(String.format(" disabled=0x%08x vertical=%s menu=%s",
mDisabledFlags,
mVertical ? "true" : "false",
mShowMenu ? "true" : "false"));
dumpButton(pw, "back", findButton(NavbarEditor.NAVBAR_BACK));
dumpButton(pw, "home", findButton(NavbarEditor.NAVBAR_HOME));
dumpButton(pw, "rcnt", findButton(NavbarEditor.NAVBAR_RECENT));
dumpButton(pw, "srch", getSearchLight());
dumpButton(pw, "cmra", getCameraButton());
pw.println(" }");
}
private static void dumpButton(PrintWriter pw, String caption, View button) {
pw.print(" " + caption + ": ");
if (button == null) {
pw.print("null");
} else {
pw.print(PhoneStatusBar.viewInfo(button)
+ " " + visibilityToString(button.getVisibility())
+ " alpha=" + button.getAlpha()
);
if (button instanceof KeyButtonView) {
pw.print(" drawingAlpha=" + ((KeyButtonView)button).getDrawingAlpha());
pw.print(" quiescentAlpha=" + ((KeyButtonView)button).getQuiescentAlpha());
}
}
pw.println();
}
private static Bundle getApplicationMetadata(Context context, String pkg) {
if (pkg != null) {
try {
ApplicationInfo ai = context.getPackageManager().
getApplicationInfo(pkg, PackageManager.GET_META_DATA);
return ai.metaData;
} catch (NameNotFoundException e) {
return null;
}
}
return null;
}
private class SettingsObserver extends ContentObserver {
private boolean mObserving = false;
SettingsObserver(Handler handler) {
super(handler);
}
void observe() {
mObserving = true;
ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(
Settings.System.getUriFor(Settings.System.LOCKSCREEN_MODLOCK_ENABLED),
false, this);
resolver.registerContentObserver(
Settings.System.getUriFor(Settings.System.NAVIGATION_BAR_MENU_ARROW_KEYS),
false, this);
resolver.registerContentObserver(
Settings.System.getUriFor(Settings.System.NAV_BUTTONS),
false, this);
// intialize mModlockDisabled
onChange(false);
}
void unobserve() {
if (mObserving) {
mContext.getContentResolver().unregisterContentObserver(this);
mObserving = false;
}
}
@Override
public void onChange(boolean selfChange) {
mModLockDisabled = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.LOCKSCREEN_MODLOCK_ENABLED, 1) == 0;
mShowDpadArrowKeys = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.NAVIGATION_BAR_MENU_ARROW_KEYS, 1) != 0;
// hide dpad keys
setVisibleOrGone(getCurrentView().findViewById(R.id.dpad_left), false);
setVisibleOrGone(getCurrentView().findViewById(R.id.dpad_right), false);
// restore previous views in case the cursor keys WERE showing and
// are should now be hidden while the IME is up.
View one = getCurrentView().findViewById(mVertical ? R.id.six : R.id.one);
View capricaSix = getCurrentView().findViewById(mVertical ? R.id.one : R.id.six);
if (mSlotOneVisibility != -1 && one != null) {
one.setVisibility(mSlotOneVisibility);
}
if (mSlotSixVisibility != -1 && capricaSix != null) {
capricaSix.setVisibility(mSlotSixVisibility);
}
mSlotOneVisibility = -1;
mSlotSixVisibility = -1;
// propogate settings
setNavigationIconHints(mNavigationIconHints, true);
}
}
}