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

Commit b70a3ad3 authored by Martin Brabham's avatar Martin Brabham Committed by Steve Kondik
Browse files

quickkeys: Add needed elements for Vision quick keys.

Change-Id: Ibad5ef7076361504fdf48b8178806ac3d91dfe46
parent 2b4e94bd
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -1732,6 +1732,24 @@ public final class Settings {
         */
        public static final String SELECTED_CUSTOM_APP = "selected_custom_app";

        /**
         * Stores the uri of the defined application for user key 1
         * @hide
         */
        public static final String USER_DEFINED_KEY1_APP = "user_defined_key1_app";

        /**
         * Stores the uri of the defined application for user key 2
         * @hide
         */
        public static final String USER_DEFINED_KEY2_APP = "user_defined_key2_app";

        /**
         * Stores the uri of the defined application for user key 3
         * @hide
         */
        public static final String USER_DEFINED_KEY3_APP = "user_defined_key3_app";

        /**
         * Specifies whether to prompt on the power dialog
         * @hide
+62 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.content.res.Resources;
import android.database.ContentObserver;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.LocalPowerManager;
@@ -1320,6 +1321,12 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
        }

        // Handle "Quick Keys" on Vision
        if ("vision".equals(Build.DEVICE)
                && (keyCode == KeyEvent.KEYCODE_USER1 || keyCode == KeyEvent.KEYCODE_USER2 || keyCode == KeyEvent.KEYCODE_USER3)) {
            return handleQuickKeys(win, keyCode, down, keyguardOn);
        }

        // Shortcuts are invoked through Search+key, so intercept those here
        if (mSearchKeyPressed) {
            if (down && repeatCount == 0 && !keyguardOn) {
@@ -1341,6 +1348,60 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return false;
    }

    /**
     * Quick Keys for Vision (HTC - G2)
     */
    private boolean handleQuickKeys(WindowState win, int code, boolean down, boolean keyguardOn) {

        WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
        if (attrs != null) {
            final int type = attrs.type;
            if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
                    || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
                // the "app" is keyguard, so give it the key
                return false;
            }
            if (down) {
                if (!keyguardOn) {
                    String property = null;
                    switch (code) {
                        case KeyEvent.KEYCODE_USER1:
                            property = Settings.System.USER_DEFINED_KEY1_APP;
                            break;
                        case KeyEvent.KEYCODE_USER2:
                            property = Settings.System.USER_DEFINED_KEY2_APP;
                            break;
                        case KeyEvent.KEYCODE_USER3:
                            property = Settings.System.USER_DEFINED_KEY3_APP;
                            break;
                        default:
                            return false;
                    }
                    String appUri = Settings.System.getString(mContext.getContentResolver(),
                            property);
                    if (appUri != null) {
                        try {
                            Intent qkIntent = Intent.parseUri(appUri, 0);
                            qkIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                            mContext.startActivity(qkIntent);
                        } catch (URISyntaxException e) {
                            // TODO: Toast Message
                        } catch (ActivityNotFoundException e) {
                            // TODO: Toast Message
                        }
                    } else {
                        // TODO: Open CMParts
                    }
                    // TODO: Add long press shortcut?
                    // mHandler.postDelayed(mHomeLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
                }
                return true;
            }
        }
        return false;
    }

    /**
     * A home key -> launch home action was detected.  Take the appropriate action
     * given the situation with the keyguard.