diff options
author | Roman Birg <roman@cyngn.com> | 2014-03-11 11:24:47 -0700 |
---|---|---|
committer | Roman Birg <roman@cyngn.com> | 2014-08-20 08:48:11 -0700 |
commit | 7622aba5b4b08658174ab496c0b2c857ca471a43 (patch) | |
tree | 4c2cf5c2a543ec49213e615416104fd5284ad8a7 | |
parent | 1e5ab915ecab69685329fe203f6f3ef90e5aa5c6 (diff) | |
download | packages_apps_InCallUI-7622aba5b4b08658174ab496c0b2c857ca471a43.tar.gz packages_apps_InCallUI-7622aba5b4b08658174ab496c0b2c857ca471a43.tar.bz2 packages_apps_InCallUI-7622aba5b4b08658174ab496c0b2c857ca471a43.zip |
InCallUI: Add initial smart cover support
Change-Id: I7bd476a725efff9a3b9cfce91771750e231ea50f
Signed-off-by: Roman Birg <roman@cyngn.com>
-rw-r--r-- | res/layout/incall_screen.xml | 1 | ||||
-rw-r--r-- | src/com/android/incallui/InCallActivity.java | 86 |
2 files changed, 86 insertions, 1 deletions
diff --git a/res/layout/incall_screen.xml b/res/layout/incall_screen.xml index d78b36dd..6403ee18 100644 --- a/res/layout/incall_screen.xml +++ b/res/layout/incall_screen.xml @@ -20,6 +20,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" + android:animateLayoutChanges="true" android:id="@+id/main"> <RelativeLayout diff --git a/src/com/android/incallui/InCallActivity.java b/src/com/android/incallui/InCallActivity.java index 56ad26da..c81ef8a3 100644 --- a/src/com/android/incallui/InCallActivity.java +++ b/src/com/android/incallui/InCallActivity.java @@ -30,10 +30,13 @@ import com.android.services.telephony.common.CallDetails; import android.app.Activity; import android.app.AlertDialog; import android.app.FragmentTransaction; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.DialogInterface; -import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnCancelListener; +import android.content.DialogInterface.OnClickListener; import android.content.Intent; +import android.content.IntentFilter; import android.content.res.Configuration; import android.content.res.Resources; import android.database.ContentObserver; @@ -42,12 +45,17 @@ import android.os.Bundle; import android.os.Handler; import android.provider.Settings; import android.telephony.MSimTelephonyManager; +import android.util.DisplayMetrics; +import android.view.Gravity; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; +import android.view.WindowManagerPolicy; import android.view.accessibility.AccessibilityEvent; +import android.widget.FrameLayout; import android.widget.Toast; /** @@ -86,6 +94,19 @@ public class InCallActivity extends Activity { } }; + private int[] mCoverWindowCoords = null; + private BroadcastReceiver mLidStateChangeReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (WindowManagerPolicy.ACTION_LID_STATE_CHANGED.equals(intent.getAction())) { + boolean on = intent.getIntExtra(WindowManagerPolicy.EXTRA_LID_STATE, + WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT) + == WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; + showSmartCover(on); + } + } + }; + @Override protected void onCreate(Bundle icicle) { Log.d(this, "onCreate()... this = " + this); @@ -97,6 +118,13 @@ public class InCallActivity extends Activity { return; } + mCoverWindowCoords = getResources().getIntArray( + com.android.internal.R.array.config_smartCoverWindowCoords); + if (mCoverWindowCoords != null && mCoverWindowCoords.length != 4) { + // make sure there are exactly 4 dimensions provided, or ignore + mCoverWindowCoords = null; + } + // set this flag so this activity will stay in front of the keyguard // Have the WindowManager filter out touch events that are "too fat". int flags = WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED @@ -150,6 +178,10 @@ public class InCallActivity extends Activity { mShowDialpadRequested = false; } updateSystemBarTranslucency(); + if (mCoverWindowCoords != null) { + registerReceiver(mLidStateChangeReceiver, new IntentFilter( + WindowManagerPolicy.ACTION_LID_STATE_CHANGED)); + } } // onPause is guaranteed to be called when the InCallActivity goes @@ -158,6 +190,9 @@ public class InCallActivity extends Activity { protected void onPause() { Log.d(this, "onPause()..."); super.onPause(); + if (mCoverWindowCoords != null) { + unregisterReceiver(mLidStateChangeReceiver); + } mIsForegroundActivity = false; @@ -454,6 +489,55 @@ public class InCallActivity extends Activity { } } + protected void showSmartCover(boolean show) { + mAnswerFragment.getView().setVisibility(show ? View.INVISIBLE : View.VISIBLE); + + DisplayMetrics metrics = getResources().getDisplayMetrics(); + final int windowHeight = mCoverWindowCoords[2] - mCoverWindowCoords[0]; + final int windowWidth = metrics.widthPixels - mCoverWindowCoords[1] + - (metrics.widthPixels - mCoverWindowCoords[3]); + + final int stretch = ViewGroup.LayoutParams.MATCH_PARENT; + + View main = findViewById(R.id.main); + View callCard = mCallCardFragment.getView(); + if (show) { + // clear bg color + main.setBackground(null); + + // center + FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(windowWidth, stretch); + lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; + main.setLayoutParams(lp); + + // adjust callcard height + ViewGroup.LayoutParams params = callCard.getLayoutParams(); + params.height = windowHeight; + + callCard.setSystemUiVisibility(callCard.getSystemUiVisibility() + | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); + + // disable touches + getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); + } else { + // reset default parameters + main.setBackgroundColor(R.color.incall_button_background); + + FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(stretch, stretch); + main.setLayoutParams(lp); + + ViewGroup.LayoutParams params = mCallCardFragment.getView().getLayoutParams(); + params.height = stretch; + + callCard.setSystemUiVisibility(callCard.getSystemUiVisibility() + & ~View.SYSTEM_UI_FLAG_FULLSCREEN & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); + + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); + } + callCard.invalidate(); + main.requestLayout(); + } + private void toast(String text) { final Toast toast = Toast.makeText(this, text, Toast.LENGTH_SHORT); |