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

Commit b3f48a40 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Added options for custom search key and long-press search key app." into gingerbread

parents 7814dacb 84fd952c
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -1757,6 +1757,30 @@ public final class Settings {
         */
        public static final String SELECTED_CUSTOM_APP = "selected_custom_app";

        /**
         * Specifies whether or not to use a custom app on search key press
         * @hide
         */
        public static final String USE_CUSTOM_SEARCH_APP_TOGGLE = "use_custom_search_app_toggle";

        /**
         * Contains activity to start on search key press
         * @hide
         */
        public static final String USE_CUSTOM_SEARCH_APP_ACTIVITY = "use_custom_search_app_activity";

        /**
         * Specifies whether or not to use a custom app on long search key press
         * @hide
         */
        public static final String USE_CUSTOM_LONG_SEARCH_APP_TOGGLE = "use_custom_long_search_app_toggle";

        /**
         * Contains activity to start on long search key press
         * @hide
         */
        public static final String USE_CUSTOM_LONG_SEARCH_APP_ACTIVITY = "use_custom_long_search_app_activity";

        /**
         * Stores the uri of the defined application for user key 1
         * @hide
+41 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.internal.view.menu.SubMenuBuilder;
import android.app.KeyguardManager;
import android.app.SearchManager;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
@@ -47,6 +48,7 @@ import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.AndroidRuntimeException;
import android.util.Config;
@@ -79,6 +81,8 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import java.net.URISyntaxException;

/**
 * Android-specific Window.
 * <p>
@@ -1250,6 +1254,17 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                if (event.getRepeatCount() == 0) {
                    dispatcher.startTracking(event, this);
                } else if (event.isLongPress() && dispatcher.isTracking(event)) {
                    // start custom app
                    boolean mCustomLongSearchAppToggle=(Settings.System.getInt(getContext().getContentResolver(),
                            Settings.System.USE_CUSTOM_LONG_SEARCH_APP_TOGGLE, 0) == 1);

                    if(mCustomLongSearchAppToggle){
                        runCustomApp(Settings.System.getString(getContext().getContentResolver(),
                            Settings.System.USE_CUSTOM_LONG_SEARCH_APP_ACTIVITY));
                        break;
                    }

                    // default behavior
                    Configuration config = getContext().getResources().getConfiguration(); 
                    if (config.keyboard == Configuration.KEYBOARD_NOKEYS
                            || config.hardKeyboardHidden
@@ -1401,6 +1416,13 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
                    break;
                }
                if (event.isTracking() && !event.isCanceled()) {
                    boolean mCustomSearchAppToggle=(Settings.System.getInt(getContext().getContentResolver(),
                            Settings.System.USE_CUSTOM_SEARCH_APP_TOGGLE, 0) == 1);

                    if(mCustomSearchAppToggle)
                        runCustomApp(Settings.System.getString(getContext().getContentResolver(),
                            Settings.System.USE_CUSTOM_SEARCH_APP_ACTIVITY));
                    else
                        launchDefaultSearch();
                }
                return true;
@@ -2807,4 +2829,21 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
    void sendCloseSystemWindows(String reason) {
        PhoneWindowManager.sendCloseSystemWindows(getContext(), reason);
    }

    void runCustomApp(String uri) {
        if (uri != null) {
            try {
                Intent i = Intent.parseUri(uri, 0);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                getContext().startActivity(i);
            } catch (URISyntaxException e) {

            } catch (ActivityNotFoundException e) {

            }
        }
    }


}