Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc138a88 authored by Evan Charlton's avatar Evan Charlton
Browse files

Clear individual notification by swiping left or right.

The user now has the ability to clear individual notifications by swiping to
the left or to the right. Only notifications which are marked as clearable
can be cleared (ongoing notifications, for example, can not be cleared).

Bug: http://b.android.com/10831
Change-Id: Ic62967456e83d46ebc474031b0a8a84f5f7f9716
parent 2a1b7ec9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.android.server.status.LatestItemContainer xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="65sp"
    android:orientation="vertical"
@@ -20,5 +20,5 @@
        android:background="@drawable/divider_horizontal_bright"
        />

</LinearLayout>
</com.android.server.status.LatestItemContainer>
+4 −0
Original line number Diff line number Diff line
@@ -310,6 +310,10 @@ class NotificationManagerService extends INotificationManager.Stub
                    Notification.FLAG_FOREGROUND_SERVICE);
        }

        public void onNotificationClear(String pkg, String tag, int id) {
            cancelNotification(pkg, tag, id, 0, Notification.FLAG_FOREGROUND_SERVICE);
        }

        public void onPanelRevealed() {
            synchronized (mNotificationList) {
                // sound
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 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.server.status;

import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;

public class LatestItemContainer extends LinearLayout {
    private static final int MAJOR_MOVE = 50;
    private static final int ANIM_DURATION = 400;
    private final GestureDetector mGestureDetector;

    private Runnable mSwipeCallback = null;
    private TranslateAnimation outRight;
    private TranslateAnimation outLeft;
    private final Handler mHandler = new Handler();

    public LatestItemContainer(Context context, AttributeSet attrs) {
        super(context, attrs);

        mGestureDetector =
                new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
                    public boolean onFling(MotionEvent e1, MotionEvent e2, float vX, float vY) {
                        if (mSwipeCallback != null) {
                            int dx = (int) (e2.getX() - e1.getX());
                            if (Math.abs(dx) > MAJOR_MOVE && Math.abs(vX) > Math.abs(vY)) {
                                if (vX > 0) {
                                    startAnimation(outRight);
                                } else {
                                    startAnimation(outLeft);
                                }
                                mHandler.postDelayed(mSwipeCallback, ANIM_DURATION);
                                return true;
                            }
                        }
                        return false;
                    }
                });
    }

    @Override
    public void onSizeChanged(int w, int h, int oldW, int oldH) {
        outRight = new TranslateAnimation(0, w, 0, 0);
        outLeft = new TranslateAnimation(0, -w, 0, 0);
        outRight.setDuration(ANIM_DURATION);
        outLeft.setDuration(ANIM_DURATION);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        boolean handled = mGestureDetector.onTouchEvent(event);
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_UP:
                if (handled) {
                    return true;
                } else {
                    return super.onInterceptTouchEvent(event);
                }
        }
        return false;
    }

    public void setOnSwipeCallback(Runnable callback) {
        mSwipeCallback = callback;
    }
}
+10 −2
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ public class StatusBarService extends IStatusBar.Stub
        void onSetDisabled(int status);
        void onClearAll();
        void onNotificationClick(String pkg, String tag, int id);
        void onNotificationClear(String pkg, String tag, int id);
        void onPanelRevealed();
    }

@@ -883,7 +884,7 @@ public class StatusBarService extends IStatusBar.Stub
    
    View makeNotificationView(StatusBarNotification notification, ViewGroup parent) {
    	Resources res = mContext.getResources();
    	NotificationData n = notification.data;
        final NotificationData n = notification.data;
        RemoteViews remoteViews = n.contentView;
        if (remoteViews == null) {
            return null;
@@ -892,7 +893,14 @@ public class StatusBarService extends IStatusBar.Stub
        // create the row view
        LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        View row = inflater.inflate(com.android.internal.R.layout.status_bar_latest_event, parent, false);
        LatestItemContainer row = (LatestItemContainer) inflater.inflate(com.android.internal.R.layout.status_bar_latest_event, parent, false);
        if (n.clearable) {
            row.setOnSwipeCallback(new Runnable() {
                public void run() {
                    mNotificationCallbacks.onNotificationClear(n.pkg, n.tag, n.id);
                }
            });
        }
        ViewGroup content = (ViewGroup)row.findViewById(com.android.internal.R.id.content);
        if (custExpBar) {
            StateListDrawable sld = new StateListDrawable();