summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/AddAdapter.java101
-rw-r--r--src/com/android/launcher3/Launcher.java47
-rw-r--r--src/com/android/launcher3/LauncherProvider.java125
-rw-r--r--src/com/android/launcher3/compat/LauncherActivityInfoCompatV16.java6
4 files changed, 114 insertions, 165 deletions
diff --git a/src/com/android/launcher3/AddAdapter.java b/src/com/android/launcher3/AddAdapter.java
deleted file mode 100644
index 5308a3de4..000000000
--- a/src/com/android/launcher3/AddAdapter.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 2008 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.launcher3;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseAdapter;
-import android.widget.TextView;
-
-import java.util.ArrayList;
-
-/**
- * Adapter showing the types of items that can be added to a {@link Workspace}.
- */
-public class AddAdapter extends BaseAdapter {
-
- private final LayoutInflater mInflater;
-
- private final ArrayList<ListItem> mItems = new ArrayList<ListItem>();
-
- public static final int ITEM_SHORTCUT = 0;
- public static final int ITEM_APPWIDGET = 1;
- public static final int ITEM_APPLICATION = 2;
- public static final int ITEM_WALLPAPER = 3;
-
- /**
- * Specific item in our list.
- */
- public class ListItem {
- public final CharSequence text;
- public final Drawable image;
- public final int actionTag;
-
- public ListItem(Resources res, int textResourceId, int imageResourceId, int actionTag) {
- text = res.getString(textResourceId);
- if (imageResourceId != -1) {
- image = res.getDrawable(imageResourceId);
- } else {
- image = null;
- }
- this.actionTag = actionTag;
- }
- }
-
- public AddAdapter(Launcher launcher) {
- super();
-
- mInflater = (LayoutInflater) launcher.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
- // Create default actions
- Resources res = launcher.getResources();
-
- mItems.add(new ListItem(res, R.string.group_wallpapers,
- R.mipmap.ic_launcher_wallpaper, ITEM_WALLPAPER));
- }
-
- public View getView(int position, View convertView, ViewGroup parent) {
- ListItem item = (ListItem) getItem(position);
-
- if (convertView == null) {
- convertView = mInflater.inflate(R.layout.add_list_item, parent, false);
- }
-
- TextView textView = (TextView) convertView;
- textView.setTag(item);
- textView.setText(item.text);
- textView.setCompoundDrawablesWithIntrinsicBounds(item.image, null, null, null);
-
- return convertView;
- }
-
- public int getCount() {
- return mItems.size();
- }
-
- public Object getItem(int position) {
- return mItems.get(position);
- }
-
- public long getItemId(int position) {
- return position;
- }
-}
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index e154e57e0..0044d7ae6 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -24,6 +24,7 @@ import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
+import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityOptions;
@@ -79,6 +80,7 @@ import android.view.Menu;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
+import android.view.Window;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
@@ -108,6 +110,9 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
@@ -1625,10 +1630,52 @@ public class Launcher extends Activity
}
registerReceiver(mReceiver, filter);
FirstFrameAnimatorHelper.initializeDrawListener(getWindow().getDecorView());
+ setupTransparentSystemBarsForLmp();
mAttached = true;
mVisible = true;
}
+ /**
+ * Sets up transparent navigation and status bars in LMP.
+ * This method is a no-op for other platform versions.
+ */
+ @TargetApi(19)
+ private void setupTransparentSystemBarsForLmp() {
+ // TODO(sansid): use the APIs directly when compiling against L sdk.
+ // Currently we use reflection to access the flags and the API to set the transparency
+ // on the System bars.
+ if (Utilities.isLmp()) {
+ try {
+ getWindow().getAttributes().systemUiVisibility |=
+ (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
+ | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
+ Field drawsSysBackgroundsField = WindowManager.LayoutParams.class.getField(
+ "FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS");
+ getWindow().addFlags(drawsSysBackgroundsField.getInt(null));
+
+ Method setStatusBarColorMethod =
+ Window.class.getDeclaredMethod("setStatusBarColor", int.class);
+ Method setNavigationBarColorMethod =
+ Window.class.getDeclaredMethod("setNavigationBarColor", int.class);
+ setStatusBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
+ setNavigationBarColorMethod.invoke(getWindow(), Color.TRANSPARENT);
+ } catch (NoSuchFieldException e) {
+ Log.w(TAG, "NoSuchFieldException while setting up transparent bars");
+ } catch (NoSuchMethodException ex) {
+ Log.w(TAG, "NoSuchMethodException while setting up transparent bars");
+ } catch (IllegalAccessException e) {
+ Log.w(TAG, "IllegalAccessException while setting up transparent bars");
+ } catch (IllegalArgumentException e) {
+ Log.w(TAG, "IllegalArgumentException while setting up transparent bars");
+ } catch (InvocationTargetException e) {
+ Log.w(TAG, "InvocationTargetException while setting up transparent bars");
+ } finally {}
+ }
+ }
+
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index bbc75b8c9..2256179c3 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -310,10 +310,21 @@ public class LauncherProvider extends ContentProvider {
if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {
Log.d(TAG, "loading default workspace");
+ // By default we use our resources
+ Resources res = getContext().getResources();
int workspaceResId = origWorkspaceResId;
// Use default workspace resource if none provided
if (workspaceResId == 0) {
+ final Partner partner = Partner.get(getContext().getPackageManager());
+ if (partner != null && partner.hasDefaultLayout()) {
+ final Resources partnerRes = partner.getResources();
+ workspaceResId = partnerRes.getIdentifier(Partner.RESOURCE_DEFAULT_LAYOUT,
+ "xml", partner.getPackageName());
+ res = partnerRes;
+ }
+ }
+ if (workspaceResId == 0) {
workspaceResId =
sp.getInt(DEFAULT_WORKSPACE_RESOURCE_ID, getDefaultWorkspaceResourceId());
}
@@ -325,7 +336,7 @@ public class LauncherProvider extends ContentProvider {
editor.putInt(DEFAULT_WORKSPACE_RESOURCE_ID, origWorkspaceResId);
}
- mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), workspaceResId);
+ mOpenHelper.loadFavorites(mOpenHelper.getWritableDatabase(), res, workspaceResId);
editor.commit();
}
}
@@ -380,11 +391,25 @@ public class LauncherProvider extends ContentProvider {
private static final String TAG_EXTRA = "extra";
private static final String TAG_INCLUDE = "include";
- private static final String ATTR_TITLE = "title";
+ // Style attrs -- "Favorite"
+ private static final String ATTR_CLASS_NAME = "className";
+ private static final String ATTR_PACKAGE_NAME = "packageName";
+ private static final String ATTR_CONTAINER = "container";
+ private static final String ATTR_SCREEN = "screen";
+ private static final String ATTR_X = "x";
+ private static final String ATTR_Y = "y";
+ private static final String ATTR_SPAN_X = "spanX";
+ private static final String ATTR_SPAN_Y = "spanY";
private static final String ATTR_ICON = "icon";
+ private static final String ATTR_TITLE = "title";
private static final String ATTR_URI = "uri";
- private static final String ATTR_PACKAGE_NAME = "packageName";
- private static final String ATTR_CLASS_NAME = "className";
+
+ // Style attrs -- "Include"
+ private static final String ATTR_WORKSPACE = "workspace";
+
+ // Style attrs -- "Extra"
+ private static final String ATTR_KEY = "key";
+ private static final String ATTR_VALUE = "value";
private final Context mContext;
private final PackageManager mPackageManager;
@@ -753,7 +778,7 @@ public class LauncherProvider extends ContentProvider {
}
// Add default hotseat icons
- loadFavorites(db, R.xml.update_workspace);
+ loadFavorites(db, mContext.getResources(), R.xml.update_workspace);
version = 9;
}
@@ -1244,9 +1269,9 @@ public class LauncherProvider extends ContentProvider {
return intent;
}
- private int loadFavorites(SQLiteDatabase db, int workspaceResourceId) {
+ private int loadFavorites(SQLiteDatabase db, Resources res, int workspaceResourceId) {
ArrayList<Long> screenIds = new ArrayList<Long>();
- int count = loadFavoritesRecursive(db, workspaceResourceId, screenIds);
+ int count = loadFavoritesRecursive(db, res, workspaceResourceId, screenIds);
// Add the screens specified by the items above
Collections.sort(screenIds);
@@ -1276,18 +1301,15 @@ public class LauncherProvider extends ContentProvider {
* @param filterContainerId The specific container id of items to load
* @param the set of screenIds which are used by the favorites
*/
- private int loadFavoritesRecursive(SQLiteDatabase db, int workspaceResourceId,
+ private int loadFavoritesRecursive(SQLiteDatabase db, Resources res, int workspaceResourceId,
ArrayList<Long> screenIds) {
-
-
ContentValues values = new ContentValues();
if (LOGD) Log.v(TAG, String.format("Loading favorites from resid=0x%08x", workspaceResourceId));
int count = 0;
try {
- XmlResourceParser parser = mContext.getResources().getXml(workspaceResourceId);
- AttributeSet attrs = Xml.asAttributeSet(parser);
+ XmlResourceParser parser = res.getXml(workspaceResourceId);
beginDocument(parser, TAG_FAVORITES);
final int depth = parser.getDepth();
@@ -1304,38 +1326,34 @@ public class LauncherProvider extends ContentProvider {
final String name = parser.getName();
if (TAG_INCLUDE.equals(name)) {
- final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.Include);
- final int resId = a.getResourceId(R.styleable.Include_workspace, 0);
+ final int resId = getAttributeResourceValue(parser, ATTR_WORKSPACE, 0);
if (LOGD) Log.v(TAG, String.format(("%" + (2*(depth+1)) + "s<include workspace=%08x>"),
"", resId));
if (resId != 0 && resId != workspaceResourceId) {
// recursively load some more favorites, why not?
- count += loadFavoritesRecursive(db, resId, screenIds);
+ count += loadFavoritesRecursive(db, res, resId, screenIds);
added = false;
} else {
Log.w(TAG, String.format("Skipping <include workspace=0x%08x>", resId));
}
- a.recycle();
-
if (LOGD) Log.v(TAG, String.format(("%" + (2*(depth+1)) + "s</include>"), ""));
continue;
}
// Assuming it's a <favorite> at this point
- TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.Favorite);
-
long container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
- if (a.hasValue(R.styleable.Favorite_container)) {
- container = Long.valueOf(a.getString(R.styleable.Favorite_container));
+ String strContainer = getAttributeValue(parser, ATTR_CONTAINER);
+ if (strContainer != null) {
+ container = Long.valueOf(strContainer);
}
- String screen = a.getString(R.styleable.Favorite_screen);
- String x = a.getString(R.styleable.Favorite_x);
- String y = a.getString(R.styleable.Favorite_y);
+ String screen = getAttributeValue(parser, ATTR_SCREEN);
+ String x = getAttributeValue(parser, ATTR_X);
+ String y = getAttributeValue(parser, ATTR_Y);
values.clear();
values.put(LauncherSettings.Favorites.CONTAINER, container);
@@ -1344,8 +1362,8 @@ public class LauncherProvider extends ContentProvider {
values.put(LauncherSettings.Favorites.CELLY, y);
if (LOGD) {
- final String title = a.getString(R.styleable.Favorite_title);
- final String pkg = a.getString(R.styleable.Favorite_packageName);
+ final String title = getAttributeValue(parser, ATTR_TITLE);
+ final String pkg = getAttributeValue(parser, ATTR_PACKAGE_NAME);
final String something = title != null ? title : pkg;
Log.v(TAG, String.format(
("%" + (2*(depth+1)) + "s<%s%s c=%d s=%s x=%s y=%s>"),
@@ -1357,14 +1375,10 @@ public class LauncherProvider extends ContentProvider {
if (TAG_FAVORITE.equals(name)) {
long id = addAppShortcut(db, values, parser);
added = id >= 0;
- } else if (TAG_SEARCH.equals(name)) {
- added = addSearchWidget(db, values);
- } else if (TAG_CLOCK.equals(name)) {
- added = addClockWidget(db, values);
} else if (TAG_APPWIDGET.equals(name)) {
- added = addAppWidget(parser, attrs, type, db, values, a);
+ added = addAppWidget(parser, type, db, values);
} else if (TAG_SHORTCUT.equals(name)) {
- long id = addUriShortcut(db, values, mContext.getResources(), parser);
+ long id = addUriShortcut(db, values, res, parser);
added = id >= 0;
} else if (TAG_RESOLVE.equals(name)) {
// This looks through the contained favorites (or meta-favorites) and
@@ -1378,18 +1392,15 @@ public class LauncherProvider extends ContentProvider {
continue;
}
final String fallback_item_name = parser.getName();
- final TypedArray ar = mContext.obtainStyledAttributes(attrs,
- R.styleable.Favorite);
if (!added) {
if (TAG_FAVORITE.equals(fallback_item_name)) {
final long id = addAppShortcut(db, values, parser);
added = id >= 0;
} else {
- Log.e(TAG, "Fallback groups can contain only favorites "
- + ar.toString());
+ Log.e(TAG, "Fallback groups can contain only favorites, found "
+ + fallback_item_name);
}
}
- ar.recycle();
}
} else if (TAG_FOLDER.equals(name)) {
// Folder contents are nested in this XML file
@@ -1418,7 +1429,6 @@ public class LauncherProvider extends ContentProvider {
}
count++;
}
- a.recycle();
}
} catch (XmlPullParserException e) {
Log.w(TAG, "Got exception parsing favorites.", e);
@@ -1681,23 +1691,12 @@ public class LauncherProvider extends ContentProvider {
return null;
}
- private boolean addSearchWidget(SQLiteDatabase db, ContentValues values) {
- ComponentName cn = getSearchWidgetProvider();
- return addAppWidget(db, values, cn, 4, 1, null);
- }
-
- private boolean addClockWidget(SQLiteDatabase db, ContentValues values) {
- ComponentName cn = new ComponentName("com.android.alarmclock",
- "com.android.alarmclock.AnalogAppWidgetProvider");
- return addAppWidget(db, values, cn, 2, 2, null);
- }
-
- private boolean addAppWidget(XmlResourceParser parser, AttributeSet attrs, int type,
- SQLiteDatabase db, ContentValues values, TypedArray a)
+ private boolean addAppWidget(XmlResourceParser parser, int type,
+ SQLiteDatabase db, ContentValues values)
throws XmlPullParserException, IOException {
- String packageName = a.getString(R.styleable.Favorite_packageName);
- String className = a.getString(R.styleable.Favorite_className);
+ String packageName = getAttributeValue(parser, ATTR_PACKAGE_NAME);
+ String className = getAttributeValue(parser, ATTR_CLASS_NAME);
if (packageName == null || className == null) {
return false;
@@ -1714,13 +1713,17 @@ public class LauncherProvider extends ContentProvider {
try {
mPackageManager.getReceiverInfo(cn, 0);
} catch (Exception e1) {
+ System.out.println("Can't find widget provider: " + className);
hasPackage = false;
}
}
if (hasPackage) {
- int spanX = a.getInt(R.styleable.Favorite_spanX, 0);
- int spanY = a.getInt(R.styleable.Favorite_spanY, 0);
+ String spanX = getAttributeValue(parser, ATTR_SPAN_X);
+ String spanY = getAttributeValue(parser, ATTR_SPAN_Y);
+
+ values.put(Favorites.SPANX, spanX);
+ values.put(Favorites.SPANY, spanY);
// Read the extras
Bundle extras = new Bundle();
@@ -1731,10 +1734,9 @@ public class LauncherProvider extends ContentProvider {
continue;
}
- TypedArray ar = mContext.obtainStyledAttributes(attrs, R.styleable.Extra);
if (TAG_EXTRA.equals(parser.getName())) {
- String key = ar.getString(R.styleable.Extra_key);
- String value = ar.getString(R.styleable.Extra_value);
+ String key = getAttributeValue(parser, ATTR_KEY);
+ String value = getAttributeValue(parser, ATTR_VALUE);
if (key != null && value != null) {
extras.putString(key, value);
} else {
@@ -1743,16 +1745,15 @@ public class LauncherProvider extends ContentProvider {
} else {
throw new RuntimeException("Widgets can contain only extras");
}
- ar.recycle();
}
- return addAppWidget(db, values, cn, spanX, spanY, extras);
+ return addAppWidget(db, values, cn, extras);
}
return false;
}
private boolean addAppWidget(SQLiteDatabase db, ContentValues values, ComponentName cn,
- int spanX, int spanY, Bundle extras) {
+ Bundle extras) {
boolean allocatedAppWidgets = false;
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
@@ -1760,8 +1761,6 @@ public class LauncherProvider extends ContentProvider {
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET);
- values.put(Favorites.SPANX, spanX);
- values.put(Favorites.SPANY, spanY);
values.put(Favorites.APPWIDGET_ID, appWidgetId);
values.put(Favorites.APPWIDGET_PROVIDER, cn.flattenToString());
values.put(Favorites._ID, generateNewItemId());
diff --git a/src/com/android/launcher3/compat/LauncherActivityInfoCompatV16.java b/src/com/android/launcher3/compat/LauncherActivityInfoCompatV16.java
index 9b9384d83..052d4343e 100644
--- a/src/com/android/launcher3/compat/LauncherActivityInfoCompatV16.java
+++ b/src/com/android/launcher3/compat/LauncherActivityInfoCompatV16.java
@@ -61,7 +61,11 @@ public class LauncherActivityInfoCompatV16 extends LauncherActivityInfoCompat {
resources = null;
}
if (resources != null) {
- d = resources.getDrawableForDensity(mActivityInfo.getIconResource(), density);
+ try {
+ d = resources.getDrawableForDensity(mActivityInfo.getIconResource(), density);
+ } catch (Resources.NotFoundException e) {
+ // Return default icon below.
+ }
}
}
if (d == null) {