Skip to content

Commit 72ff7f3

Browse files
romanbbarnavgosain
authored andcommitted
InCallUI: Add initial smart cover support
Change-Id: I7bd476a725efff9a3b9cfce91771750e231ea50f Signed-off-by: Roman Birg <roman@cyngn.com>
1 parent 6b224af commit 72ff7f3

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

res/layout/incall_screen.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
android:layout_width="match_parent"
2121
android:layout_height="match_parent"
2222
android:background="@android:color/black"
23+
android:animateLayoutChanges="true"
2324
android:id="@+id/main">
2425

2526
<RelativeLayout

src/com/android/incallui/InCallActivity.java

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030
import android.app.Activity;
3131
import android.app.AlertDialog;
3232
import android.app.FragmentTransaction;
33+
import android.content.BroadcastReceiver;
34+
import android.content.Context;
3335
import android.content.DialogInterface;
34-
import android.content.DialogInterface.OnClickListener;
3536
import android.content.DialogInterface.OnCancelListener;
37+
import android.content.DialogInterface.OnClickListener;
3638
import android.content.Intent;
39+
import android.content.IntentFilter;
3740
import android.content.res.Configuration;
3841
import android.content.res.Resources;
3942
import android.database.ContentObserver;
@@ -42,12 +45,17 @@
4245
import android.os.Handler;
4346
import android.provider.Settings;
4447
import android.telephony.MSimTelephonyManager;
48+
import android.util.DisplayMetrics;
49+
import android.view.Gravity;
4550
import android.view.KeyEvent;
4651
import android.view.MotionEvent;
4752
import android.view.View;
53+
import android.view.ViewGroup;
4854
import android.view.Window;
4955
import android.view.WindowManager;
56+
import android.view.WindowManagerPolicy;
5057
import android.view.accessibility.AccessibilityEvent;
58+
import android.widget.FrameLayout;
5159
import 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

Comments
 (0)