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

Commit 827cef20 authored by Tony Wickham's avatar Tony Wickham
Browse files

Added ColorExtractionService and ExtractedColors.

- Launcher has an instance of ExtractedColors, which is loaded from
  LauncherProvider in onCreate() and whenever the wallpaper changes.
  - When the wallpaper changes, the ColorExtractionService is started
    in the :wallpaper-chooser process.
  - ColorExtractionService builds an ExtractedColors instance and saves
    it as a String in LauncherProvider.
  - When the results are saved, Launcher gets a callback through
    LauncherProviderChangeListener and reloads the ExtractedColors.
- Whenever Launcher loads Extractecolors, it also re-colors items
  (currently a no-op).

Change-Id: I319e2cfe0a86abcbc6bb39ef6b9fbbcad54ad743
parent 855b1b5f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -141,6 +141,11 @@
            </intent-filter>
        </receiver>

        <service android:name=".dynamicui.ColorExtractionService"
            android:exported="false"
            android:process=":wallpaper_chooser">
        </service>

        <!-- The settings provider contains Home's data, like the workspace favorites -->
        <provider
            android:name="com.android.launcher3.LauncherProvider"
+2 −0
Original line number Diff line number Diff line
@@ -52,12 +52,14 @@ repositories {
dependencies {
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:palette-v7:23.2.0'
    compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2'
    compile project(":WallpaperPicker-Lib")

    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
    androidTestCompile 'com.android.support:support-annotations:23.2.0'
}

protobuf {
+17 −0
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.logging.LoggerUtils;
@@ -279,6 +280,7 @@ public class Launcher extends Activity

    private LauncherModel mModel;
    private IconCache mIconCache;
    private ExtractedColors mExtractedColors;
    @Thunk boolean mUserPresent = true;
    private boolean mVisible = false;
    private boolean mHasFocus = false;
@@ -447,6 +449,8 @@ public class Launcher extends Activity
        app.getInvariantDeviceProfile().portraitProfile.setSearchBarHeight(getSearchBarHeight());
        setupViews();
        mDeviceProfile.layout(this);
        mExtractedColors = new ExtractedColors();
        loadExtractedColorsAndColorItems();

        lockAllApps();

@@ -509,6 +513,19 @@ public class Launcher extends Activity
        }
    }

    @Override
    public void onExtractedColorsChanged() {
        loadExtractedColorsAndColorItems();
    }

    private void loadExtractedColorsAndColorItems() {
        if (mExtractedColors != null) {
            mExtractedColors.load(this);
            // TODO: pass mExtractedColors to interested items such as hotseat.
            mHotseat.setBackgroundColor(mExtractedColors.getColor(ExtractedColors.VIBRANT_INDEX));
        }
    }

    private LauncherCallbacks mLauncherCallbacks;

    public void onPostCreate(Bundle savedInstanceState) {
+8 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.util.ConfigMonitor;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Thunk;
@@ -108,6 +109,11 @@ public class LauncherAppState {
        filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
        filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
        filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_AVAILABILITY_CHANGED);
        // For extracting colors from the wallpaper
        if (Utilities.isNycOrAbove()) {
            // TODO: add a broadcast entry to the manifest for pre-N.
            filter.addAction(Intent.ACTION_WALLPAPER_CHANGED);
        }

        sContext.registerReceiver(mModel, filter);
        UserManagerCompat.getInstance(sContext).enableAndResetCache();
@@ -121,6 +127,8 @@ public class LauncherAppState {
            }, new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
        }
        new ConfigMonitor(sContext).register();

        ExtractionUtils.startColorExtractionServiceIfNecessary(sContext);
    }

    /**
+3 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
import com.android.launcher3.compat.UserHandleCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.ProviderConfig;
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.model.GridSizeMigrationTask;
@@ -1237,6 +1238,8 @@ public class LauncherModel extends BroadcastReceiver
                        PackageUpdatedTask.OP_USER_AVAILABILITY_CHANGE,
                        new String[0], user));
            }
        } else if (Intent.ACTION_WALLPAPER_CHANGED.equals(action)) {
            ExtractionUtils.startColorExtractionServiceIfNecessary(context);
        }
    }

Loading