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

Commit aa7e529b authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Fixing bug where search bar is not updated when search package is first installed."

parents 239d99c4 8eaeb7dc
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -35,8 +35,6 @@ public class Constants {
            public static final boolean EnableTaskStackClipping = true;
            public static final boolean EnableTaskStackClipping = true;
            // Enables tapping on the TaskBar to launch the task
            // Enables tapping on the TaskBar to launch the task
            public static final boolean EnableTaskBarTouchEvents = true;
            public static final boolean EnableTaskBarTouchEvents = true;
            // Enables the use of theme colors as the task bar background
            public static final boolean EnableTaskBarThemeColors = true;
            // Enables app-info pane on long-pressing the icon
            // Enables app-info pane on long-pressing the icon
            public static final boolean EnableDevAppInfoOnLongPress = true;
            public static final boolean EnableDevAppInfoOnLongPress = true;
            // Enables the search bar layout
            // Enables the search bar layout
@@ -95,6 +93,8 @@ public class Constants {
        public static class App {
        public static class App {
            public static int AppWidgetHostId = 1024;
            public static int AppWidgetHostId = 1024;
            public static String Key_SearchAppWidgetId = "searchAppWidgetId";
            public static String Key_SearchAppWidgetId = "searchAppWidgetId";
            public static String Key_DebugModeEnabled = "debugModeEnabled";
            public static String DebugModeVersion = "A";
        }
        }
        public static class Window {
        public static class Window {
            // The dark background dim is set behind the empty recents view
            // The dark background dim is set behind the empty recents view
+67 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2014 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.systemui.recents;

import android.os.Handler;
import android.os.SystemClock;
import android.view.KeyEvent;

/**
 * A trigger for catching a debug chord.
 * We currently use volume up then volume down to trigger this mode.
 */
public class DebugTrigger {

    Handler mHandler;
    Runnable mTriggeredRunnable;

    int mLastKeyCode;
    long mLastKeyCodeTime;

    public DebugTrigger(Runnable triggeredRunnable) {
        mHandler = new Handler();
        mTriggeredRunnable = triggeredRunnable;
    }

    /** Resets the debug trigger */
    void reset() {
        mLastKeyCode = 0;
        mLastKeyCodeTime = 0;
    }

    /**
     * Processes a key event and tests if it is a part of the trigger. If the chord is complete,
     * then we just call the callback.
     */
    public void onKeyEvent(int keyCode) {
        if (mLastKeyCode == 0) {
            if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                mLastKeyCode = keyCode;
                mLastKeyCodeTime = SystemClock.uptimeMillis();
                return;
            }
        } else {
            if (mLastKeyCode == KeyEvent.KEYCODE_VOLUME_UP &&
                    keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                if ((SystemClock.uptimeMillis() - mLastKeyCodeTime) < 750) {
                    mTriggeredRunnable.run();
                }
            }
        }
        reset();
    }
}
+36 −3
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.recents;


import android.app.Activity;
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.ActivityOptions;
import android.app.SearchManager;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.appwidget.AppWidgetProviderInfo;
@@ -25,12 +26,14 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserHandle;
import android.util.Pair;
import android.util.Pair;
import android.view.KeyEvent;
import android.view.KeyEvent;
import android.view.View;
import android.view.View;
import android.view.ViewStub;
import android.view.ViewStub;
import android.widget.Toast;
import com.android.systemui.R;
import com.android.systemui.R;
import com.android.systemui.recents.model.RecentsTaskLoader;
import com.android.systemui.recents.model.RecentsTaskLoader;
import com.android.systemui.recents.model.SpaceNode;
import com.android.systemui.recents.model.SpaceNode;
@@ -110,7 +113,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
    }
    }


    // Broadcast receiver to handle messages from our RecentsService
    // Broadcast receiver to handle messages from our RecentsService
    BroadcastReceiver mServiceBroadcastReceiver = new BroadcastReceiver() {
    final BroadcastReceiver mServiceBroadcastReceiver = new BroadcastReceiver() {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            String action = intent.getAction();
@@ -144,18 +147,29 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
                mRecentsView.startEnterRecentsAnimation(new ViewAnimation.TaskViewEnterContext(mFullScreenOverlayView));
                mRecentsView.startEnterRecentsAnimation(new ViewAnimation.TaskViewEnterContext(mFullScreenOverlayView));
                // Call our callback
                // Call our callback
                onEnterAnimationTriggered();
                onEnterAnimationTriggered();
            } else if (action.equals(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED)) {
                // Refresh the search widget
                refreshSearchWidget();
            }
            }
        }
        }
    };
    };


    // Broadcast receiver to handle messages from the system
    // Broadcast receiver to handle messages from the system
    BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
    final BroadcastReceiver mScreenOffReceiver = new BroadcastReceiver() {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            mFinishWithoutAnimationRunnable.run();
            mFinishWithoutAnimationRunnable.run();
        }
        }
    };
    };


    // Debug trigger
    final DebugTrigger mDebugTrigger = new DebugTrigger(new Runnable() {
        @Override
        public void run() {
            onDebugModeTriggered();
        }
    });

    /** Updates the set of recent tasks */
    /** Updates the set of recent tasks */
    void updateRecentsTasks(Intent launchIntent) {
    void updateRecentsTasks(Intent launchIntent) {
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
@@ -432,6 +446,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        filter.addAction(RecentsService.ACTION_HIDE_RECENTS_ACTIVITY);
        filter.addAction(RecentsService.ACTION_HIDE_RECENTS_ACTIVITY);
        filter.addAction(RecentsService.ACTION_TOGGLE_RECENTS_ACTIVITY);
        filter.addAction(RecentsService.ACTION_TOGGLE_RECENTS_ACTIVITY);
        filter.addAction(RecentsService.ACTION_START_ENTER_ANIMATION);
        filter.addAction(RecentsService.ACTION_START_ENTER_ANIMATION);
        filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
        registerReceiver(mServiceBroadcastReceiver, filter);
        registerReceiver(mServiceBroadcastReceiver, filter);


        // Register the broadcast receiver to handle messages when the screen is turned off
        // Register the broadcast receiver to handle messages when the screen is turned off
@@ -514,7 +529,8 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
            mRecentsView.focusNextTask(!backward);
            mRecentsView.focusNextTask(!backward);
            return true;
            return true;
        }
        }

        // Pass through the debug trigger
        mDebugTrigger.onKeyEvent(keyCode);
        return super.onKeyDown(keyCode, event);
        return super.onKeyDown(keyCode, event);
    }
    }


