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

Commit 51387974 authored by Joe Onorato's avatar Joe Onorato Committed by Android (Google) Code Review
Browse files

Merge "Move the volume, media, call, camera and search key handling from...

Merge "Move the volume, media, call, camera and search key handling from PhoneWindow to a new PhoneFallbackEventHandler class that is used for all windows, not just ones with decors."
parents bc4119a3 86f67860
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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 android.view;

/**
 * @hide
 */
public interface FallbackEventHandler {
    public void setView(View v);
    public void preDispatchKeyEvent(KeyEvent event);
    public boolean dispatchKeyEvent(KeyEvent event);
}
+11 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.view.accessibility.AccessibilityManager;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.Scroller;
import com.android.internal.policy.PolicyManager;
import com.android.internal.view.BaseSurfaceHolder;
import com.android.internal.view.IInputMethodCallback;
import com.android.internal.view.IInputMethodSession;
@@ -160,6 +161,7 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
    InputChannel mInputChannel;
    InputQueue.Callback mInputQueueCallback;
    InputQueue mInputQueue;
    FallbackEventHandler mFallbackEventHandler;
    
    final Rect mTempRect; // used in the transaction to not thrash the heap.
    final Rect mVisRect; // used to retrieve visible rect of focused view.
@@ -273,6 +275,7 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
        mAttachInfo = new View.AttachInfo(sWindowSession, mWindow, this, this);
        mViewConfiguration = ViewConfiguration.get(context);
        mDensity = context.getResources().getDisplayMetrics().densityDpi;
        mFallbackEventHandler = PolicyManager.makeNewFallbackEventHandler(context);
    }

    public static void addFirstDrawHandler(Runnable callback) {
@@ -325,6 +328,7 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
        synchronized (this) {
            if (mView == null) {
                mView = view;
                mFallbackEventHandler.setView(view);
                mWindowAttributes.copyFrom(attrs);
                attrs = mWindowAttributes;
                
@@ -386,6 +390,7 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
                    mView = null;
                    mAttachInfo.mRootView = null;
                    mInputChannel = null;
                    mFallbackEventHandler.setView(null);
                    unscheduleTraversals();
                    throw new RuntimeException("Adding window failed", e);
                } finally {
@@ -404,6 +409,7 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
                    mView = null;
                    mAttachInfo.mRootView = null;
                    mAdded = false;
                    mFallbackEventHandler.setView(null);
                    unscheduleTraversals();
                    switch (res) {
                        case WindowManagerImpl.ADD_BAD_APP_TOKEN:
@@ -2422,8 +2428,13 @@ public final class ViewRoot extends Handler implements ViewParent, View.AttachIn
                if (Config.LOGV) {
                    captureKeyLog("captureDispatchKeyEvent", event);
                }
                mFallbackEventHandler.preDispatchKeyEvent(event);
                boolean keyHandled = mView.dispatchKeyEvent(event);

                if (!keyHandled) {
                    mFallbackEventHandler.dispatchKeyEvent(event);
                }

                if (!keyHandled && isDown) {
                    int direction = 0;
                    switch (event.getKeyCode()) {
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.policy;

import android.content.Context;
import android.view.FallbackEventHandler;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManagerPolicy;
@@ -33,4 +34,6 @@ public interface IPolicy {
    public LayoutInflater makeNewLayoutInflater(Context context);

    public WindowManagerPolicy makeNewWindowManager();

    public FallbackEventHandler makeNewFallbackEventHandler(Context context);
}
+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.policy;

import android.content.Context;
import android.view.FallbackEventHandler;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManagerPolicy;
@@ -65,4 +66,8 @@ public final class PolicyManager {
    public static WindowManagerPolicy makeNewWindowManager() {
        return sPolicy.makeNewWindowManager();
    }

    public static FallbackEventHandler makeNewFallbackEventHandler(Context context) {
        return sPolicy.makeNewFallbackEventHandler(context);
    }
}
+68 −0
Original line number Diff line number Diff line
@@ -27,10 +27,12 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.ServiceManager;
import android.provider.Settings;
import android.util.Log;
import android.view.KeyEvent;
import android.view.VolumePanel;

import java.util.Iterator;
import java.util.HashMap;
@@ -45,6 +47,7 @@ public class AudioManager {

    private final Context mContext;
    private final Handler mHandler;
    private long mVolumeKeyUpTime;

    private static String TAG = "AudioManager";
    private static boolean DEBUG = false;
@@ -357,6 +360,71 @@ public class AudioManager {
        return sService;
    }

    /**
     * @hide
     */
    public void preDispatchKeyEvent(int keyCode, int stream) {
        /*
         * If the user hits another key within the play sound delay, then
         * cancel the sound
         */
        if (keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_UP
                && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
                && mVolumeKeyUpTime + VolumePanel.PLAY_SOUND_DELAY
                        > SystemClock.uptimeMillis()) {
            /*
             * The user has hit another key during the delay (e.g., 300ms)
             * since the last volume key up, so cancel any sounds.
             */
            adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME,
                        stream, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
        }
    }

    /**
     * @hide
     */
    public void handleKeyDown(int keyCode, int stream) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                /*
                 * Adjust the volume in on key down since it is more
                 * responsive to the user.
                 */
                adjustSuggestedStreamVolume(
                        keyCode == KeyEvent.KEYCODE_VOLUME_UP
                                ? AudioManager.ADJUST_RAISE
                                : AudioManager.ADJUST_LOWER,
                        stream,
                        AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE);
                break;
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                // TODO: Actually handle MUTE.
                break;
        }
    }

    /**
     * @hide
     */
    public void handleKeyUp(int keyCode, int stream) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_UP:
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                /*
                 * Play a sound. This is done on key up since we don't want the
                 * sound to play when a user holds down volume down to mute.
                 */
                adjustSuggestedStreamVolume(ADJUST_SAME, stream, FLAG_PLAY_SOUND);
                mVolumeKeyUpTime = SystemClock.uptimeMillis();
                break;
            case KeyEvent.KEYCODE_VOLUME_MUTE:
                // TODO: Actually handle MUTE.
                break;
        }
    }

    /**
     * Adjusts the volume of a particular stream by one step in a direction.
     * <p>
Loading