3030import android .app .Activity ;
3131import android .app .AlertDialog ;
3232import android .app .FragmentTransaction ;
33+ import android .content .BroadcastReceiver ;
34+ import android .content .Context ;
3335import android .content .DialogInterface ;
34- import android .content .DialogInterface .OnClickListener ;
3536import android .content .DialogInterface .OnCancelListener ;
37+ import android .content .DialogInterface .OnClickListener ;
3638import android .content .Intent ;
39+ import android .content .IntentFilter ;
3740import android .content .res .Configuration ;
3841import android .content .res .Resources ;
3942import android .database .ContentObserver ;
4245import android .os .Handler ;
4346import android .provider .Settings ;
4447import android .telephony .MSimTelephonyManager ;
48+ import android .util .DisplayMetrics ;
49+ import android .view .Gravity ;
4550import android .view .KeyEvent ;
4651import android .view .MotionEvent ;
4752import android .view .View ;
53+ import android .view .ViewGroup ;
4854import android .view .Window ;
4955import android .view .WindowManager ;
56+ import android .view .WindowManagerPolicy ;
5057import android .view .accessibility .AccessibilityEvent ;
58+ import android .widget .FrameLayout ;
5159import android .widget .Toast ;
5260
5361/**
@@ -86,6 +94,19 @@ public void onChange(boolean selfChange, Uri uri) {
8694 }
8795 };
8896
97+ private int [] mCoverWindowCoords = null ;
98+ private BroadcastReceiver mLidStateChangeReceiver = new BroadcastReceiver () {
99+ @ Override
100+ public void onReceive (Context context , Intent intent ) {
101+ if (WindowManagerPolicy .ACTION_LID_STATE_CHANGED .equals (intent .getAction ())) {
102+ boolean on = intent .getIntExtra (WindowManagerPolicy .EXTRA_LID_STATE ,
103+ WindowManagerPolicy .WindowManagerFuncs .LID_ABSENT )
104+ == WindowManagerPolicy .WindowManagerFuncs .LID_CLOSED ;
105+ showSmartCover (on );
106+ }
107+ }
108+ };
109+
89110 @ Override
90111 protected void onCreate (Bundle icicle ) {
91112 Log .d (this , "onCreate()... this = " + this );
@@ -97,6 +118,13 @@ protected void onCreate(Bundle icicle) {
97118 return ;
98119 }
99120
121+ mCoverWindowCoords = getResources ().getIntArray (
122+ com .android .internal .R .array .config_smartCoverWindowCoords );
123+ if (mCoverWindowCoords != null && mCoverWindowCoords .length != 4 ) {
124+ // make sure there are exactly 4 dimensions provided, or ignore
125+ mCoverWindowCoords = null ;
126+ }
127+
100128 // set this flag so this activity will stay in front of the keyguard
101129 // Have the WindowManager filter out touch events that are "too fat".
102130 int flags = WindowManager .LayoutParams .FLAG_SHOW_WHEN_LOCKED
@@ -150,6 +178,10 @@ protected void onResume() {
150178 mShowDialpadRequested = false ;
151179 }
152180 updateSystemBarTranslucency ();
181+ if (mCoverWindowCoords != null ) {
182+ registerReceiver (mLidStateChangeReceiver , new IntentFilter (
183+ WindowManagerPolicy .ACTION_LID_STATE_CHANGED ));
184+ }
153185 }
154186
155187 // onPause is guaranteed to be called when the InCallActivity goes
@@ -158,6 +190,9 @@ protected void onResume() {
158190 protected void onPause () {
159191 Log .d (this , "onPause()..." );
160192 super .onPause ();
193+ if (mCoverWindowCoords != null ) {
194+ unregisterReceiver (mLidStateChangeReceiver );
195+ }
161196
162197 mIsForegroundActivity = false ;
163198
@@ -454,6 +489,55 @@ protected void initializeInCall() {
454489 }
455490 }
456491
492+ protected void showSmartCover (boolean show ) {
493+ mAnswerFragment .getView ().setVisibility (show ? View .INVISIBLE : View .VISIBLE );
494+
495+ DisplayMetrics metrics = getResources ().getDisplayMetrics ();
496+ final int windowHeight = mCoverWindowCoords [2 ] - mCoverWindowCoords [0 ];
497+ final int windowWidth = metrics .widthPixels - mCoverWindowCoords [1 ]
498+ - (metrics .widthPixels - mCoverWindowCoords [3 ]);
499+
500+ final int stretch = ViewGroup .LayoutParams .MATCH_PARENT ;
501+
502+ View main = findViewById (R .id .main );
503+ View callCard = mCallCardFragment .getView ();
504+ if (show ) {
505+ // clear bg color
506+ main .setBackground (null );
507+
508+ // center
509+ FrameLayout .LayoutParams lp = new FrameLayout .LayoutParams (windowWidth , stretch );
510+ lp .gravity = Gravity .TOP | Gravity .CENTER_HORIZONTAL ;
511+ main .setLayoutParams (lp );
512+
513+ // adjust callcard height
514+ ViewGroup .LayoutParams params = callCard .getLayoutParams ();
515+ params .height = windowHeight ;
516+
517+ callCard .setSystemUiVisibility (callCard .getSystemUiVisibility ()
518+ | View .SYSTEM_UI_FLAG_FULLSCREEN | View .SYSTEM_UI_FLAG_HIDE_NAVIGATION );
519+
520+ // disable touches
521+ getWindow ().addFlags (WindowManager .LayoutParams .FLAG_NOT_TOUCHABLE );
522+ } else {
523+ // reset default parameters
524+ main .setBackgroundColor (R .color .incall_button_background );
525+
526+ FrameLayout .LayoutParams lp = new FrameLayout .LayoutParams (stretch , stretch );
527+ main .setLayoutParams (lp );
528+
529+ ViewGroup .LayoutParams params = mCallCardFragment .getView ().getLayoutParams ();
530+ params .height = stretch ;
531+
532+ callCard .setSystemUiVisibility (callCard .getSystemUiVisibility ()
533+ & ~View .SYSTEM_UI_FLAG_FULLSCREEN & ~View .SYSTEM_UI_FLAG_HIDE_NAVIGATION );
534+
535+ getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_NOT_TOUCHABLE );
536+ }
537+ callCard .invalidate ();
538+ main .requestLayout ();
539+ }
540+
457541 private void toast (String text ) {
458542 final Toast toast = Toast .makeText (this , text , Toast .LENGTH_SHORT );
459543
0 commit comments