summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2014-02-24 01:04:33 +0100
committerMatt Garnes <matt@cyngn.com>2014-06-17 17:38:02 -0700
commit56db21e5af4c17f9308ceb07b0f3ab651743b5cd (patch)
tree03d9c1b1a761c78a277d888b3698ece86826df07 /src/com/android
parentcf43a17640a7eede4106670f97e0834b5ea0f976 (diff)
downloadandroid_packages_apps_Trebuchet-56db21e5af4c17f9308ceb07b0f3ab651743b5cd.tar.gz
android_packages_apps_Trebuchet-56db21e5af4c17f9308ceb07b0f3ab651743b5cd.tar.bz2
android_packages_apps_Trebuchet-56db21e5af4c17f9308ceb07b0f3ab651743b5cd.zip
trebuchet: custom home
Change-Id: I4faee66580ab0e41ee8e8bcbd79ce680d45bce97 Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/launcher/home/Home.java201
-rw-r--r--src/com/android/launcher3/Launcher.java44
-rw-r--r--src/com/android/launcher3/settings/SettingsProvider.java2
3 files changed, 245 insertions, 2 deletions
diff --git a/src/com/android/launcher/home/Home.java b/src/com/android/launcher/home/Home.java
new file mode 100644
index 000000000..5dce71e86
--- /dev/null
+++ b/src/com/android/launcher/home/Home.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2014 The CyanogenMod 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.launcher.home;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup.LayoutParams;
+
+/**
+ * The generic contract that should supports a <code>Home</code> app to could
+ * be invoked and registered by an Android launcher.<br/>
+ * <br/>
+ * This interface contains the version 1 of the <code>Home Host App</code> protocol.<br/>
+ * <br/>
+ * <br/>
+ * A <code>Home</code> app should:
+ * <ul>
+ * <li>
+ * should have at least a constructor with no arguments
+ * </li>
+ * <li>
+ * declares inside its manifest a <code>com.android.launcher.home</code> metadata with the
+ * full qualified that contains this interface<br/>
+ * <pre>
+ * &lt;meta-data android:name="com.android.launcher.home" value="org.cyanogenmod.launcher.home.HomeStub"/&gt;
+ * </pre>
+ * </li>
+ * <li>
+ * define the "com.android.launcher.home.permissions.HOME_APP" permission<br/>
+ * <pre>
+ * &lt;uses-permission android:name="com.android.launcher.home.permissions.HOME_APP"/&gt;
+ * </pre>
+ * </li>
+ * <li>
+ * implements the contract defined by this protocol.
+ * </li>
+ * </ul>
+ * <br/>
+ * Implementors classes of this protocol should be aware that all the {@link Context} references
+ * passed to this class owns to the host launcher app. This means that you cannot access
+ * to settings defined by the <code>Home</code> app inside its shared context.
+ */
+public interface Home {
+
+ /**
+ * A SHA-1 hash of all declared method of this interface. Home apps should compute as:<br/>
+ * <br/>
+ * <pre>
+ * for method in Home.class.getDeclaredMehod
+ * sha1.update method.toString.bytes
+ * </pre><br/>
+ * DO NOT MODIFY!
+ */
+ public static final String SIGNATURE = "5/A6Mxkz8gHHzzVf4qZR+hiSOAw=";
+
+ /**
+ * Defines the name of the metadata used to declared the full qualified Home stub class
+ * that implements this protocol.
+ */
+ public static final String METADATA_HOME_STUB = "com.android.launcher.home";
+
+ /**
+ * Defines the name of the permission that the Home app should explicitly declare.
+ */
+ public static final String PERMISSION_HOME_APP = "com.android.launcher.home.permissions.HOME_APP";
+
+ // Notification flags
+ public static final int FLAG_NOTIFY_MASK = 0x0000;
+ public static final int FLAG_NOTIFY_ON_RESUME = FLAG_NOTIFY_MASK + 0x0002;
+ public static final int FLAG_NOTIFY_ON_PAUSE = FLAG_NOTIFY_MASK + 0x0004;
+ public static final int FLAG_NOTIFY_ON_SHOW = FLAG_NOTIFY_MASK + 0x0008;
+ public static final int FLAG_NOTIFY_ON_SCROLL_PROGRESS_CHANGED = FLAG_NOTIFY_MASK + 0x0010;
+ public static final int FLAG_NOTIFY_ON_HIDE = FLAG_NOTIFY_MASK + 0x0020;
+ public static final int FLAG_NOTIFY_ALL = FLAG_NOTIFY_ON_RESUME | FLAG_NOTIFY_ON_PAUSE |
+ FLAG_NOTIFY_ON_SHOW | FLAG_NOTIFY_ON_SCROLL_PROGRESS_CHANGED | FLAG_NOTIFY_ON_HIDE;
+
+ // Operation support flags
+ public static final int FLAG_OP_MASK = 0x1000;
+ public static final int FLAG_OP_CUSTOM_SEARCH = FLAG_OP_MASK + 0x0002;
+ public static final int FLAG_OP_ALL = FLAG_OP_CUSTOM_SEARCH;
+
+ // Search modes
+ public static final int MODE_SEARCH_TEXT = 0x0000;
+ public static final int MODE_SEARCH_VOICE = 0x0001;
+
+ /**
+ * Invoked the first time the <code>Home</code> app is created.<br/>
+ * This method should be used by implementors classes of this protocol to load the needed
+ * resources.
+ * @param context the current {@link Context} of the host launcher.
+ */
+ void onStart(Context context);
+
+ /**
+ * Invoked when the <code>Home</code> app should be destroy.<br/>
+ * This method should be used by implementors classes of this protocol to unload all unneeded
+ * resources.
+ * @param context the current {@link Context} of the host launcher.
+ */
+ void onDestroy(Context context);
+
+ /**
+ * Invoked when the host launcher enters in resume mode.
+ * @param context the current {@link Context} of the host launcher.
+ */
+ void onResume(Context context);
+
+ /**
+ * Invoked when the host launcher enters in pause mode.
+ * @param context the current {@link Context} of the host launcher.
+ */
+ void onPause(Context context);
+
+ /**
+ * Invoked when the custom content page is totally displayed.
+ * @param context the current {@link Context} of the host launcher.
+ */
+ void onShow(Context context);
+
+ /**
+ * Invoked when the custom content page is scrolled.
+ * @param context the current {@link Context} of the host launcher.
+ * @param progress the current scroll progress.
+ */
+ void onScrollProgressChanged(Context context, float progress);
+
+ /**
+ * Invoked when the custom content page is totally hidden.
+ * @param context the current {@link Context} of the host launcher.
+ */
+ void onHide(Context context);
+
+ /**
+ * Invoked by the host launcher to request an invalidation of the ui elements and data used by
+ * the <code>Home</code> implementation class.
+ * @param context the current {@link Context} of the host launcher.
+ */
+ void onInvalidate(Context context);
+
+ /**
+ * Invoked when the host launcher request enter in search mode.
+ * @param context the current {@link Context} of the host launcher.
+ * @param mode the requested search mode. Must be one of:
+ * <ul>
+ * <li>{@link #MODE_SEARCH_TEXT}: Textual mode</li>
+ * <li>{@link #MODE_SEARCH_VOICE}: Voice mode</li>
+ * </ul>
+ */
+ void onRequestSearch(Context context, int mode);
+
+ /**
+ * Returns an instance of a {@link View} that holds the custom content to be displayed
+ * by this <code>Home</code> app.
+ * @param context the current {@link Context} of the host launcher.
+ * @return View The custom content view that will be enclosed inside a
+ * <code>com.android.launcher3.Launcher.QSBScroller</code>.<br/>
+ * Be aware the the height layout of the returned should be defined as
+ * {link {@link LayoutParams#WRAP_CONTENT}, so the view could be scrolled inside the
+ * custom content page.
+ */
+ View createCustomView(Context context);
+
+ /**
+ * Returns the name of the Home app (LIMIT: 30 characters).
+ * @param context the current {@link Context} of the host launcher.
+ */
+ String getName(Context context);
+
+ /**
+ * Implementations should return the combination of notification flags that want to listen to.
+ * @see #FLAG_NOTIFY_ON_RESUME
+ * @see #FLAG_NOTIFY_ON_PAUSE
+ * @see #FLAG_NOTIFY_ON_SHOW
+ * @see #FLAG_NOTIFY_ON_SCROLL_PROGRESS_CHANGED
+ * @see #FLAG_NOTIFY_ON_HIDE
+ * @see #FLAG_NOTIFY_ALL
+ */
+ int getNotificationFlags();
+
+ /**
+ * Implementations should return the combination of operation flags that want they want
+ * to support to.
+ * @see #FLAG_OP_CUSTOM_SEARCH
+ * @see #FLAG_OP_ALL
+ */
+ int getOperationFlags();
+}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index d58170a2a..2947eda0f 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -56,6 +56,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
@@ -99,6 +100,7 @@ import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
+import com.android.launcher.home.Home;
import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.PagedView.TransitionEffect;
import com.android.launcher3.settings.SettingsProvider;
@@ -289,6 +291,9 @@ public class Launcher extends Activity
private AppsCustomizePagedView mAppsCustomizeContent;
private boolean mAutoAdvanceRunning = false;
private View mQsb;
+ private View mQsbBar;
+ private ImageView mQsbBarSearch;
+ private ImageView mQsbBarVoice;
private Bundle mSavedState;
// We set the state in both onCreate and then onNewIntent in some cases, which causes both
@@ -578,6 +583,10 @@ public class Launcher extends Activity
}
/** To be overridden by subclasses to hint to Launcher that we have custom content */
+ protected boolean hasCustomSearchSupport() {
+ return false;
+ }
+
protected boolean hasCustomContentToLeft() {
return isGelIntegrationSupported() && isGelIntegrationEnabled();
}
@@ -652,6 +661,15 @@ public class Launcher extends Activity
}
}
+ /** To be overriden by subclasses to hint to Launcher that we have custom content and
+ * support {@link #hasCustomSearchSupport()}
+ * @see com.android.launcher.home.Home#MODE_SEARCH_TEXT
+ * @see com.android.launcher.home.Home#MODE_SEARCH_VOICE
+ * */
+ protected void requestSearch(int mode) {
+ // To be implemented
+ }
+
private void updateGlobalIcons() {
boolean searchVisible = false;
boolean voiceVisible = false;
@@ -2739,8 +2757,12 @@ public class Launcher extends Activity
* @param v The view that was clicked.
*/
public void onClickSearchButton(View v) {
- v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
+ if (hasCustomSearchSupport()) {
+ requestSearch(Home.MODE_SEARCH_TEXT);
+ return;
+ }
+ v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
onSearchRequested();
}
@@ -2750,8 +2772,12 @@ public class Launcher extends Activity
* @param v The view that was clicked.
*/
public void onClickVoiceButton(View v) {
- v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
+ if (hasCustomSearchSupport()) {
+ requestSearch(Home.MODE_SEARCH_VOICE);
+ return;
+ }
+ v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
startVoice();
}
@@ -3825,6 +3851,20 @@ public class Launcher extends Activity
return mQsb;
}
+ public ImageView getQsbBarSearchButton() {
+ if (mQsbBarSearch == null && getQsbBar() != null) {
+ return (ImageView) getQsbBar().findViewById(R.id.search_button);
+ }
+ return mQsbBarSearch;
+ }
+
+ public ImageView getQsbBarVoiceButton() {
+ if (mQsbBarVoice == null && getQsbBar() != null) {
+ return (ImageView) getQsbBar().findViewById(R.id.voice_button);
+ }
+ return mQsbBarVoice;
+ }
+
protected boolean updateGlobalSearchIcon() {
final View searchButtonContainer = findViewById(R.id.search_button_container);
final ImageView searchButton = (ImageView) findViewById(R.id.search_button);
diff --git a/src/com/android/launcher3/settings/SettingsProvider.java b/src/com/android/launcher3/settings/SettingsProvider.java
index 52c30440e..d7782b2e6 100644
--- a/src/com/android/launcher3/settings/SettingsProvider.java
+++ b/src/com/android/launcher3/settings/SettingsProvider.java
@@ -40,6 +40,8 @@ public final class SettingsProvider {
public static final String SETTINGS_UI_GENERAL_ICONS_LARGE = "ui_general_icons_large";
public static final String SETTINGS_UI_DRAWER_SORT_MODE = "ui_drawer_sort_mode";
+ public static final String SETTINGS_HOME_LAST_APP = "home_last_app";
+
public static SharedPreferences get(Context context) {
return context.getSharedPreferences(SETTINGS_KEY, Context.MODE_MULTI_PROCESS);
}