Merge "Close notification guts after applying changes" into qt-dev am: 2cf73d7976

am: ea5eebce3e

Change-Id: I3a059364e71180aa2f35e112d42dd985548507ca
This commit is contained in:
Evan Laird
2019-05-31 15:22:08 -07:00
committed by android-build-merger
3 changed files with 28 additions and 6 deletions

View File

@@ -43,6 +43,18 @@ import javax.inject.Singleton
const val TAG = "ChannelDialogController" const val TAG = "ChannelDialogController"
/**
* ChannelEditorDialogController is the controller for the dialog half-shelf
* that allows users to quickly turn off channels. It is launched from the NotificationInfo
* guts view and displays controls for toggling app notifications as well as up to 4 channels
* from that app like so:
*
* APP TOGGLE <on/off>
* - Channel from which we launched <on/off>
* - <on/off>
* - the next 3 channels sorted alphabetically for that app <on/off>
* - <on/off>
*/
@Singleton @Singleton
class ChannelEditorDialogController @Inject constructor( class ChannelEditorDialogController @Inject constructor(
c: Context, c: Context,
@@ -58,6 +70,9 @@ class ChannelEditorDialogController @Inject constructor(
private var appName: String? = null private var appName: String? = null
private var onSettingsClickListener: NotificationInfo.OnSettingsClickListener? = null private var onSettingsClickListener: NotificationInfo.OnSettingsClickListener? = null
// Caller should set this if they care about when we dismiss
var onFinishListener: OnChannelEditorDialogFinishedListener? = null
// Channels handed to us from NotificationInfo // Channels handed to us from NotificationInfo
@VisibleForTesting @VisibleForTesting
internal val providedChannels = mutableListOf<NotificationChannel>() internal val providedChannels = mutableListOf<NotificationChannel>()
@@ -144,6 +159,7 @@ class ChannelEditorDialogController @Inject constructor(
private fun done() { private fun done() {
resetState() resetState()
dialog.dismiss() dialog.dismiss()
onFinishListener?.onChannelEditorDialogFinished()
} }
private fun resetState() { private fun resetState() {
@@ -242,7 +258,7 @@ class ChannelEditorDialogController @Inject constructor(
findViewById<TextView>(R.id.see_more_button)?.setOnClickListener { findViewById<TextView>(R.id.see_more_button)?.setOnClickListener {
onSettingsClickListener?.onClick(it, null, appUid!!) onSettingsClickListener?.onClick(it, null, appUid!!)
dismiss() done()
} }
window?.apply { window?.apply {
@@ -267,3 +283,7 @@ class ChannelEditorDialogController @Inject constructor(
or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)
} }
interface OnChannelEditorDialogFinishedListener {
fun onChannelEditorDialogFinished()
}

View File

@@ -159,13 +159,13 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
// used by standard ui // used by standard ui
private OnClickListener mOnDismissSettings = v -> { private OnClickListener mOnDismissSettings = v -> {
mPressedApply = true; mPressedApply = true;
closeControls(v); closeControls(v, true);
}; };
// used by blocking helper // used by blocking helper
private OnClickListener mOnKeepShowing = v -> { private OnClickListener mOnKeepShowing = v -> {
mExitReason = NotificationCounters.BLOCKING_HELPER_KEEP_SHOWING; mExitReason = NotificationCounters.BLOCKING_HELPER_KEEP_SHOWING;
closeControls(v); closeControls(v, true);
mMetricsLogger.write(getLogMaker().setCategory( mMetricsLogger.write(getLogMaker().setCategory(
MetricsEvent.NOTIFICATION_BLOCKING_HELPER) MetricsEvent.NOTIFICATION_BLOCKING_HELPER)
.setType(MetricsEvent.TYPE_ACTION) .setType(MetricsEvent.TYPE_ACTION)
@@ -445,6 +445,8 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
if (mChannelEditorDialogController != null) { if (mChannelEditorDialogController != null) {
mChannelEditorDialogController.prepareDialogForApp(mAppName, mPackageName, mAppUid, mChannelEditorDialogController.prepareDialogForApp(mAppName, mPackageName, mAppUid,
mUniqueChannelsInRow, mPkgIcon, mOnSettingsClickListener); mUniqueChannelsInRow, mPkgIcon, mOnSettingsClickListener);
mChannelEditorDialogController.setOnFinishListener(
() -> closeControls(this, false));
mChannelEditorDialogController.show(); mChannelEditorDialogController.show();
} }
}); });
@@ -725,7 +727,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
* {@link #swapContent(boolean, boolean)} for where undo is handled. * {@link #swapContent(boolean, boolean)} for where undo is handled.
*/ */
@VisibleForTesting @VisibleForTesting
void closeControls(View v) { void closeControls(View v, boolean save) {
int[] parentLoc = new int[2]; int[] parentLoc = new int[2];
int[] targetLoc = new int[2]; int[] targetLoc = new int[2];
mGutsContainer.getLocationOnScreen(parentLoc); mGutsContainer.getLocationOnScreen(parentLoc);
@@ -734,7 +736,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
final int centerY = v.getHeight() / 2; final int centerY = v.getHeight() / 2;
final int x = targetLoc[0] - parentLoc[0] + centerX; final int x = targetLoc[0] - parentLoc[0] + centerX;
final int y = targetLoc[1] - parentLoc[1] + centerY; final int y = targetLoc[1] - parentLoc[1] + centerY;
mGutsContainer.closeControls(x, y, true /* save */, false /* force */); mGutsContainer.closeControls(x, y, save, false /* force */);
} }
@Override @Override

View File

@@ -646,7 +646,7 @@ public class NotificationInfoTest extends SysuiTestCase {
doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean()); doCallRealMethod().when(guts).closeControls(anyInt(), anyInt(), anyBoolean(), anyBoolean());
mNotificationInfo.setGutsParent(guts); mNotificationInfo.setGutsParent(guts);
mNotificationInfo.closeControls(mNotificationInfo); mNotificationInfo.closeControls(mNotificationInfo, true);
verify(mBlockingHelperManager).dismissCurrentBlockingHelper(); verify(mBlockingHelperManager).dismissCurrentBlockingHelper();
} }