@@ -547,6 +563,23 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        }
        }
    }
    }


    /** Called when debug mode is triggered */
    public void onDebugModeTriggered() {
        if (mConfig.developerOptionsEnabled) {
            SharedPreferences settings = getSharedPreferences(getPackageName(), 0);
            if (settings.getBoolean(Constants.Values.App.Key_DebugModeEnabled, false)) {
                // Disable the debug mode
                settings.edit().remove(Constants.Values.App.Key_DebugModeEnabled).apply();
            } else {
                // Enable the debug mode
                settings.edit().putBoolean(Constants.Values.App.Key_DebugModeEnabled, true).apply();
            }
            Toast.makeText(this, "Debug mode (" + Constants.Values.App.DebugModeVersion +
                    ") toggled, please restart Recents now", Toast.LENGTH_SHORT).show();
        }
    }

    /** Called when the enter recents animation is triggered. */
    public void onEnterAnimationTriggered() {
    public void onEnterAnimationTriggered() {
        // Animate the scrims in
        // Animate the scrims in
        mScrimViews.startEnterRecentsAnimation();
        mScrimViews.startEnterRecentsAnimation();
+5 −1
Original line number Original line Diff line number Diff line
@@ -103,6 +103,7 @@ public class RecentsConfiguration {


    /** Dev options */
    /** Dev options */
    public boolean developerOptionsEnabled;
    public boolean developerOptionsEnabled;
    public boolean debugModeEnabled;


    /** Private constructor */
    /** Private constructor */
    private RecentsConfiguration(Context context) {
    private RecentsConfiguration(Context context) {
@@ -141,10 +142,14 @@ public class RecentsConfiguration {


    /** Updates the state, given the specified context */
    /** Updates the state, given the specified context */
    void update(Context context) {
    void update(Context context) {
        SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0);
        Resources res = context.getResources();
        Resources res = context.getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        DisplayMetrics dm = res.getDisplayMetrics();
        mDisplayMetrics = dm;
        mDisplayMetrics = dm;


        // Debug mode
        debugModeEnabled = settings.getBoolean(Constants.Values.App.Key_DebugModeEnabled, false);

        // Animations
        // Animations
        animationPxMovementPerSecond =
        animationPxMovementPerSecond =
                res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second);
                res.getDimensionPixelSize(R.dimen.recents_animation_movement_in_dps_per_second);
@@ -168,7 +173,6 @@ public class RecentsConfiguration {
        searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height);
        searchBarSpaceHeightPx = res.getDimensionPixelSize(R.dimen.recents_search_bar_space_height);


        // Update the search widget id
        // Update the search widget id
        SharedPreferences settings = context.getSharedPreferences(context.getPackageName(), 0);
        searchBarAppWidgetId = settings.getInt(Constants.Values.App.Key_SearchAppWidgetId, -1);
        searchBarAppWidgetId = settings.getInt(Constants.Values.App.Key_SearchAppWidgetId, -1);


        // Task stack
        // Task stack
+6 −6
Original line number Original line Diff line number Diff line
@@ -68,20 +68,20 @@ public class Utilities {
    }
    }


    /** Calculates the luminance-preserved greyscale of a given color. */
    /** Calculates the luminance-preserved greyscale of a given color. */
    private static int colorToGreyscale(int color) {
    public static int colorToGreyscale(int color) {
        return Math.round(0.2126f * Color.red(color) + 0.7152f * Color.green(color) +
        return Math.round(0.2126f * Color.red(color) + 0.7152f * Color.green(color) +
                0.0722f * Color.blue(color));
                0.0722f * Color.blue(color));
    }
    }


    /** Returns the ideal color to draw on top of a specified background color. */
    /** Returns the ideal color to draw on top of a specified background color. */
    public static int getIdealColorForBackgroundColor(int color, int lightRes, int darkRes) {
    public static int getIdealColorForBackgroundColorGreyscale(int greyscale, int lightRes,
        int greyscale = colorToGreyscale(color);
                                                               int darkRes) {
        return (greyscale < 128) ? lightRes : darkRes;
        return (greyscale < 128) ? lightRes : darkRes;
    }
    }
    /** Returns the ideal drawable to draw on top of a specified background color. */
    /** Returns the ideal drawable to draw on top of a specified background color. */
    public static Drawable getIdealResourceForBackgroundColor(int color, Drawable lightRes,
    public static Drawable getIdealResourceForBackgroundColorGreyscale(int greyscale,
                                                                       Drawable lightRes,
                                                                       Drawable darkRes) {
                                                                       Drawable darkRes) {
        int greyscale = colorToGreyscale(color);
        return (greyscale < 128) ? lightRes : darkRes;
        return (greyscale < 128) ? lightRes : darkRes;
    }
    }


Loading