summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/AllApps2D.java348
-rw-r--r--src/com/android/launcher2/AllApps3D.java1488
-rw-r--r--src/com/android/launcher2/AllAppsBackground.java53
-rw-r--r--src/com/android/launcher2/AllAppsPagedView.java709
-rw-r--r--src/com/android/launcher2/AllAppsTabbed.java286
-rw-r--r--src/com/android/launcher2/ApplicationInfoDropTarget.java171
-rw-r--r--src/com/android/launcher2/AppsCustomizePagedView.java80
-rw-r--r--src/com/android/launcher2/CustomizePagedView.java1275
-rw-r--r--src/com/android/launcher2/CustomizeTrayTabHost.java211
-rw-r--r--src/com/android/launcher2/DeleteZone.java270
-rw-r--r--src/com/android/launcher2/IconDropTarget.java136
-rw-r--r--src/com/android/launcher2/Launcher.java1
-rw-r--r--src/com/android/launcher2/PagedView.java8
-rw-r--r--src/com/android/launcher2/PagedViewExtendedLayout.java121
-rw-r--r--src/com/android/launcher2/PagedViewWidget.java17
-rw-r--r--src/com/android/launcher2/allapps.rs385
16 files changed, 28 insertions, 5531 deletions
diff --git a/src/com/android/launcher2/AllApps2D.java b/src/com/android/launcher2/AllApps2D.java
deleted file mode 100644
index 4547f54..0000000
--- a/src/com/android/launcher2/AllApps2D.java
+++ /dev/null
@@ -1,348 +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.launcher2;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.animation.AnimationUtils;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.GridView;
-import android.widget.ImageButton;
-import android.widget.RelativeLayout;
-import android.widget.TextView;
-
-import com.android.launcher.R;
-import com.android.launcher2.DropTarget.DragObject;
-
-import java.util.ArrayList;
-import java.util.Collections;
-
-public class AllApps2D
- extends RelativeLayout
- implements AllAppsView,
- AdapterView.OnItemClickListener,
- AdapterView.OnItemLongClickListener,
- View.OnKeyListener,
- DragSource {
-
- private static final String TAG = "Launcher.AllApps2D";
- private static final boolean DEBUG = false;
-
- private Launcher mLauncher;
- private DragController mDragController;
-
- private GridView mGrid;
-
- /** All applications in the system (we might only be showing a subset) */
- private ArrayList<ApplicationInfo> mAllAppsList = new ArrayList<ApplicationInfo>();
-
- /** Currently visible applications in the grid */
- private ArrayList<ApplicationInfo> mVisibleAppsList = new ArrayList<ApplicationInfo>();
-
- public enum AppType { APP, GAME, DOWNLOADED, ALL };
-
- private AppType mCurrentFilter = AppType.ALL;
-
- // preserve compatibility with 3D all apps:
- // 0.0 -> hidden
- // 1.0 -> shown and opaque
- // intermediate values -> partially shown & partially opaque
- private float mZoom;
-
- private AppsAdapter mAppsAdapter;
-
- // ------------------------------------------------------------
-
- public static class HomeButton extends ImageButton {
- public HomeButton(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- @Override
- public View focusSearch(int direction) {
- if (direction == FOCUS_UP) return super.focusSearch(direction);
- return null;
- }
- }
-
- public class AppsAdapter extends ArrayAdapter<ApplicationInfo> {
- private final LayoutInflater mInflater;
-
- public AppsAdapter(Context context, ArrayList<ApplicationInfo> apps) {
- super(context, 0, apps);
- mInflater = LayoutInflater.from(context);
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- final ApplicationInfo info = getItem(position);
-
- if (convertView == null) {
- convertView = mInflater.inflate(R.layout.application_boxed, parent, false);
- }
-
-// if (!info.filtered) {
-// info.icon = Utilities.createIconThumbnail(info.icon, getContext());
-// info.filtered = true;
-// }
-
- final TextView textView = (TextView) convertView;
- if (DEBUG) {
- Log.d(TAG, "icon bitmap = " + info.iconBitmap
- + " density = " + info.iconBitmap.getDensity());
- }
- info.iconBitmap.setDensity(Bitmap.DENSITY_NONE);
- textView.setCompoundDrawablesWithIntrinsicBounds(null, new BitmapDrawable(info.iconBitmap), null, null);
- textView.setText(info.title);
-
- return convertView;
- }
- }
-
- public AllApps2D(Context context, AttributeSet attrs) {
- super(context, attrs);
- setVisibility(View.GONE);
- setSoundEffectsEnabled(false);
-
- mAppsAdapter = new AppsAdapter(getContext(), mVisibleAppsList);
- }
-
- @Override
- protected void onFinishInflate() {
- try {
- mGrid = (GridView)findViewWithTag("all_apps_2d_grid");
- if (mGrid == null) throw new Resources.NotFoundException();
- mGrid.setOnItemClickListener(this);
- mGrid.setOnItemLongClickListener(this);
-
- // The home button is optional; some layouts might not use it
- ImageButton homeButton = (ImageButton) findViewWithTag("all_apps_2d_home");
- if (homeButton != null) {
- homeButton.setOnClickListener(
- new View.OnClickListener() {
- public void onClick(View v) {
- mLauncher.showWorkspace(true);
- }
- });
- }
- } catch (Resources.NotFoundException e) {
- Log.e(TAG, "Can't find necessary layout elements for AllApps2D");
- }
-
- setOnKeyListener(this);
- }
-
- public AllApps2D(Context context, AttributeSet attrs, int defStyle) {
- this(context, attrs);
- }
-
- @Override
- public void setup(Launcher launcher, DragController dragController) {
- mLauncher = launcher;
- mDragController = dragController;
- }
-
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- if (!isVisible()) return false;
-
- switch (keyCode) {
- case KeyEvent.KEYCODE_BACK:
- mLauncher.showWorkspace(true);
- break;
- default:
- return false;
- }
-
- return true;
- }
-
- public void onItemClick(AdapterView parent, View v, int position, long id) {
- ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
- mLauncher.startActivitySafely(app.intent, app);
- }
-
- public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
- if (!view.isInTouchMode()) {
- return false;
- }
-
- ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
- app = new ApplicationInfo(app);
-
- mDragController.startDrag(view, this, app, DragController.DRAG_ACTION_COPY);
- mLauncher.showWorkspace(true);
-
- return true;
- }
-
- protected void onFocusChanged(boolean gainFocus, int direction, android.graphics.Rect prev) {
- if (gainFocus) {
- mGrid.requestFocus();
- }
- }
-
- @Override
- public void onDragViewVisible() {
- }
-
- @Override
- public void onDropCompleted(View target, DragObject d, boolean success) {
- }
-
- /**
- * Zoom to the specifed level.
- *
- * @param zoom [0..1] 0 is hidden, 1 is open
- */
- public void zoom(float zoom, boolean animate) {
-// Log.d(TAG, "zooming " + ((zoom == 1.0) ? "open" : "closed"));
- cancelLongPress();
-
- mZoom = zoom;
-
- if (isVisible()) {
- getParent().bringChildToFront(this);
- setVisibility(View.VISIBLE);
- mGrid.setAdapter(mAppsAdapter);
- if (animate) {
- startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.all_apps_2d_fade_in));
- } else {
- onAnimationEnd();
- }
- } else {
- if (animate) {
- startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.all_apps_2d_fade_out));
- } else {
- onAnimationEnd();
- }
- }
- }
-
- protected void onAnimationEnd() {
- if (!isVisible()) {
- setVisibility(View.GONE);
- mGrid.setAdapter(null);
- mZoom = 0.0f;
- } else {
- mZoom = 1.0f;
- }
-
- mLauncher.zoomed(mZoom);
- }
-
- public boolean isVisible() {
- return mZoom > 0.001f;
- }
-
- public boolean isAnimating() {
- return (getAnimation() != null);
- }
-
- public void setApps(ArrayList<ApplicationInfo> list) {
- mAllAppsList.clear();
- addApps(list);
- filterApps(mCurrentFilter);
- }
-
- public void addApps(ArrayList<ApplicationInfo> list) {
- final int N = list.size();
-
- for (int i=0; i<N; i++) {
- final ApplicationInfo item = list.get(i);
- int index = Collections.binarySearch(mAllAppsList, item,
- LauncherModel.APP_NAME_COMPARATOR);
- if (index < 0) {
- index = -(index+1);
- }
- mAllAppsList.add(index, item);
- }
- filterApps(mCurrentFilter);
- }
-
- public void removeApps(ArrayList<ApplicationInfo> list) {
- final int N = list.size();
-
- for (int i=0; i<N; i++) {
- final ApplicationInfo item = list.get(i);
- int index = findAppByComponent(mAllAppsList, item);
- if (index >= 0) {
- mAllAppsList.remove(index);
- } else {
- Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
- // Try to recover. This should keep us from crashing for now.
- }
- }
- filterApps(mCurrentFilter);
- }
-
- public void updateApps(ArrayList<ApplicationInfo> list) {
- // Just remove and add, because they may need to be re-sorted.
- removeApps(list);
- addApps(list);
- }
-
- public void filterApps(AppType appType) {
- mCurrentFilter = appType;
-
- mAppsAdapter.setNotifyOnChange(false);
- mVisibleAppsList.clear();
- if (appType == AppType.ALL) {
- mVisibleAppsList.addAll(mAllAppsList);
- } else if (appType == AppType.DOWNLOADED) {
- for (ApplicationInfo info : mAllAppsList) {
- if ((info.flags & ApplicationInfo.DOWNLOADED_FLAG) != 0) {
- mVisibleAppsList.add(info);
- }
- }
- }
- mAppsAdapter.notifyDataSetChanged();
- }
-
- private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
- ComponentName component = item.intent.getComponent();
- final int N = list.size();
- for (int i=0; i<N; i++) {
- ApplicationInfo x = list.get(i);
- if (x.intent.getComponent().equals(component)) {
- return i;
- }
- }
- return -1;
- }
-
- public void dumpState() {
- ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
- }
-
- public void surrender() {
- }
-
- public void reset() {
- // Do nothing
- }
-}
-
-
diff --git a/src/com/android/launcher2/AllApps3D.java b/src/com/android/launcher2/AllApps3D.java
deleted file mode 100644
index 837ddbb..0000000
--- a/src/com/android/launcher2/AllApps3D.java
+++ /dev/null
@@ -1,1488 +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.launcher2;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.PixelFormat;
-import android.graphics.Rect;
-import android.renderscript.Allocation;
-import android.renderscript.Element;
-import android.renderscript.Matrix4f;
-import android.renderscript.Mesh;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramFragmentFixedFunction;
-import android.renderscript.ProgramStore;
-import android.renderscript.ProgramVertex;
-import android.renderscript.ProgramVertexFixedFunction;
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-import android.renderscript.RenderScriptGL;
-import android.renderscript.Sampler;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.view.SoundEffectConstants;
-import android.view.SurfaceHolder;
-import android.view.VelocityTracker;
-import android.view.View;
-import android.view.ViewConfiguration;
-import android.view.accessibility.AccessibilityEvent;
-
-import com.android.launcher.R;
-import com.android.launcher2.DropTarget.DragObject;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-
-public class AllApps3D extends RSSurfaceView
- implements AllAppsView, View.OnClickListener, View.OnLongClickListener, DragSource {
- private static final String TAG = "Launcher.AllApps3D";
-
- /** Bit for mLocks for when there are icons being loaded. */
- private static final int LOCK_ICONS_PENDING = 1;
-
- private static final int TRACKING_NONE = 0;
- private static final int TRACKING_FLING = 1;
- private static final int TRACKING_HOME = 2;
-
- private static final int SELECTED_NONE = 0;
- private static final int SELECTED_FOCUSED = 1;
- private static final int SELECTED_PRESSED = 2;
-
- private static final int SELECTION_NONE = 0;
- private static final int SELECTION_ICONS = 1;
- private static final int SELECTION_HOME = 2;
-
- private Launcher mLauncher;
- private DragController mDragController;
-
- /** When this is 0, modifications are allowed, when it's not, they're not.
- * TODO: What about scrolling? */
- private int mLocks = LOCK_ICONS_PENDING;
-
- private int mSlop;
- private int mMaxFlingVelocity;
-
- private Defines mDefines = new Defines();
- private ArrayList<ApplicationInfo> mAllAppsList;
-
- private static RenderScriptGL sRS;
- private static RolloRS sRollo;
-
- private static boolean sZoomDirty = false;
- private static boolean sAnimateNextZoom;
- private static float sNextZoom;
-
- /**
- * True when we are using arrow keys or trackball to drive navigation
- */
- private boolean mArrowNavigation = false;
- private boolean mStartedScrolling;
-
- /**
- * Used to keep track of the selection when AllAppsView loses window focus.
- * One of the SELECTION_ constants.
- */
- private int mLastSelection;
-
- /**
- * Used to keep track of the selection when AllAppsView loses window focus
- */
- private int mLastSelectedIcon;
-
- private VelocityTracker mVelocityTracker;
- private int mTouchTracking;
- private int mMotionDownRawX;
- private int mMotionDownRawY;
- private int mDownIconIndex = -1;
- private int mCurrentIconIndex = -1;
- private int[] mTouchYBorders;
- private int[] mTouchXBorders;
-
- private boolean mShouldGainFocus;
-
- private boolean mHaveSurface = false;
- private float mZoom;
- private float mVelocity;
- private AAMessage mMessageProc;
-
- private int mColumnsPerPage;
- private int mRowsPerPage;
- private boolean mSurrendered;
-
- private int mRestoreFocusIndex = -1;
-
- @SuppressWarnings({"UnusedDeclaration"})
- static class Defines {
- public static final int COLUMNS_PER_PAGE_PORTRAIT = 4;
- public static final int ROWS_PER_PAGE_PORTRAIT = 4;
-
- public static final int COLUMNS_PER_PAGE_LANDSCAPE = 6;
- public static final int ROWS_PER_PAGE_LANDSCAPE = 3;
-
- public static final int SELECTION_TEXTURE_WIDTH_PX = 74 + 20;
- public static final int SELECTION_TEXTURE_HEIGHT_PX = 74 + 20;
- }
-
- public AllApps3D(Context context, AttributeSet attrs) {
- super(context, attrs);
- setFocusable(true);
- setSoundEffectsEnabled(false);
- final ViewConfiguration config = ViewConfiguration.get(context);
- mSlop = config.getScaledTouchSlop();
- mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
-
- setOnClickListener(this);
- setOnLongClickListener(this);
- setZOrderOnTop(true);
- getHolder().setFormat(PixelFormat.TRANSLUCENT);
-
- if (sRS == null) {
- RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
- sc.setDepth(16, 16);
- sc.setAlpha(8, 8);
- sRS = createRenderScriptGL(sc);
- } else {
- // Is this even possible?
- setRenderScriptGL(sRS);
- }
-
- if (sRollo != null) {
- sRollo.mAllApps = this;
- sRollo.mRes = getResources();
- sRollo.mInitialize = true;
- }
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public AllApps3D(Context context, AttributeSet attrs, int defStyle) {
- this(context, attrs);
- }
-
- public void surrender() {
- if (sRS != null) {
- sRS.setSurface(null, 0, 0);
- sRS.setMessageHandler(null);
- }
- mSurrendered = true;
- }
-
- /**
- * Note that this implementation prohibits this view from ever being reattached.
- */
- @Override
- protected void onDetachedFromWindow() {
- sRS.setMessageHandler(null);
- if (!mSurrendered) {
- Log.i(TAG, "onDetachedFromWindow");
- destroyRenderScriptGL();
- sRS = null;
- sRollo = null;
- super.onDetachedFromWindow();
- }
- }
-
- /**
- * If you have an attached click listener, View always plays the click sound!?!?
- * Deal with sound effects by hand.
- */
- public void reallyPlaySoundEffect(int sound) {
- boolean old = isSoundEffectsEnabled();
- setSoundEffectsEnabled(true);
- playSoundEffect(sound);
- setSoundEffectsEnabled(old);
- }
-
- @Override
- public void setup(Launcher launcher, DragController dragController) {
- mLauncher = launcher;
- mDragController = dragController;
- }
-
- @Override
- public void surfaceDestroyed(SurfaceHolder holder) {
- super.surfaceDestroyed(holder);
- // Without this, we leak mMessageCallback which leaks the context.
- if (!mSurrendered) {
- sRS.setMessageHandler(null);
- }
- // We may lose any callbacks that are pending, so make sure that we re-sync that
- // on the next surfaceChanged.
- sZoomDirty = true;
- mHaveSurface = false;
- }
-
- @Override
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- //long startTime = SystemClock.uptimeMillis();
-
- super.surfaceChanged(holder, format, w, h);
-
- final boolean isPortrait = w < h;
- mColumnsPerPage = isPortrait ? Defines.COLUMNS_PER_PAGE_PORTRAIT :
- Defines.COLUMNS_PER_PAGE_LANDSCAPE;
- mRowsPerPage = isPortrait ? Defines.ROWS_PER_PAGE_PORTRAIT :
- Defines.ROWS_PER_PAGE_LANDSCAPE;
-
- if (mSurrendered) return;
-
- mHaveSurface = true;
-
- if (sRollo == null) {
- sRollo = new RolloRS(this);
- sRollo.init(getResources(), w, h);
- if (mAllAppsList != null) {
- sRollo.setApps(mAllAppsList);
- }
- if (mShouldGainFocus) {
- gainFocus();
- mShouldGainFocus = false;
- }
- } else if (sRollo.mInitialize) {
- sRollo.initGl();
- sRollo.mInitialize = false;
- }
-
- initTouchState(w, h);
-
- sRollo.dirtyCheck();
- sRollo.resize(w, h);
-
- Log.d(TAG, "sc " + sRS);
- if (sRS != null) {
- mMessageProc = new AAMessage();
- sRS.setMessageHandler(mMessageProc);
- }
-
- //long endTime = SystemClock.uptimeMillis();
- //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
- }
-
- @Override
- public void onWindowFocusChanged(boolean hasWindowFocus) {
- super.onWindowFocusChanged(hasWindowFocus);
-
- if (mSurrendered) return;
-
- if (mArrowNavigation) {
- if (!hasWindowFocus) {
- // Clear selection when we lose window focus
- mLastSelectedIcon = sRollo.mScript.get_gSelectedIconIndex();
- sRollo.setHomeSelected(SELECTED_NONE);
- sRollo.clearSelectedIcon();
- } else {
- if (sRollo.mScript.get_gIconCount() > 0) {
- if (mLastSelection == SELECTION_ICONS) {
- int selection = mLastSelectedIcon;
- final int firstIcon = Math.round(sRollo.mScrollPos) * mColumnsPerPage;
- if (selection < 0 || // No selection
- selection < firstIcon || // off the top of the screen
- selection >= sRollo.mScript.get_gIconCount() || // past last icon
- selection >= firstIcon + // past last icon on screen
- (mColumnsPerPage * mRowsPerPage)) {
- selection = firstIcon;
- }
-
- // Select the first icon when we gain window focus
- sRollo.selectIcon(selection, SELECTED_FOCUSED);
- } else if (mLastSelection == SELECTION_HOME) {
- sRollo.setHomeSelected(SELECTED_FOCUSED);
- }
- }
- }
- }
- }
-
- @Override
- protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
- super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
-
- if (!isVisible() || mSurrendered) {
- return;
- }
-
- if (gainFocus) {
- if (sRollo != null) {
- gainFocus();
- } else {
- mShouldGainFocus = true;
- }
- } else {
- if (sRollo != null) {
- if (mArrowNavigation) {
- // Clear selection when we lose focus
- sRollo.clearSelectedIcon();
- sRollo.setHomeSelected(SELECTED_NONE);
- mArrowNavigation = false;
- }
- } else {
- mShouldGainFocus = false;
- }
- }
- }
-
- private void gainFocus() {
- if (!mArrowNavigation && sRollo.mScript.get_gIconCount() > 0) {
- // Select the first icon when we gain keyboard focus
- mArrowNavigation = true;
- sRollo.selectIcon(Math.round(sRollo.mScrollPos) * mColumnsPerPage, SELECTED_FOCUSED);
- }
- }
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
-
- boolean handled = false;
-
- if (!isVisible()) {
- return false;
- }
- final int iconCount = sRollo.mScript.get_gIconCount();
-
- if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
- if (mArrowNavigation) {
- if (mLastSelection == SELECTION_HOME) {
- reallyPlaySoundEffect(SoundEffectConstants.CLICK);
- mLauncher.showWorkspace(true);
- } else {
- int whichApp = sRollo.mScript.get_gSelectedIconIndex();
- if (whichApp >= 0) {
- ApplicationInfo app = mAllAppsList.get(whichApp);
- mLauncher.startActivitySafely(app.intent, app);
- handled = true;
- }
- }
- }
- }
-
- if (iconCount > 0) {
- final boolean isPortrait = getWidth() < getHeight();
-
- mArrowNavigation = true;
-
- int currentSelection = sRollo.mScript.get_gSelectedIconIndex();
- int currentTopRow = Math.round(sRollo.mScrollPos);
-
- // The column of the current selection, in the range 0..COLUMNS_PER_PAGE_PORTRAIT-1
- final int currentPageCol = currentSelection % mColumnsPerPage;
-
- // The row of the current selection, in the range 0..ROWS_PER_PAGE_PORTRAIT-1
- final int currentPageRow = (currentSelection - (currentTopRow * mColumnsPerPage))
- / mRowsPerPage;
-
- int newSelection = currentSelection;
-
- switch (keyCode) {
- case KeyEvent.KEYCODE_DPAD_UP:
- if (mLastSelection == SELECTION_HOME) {
- if (isPortrait) {
- sRollo.setHomeSelected(SELECTED_NONE);
- int lastRowCount = iconCount % mColumnsPerPage;
- if (lastRowCount == 0) {
- lastRowCount = mColumnsPerPage;
- }
- newSelection = iconCount - lastRowCount + (mColumnsPerPage / 2);
- if (newSelection >= iconCount) {
- newSelection = iconCount-1;
- }
- int target = (newSelection / mColumnsPerPage) - (mRowsPerPage - 1);
- if (target < 0) {
- target = 0;
- }
- if (currentTopRow != target) {
- sRollo.moveTo(target);
- }
- }
- } else {
- if (currentPageRow > 0) {
- newSelection = currentSelection - mColumnsPerPage;
- if (currentTopRow > newSelection / mColumnsPerPage) {
- sRollo.moveTo(newSelection / mColumnsPerPage);
- }
- } else if (currentTopRow > 0) {
- newSelection = currentSelection - mColumnsPerPage;
- sRollo.moveTo(newSelection / mColumnsPerPage);
- } else if (currentPageRow != 0) {
- newSelection = currentTopRow * mRowsPerPage;
- }
- }
- handled = true;
- break;
-
- case KeyEvent.KEYCODE_DPAD_DOWN: {
- final int rowCount = iconCount / mColumnsPerPage
- + (iconCount % mColumnsPerPage == 0 ? 0 : 1);
- final int currentRow = currentSelection / mColumnsPerPage;
- if (mLastSelection != SELECTION_HOME) {
- if (currentRow < rowCount-1) {
- sRollo.setHomeSelected(SELECTED_NONE);
- if (currentSelection < 0) {
- newSelection = 0;
- } else {
- newSelection = currentSelection + mColumnsPerPage;
- }
- if (newSelection >= iconCount) {
- // Go from D to G in this arrangement:
- // A B C D
- // E F G
- newSelection = iconCount - 1;
- }
- if (currentPageRow >= mRowsPerPage - 1) {
- sRollo.moveTo((newSelection / mColumnsPerPage) - mRowsPerPage + 1);
- }
- } else if (isPortrait) {
- newSelection = -1;
- sRollo.setHomeSelected(SELECTED_FOCUSED);
- }
- }
- handled = true;
- break;
- }
- case KeyEvent.KEYCODE_DPAD_LEFT:
- if (mLastSelection != SELECTION_HOME) {
- if (currentPageCol > 0) {
- newSelection = currentSelection - 1;
- }
- } else if (!isPortrait) {
- newSelection = ((int) (sRollo.mScrollPos) * mColumnsPerPage) +
- (mRowsPerPage / 2 * mColumnsPerPage) + mColumnsPerPage - 1;
- sRollo.setHomeSelected(SELECTED_NONE);
- }
- handled = true;
- break;
- case KeyEvent.KEYCODE_DPAD_RIGHT:
- if (mLastSelection != SELECTION_HOME) {
- if (!isPortrait && (currentPageCol == mColumnsPerPage - 1 ||
- currentSelection == iconCount - 1)) {
- newSelection = -1;
- sRollo.setHomeSelected(SELECTED_FOCUSED);
- } else if ((currentPageCol < mColumnsPerPage - 1) &&
- (currentSelection < iconCount - 1)) {
- newSelection = currentSelection + 1;
- }
- }
- handled = true;
- break;
- }
- if (newSelection != currentSelection) {
- sRollo.selectIcon(newSelection, SELECTED_FOCUSED);
- }
- }
- return handled;
- }
-
- void initTouchState(int width, int height) {
- boolean isPortrait = width < height;
-
- int[] viewPos = new int[2];
- getLocationOnScreen(viewPos);
-
- mTouchXBorders = new int[mColumnsPerPage + 1];
- mTouchYBorders = new int[mRowsPerPage + 1];
-
- // TODO: Put this in a config file/define
- int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE_PORTRAIT;
- if (!isPortrait) cellHeight -= 12;
- int centerY = (int) (height * (isPortrait ? 0.5f : 0.47f));
- if (!isPortrait) centerY += cellHeight / 2;
- int half = (int) Math.floor((mRowsPerPage + 1) / 2);
- int end = mTouchYBorders.length - (half + 1);
-
- for (int i = -half; i <= end; i++) {
- mTouchYBorders[i + half] = centerY + (i * cellHeight) - viewPos[1];
- }
-
- int x = 0;
- // TODO: Put this in a config file/define
- int columnWidth = 120;
- for (int i = 0; i < mColumnsPerPage + 1; i++) {
- mTouchXBorders[i] = x - viewPos[0];
- x += columnWidth;
- }
- }
-
- int chooseTappedIcon(int x, int y) {
- float pos = sRollo != null ? sRollo.mScrollPos : 0;
-
- int oldY = y;
-
- // Adjust for scroll position if not zero.
- y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
-
- int col = -1;
- int row = -1;
- final int columnsCount = mColumnsPerPage;
- for (int i=0; i< columnsCount; i++) {
- if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
- col = i;
- break;
- }
- }
- final int rowsCount = mRowsPerPage;
- for (int i=0; i< rowsCount; i++) {
- if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
- row = i;
- break;
- }
- }
-
- if (row < 0 || col < 0) {
- return -1;
- }
-
- int index = (((int) pos) * columnsCount) + (row * columnsCount) + col;
-
- if (index >= mAllAppsList.size()) {
- return -1;
- } else {
- return index;
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent ev)
- {
- mArrowNavigation = false;
-
- if (!isVisible()) {
- return true;
- }
-
- if (mLocks != 0) {
- return true;
- }
-
- super.onTouchEvent(ev);
-
- int x = (int)ev.getX();
- int y = (int)ev.getY();
-
- final boolean isPortrait = getWidth() < getHeight();
- int action = ev.getAction();
- switch (action) {
- case MotionEvent.ACTION_DOWN:
- if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
- (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
- mTouchTracking = TRACKING_HOME;
- sRollo.setHomeSelected(SELECTED_PRESSED);
- mCurrentIconIndex = -1;
- } else {
- mTouchTracking = TRACKING_FLING;
-
- mMotionDownRawX = (int)ev.getRawX();
- mMotionDownRawY = (int)ev.getRawY();
-
- if (!sRollo.checkClickOK()) {
- sRollo.clearSelectedIcon();
- } else {
- mDownIconIndex = mCurrentIconIndex
- = sRollo.selectIcon(x, y, SELECTED_PRESSED);
- if (mDownIconIndex < 0) {
- // if nothing was selected, no long press.
- cancelLongPress();
- }
- }
- sRollo.move(ev.getRawY() / getHeight());
- mVelocityTracker = VelocityTracker.obtain();
- mVelocityTracker.addMovement(ev);
- mStartedScrolling = false;
- }
- break;
- case MotionEvent.ACTION_MOVE:
- case MotionEvent.ACTION_OUTSIDE:
- if (mTouchTracking == TRACKING_HOME) {
- sRollo.setHomeSelected((isPortrait &&
- y > mTouchYBorders[mTouchYBorders.length-1]) || (!isPortrait
- && x > mTouchXBorders[mTouchXBorders.length-1])
- ? SELECTED_PRESSED : SELECTED_NONE);
- } else if (mTouchTracking == TRACKING_FLING) {
- int rawY = (int)ev.getRawY();
- int slop;
- slop = Math.abs(rawY - mMotionDownRawY);
-
- if (!mStartedScrolling && slop < mSlop) {
- // don't update anything so when we do start scrolling
- // below, we get the right delta.
- mCurrentIconIndex = chooseTappedIcon(x, y);
- if (mDownIconIndex != mCurrentIconIndex) {
- // If a different icon is selected, don't allow it to be picked up.
- // This handles off-axis dragging.
- cancelLongPress();
- mCurrentIconIndex = -1;
- }
- } else {
- if (!mStartedScrolling) {
- cancelLongPress();
- mCurrentIconIndex = -1;
- }
- sRollo.move(ev.getRawY() / getHeight());
-
- mStartedScrolling = true;
- sRollo.clearSelectedIcon();
- mVelocityTracker.addMovement(ev);
- }
- }
- break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- if (mTouchTracking == TRACKING_HOME) {
- if (action == MotionEvent.ACTION_UP) {
- if ((isPortrait && y > mTouchYBorders[mTouchYBorders.length-1]) ||
- (!isPortrait && x > mTouchXBorders[mTouchXBorders.length-1])) {
- reallyPlaySoundEffect(SoundEffectConstants.CLICK);
- mLauncher.showWorkspace(true);
- }
- sRollo.setHomeSelected(SELECTED_NONE);
- }
- mCurrentIconIndex = -1;
- } else if (mTouchTracking == TRACKING_FLING) {
- mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
- sRollo.clearSelectedIcon();
- sRollo.fling(ev.getRawY() / getHeight(),
- mVelocityTracker.getYVelocity() / getHeight());
-
- if (mVelocityTracker != null) {
- mVelocityTracker.recycle();
- mVelocityTracker = null;
- }
- }
- mTouchTracking = TRACKING_NONE;
- break;
- }
-
- return true;
- }
-
- public void onClick(View v) {
- if (mLocks != 0 || !isVisible()) {
- return;
- }
- if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
- && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
- reallyPlaySoundEffect(SoundEffectConstants.CLICK);
- ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
- mLauncher.startActivitySafely(app.intent, app);
- }
- }
-
- public boolean onLongClick(View v) {
- // We don't accept long click events in these cases
- // - If the workspace isn't ready to accept a drop
- // - If we're not done loading (because we might be confused about which item
- // to pick up
- // - If we're not visible
- if (!isVisible() || mLauncher.isWorkspaceLocked() || mLocks != 0) {
- return true;
- }
- if (sRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
- && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
- ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
-
- final Bitmap bmp = app.iconBitmap;
-
- // We don't really have an accurate location to use. This will do.
- int screenX = mMotionDownRawX - (bmp.getWidth() / 2);
- int screenY = mMotionDownRawY - bmp.getHeight();
-
- mLauncher.lockScreenOrientation();
- mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, bmp);
- mDragController.startDrag(
- bmp, screenX, screenY, this, app, DragController.DRAG_ACTION_COPY);
-
- mLauncher.showWorkspace(true);
- }
- return true;
- }
-
- @Override
- public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
- if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
- if (!isVisible()) {
- return false;
- }
- String text = null;
- int index;
- int count = mAllAppsList.size() + 1; // +1 is home
- int pos = -1;
- switch (mLastSelection) {
- case SELECTION_ICONS:
- index = sRollo.mScript.get_gSelectedIconIndex();
- if (index >= 0) {
- ApplicationInfo info = mAllAppsList.get(index);
- if (info.title != null) {
- text = info.title.toString();
- pos = index;
- }
- }
- break;
- case SELECTION_HOME:
- text = getContext().getString(R.string.all_apps_home_button_label);
- pos = count;
- break;
- }
- if (text != null) {
- event.setEnabled(true);
- event.getText().add(text);
- //event.setContentDescription(text);
- event.setItemCount(count);
- event.setCurrentItemIndex(pos);
- }
- }
- return false;
- }
-
- @Override
- public void onDragViewVisible() {
- }
-
- @Override
- public void onDropCompleted(View target, DragObject d, boolean success) {
- mLauncher.getWorkspace().onDragStopped(success);
- mLauncher.unlockScreenOrientation();
- }
-
- /**
- * Zoom to the specifed level.
- *
- * @param zoom [0..1] 0 is hidden, 1 is open
- */
- public void zoom(float zoom, boolean animate) {
- cancelLongPress();
- sNextZoom = zoom;
- sAnimateNextZoom = animate;
- // if we do setZoom while we don't have a surface, we won't
- // get the callbacks that actually set mZoom.
- if (sRollo == null || !mHaveSurface) {
- sZoomDirty = true;
- mZoom = zoom;
- } else {
- sRollo.setZoom(zoom, animate);
- }
- }
-
- /**
- * If sRollo is null, then we're not visible. This is also used to guard against
- * sRollo being null.
- */
- public boolean isVisible() {
- return sRollo != null && mZoom > 0.001f;
- }
-
- public boolean isAnimating() {
- return isVisible() && mZoom <= 0.999f;
- }
-
- public void setApps(ArrayList<ApplicationInfo> list) {
- if (sRS == null) {
- // We've been removed from the window. Don't bother with all this.
- return;
- }
-
- if (list != null) {
- Collections.sort(list, LauncherModel.APP_NAME_COMPARATOR);
- }
-
- boolean reload = false;
- if (mAllAppsList == null) {
- reload = true;
- } else if (list.size() != mAllAppsList.size()) {
- reload = true;
- } else {
- final int count = list.size();
- for (int i = 0; i < count; i++) {
- if (list.get(i) != mAllAppsList.get(i)) {
- reload = true;
- break;
- }
- }
- }
-
- mAllAppsList = list;
- if (sRollo != null && reload) {
- sRollo.setApps(list);
- }
-
- if (hasFocus() && mRestoreFocusIndex != -1) {
- sRollo.selectIcon(mRestoreFocusIndex, SELECTED_FOCUSED);
- mRestoreFocusIndex = -1;
- }
-
- mLocks &= ~LOCK_ICONS_PENDING;
- }
-
- public void addApps(ArrayList<ApplicationInfo> list) {
- if (mAllAppsList == null) {
- // Not done loading yet. We'll find out about it later.
- return;
- }
- if (sRS == null) {
- // We've been removed from the window. Don't bother with all this.
- return;
- }
-
- final int N = list.size();
- if (sRollo != null) {
- sRollo.pause();
- sRollo.reallocAppsList(sRollo.mScript.get_gIconCount() + N);
- }
-
- for (int i=0; i<N; i++) {
- final ApplicationInfo item = list.get(i);
- int index = Collections.binarySearch(mAllAppsList, item,
- LauncherModel.APP_NAME_COMPARATOR);
- if (index < 0) {
- index = -(index+1);
- }
- mAllAppsList.add(index, item);
- if (sRollo != null) {
- sRollo.addApp(index, item);
- }
- }
-
- if (sRollo != null) {
- sRollo.saveAppsList();
- sRollo.resume();
- }
- }
-
- public void removeApps(ArrayList<ApplicationInfo> list) {
- if (mAllAppsList == null) {
- // Not done loading yet. We'll find out about it later.
- return;
- }
-
- if (sRollo != null) {
- sRollo.pause();
- }
- final int N = list.size();
- for (int i=0; i<N; i++) {
- final ApplicationInfo item = list.get(i);
- int index = findAppByComponent(mAllAppsList, item);
- if (index >= 0) {
- mAllAppsList.remove(index);
- if (sRollo != null) {
- sRollo.removeApp(index);
- }
- } else {
- Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
- // Try to recover. This should keep us from crashing for now.
- }
- }
-
- if (sRollo != null) {
- sRollo.saveAppsList();
- sRollo.resume();
- }
- }
-
- public void updateApps(ArrayList<ApplicationInfo> list) {
- // Just remove and add, because they may need to be re-sorted.
- removeApps(list);
- addApps(list);
- }
-
- private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
- ComponentName component = item.intent.getComponent();
- final int N = list.size();
- for (int i=0; i<N; i++) {
- ApplicationInfo x = list.get(i);
- if (x.intent.getComponent().equals(component)) {
- return i;
- }
- }
- return -1;
- }
-
- class AAMessage extends RenderScript.RSMessageHandler {
- public void run() {
- sRollo.mScrollPos = ((float)mData[0]) / (1 << 16);
- mVelocity = ((float)mData[1]) / (1 << 16);
-
- boolean lastVisible = isVisible();
- mZoom = ((float)mData[2]) / (1 << 16);
-
- final boolean visible = isVisible();
- if (visible != lastVisible) {
- post(new Runnable() {
- public void run() {
- if (visible) {
- showSurface();
- } else {
- hideSurface();
- }
- }
- });
- }
-
- sZoomDirty = false;
- }
- }
-
- public static class RolloRS {
- // Allocations ======
- private int mWidth;
- private int mHeight;
-
- private Resources mRes;
- ScriptC_allapps mScript;
-
- private Mesh mMesh;
- private ProgramVertexFixedFunction.Constants mPVA;
-
- private ScriptField_VpConsts mUniformAlloc;
-
- private Allocation mHomeButtonNormal;
- private Allocation mHomeButtonFocused;
- private Allocation mHomeButtonPressed;
-
- private Allocation[] mIcons;
- private Allocation mAllocIcons;
-
- private Allocation[] mLabels;
- private Allocation mAllocLabels;
-
- private Bitmap mSelectionBitmap;
- private Canvas mSelectionCanvas;
-
- private float mScrollPos;
-
- AllApps3D mAllApps;
- boolean mInitialize;
-
- private boolean checkClickOK() {
- return (Math.abs(mAllApps.mVelocity) < 0.4f) &&
- (Math.abs(mScrollPos - Math.round(mScrollPos)) < 0.4f);
- }
-
- void pause() {
- if (sRS != null) {
- sRS.bindRootScript(null);
- }
- }
-
- void resume() {
- if (sRS != null) {
- sRS.bindRootScript(mScript);
- }
- }
-
- public RolloRS(AllApps3D allApps) {
- mAllApps = allApps;
- }
-
- public void init(Resources res, int width, int height) {
- mRes = res;
- mWidth = width;
- mHeight = height;
- mScript = new ScriptC_allapps(sRS, mRes, R.raw.allapps);
-
- initProgramVertex();
- initProgramFragment();
- initProgramStore();
- initGl();
- initData();
-
- mScript.bind_gIcons(mAllocIcons);
- mScript.bind_gLabels(mAllocLabels);
- sRS.bindRootScript(mScript);
- }
-
- public void initMesh() {
- Mesh.TriangleMeshBuilder tm = new Mesh.TriangleMeshBuilder(sRS, 2, 0);
-
- for (int ct=0; ct < 16; ct++) {
- float pos = (1.f / (16.f - 1)) * ct;
- tm.addVertex(0.0f, pos);
- tm.addVertex(1.0f, pos);
- }
- for (int ct=0; ct < (16 * 2 - 2); ct+= 2) {
- tm.addTriangle(ct, ct+1, ct+2);
- tm.addTriangle(ct+1, ct+3, ct+2);
- }
- mMesh = tm.create(true);
- mScript.set_gSMCell(mMesh);
- }
-
- Matrix4f getProjectionMatrix(int w, int h) {
- // range -1,1 in the narrow axis at z = 0.
- Matrix4f m1 = new Matrix4f();
- Matrix4f m2 = new Matrix4f();
-
- if(w > h) {
- float aspect = ((float)w) / h;
- m1.loadFrustum(-aspect,aspect, -1,1, 1,100);
- } else {
- float aspect = ((float)h) / w;
- m1.loadFrustum(-1,1, -aspect,aspect, 1,100);
- }
-
- m2.loadRotate(180, 0, 1, 0);
- m1.loadMultiply(m1, m2);
-
- m2.loadScale(-2, 2, 1);
- m1.loadMultiply(m1, m2);
-
- m2.loadTranslate(0, 0, 2);
- m1.loadMultiply(m1, m2);
- return m1;
- }
-
- void resize(int w, int h) {
- Matrix4f proj = getProjectionMatrix(w, h);
- mPVA.setProjection(proj);
-
- if (mUniformAlloc != null) {
- ScriptField_VpConsts.Item i = new ScriptField_VpConsts.Item();
- i.Proj = proj;
- i.ScaleOffset.x = (2.f / 480.f);
- i.ScaleOffset.y = 0;
- i.ScaleOffset.z = -((float)w / 2) - 0.25f;
- if (w < h) {
- // portrait
- i.ScaleOffset.w = -380.25f;
- i.BendPos.x = 120.f; // bottom of screen
- i.BendPos.y = h - 82.f; // top of screen
- } else {
- // landscape
- i.ScaleOffset.w = -206.25f;
- i.BendPos.x = 50.f;
- i.BendPos.y = h - 30.f;
- }
- mUniformAlloc.set(i, 0, true);
- }
-
- mWidth = w;
- mHeight = h;
- }
-
- private void initProgramVertex() {
- mPVA = new ProgramVertexFixedFunction.Constants(sRS);
- resize(mWidth, mHeight);
-
- ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(sRS);
- pvb.setTextureMatrixEnable(true);
- ProgramVertex pv = pvb.create();
- ((ProgramVertexFixedFunction)pv).bindConstants(mPVA);
- sRS.bindProgramVertex(pv);
-
- mUniformAlloc = new ScriptField_VpConsts(sRS, 1);
- mScript.bind_vpConstants(mUniformAlloc);
-
- initMesh();
- ProgramVertex.Builder sb = new ProgramVertex.Builder(sRS);
- String t = "varying vec4 varColor;\n" +
- "varying vec2 varTex0;\n" +
- "void main() {\n" +
- // Animation
- " float ani = UNI_Position.z;\n" +
-
- " float bendY1 = UNI_BendPos.x;\n" +
- " float bendY2 = UNI_BendPos.y;\n" +
- " float bendAngle = 47.0 * (3.14 / 180.0);\n" +
- " float bendDistance = bendY1 * 0.4;\n" +
- " float distanceDimLevel = 0.6;\n" +
-
- " float bendStep = (bendAngle / bendDistance) * (bendAngle * 0.5);\n" +
- " float aDy = cos(bendAngle);\n" +
- " float aDz = sin(bendAngle);\n" +
-
- " float scale = (2.0 / " + mWidth + ".0);\n" +
- " float x = UNI_Position.x + UNI_ImgSize.x * (1.0 - ani) * (ATTRIB_position.x - 0.5);\n" +
- " float ys= UNI_Position.y + UNI_ImgSize.y * (1.0 - ani) * ATTRIB_position.y;\n" +
- " float y = 0.0;\n" +
- " float z = 0.0;\n" +
- " float lum = 1.0;\n" +
-
- " float cv = min(ys, bendY1 - bendDistance) - (bendY1 - bendDistance);\n" +
- " y += cv * aDy;\n" +
- " z += -cv * aDz;\n" +
- " cv = clamp(ys, bendY1 - bendDistance, bendY1) - bendY1;\n" + // curve range
- " lum += cv / bendDistance * distanceDimLevel;\n" +
- " y += cv * cos(cv * bendStep);\n" +
- " z += cv * sin(cv * bendStep);\n" +
-
- " cv = max(ys, bendY2 + bendDistance) - (bendY2 + bendDistance);\n" +
- " y += cv * aDy;\n" +
- " z += cv * aDz;\n" +
- " cv = clamp(ys, bendY2, bendY2 + bendDistance) - bendY2;\n" +
- " lum -= cv / bendDistance * distanceDimLevel;\n" +
- " y += cv * cos(cv * bendStep);\n" +
- " z += cv * sin(cv * bendStep);\n" +
-
- " y += clamp(ys, bendY1, bendY2);\n" +
-
- " vec4 pos;\n" +
- " pos.x = (x + UNI_ScaleOffset.z) * UNI_ScaleOffset.x;\n" +
- " pos.y = (y + UNI_ScaleOffset.w) * UNI_ScaleOffset.x;\n" +
- " pos.z = z * UNI_ScaleOffset.x;\n" +
- " pos.w = 1.0;\n" +
-
- " pos.x *= 1.0 + ani * 4.0;\n" +
- " pos.y *= 1.0 + ani * 4.0;\n" +
- " pos.z -= ani * 1.5;\n" +
- " lum *= 1.0 - ani;\n" +
-
- " gl_Position = UNI_Proj * pos;\n" +
- " varColor.rgba = vec4(lum, lum, lum, 1.0);\n" +
- " varTex0.xy = ATTRIB_position;\n" +
- " varTex0.y = 1.0 - varTex0.y;\n" +
- "}\n";
- sb.setShader(t);
- sb.addConstant(mUniformAlloc.getType());
- sb.addInput(mMesh.getVertexAllocation(0).getType().getElement());
- ProgramVertex pvc = sb.create();
- pvc.bindConstants(mUniformAlloc.getAllocation(), 0);
-
- mScript.set_gPVCurve(pvc);
- }
-
- private void initProgramFragment() {
- Sampler.Builder sb = new Sampler.Builder(sRS);
- sb.setMinification(Sampler.Value.LINEAR_MIP_LINEAR);
- sb.setMagnification(Sampler.Value.NEAREST);
- sb.setWrapS(Sampler.Value.CLAMP);
- sb.setWrapT(Sampler.Value.CLAMP);
- Sampler linear = sb.create();
-
- sb.setMinification(Sampler.Value.NEAREST);
- sb.setMagnification(Sampler.Value.NEAREST);
- Sampler nearest = sb.create();
-
- ProgramFragmentFixedFunction.Builder bf = new ProgramFragmentFixedFunction.Builder(sRS);
- bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
- ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
- bf.setVaryingColor(true);
- ProgramFragment pfTexMip = bf.create();
- pfTexMip.bindSampler(linear, 0);
-
- bf.setVaryingColor(false);
- ProgramFragment pfTexNearest = bf.create();
- pfTexNearest.bindSampler(nearest, 0);
-
- bf.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.MODULATE,
- ProgramFragmentFixedFunction.Builder.Format.ALPHA, 0);
- bf.setVaryingColor(true);
- ProgramFragment pfTexMipAlpha = bf.create();
- pfTexMipAlpha.bindSampler(linear, 0);
-
- mScript.set_gPFTexNearest(pfTexNearest);
- mScript.set_gPFTexMip(pfTexMip);
- mScript.set_gPFTexMipAlpha(pfTexMipAlpha);
- }
-
- private void initProgramStore() {
- ProgramStore.Builder bs = new ProgramStore.Builder(sRS);
- bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
- bs.setColorMaskEnabled(true,true,true,false);
- bs.setDitherEnabled(true);
- bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
- ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
- mScript.set_gPS(bs.create());
- }
-
- private void initGl() {
- }
-
- private void initData() {
- mScript.set_COLUMNS_PER_PAGE_PORTRAIT(Defines.COLUMNS_PER_PAGE_PORTRAIT);
- mScript.set_ROWS_PER_PAGE_PORTRAIT(Defines.ROWS_PER_PAGE_PORTRAIT);
- mScript.set_COLUMNS_PER_PAGE_LANDSCAPE(Defines.COLUMNS_PER_PAGE_LANDSCAPE);
- mScript.set_ROWS_PER_PAGE_LANDSCAPE(Defines.ROWS_PER_PAGE_LANDSCAPE);
-
- mHomeButtonNormal = Allocation.createFromBitmapResource(sRS, mRes,
- R.drawable.home_button_normal);
- mHomeButtonFocused = Allocation.createFromBitmapResource(sRS, mRes,
- R.drawable.home_button_focused);
- mHomeButtonPressed = Allocation.createFromBitmapResource(sRS, mRes,
- R.drawable.home_button_pressed);
-
- mScript.set_gHomeButton(mHomeButtonNormal);
-
- mSelectionBitmap = Bitmap.createBitmap(Defines.SELECTION_TEXTURE_WIDTH_PX,
- Defines.SELECTION_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
- mSelectionCanvas = new Canvas(mSelectionBitmap);
-
- setApps(null);
- }
-
- void dirtyCheck() {
- if (sZoomDirty) {
- setZoom(mAllApps.sNextZoom, mAllApps.sAnimateNextZoom);
- }
- }
-
- @SuppressWarnings({"ConstantConditions"})
- private void setApps(ArrayList<ApplicationInfo> list) {
- sRollo.pause();
- final int count = list != null ? list.size() : 0;
- int allocCount = count;
- if (allocCount < 1) {
- allocCount = 1;
- }
-
- mIcons = new Allocation[count];
- mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
-
- mLabels = new Allocation[count];
- mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), allocCount);
-
- mScript.set_gIconCount(count);
- for (int i=0; i < count; i++) {
- createAppIconAllocations(i, list.get(i));
- }
- saveAppsList();
- android.util.Log.e("rs", "setApps");
- sRollo.resume();
- }
-
- private void setZoom(float zoom, boolean animate) {
- if (animate) {
- sRollo.clearSelectedIcon();
- sRollo.setHomeSelected(SELECTED_NONE);
- }
- sRollo.mScript.invoke_setZoom(zoom, animate ? 1 : 0);
- }
-
- private void createAppIconAllocations(int index, ApplicationInfo item) {
- mIcons[index] = Allocation.createFromBitmap(sRS, item.iconBitmap,
- Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- mLabels[index] = Allocation.createFromBitmap(sRS, item.titleBitmap,
- Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
- Allocation.USAGE_GRAPHICS_TEXTURE);
- }
-
- /**
- * Puts the empty spaces at the end. Updates mState.iconCount. You must
- * fill in the values and call saveAppsList().
- */
- private void reallocAppsList(int count) {
- Allocation[] icons = new Allocation[count];
- mAllocIcons = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
-
- Allocation[] labels = new Allocation[count];
- mAllocLabels = Allocation.createSized(sRS, Element.ALLOCATION(sRS), count);
-
- final int oldCount = sRollo.mScript.get_gIconCount();
-
- System.arraycopy(mIcons, 0, icons, 0, oldCount);
- System.arraycopy(mLabels, 0, labels, 0, oldCount);
-
- mIcons = icons;
- mLabels = labels;
- }
-
- /**
- * Handle the allocations for the new app. Make sure you call saveAppsList when done.
- */
- private void addApp(int index, ApplicationInfo item) {
- final int count = mScript.get_gIconCount() - index;
- final int dest = index + 1;
-
- System.arraycopy(mIcons, index, mIcons, dest, count);
- System.arraycopy(mLabels, index, mLabels, dest, count);
-
- createAppIconAllocations(index, item);
-
- mScript.set_gIconCount(mScript.get_gIconCount() + 1);
- }
-
- /**
- * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
- */
- private void removeApp(int index) {
- final int count = mScript.get_gIconCount() - index - 1;
- final int src = index + 1;
-
- System.arraycopy(mIcons, src, mIcons, index, count);
- System.arraycopy(mLabels, src, mLabels, index, count);
-
- mScript.set_gIconCount(mScript.get_gIconCount() - 1);
- final int last = mScript.get_gIconCount();
-
- mIcons[last] = null;
- mLabels[last] = null;
- }
-
- /**
- * Send the apps list structures to RS.
- */
- private void saveAppsList() {
- // WTF: how could mScript be not null but mAllocIconIds null b/2460740.
- if (mScript != null && mAllocIcons != null) {
- if (mIcons.length > 0) {
- mAllocIcons.copyFrom(mIcons);
- mAllocLabels.copyFrom(mLabels);
- }
-
- mScript.bind_gIcons(mAllocIcons);
- mScript.bind_gLabels(mAllocLabels);
- }
- }
-
- void fling(float pos, float v) {
- mScript.invoke_fling(pos, v);
- }
-
- void move(float pos) {
- mScript.invoke_move(pos);
- }
-
- void moveTo(float row) {
- mScript.invoke_moveTo(row);
- }
-
- /**
- * You need to call save() on mState on your own after calling this.
- *
- * @return the index of the icon that was selected.
- */
- int selectIcon(int x, int y, int pressed) {
- if (mAllApps != null) {
- final int index = mAllApps.chooseTappedIcon(x, y);
- selectIcon(index, pressed);
- return index;
- } else {
- return -1;
- }
- }
-
- /**
- * Select the icon at the given index.
- *
- * @param index The index.
- * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
- */
- void selectIcon(int index, int pressed) {
- final ArrayList<ApplicationInfo> appsList = mAllApps.mAllAppsList;
- if (appsList == null || index < 0 || index >= appsList.size()) {
- if (mAllApps != null) {
- mAllApps.mRestoreFocusIndex = index;
- }
- mScript.set_gSelectedIconIndex(-1);
- if (mAllApps.mLastSelection == SELECTION_ICONS) {
- mAllApps.mLastSelection = SELECTION_NONE;
- }
- } else {
- if (pressed == SELECTED_FOCUSED) {
- mAllApps.mLastSelection = SELECTION_ICONS;
- }
-
- int prev = mScript.get_gSelectedIconIndex();
- mScript.set_gSelectedIconIndex(index);
-
- ApplicationInfo info = appsList.get(index);
- Bitmap selectionBitmap = mSelectionBitmap;
-
- Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas,
- selectionBitmap.getWidth(), selectionBitmap.getHeight(),
- pressed == SELECTED_PRESSED, info.iconBitmap);
-
- Allocation si = Allocation.createFromBitmap(sRS, selectionBitmap);
- mScript.set_gSelectedIconTexture(si);
-
- if (prev != index) {
- if (info.title != null && info.title.length() > 0) {
- //setContentDescription(info.title);
- mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
- }
- }
- }
- }
-
- /**
- * You need to call save() on mState on your own after calling this.
- */
- void clearSelectedIcon() {
- mScript.set_gSelectedIconIndex(-1);
- }
-
- void setHomeSelected(int mode) {
- final int prev = mAllApps.mLastSelection;
- switch (mode) {
- case SELECTED_NONE:
- mScript.set_gHomeButton(mHomeButtonNormal);
- break;
- case SELECTED_FOCUSED:
- mAllApps.mLastSelection = SELECTION_HOME;
- mScript.set_gHomeButton(mHomeButtonFocused);
- if (prev != SELECTION_HOME) {
- mAllApps.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
- }
- break;
- case SELECTED_PRESSED:
- mScript.set_gHomeButton(mHomeButtonPressed);
- break;
- }
- }
-
- public void dumpState() {
- Log.d(TAG, "sRollo.mWidth=" + mWidth);
- Log.d(TAG, "sRollo.mHeight=" + mHeight);
- Log.d(TAG, "sRollo.mIcons=" + Arrays.toString(mIcons));
- if (mIcons != null) {
- Log.d(TAG, "sRollo.mIcons.length=" + mIcons.length);
- }
- //Log.d(TAG, "sRollo.mState.newPositionX=" + mState.newPositionX);
- //Log.d(TAG, "sRollo.mState.newTouchDown=" + mState.newTouchDown);
- //Log.d(TAG, "sRollo.mState.flingVelocity=" + mState.flingVelocity);
- //Log.d(TAG, "sRollo.mState.iconCount=" + mState.iconCount);
- //Log.d(TAG, "sRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
- //Log.d(TAG, "sRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
- //Log.d(TAG, "sRollo.mState.zoomTarget=" + mState.zoomTarget);
- //Log.d(TAG, "sRollo.mState.homeButtonId=" + mState.homeButtonId);
- //Log.d(TAG, "sRollo.mState.targetPos=" + mState.targetPos);
- }
- }
-
- public void dumpState() {
- Log.d(TAG, "sRS=" + sRS);
- Log.d(TAG, "sRollo=" + sRollo);
- ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
- Log.d(TAG, "mTouchXBorders=" + Arrays.toString(mTouchXBorders));
- Log.d(TAG, "mTouchYBorders=" + Arrays.toString(mTouchYBorders));
- Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
- Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
- Log.d(TAG, "mLastSelection=" + mLastSelection);
- Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
- Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
- Log.d(TAG, "mTouchTracking=" + mTouchTracking);
- Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
- Log.d(TAG, "sZoomDirty=" + sZoomDirty);
- Log.d(TAG, "sAnimateNextZoom=" + sAnimateNextZoom);
- Log.d(TAG, "mZoom=" + mZoom);
- Log.d(TAG, "mScrollPos=" + sRollo.mScrollPos);
- Log.d(TAG, "mVelocity=" + mVelocity);
- Log.d(TAG, "mMessageProc=" + mMessageProc);
- if (sRollo != null) {
- sRollo.dumpState();
- }
- if (sRS != null) {
- sRS.contextDump();
- }
- }
-
- public void reset() {
- // Do nothing
- }
-}
diff --git a/src/com/android/launcher2/AllAppsBackground.java b/src/com/android/launcher2/AllAppsBackground.java
deleted file mode 100644
index 51e1ee4..0000000
--- a/src/com/android/launcher2/AllAppsBackground.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2010 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.launcher2;
-
-import com.android.launcher.R;
-
-import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.drawable.Drawable;
-import android.util.AttributeSet;
-import android.view.View;
-
-/**
- * The background for AllApps which moves independently of the AllApps tray (for example, when we
- * transition between AllApps and the Workspace while in spring-loaded mode).
- */
-public class AllAppsBackground extends View {
- private Drawable mBackground;
-
- public AllAppsBackground(Context context) {
- this(context, null);
- }
-
- public AllAppsBackground(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public AllAppsBackground(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- mBackground = getResources().getDrawable(R.drawable.all_apps_bg_gradient);
- }
-
- @Override
- public void onDraw(Canvas canvas) {
- mBackground.setBounds(mScrollX, 0, mScrollX + getMeasuredWidth(),
- getMeasuredHeight());
- mBackground.draw(canvas);
- }
-}
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
deleted file mode 100644
index b3136e6..0000000
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ /dev/null
@@ -1,709 +0,0 @@
-/*
- * Copyright (C) 2010 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.launcher2;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
-import android.util.AttributeSet;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.animation.AnimationUtils;
-import android.widget.Checkable;
-import android.widget.TextView;
-
-import com.android.launcher.R;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-
-/**
- * An implementation of PagedView that populates the pages of the workspace
- * with all of the user's applications.
- */
-public class AllAppsPagedView extends PagedViewWithDraggableItems implements AllAppsView,
- View.OnClickListener, DragSource, DropTarget {
-
- private static final String TAG = "AllAppsPagedView";
-
- private Launcher mLauncher;
- private DragController mDragController;
-
- // preserve compatibility with 3D all apps:
- // 0.0 -> hidden
- // 1.0 -> shown and opaque
- // intermediate values -> partially shown & partially opaque
- private float mZoom;
-
- // set of all applications
- private ArrayList<ApplicationInfo> mApps;
- private ArrayList<ApplicationInfo> mFilteredApps;
-
- // the types of applications to filter
- static final int ALL_APPS_FLAG = -1;
- private int mAppFilter = ALL_APPS_FLAG;
-
- private final LayoutInflater mInflater;
- private boolean mAllowHardwareLayerCreation;
-
- private int mPageContentWidth;
- private boolean mHasMadeSuccessfulDrop;
-
- private int mLastMeasureWidth = -1;
- private int mLastMeasureHeight = -1;
- private boolean mWaitingToInitPages = true;
-
- private int mMaxCellCountY;
-
- public AllAppsPagedView(Context context) {
- this(context, null);
- }
-
- public AllAppsPagedView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public AllAppsPagedView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
- mInflater = LayoutInflater.from(context);
- mApps = new ArrayList<ApplicationInfo>();
- mFilteredApps = new ArrayList<ApplicationInfo>();
- a.recycle();
- setSoundEffectsEnabled(false);
-
- final Resources r = context.getResources();
- setDragSlopeThreshold(
- r.getInteger(R.integer.config_appsCustomizeDragSlopeThreshold) / 100.0f);
- mMaxCellCountY = r.getInteger(R.integer.all_apps_view_maxCellCountY);
- }
-
- @Override
- protected void init() {
- super.init();
- mCenterPagesVertically = false;
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- final int width = MeasureSpec.getSize(widthMeasureSpec);
- final int height = MeasureSpec.getSize(heightMeasureSpec);
-
- if (mLastMeasureWidth != width || mLastMeasureHeight != height) {
- // Create a dummy page and set it up to find out the content width (used by our parent)
- PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
- setupPage(layout);
- mPageContentWidth = layout.getContentWidth();
-
- mCellCountX = determineCellCountX(width, layout);
- mCellCountY = determineCellCountY(height, layout);
- mLastMeasureWidth = width;
- mLastMeasureHeight = height;
- postInvalidatePageData(true);
- }
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
-
- @Override
- protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
- if (mWaitingToInitPages) {
- mWaitingToInitPages = false;
- postInvalidatePageData(false);
- }
- super.onLayout(changed, left, top, right, bottom);
- }
-
- private int determineCellCountX(int availableWidth, PagedViewCellLayout layout) {
- int cellCountX = 0;
- final int cellWidth = layout.getCellWidth();
-
- // Subtract padding for current page and adjacent pages
- availableWidth -= mPageLayoutPaddingLeft * 2 + mPageLayoutPaddingRight * 2;
-
- availableWidth -= cellWidth; // Assume at least one column
- cellCountX = 1 + availableWidth / (cellWidth + mPageLayoutWidthGap);
- availableWidth = availableWidth % (cellWidth + mPageLayoutWidthGap);
-
- // Ensures that we show at least 30% of the holo icons on each side
- final int minLeftoverWidth = (int) (cellWidth * 0.6f);
-
- // Reserve room for the holo outlines
- if (cellCountX <= 4) {
- // When we're really tight on space, just pack the icons a bit closer together
- final int missingWidth = minLeftoverWidth - availableWidth;
- if (missingWidth > 0) {
- mPageLayoutWidthGap -= Math.ceil(missingWidth * 1.0f / (cellCountX - 1));
- }
- } else {
- if (cellCountX >= 8) {
- // Carve out a few extra columns for very large widths
- cellCountX = (int) (cellCountX * 0.9f);
- } else if (availableWidth < minLeftoverWidth) {
- cellCountX -= 1;
- }
- }
- return cellCountX;
- }
-
- private int determineCellCountY(int availableHeight, PagedViewCellLayout layout) {
- final int cellHeight = layout.getCellHeight();
- final int screenHeight = mLauncher.getResources().getDisplayMetrics().heightPixels;
-
- availableHeight -= mPageLayoutPaddingTop + mPageLayoutPaddingBottom;
- availableHeight -= cellHeight; // Assume at least one row
- Resources r = getContext().getResources();
- float scaleFactor = r.getInteger(R.integer.config_appsCustomizeZoomScaleFactor) / 100f;
- availableHeight -= screenHeight * scaleFactor;
- if (availableHeight > 0) {
- return Math.min(mMaxCellCountY,
- 1 + availableHeight / (cellHeight + mPageLayoutHeightGap));
- }
- return 0;
- }
-
- int getCellCountX() {
- return mCellCountX;
- }
-
- int getCellCountY() {
- return mCellCountY;
- }
-
- void allowHardwareLayerCreation() {
- // This is called after the first time we launch into All Apps. Before that point,
- // there's no need for hardware layers here since there's a hardware layer set on the
- // parent, AllAppsTabbed, during the AllApps transition -- creating hardware layers here
- // before the animation is done slows down the animation
- if (mAllowHardwareLayerCreation) {
- return;
- }
- mAllowHardwareLayerCreation = true;
- int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- PagedViewCellLayout page = (PagedViewCellLayout) getChildAt(i);
- page.allowHardwareLayerCreation();
- }
- }
-
- @Override
- public void setup(Launcher launcher, DragController dragController) {
- mLauncher = launcher;
- mDragController = dragController;
- }
-
- public void setAppFilter(int filterType) {
- mAppFilter = filterType;
- if (mApps != null) {
- mFilteredApps = rebuildFilteredApps(mApps);
- setCurrentPage(0);
- invalidatePageData();
- }
- }
-
- void resetSuccessfulDropFlag() {
- mHasMadeSuccessfulDrop = false;
- }
-
- @Override
- public void zoom(float zoom, boolean animate) {
- mZoom = zoom;
- cancelLongPress();
-
- if (isVisible()) {
- if (animate) {
- startAnimation(AnimationUtils.loadAnimation(getContext(),
- R.anim.all_apps_2d_fade_in));
- } else {
- onAnimationEnd();
- }
- } else {
- if (animate) {
- startAnimation(AnimationUtils.loadAnimation(getContext(),
- R.anim.all_apps_2d_fade_out));
- } else {
- onAnimationEnd();
- }
- }
- }
-
- protected void onAnimationEnd() {
- if (!isVisible()) {
- mZoom = 0.0f;
-
- endChoiceMode();
- } else {
- mZoom = 1.0f;
- }
-
- if (mLauncher != null)
- mLauncher.zoomed(mZoom);
- }
-
- private int getChildIndexForGrandChild(View v) {
- final int childCount = getChildCount();
- for (int i = 0; i < childCount; ++i) {
- final Page layout = (Page) getChildAt(i);
- if (layout.indexOfChildOnPage(v) > -1) {
- return i;
- }
- }
- return -1;
- }
-
- @Override
- public void onClick(View v) {
- // if we are already in a choice mode, then just change the selection
- if (v instanceof Checkable) {
- if (!isChoiceMode(CHOICE_MODE_NONE)) {
- Checkable c = (Checkable) v;
- if (isChoiceMode(CHOICE_MODE_SINGLE)) {
- // Uncheck all the other grandchildren, and toggle the clicked one
- boolean wasChecked = c.isChecked();
- resetCheckedGrandchildren();
- c.setChecked(!wasChecked);
- } else {
- c.toggle();
- }
- if (getCheckedGrandchildren().size() == 0) {
- endChoiceMode();
- }
-
- return;
- }
- }
-
- // otherwise continue and launch the application
- int childIndex = getChildIndexForGrandChild(v);
- if (childIndex == getCurrentPage()) {
- final ApplicationInfo app = (ApplicationInfo) v.getTag();
-
- // animate some feedback to the click
- animateClickFeedback(v, new Runnable() {
- @Override
- public void run() {
- mLauncher.startActivitySafely(app.intent, app);
- }
- });
-
- endChoiceMode();
- }
- }
-
- private void setupDragMode(ApplicationInfo info) {
- mLauncher.getWorkspace().shrink(Workspace.ShrinkState.BOTTOM_VISIBLE);
-
- // Only show the uninstall button if the app is uninstallable.
- if ((info.flags & ApplicationInfo.DOWNLOADED_FLAG) != 0) {
- DeleteZone allAppsDeleteZone = (DeleteZone)
- mLauncher.findViewById(R.id.all_apps_delete_zone);
- allAppsDeleteZone.setDragAndDropEnabled(true);
-
- if ((info.flags & ApplicationInfo.UPDATED_SYSTEM_APP_FLAG) != 0) {
- allAppsDeleteZone.setText(R.string.delete_zone_label_all_apps_system_app);
- } else {
- allAppsDeleteZone.setText(R.string.delete_zone_label_all_apps);
- }
- }
-
- ApplicationInfoDropTarget allAppsInfoButton =
- (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
- allAppsInfoButton.setDragAndDropEnabled(true);
- }
-
- private void tearDownDragMode() {
- post(new Runnable() {
- // Once the drag operation has fully completed, hence the post, we want to disable the
- // deleteZone and the appInfoButton in all apps, and re-enable the instance which
- // live in the workspace
- public void run() {
- DeleteZone allAppsDeleteZone =
- (DeleteZone) mLauncher.findViewById(R.id.all_apps_delete_zone);
- // if onDestroy was called on Launcher, we might have already deleted the
- // all apps delete zone / info button, so check if they are null
- if (allAppsDeleteZone != null) allAppsDeleteZone.setDragAndDropEnabled(false);
-
- ApplicationInfoDropTarget allAppsInfoButton =
- (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
- if (allAppsInfoButton != null) allAppsInfoButton.setDragAndDropEnabled(false);
- }
- });
- resetCheckedGrandchildren();
- mDragController.removeDropTarget(this);
- }
-
- @Override
- protected boolean beginDragging(View v) {
- if (!v.isInTouchMode()) return false;
- if (!super.beginDragging(v)) return false;
-
- ApplicationInfo app = (ApplicationInfo) v.getTag();
- app = new ApplicationInfo(app);
-
- // Start drag mode after the item is selected
- setupDragMode(app);
-
- // get icon (top compound drawable, index is 1)
- final TextView tv = (TextView) v;
- final Drawable icon = tv.getCompoundDrawables()[1];
- Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
- Bitmap.Config.ARGB_8888);
- Canvas c = new Canvas(b);
- c.translate((v.getWidth() - icon.getIntrinsicWidth()) / 2, v.getPaddingTop());
- icon.draw(c);
-
- Rect dragRect = null;
- if (v instanceof TextView) {
- int iconSize = getResources().getDimensionPixelSize(R.dimen.app_icon_size);
- int top = v.getPaddingTop();
- int left = (b.getWidth() - iconSize) / 2;
- int right = left + iconSize;
- int bottom = top + iconSize;
- dragRect = new Rect(left, top, right, bottom);
- }
-
- // We toggle the checked state _after_ we create the view for the drag in case toggling the
- // checked state changes the view's look
- if (v instanceof Checkable) {
- // In preparation for drag, we always reset the checked grand children regardless of
- // what choice mode we are in
- resetCheckedGrandchildren();
-
- // Toggle the selection on the dragged app
- Checkable checkable = (Checkable) v;
-
- // Note: we toggle the checkable state to actually cause an alpha fade for the duration
- // of the drag of the item. (The fade-in will occur when all checked states are
- // disabled when dragging ends)
- checkable.toggle();
- }
-
- // Start the drag
- mLauncher.lockScreenOrientation();
- mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
- mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, dragRect);
- b.recycle();
- return true;
- }
-
- @Override
- public void onDragViewVisible() {
- }
-
- @Override
- public void onDropCompleted(View target, DragObject d, boolean success) {
- // close the choice action mode if we have a proper drop
- if (target != this) {
- endChoiceMode();
- }
- tearDownDragMode();
- mLauncher.getWorkspace().onDragStopped(success);
- mLauncher.unlockScreenOrientation();
-
- if (!success && !mHasMadeSuccessfulDrop) {
- mLauncher.getWorkspace().shrink(Workspace.ShrinkState.BOTTOM_HIDDEN);
- } else {
- mHasMadeSuccessfulDrop |= success;
- }
- }
-
- int getPageContentWidth() {
- return mPageContentWidth;
- }
-
- @Override
- public boolean isVisible() {
- return mZoom > 0.001f;
- }
-
- @Override
- public boolean isAnimating() {
- return (getAnimation() != null);
- }
-
- private ArrayList<ApplicationInfo> rebuildFilteredApps(ArrayList<ApplicationInfo> apps) {
- ArrayList<ApplicationInfo> filteredApps = new ArrayList<ApplicationInfo>();
- if (mAppFilter == ALL_APPS_FLAG) {
- return apps;
- } else {
- final int length = apps.size();
- for (int i = 0; i < length; ++i) {
- ApplicationInfo info = apps.get(i);
- if ((info.flags & mAppFilter) > 0) {
- filteredApps.add(info);
- }
- }
- Collections.sort(filteredApps, LauncherModel.APP_INSTALL_TIME_COMPARATOR);
- }
- return filteredApps;
- }
-
- @Override
- public void setApps(ArrayList<ApplicationInfo> list) {
- mApps = list;
- Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
- mFilteredApps = rebuildFilteredApps(mApps);
- invalidatePageData();
- }
-
- private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
- // we add it in place, in alphabetical order
- final int count = list.size();
- for (int i = 0; i < count; ++i) {
- final ApplicationInfo info = list.get(i);
- final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
- if (index < 0) {
- mApps.add(-(index + 1), info);
- } else {
- mApps.add(index, info);
- }
- }
- mFilteredApps = rebuildFilteredApps(mApps);
- }
- @Override
- public void addApps(ArrayList<ApplicationInfo> list) {
- addAppsWithoutInvalidate(list);
- invalidatePageData();
- }
-
- private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
- // End the choice mode if any of the items in the list that are being removed are
- // currently selected
- ArrayList<Checkable> checkedList = getCheckedGrandchildren();
- HashSet<ApplicationInfo> checkedAppInfos = new HashSet<ApplicationInfo>();
- for (Checkable checked : checkedList) {
- PagedViewIcon icon = (PagedViewIcon) checked;
- checkedAppInfos.add((ApplicationInfo) icon.getTag());
- }
- for (ApplicationInfo info : list) {
- if (checkedAppInfos.contains(info)) {
- endChoiceMode();
- break;
- }
- }
-
- // Loop through all the apps and remove apps that have the same component
- final int length = list.size();
- for (int i = 0; i < length; ++i) {
- final ApplicationInfo info = list.get(i);
- int removeIndex = findAppByComponent(mApps, info);
- if (removeIndex > -1) {
- mApps.remove(removeIndex);
- }
- }
- mFilteredApps = rebuildFilteredApps(mApps);
- }
-
- @Override
- public void removeApps(ArrayList<ApplicationInfo> list) {
- removeAppsWithoutInvalidate(list);
- invalidatePageData();
- }
-
- @Override
- public void updateApps(ArrayList<ApplicationInfo> list) {
- removeAppsWithoutInvalidate(list);
- addAppsWithoutInvalidate(list);
- invalidatePageData();
- }
-
- private int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
- if (item != null && item.intent != null) {
- ComponentName removeComponent = item.intent.getComponent();
- final int length = list.size();
- for (int i = 0; i < length; ++i) {
- ApplicationInfo info = list.get(i);
- if (info.intent.getComponent().equals(removeComponent)) {
- return i;
- }
- }
- }
- return -1;
- }
-
- @Override
- public void dumpState() {
- ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps);
- }
-
- @Override
- public void surrender() {
- // do nothing?
- }
-
- public void reset() {
- setCurrentPage(0);
- invalidatePageData();
- }
-
- private void setupPage(PagedViewCellLayout layout) {
- layout.setCellCount(mCellCountX, mCellCountY);
- layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight,
- mPageLayoutPaddingBottom);
- layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
- }
-
- @Override
- protected void invalidatePageData() {
- if (mWaitingToInitPages || mCellCountX <= 0 || mCellCountY <= 0) {
- // We don't know our size yet, which means we haven't calculated cell count x/y;
- // onMeasure will call us once we figure out our size
- return;
- }
- super.invalidatePageData();
- }
-
- @Override
- public void syncPages() {
- /*
- // ensure that we have the right number of pages (min of 1, since we have placeholders)
- int numPages = Math.max(1,
- (int) Math.ceil((float) mFilteredApps.size() / (mCellCountX * mCellCountY)));
- int curNumPages = getChildCount();
- // remove any extra pages after the "last" page
- int extraPageDiff = curNumPages - numPages;
- for (int i = 0; i < extraPageDiff; ++i) {
- removeViewAt(numPages);
- }
- // add any necessary pages
- for (int i = curNumPages; i < numPages; ++i) {
- PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
- if (mAllowHardwareLayerCreation) {
- layout.allowHardwareLayerCreation();
- }
- setupPage(layout);
- addView(layout);
- }
-
- // bound the current page
- setCurrentPage(Math.max(0, Math.min(numPages - 1, getCurrentPage())));
- */
- }
-
- @Override
- public void syncPageItems(int page) {
- /*
- // Ensure that we have the right number of items on the pages
- final int numPages = getPageCount();
- final int cellsPerPage = mCellCountX * mCellCountY;
- final int startIndex = page * cellsPerPage;
- final int endIndex = Math.min(startIndex + cellsPerPage, mFilteredApps.size());
- PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
-
- if (!mFilteredApps.isEmpty()) {
- int curNumPageItems = layout.getPageChildCount();
- int numPageItems = endIndex - startIndex;
- boolean createHolographicOutlines = (numPages > 1);
-
- // If we were previously an empty page, then restart anew
- boolean wasEmptyPage = false;
- if (curNumPageItems == 1) {
- View icon = layout.getChildOnPageAt(0);
- if (icon.getTag() == null) {
- wasEmptyPage = true;
- }
- }
-
- if (wasEmptyPage) {
- // Remove all the previous items
- curNumPageItems = 0;
- layout.removeAllViewsOnPage();
- } else {
- // Remove any extra items
- int extraPageItemsDiff = curNumPageItems - numPageItems;
- for (int i = 0; i < extraPageItemsDiff; ++i) {
- layout.removeViewOnPageAt(numPageItems);
- }
- }
-
- // Add any necessary items
- for (int i = curNumPageItems; i < numPageItems; ++i) {
- TextView text = (TextView) mInflater.inflate(
- R.layout.all_apps_paged_view_application, layout, false);
- text.setOnClickListener(this);
- text.setOnLongClickListener(this);
- text.setOnTouchListener(this);
-
- layout.addViewToCellLayout(text, -1, i,
- new PagedViewCellLayout.LayoutParams(0, 0, 1, 1));
- }
-
- // Actually reapply to the existing text views
- for (int i = startIndex; i < endIndex; ++i) {
- final int index = i - startIndex;
- final ApplicationInfo info = mFilteredApps.get(i);
- PagedViewIcon icon = (PagedViewIcon) layout.getChildOnPageAt(index);
- icon.applyFromApplicationInfo(
- info, null, true, createHolographicOutlines);
-
- PagedViewCellLayout.LayoutParams params =
- (PagedViewCellLayout.LayoutParams) icon.getLayoutParams();
- params.cellX = index % mCellCountX;
- params.cellY = index / mCellCountX;
- }
-
- // We should try and sync all the holographic icons after adding/removing new items
- layout.reloadHolographicIcons(createHolographicOutlines);
-
- // Default to left-aligned icons
- layout.enableCenteredContent(false);
- } else {
- // There are no items, so show the user a small message
- TextView icon = (TextView) mInflater.inflate(
- R.layout.all_apps_no_items_placeholder, layout, false);
- switch (mAppFilter) {
- case ApplicationInfo.DOWNLOADED_FLAG:
- icon.setText(mContext.getString(R.string.all_apps_no_downloads));
- break;
- default: break;
- }
-
- // Center-align the message
- final boolean createHolographicOutlines = (numPages > 1);
- layout.enableCenteredContent(true);
- layout.removeAllViewsOnPage();
- layout.addViewToCellLayout(icon, -1, 0,
- new PagedViewCellLayout.LayoutParams(0, 0, 4, 1));
- }
- layout.createHardwareLayers();
- */
- }
-
- /*
- * We don't actually use AllAppsPagedView as a drop target... it's only used to intercept a drop
- * to the workspace.
- */
- public boolean acceptDrop(DragObject d) {
- return false;
- }
- public DropTarget getDropTargetDelegate(DragObject d) {
- return null;
- }
- public void onDragEnter(DragObject d) {}
- public void onDragExit(DragObject d) {}
- public void onDragOver(DragObject d) {}
- public void onDrop(DragObject d) {}
-
- public boolean isDropEnabled() {
- return true;
- }
-}
diff --git a/src/com/android/launcher2/AllAppsTabbed.java b/src/com/android/launcher2/AllAppsTabbed.java
deleted file mode 100644
index b765e17..0000000
--- a/src/com/android/launcher2/AllAppsTabbed.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * Copyright (C) 2010 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.launcher2;
-
-import com.android.launcher.R;
-
-import android.animation.Animator;
-import android.animation.AnimatorListenerAdapter;
-import android.animation.ObjectAnimator;
-import android.animation.ValueAnimator;
-import android.content.Context;
-import android.content.res.Resources;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TabHost;
-import android.widget.TabWidget;
-import android.widget.TextView;
-
-import java.util.ArrayList;
-
-/**
- * Implements a tabbed version of AllApps2D.
- */
-public class AllAppsTabbed extends TabHost implements AllAppsView, LauncherTransitionable {
-
- private static final String TAG = "Launcher.AllAppsTabbed";
-
- private static final String TAG_ALL = "ALL";
- private static final String TAG_DOWNLOADED = "DOWNLOADED";
-
- private AllAppsPagedView mAllApps;
- private AllAppsBackground mBackground;
- private Launcher mLauncher;
- private Context mContext;
- private final LayoutInflater mInflater;
- private boolean mFirstLayout = true;
-
- public AllAppsTabbed(Context context, AttributeSet attrs) {
- super(context, attrs);
- mContext = context;
- mInflater = LayoutInflater.from(context);
- }
-
- @Override
- protected void onFinishInflate() {
- // setup the tab host
- setup();
-
- try {
- mAllApps = (AllAppsPagedView) findViewById(R.id.all_apps_paged_view);
- if (mAllApps == null) throw new Resources.NotFoundException();
- mBackground = (AllAppsBackground) findViewById(R.id.all_apps_background);
- if (mBackground == null) throw new Resources.NotFoundException();
- } catch (Resources.NotFoundException e) {
- Log.e(TAG, "Can't find necessary layout elements for AllAppsTabbed");
- }
-
- // share the same AllApps workspace across all the tabs
- TabContentFactory contentFactory = new TabContentFactory() {
- public View createTabContent(String tag) {
- return mAllApps;
- }
- };
-
- // Create the tabs and wire them up properly
- AppsCustomizeTabKeyEventListener keyListener = new AppsCustomizeTabKeyEventListener();
- TextView tabView;
- TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
- tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
- tabView.setText(mContext.getString(R.string.all_apps_tab_all));
- addTab(newTabSpec(TAG_ALL).setIndicator(tabView).setContent(contentFactory));
-
- tabView = (TextView) mInflater.inflate(R.layout.tab_widget_indicator, tabWidget, false);
- tabView.setText(mContext.getString(R.string.all_apps_tab_downloaded));
- addTab(newTabSpec(TAG_DOWNLOADED).setIndicator(tabView).setContent(contentFactory));
-
- // Setup the key listener to jump between the last tab view and the market icon
- View lastTab = tabWidget.getChildTabViewAt(tabWidget.getTabCount() - 1);
- lastTab.setOnKeyListener(keyListener);
- View shopButton = findViewById(R.id.market_button);
- shopButton.setOnKeyListener(keyListener);
-
- setOnTabChangedListener(new OnTabChangeListener() {
- public void onTabChanged(String tabId) {
- // animate the changing of the tab content by fading pages in and out
- final Resources res = getResources();
- final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
- final float alpha = mAllApps.getAlpha();
- ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 0.0f).
- setDuration(duration);
- alphaAnim.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- String tag = getCurrentTabTag();
- if (tag == TAG_ALL) {
- mAllApps.setAppFilter(AllAppsPagedView.ALL_APPS_FLAG);
- } else if (tag == TAG_DOWNLOADED) {
- mAllApps.setAppFilter(ApplicationInfo.DOWNLOADED_FLAG);
- }
-
- final float alpha = mAllApps.getAlpha();
- ObjectAnimator.ofFloat(mAllApps, "alpha", alpha, 1.0f).
- setDuration(duration).start();
- }
- });
- alphaAnim.start();
- }
- });
-
-
- // It needs to be INVISIBLE so that it will be measured in the layout.
- // Otherwise the animations is messed up when we show it for the first time.
- setVisibility(INVISIBLE);
- }
-
- @Override
- public void setup(Launcher launcher, DragController dragController) {
- mLauncher = launcher;
- mAllApps.setup(launcher, dragController);
- }
-
- @Override
- public void zoom(float zoom, boolean animate) {
- // NOTE: animate parameter is ignored for the TabHost itself
- setVisibility((zoom == 0.0f) ? View.GONE : View.VISIBLE);
- mAllApps.zoom(zoom, animate);
- }
-
- @Override
- public void setVisibility(int visibility) {
- if (visibility == View.GONE && mFirstLayout) {
- // It needs to be INVISIBLE so that it will be measured in the layout.
- // Otherwise the animations is messed up when we show it for the first time.
- visibility = View.INVISIBLE;
- }
- final boolean isVisible = (visibility == View.VISIBLE);
- super.setVisibility(visibility);
- float zoom = (isVisible ? 1.0f : 0.0f);
- mAllApps.zoom(zoom, false);
- }
-
- @Override
- public boolean isVisible() {
- return mAllApps.isVisible();
- }
-
- @Override
- protected void onLayout(boolean changed, int l, int t, int r, int b) {
- if (mFirstLayout) {
- mFirstLayout = false;
- }
- // Set the width of the tab bar properly
- int pageWidth = mAllApps.getPageContentWidth();
- TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
- View allAppsTabBar = (View) findViewById(R.id.all_apps_tab_bar);
- if (allAppsTabBar == null) throw new Resources.NotFoundException();
- int tabWidgetPadding = 0;
- final int childCount = tabWidget.getChildCount();
- if (childCount > 0) {
- tabWidgetPadding += tabWidget.getChildAt(0).getPaddingLeft() * 2;
- }
-
- int newWidth = Math.min(getMeasuredWidth(), pageWidth + tabWidgetPadding);
- if (newWidth != allAppsTabBar.getLayoutParams().width) {
- allAppsTabBar.getLayoutParams().width = newWidth;
- post(new Runnable() {
- public void run() {
- requestLayout();
- }
- });
- }
-
- super.onLayout(changed, l, t, r, b);
- }
-
- @Override
- public boolean isAnimating() {
- return (getAnimation() != null);
- }
-
- @Override
- public void onLauncherTransitionStart(Animator animation) {
- if (animation != null) {
- // Turn on hardware layers for performance
- setLayerType(LAYER_TYPE_HARDWARE, null);
- // Re-enable the rendering of the dimmed background in All Apps for performance reasons
- // if we're fading it in
- if (mLauncher.getWorkspace().getBackgroundAlpha() == 0f) {
- mLauncher.getWorkspace().disableBackground();
- mBackground.setVisibility(VISIBLE);
- }
- // just a sanity check that we don't build a layer before a call to onLayout
- if (!mFirstLayout) {
- // force building the layer at the beginning of the animation, so you don't get a
- // blip early in the animation
- buildLayer();
- }
- }
- }
-
- @Override
- public void onLauncherTransitionEnd(Animator animation) {
- if (animation != null) {
- setLayerType(LAYER_TYPE_NONE, null);
- // To improve the performance of the first time All Apps is run, we initially keep
- // hardware layers in AllAppsPagedView disabled since AllAppsTabbed itself is drawn in a
- // hardware layer, and creating additional hardware layers slows down the animation. We
- // create them here, after the animation is over.
- }
- // Move the rendering of the dimmed background to workspace after the all apps animation
- // is done, so that the background is not rendered *above* the mini workspace screens
- if (mBackground.getVisibility() != GONE) {
- mLauncher.getWorkspace().enableBackground();
- mBackground.setVisibility(GONE);
- }
- mAllApps.allowHardwareLayerCreation();
- }
-
- @Override
- public void setApps(ArrayList<ApplicationInfo> list) {
- mAllApps.setApps(list);
- }
-
- @Override
- public void addApps(ArrayList<ApplicationInfo> list) {
- mAllApps.addApps(list);
- }
-
- @Override
- public void removeApps(ArrayList<ApplicationInfo> list) {
- mAllApps.removeApps(list);
- }
-
- @Override
- public void updateApps(ArrayList<ApplicationInfo> list) {
- mAllApps.updateApps(list);
- }
-
- @Override
- public void dumpState() {
- mAllApps.dumpState();
- }
-
- @Override
- public void surrender() {
- mAllApps.surrender();
- }
-
- public void reset() {
- mAllApps.reset();
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- if (ev.getY() > mAllApps.getBottom()) {
- return false;
- }
- return true;
- }
-
- @Override
- public int getDescendantFocusability() {
- if (getVisibility() != View.VISIBLE) {
- return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
- }
- return super.getDescendantFocusability();
- }
-}
diff --git a/src/com/android/launcher2/ApplicationInfoDropTarget.java b/src/com/android/launcher2/ApplicationInfoDropTarget.java
deleted file mode 100644
index 4a9727d..0000000
--- a/src/com/android/launcher2/ApplicationInfoDropTarget.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2010 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.launcher2;
-
-import android.animation.Animator;
-import android.animation.AnimatorSet;
-import android.animation.ObjectAnimator;
-import android.animation.Animator.AnimatorListener;
-import android.content.ComponentName;
-import android.content.Context;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
-import android.util.AttributeSet;
-import android.view.View;
-
-import com.android.launcher.R;
-
-/**
- * Implements a DropTarget which allows applications to be dropped on it,
- * in order to launch the application info for that app.
- */
-public class ApplicationInfoDropTarget extends IconDropTarget {
- private static final int sFadeInAnimationDuration = 200;
- private static final int sFadeOutAnimationDuration = 100;
-
- private AnimatorSet mFadeAnimator;
-
- public ApplicationInfoDropTarget(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public ApplicationInfoDropTarget(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- // Set the hover paint colour
- int colour = getContext().getResources().getColor(R.color.info_target_hover_tint);
- mHoverPaint.setColorFilter(new PorterDuffColorFilter(colour, PorterDuff.Mode.SRC_ATOP));
-
- // For the application info drop target, we just ignore the left padding since we don't want
- // to overlap with the delete zone padding
- int tb = getResources().getDimensionPixelSize(
- R.dimen.delete_zone_vertical_drag_padding);
- int lr = getResources().getDimensionPixelSize(
- R.dimen.delete_zone_horizontal_drag_padding);
- setDragPadding(tb, lr, tb, 0);
- }
-
- public boolean acceptDrop(DragObject d) {
- // acceptDrop is called just before onDrop. We do the work here, rather than
- // in onDrop, because it allows us to reject the drop (by returning false)
- // so that the object being dragged isn't removed from the home screen.
- if (getVisibility() != VISIBLE) return false;
-
- ComponentName componentName = null;
- if (d.dragInfo instanceof ApplicationInfo) {
- componentName = ((ApplicationInfo) d.dragInfo).componentName;
- } else if (d.dragInfo instanceof ShortcutInfo) {
- componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
- }
- mLauncher.startApplicationDetailsActivity(componentName);
- return false;
- }
-
- public void onDragEnter(DragObject d) {
- if (!mDragAndDropEnabled) return;
- d.dragView.setPaint(mHoverPaint);
- }
-
- public void onDragExit(DragObject d) {
- if (!mDragAndDropEnabled) return;
- d.dragView.setPaint(null);
- }
-
- public void onDragStart(DragSource source, Object info, int dragAction) {
- if (info != null && mDragAndDropEnabled) {
- final int itemType = ((ItemInfo)info).itemType;
- mActive = (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION);
- if (mActive) {
- // Fade in this icon
- if (mFadeAnimator != null) mFadeAnimator.cancel();
- mFadeAnimator = new AnimatorSet();
- Animator infoButtonAnimator = ObjectAnimator.ofFloat(this, "alpha", 0.0f, 1.0f);
- infoButtonAnimator.setDuration(sFadeInAnimationDuration);
-
- mFadeAnimator.play(infoButtonAnimator);
-
- setVisibility(VISIBLE);
-
- // Fade out the overlapping views
- if (mOverlappingViews != null) {
- for (View view : mOverlappingViews) {
- ObjectAnimator oa = ObjectAnimator.ofFloat(view, "alpha", 0.0f);
- oa.setDuration(sFadeOutAnimationDuration);
- mFadeAnimator.play(oa);
- }
- mFadeAnimator.addListener(new AnimatorListener() {
- public void onAnimationStart(Animator animation) {}
- public void onAnimationRepeat(Animator animation) {}
- public void onAnimationEnd(Animator animation) {
- onEndOrCancel();
- }
- public void onAnimationCancel(Animator animation) {
- onEndOrCancel();
- }
- private void onEndOrCancel() {
- for (View view : mOverlappingViews) {
- view.setVisibility(INVISIBLE);
- }
- mFadeAnimator = null;
- }
- });
- }
- mFadeAnimator.start();
- }
- }
- }
-
- public void onDragEnd() {
- if (!mDragAndDropEnabled) return;
- if (mActive) mActive = false;
-
- // Fade out this icon
- if (mFadeAnimator != null) mFadeAnimator.cancel();
- mFadeAnimator = new AnimatorSet();
- Animator infoButtonAnimator = ObjectAnimator.ofFloat(this, "alpha", 0.0f);
- infoButtonAnimator.setDuration(sFadeOutAnimationDuration);
- mFadeAnimator.addListener(new AnimatorListener() {
- public void onAnimationStart(Animator animation) {}
- public void onAnimationRepeat(Animator animation) {}
- public void onAnimationEnd(Animator animation) {
- onEndOrCancel();
- }
- public void onAnimationCancel(Animator animation) {
- onEndOrCancel();
- }
- private void onEndOrCancel() {
- setVisibility(GONE);
- mFadeAnimator = null;
- }
- });
- mFadeAnimator.play(infoButtonAnimator);
-
- // Fade in the overlapping views
- if (mOverlappingViews != null) {
- for (View view : mOverlappingViews) {
- // Check whether the views are enabled first, before trying to fade them in
- if (view.isEnabled()) {
- ObjectAnimator oa = ObjectAnimator.ofFloat(view, "alpha", 1.0f);
- oa.setDuration(sFadeInAnimationDuration);
- mFadeAnimator.play(oa);
- view.setVisibility(VISIBLE);
- }
- }
- }
- mFadeAnimator.start();
- }
-}
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 1d7b34d..da6e7de 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -33,9 +33,6 @@ import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.PorterDuff.Mode;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
@@ -64,6 +61,7 @@ import java.util.List;
interface AsyncTaskCallback {
void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data);
}
+
/**
* The data needed to perform either of the custom AsyncTasks.
*/
@@ -72,8 +70,8 @@ class AsyncTaskPageData {
AsyncTaskCallback postR) {
page = p;
items = l;
- srcImages = si;
- images = new ArrayList<Bitmap>();
+ sourceImages = si;
+ generatedImages = new ArrayList<Bitmap>();
cellWidth = cellHeight = -1;
doInBackgroundCallback = bgR;
postExecuteCallback = postR;
@@ -82,7 +80,7 @@ class AsyncTaskPageData {
AsyncTaskCallback postR) {
page = p;
items = l;
- images = new ArrayList<Bitmap>();
+ generatedImages = new ArrayList<Bitmap>();
cellWidth = cw;
cellHeight = ch;
doInBackgroundCallback = bgR;
@@ -90,13 +88,14 @@ class AsyncTaskPageData {
}
int page;
ArrayList<Object> items;
- ArrayList<Bitmap> srcImages;
- ArrayList<Bitmap> images;
+ ArrayList<Bitmap> sourceImages;
+ ArrayList<Bitmap> generatedImages;
int cellWidth;
int cellHeight;
AsyncTaskCallback doInBackgroundCallback;
AsyncTaskCallback postExecuteCallback;
}
+
/**
* A generic template for an async task used in AppsCustomize.
*/
@@ -131,22 +130,6 @@ class AppsCustomizeAsyncTask extends AsyncTask<AsyncTaskPageData, Void, AsyncTas
AppsCustomizePagedView.ContentType pageContentType;
int threadPriority;
}
-/**
- * An AsyncTask that loads widget previews from package manager in the background.
- */
-class LoadWidgetPreviewsTask extends AppsCustomizeAsyncTask {
- LoadWidgetPreviewsTask(int p, AppsCustomizePagedView.ContentType t) {
- super(p, t);
- }
-}
-/**
- * An AsyncTask that generates holgoraphic outlines for a specified set of bitmaps.
- */
-class GenerateHoloOutlinesTask extends AppsCustomizeAsyncTask {
- GenerateHoloOutlinesTask(int p, AppsCustomizePagedView.ContentType t) {
- super(p, t);
- }
-}
/**
* The Apps/Customize page that displays all the applications, widgets, and shortcuts.
@@ -462,22 +445,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
return true;
}
private void endDragging(boolean success) {
- post(new Runnable() {
- // Once the drag operation has fully completed, hence the post, we want to disable the
- // deleteZone and the appInfoButton in all apps, and re-enable the instance which
- // live in the workspace
- public void run() {
- // if onDestroy was called on Launcher, we might have already deleted the
- // all apps delete zone / info button, so check if they are null
- DeleteZone allAppsDeleteZone =
- (DeleteZone) mLauncher.findViewById(R.id.all_apps_delete_zone);
- ApplicationInfoDropTarget allAppsInfoButton =
- (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.all_apps_info_target);
-
- if (allAppsDeleteZone != null) allAppsDeleteZone.setDragAndDropEnabled(false);
- if (allAppsInfoButton != null) allAppsInfoButton.setDragAndDropEnabled(false);
- }
- });
mLauncher.exitSpringLoadedDragMode();
mLauncher.getWorkspace().onDragStopped(success);
mLauncher.unlockScreenOrientation();
@@ -624,7 +591,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
while (iter.hasNext()) {
AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
int taskPage = task.page;
- if (taskPage < (mCurrentPage - 2) || taskPage > (mCurrentPage + 2)) {
+ if (taskPage < getAssociatedLowerPageBound(mCurrentPage) ||
+ taskPage > getAssociatedUpperPageBound(mCurrentPage)) {
task.cancel(false);
iter.remove();
} else {
@@ -641,7 +609,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// Load each of the widget/shortcut previews
ArrayList<Object> items = data.items;
- ArrayList<Bitmap> images = data.images;
+ ArrayList<Bitmap> images = data.generatedImages;
int count = items.size();
int cellWidth = data.cellWidth;
int cellHeight = data.cellHeight;
@@ -655,12 +623,12 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
int[] cellSpans = CellLayout.rectToCell(getResources(),
info.minWidth, info.minHeight, null);
- images.add(getWidgetPreviewInBackground(info, cellSpans[0],cellSpans[1],
+ images.add(getWidgetPreview(info, cellSpans[0],cellSpans[1],
cellWidth, cellHeight));
} else if (rawInfo instanceof ResolveInfo) {
// Fill in the shortcuts information
ResolveInfo info = (ResolveInfo) rawInfo;
- images.add(getShortcutPreviewInBackground(info, cellWidth, cellHeight));
+ images.add(getShortcutPreview(info, cellWidth, cellHeight));
}
}
}
@@ -676,7 +644,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
});
// Ensure that the task is appropriately prioritized and runs in parallel
- LoadWidgetPreviewsTask t = new LoadWidgetPreviewsTask(page, mContentType);
+ AppsCustomizeAsyncTask t = new AppsCustomizeAsyncTask(page, mContentType);
t.setThreadPriority(getThreadPriorityForPage(page));
t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, pageData);
mRunningTasks.add(t);
@@ -693,8 +661,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// Ensure that this task starts running at the correct priority
task.syncThreadPriority();
- ArrayList<Bitmap> images = data.images;
- ArrayList<Bitmap> srcImages = data.srcImages;
+ ArrayList<Bitmap> images = data.generatedImages;
+ ArrayList<Bitmap> srcImages = data.sourceImages;
int count = srcImages.size();
Canvas c = new Canvas();
for (int i = 0; i < count && !task.isCancelled(); ++i) {
@@ -726,8 +694,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
});
// Ensure that the outline task always runs in the background, serially
- GenerateHoloOutlinesTask t =
- new GenerateHoloOutlinesTask(page, mContentType);
+ AppsCustomizeAsyncTask t =
+ new AppsCustomizeAsyncTask(page, mContentType);
t.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
t.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, pageData);
mRunningTasks.add(t);
@@ -762,7 +730,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
d.setBounds(oldBounds); // Restore the bounds
}
}
- private Bitmap getShortcutPreviewInBackground(ResolveInfo info, int cellWidth,
+ private Bitmap getShortcutPreview(ResolveInfo info, int cellWidth,
int cellHeight) {
Resources resources = mLauncher.getResources();
int iconSize = resources.getDimensionPixelSize(R.dimen.app_icon_size);
@@ -776,7 +744,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
renderDrawableToBitmap(icon, preview, 0, 0, iconSize, iconSize, 1f, 1f);
return preview;
}
- private Bitmap getWidgetPreviewInBackground(AppWidgetProviderInfo info,
+ private Bitmap getWidgetPreview(AppWidgetProviderInfo info,
int cellHSpan, int cellVSpan, int cellWidth, int cellHeight) {
// Calculate the size of the drawable
@@ -901,7 +869,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
createItemInfo = new PendingAddWidgetInfo(info, null, null);
int[] cellSpans = CellLayout.rectToCell(getResources(),
info.minWidth, info.minHeight, null);
- FastBitmapDrawable preview = new FastBitmapDrawable(data.images.get(i));
+ FastBitmapDrawable preview = new FastBitmapDrawable(data.generatedImages.get(i));
widget.applyFromAppWidgetProviderInfo(info, preview, -1, cellSpans,
mHolographicOutlineHelper);
widget.setTag(createItemInfo);
@@ -912,7 +880,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
createItemInfo.componentName = new ComponentName(info.activityInfo.packageName,
info.activityInfo.name);
- FastBitmapDrawable preview = new FastBitmapDrawable(data.images.get(i));
+ FastBitmapDrawable preview = new FastBitmapDrawable(data.generatedImages.get(i));
widget.applyFromResolveInfo(mPackageManager, info, preview,
mHolographicOutlineHelper);
widget.setTag(createItemInfo);
@@ -933,7 +901,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
invalidate();
forceUpdateAdjacentPagesAlpha();
- prepareGenerateHoloOutlinesTask(data.page, data.items, data.images);
+ prepareGenerateHoloOutlinesTask(data.page, data.items, data.generatedImages);
}
private void onHolographicPageItemsLoaded(AsyncTaskPageData data) {
// Invalidate early to short-circuit children invalidates
@@ -946,13 +914,13 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
int count = cl.getPageChildCount();
for (int i = 0; i < count; ++i) {
PagedViewIcon icon = (PagedViewIcon) cl.getChildOnPageAt(i);
- icon.setHolographicOutline(data.images.get(i));
+ icon.setHolographicOutline(data.generatedImages.get(i));
}
} else {
int count = layout.getChildCount();
for (int i = 0; i < count; ++i) {
View v = layout.getChildAt(i);
- ((PagedViewWidget) v).setHolographicOutline(data.images.get(i));
+ ((PagedViewWidget) v).setHolographicOutline(data.generatedImages.get(i));
}
}
}
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java
deleted file mode 100644
index c98e885..0000000
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ /dev/null
@@ -1,1275 +0,0 @@
-/*
- * Copyright (C) 2010 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.launcher2;
-
-import android.animation.Animator;
-import android.animation.AnimatorListenerAdapter;
-import android.animation.ObjectAnimator;
-import android.animation.PropertyValuesHolder;
-import android.animation.TimeInterpolator;
-import android.app.WallpaperManager;
-import android.appwidget.AppWidgetManager;
-import android.appwidget.AppWidgetProviderInfo;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.content.res.XmlResourceParser;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.Bitmap.Config;
-import android.graphics.drawable.Drawable;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.util.Slog;
-import android.util.TypedValue;
-import android.util.Xml;
-import android.view.ActionMode;
-import android.view.Gravity;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.animation.DecelerateInterpolator;
-import android.view.animation.LinearInterpolator;
-import android.widget.Checkable;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import com.android.launcher.R;
-import com.android.launcher2.DropTarget.DragObject;
-
-import org.xmlpull.v1.XmlPullParser;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-
-public class CustomizePagedView extends PagedViewWithDraggableItems
- implements View.OnClickListener, DragSource, ActionMode.Callback {
-
- public enum CustomizationType {
- WidgetCustomization,
- ShortcutCustomization,
- WallpaperCustomization,
- ApplicationCustomization
- }
-
- private static final String TAG = "CustomizeWorkspace";
-
- private Launcher mLauncher;
- private DragController mDragController;
- private PackageManager mPackageManager;
-
- private CustomizationType mCustomizationType;
-
- // The layout used to emulate the workspace in resolve the cell dimensions of a widget
- private PagedViewCellLayout mWorkspaceWidgetLayout;
-
- // The mapping between the pages and the widgets that will be laid out on them
- private ArrayList<ArrayList<AppWidgetProviderInfo>> mWidgetPages;
-
- // This is used if we want to set a min width on pages so that things inside them left align to
- // a fixed size
- private int mMinPageWidth;
-
- // The max dimensions for the ImageView we use for displaying a widget
- private int mMaxWidgetWidth;
-
- // The max number of widget cells to take a "page" of widgets
- private int mMaxWidgetsCellHSpan;
-
- // The size of the items on the wallpaper tab
- private int mWallpaperCellHSpan;
-
- // The max number of wallpaper cells to take a "page" of wallpaper items
- private int mMaxWallpaperCellHSpan;
-
- // The maximum number of rows in a paged view.
- private int mMaxCellCountY;
-
- // The raw sources of data for each of the different tabs of the customization page
- private List<AppWidgetProviderInfo> mWidgetList;
- private List<ResolveInfo> mShortcutList;
- private List<ResolveInfo> mWallpaperList;
- private List<ApplicationInfo> mApps;
-
- private static final int sMinWidgetCellHSpan = 2;
- private static final int sMaxWidgetCellHSpan = 4;
-
- private int mChoiceModeTitleText;
-
- // The scale factor for widget previews inside the widget drawer
- private static final float sScaleFactor = 0.75f;
-
- private final Canvas mCanvas = new Canvas();
- private final LayoutInflater mInflater;
-
- private boolean mFirstMeasure = true;
-
- private final float mTmpFloatPos[] = new float[2];
- private final float ANIMATION_SCALE = 0.5f;
-
- // The duration of the translation animation that occurs during you drag and drop
- private final int TRANSLATE_ANIM_DURATION = 400;
-
- // The duration of the scale & alpha animation that occurs during drag and drop
- private final int DROP_ANIM_DURATION = 200;
-
- private TimeInterpolator mQuintEaseOutInterpolator = new DecelerateInterpolator(2.5f);
-
- // The Bitmap used to generate the drag view
- private Bitmap mDragBitmap;
-
- private int[] mDragViewOrigin = new int[2];
-
- private int mPageContentWidth = -1;
- private int mPageContentHeight = -1;
-
- private AllAppsPagedView mAllAppsPagedView;
-
- private boolean mWaitingToInitPages = true;
-
- public CustomizePagedView(Context context) {
- this(context, null, 0);
- }
-
- public CustomizePagedView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public CustomizePagedView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- TypedArray a;
- a = context.obtainStyledAttributes(attrs, R.styleable.CustomizePagedView, defStyle, 0);
- mWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellSpanX, 4);
- mMaxWallpaperCellHSpan = a.getInt(R.styleable.CustomizePagedView_wallpaperCellCountX, 8);
- mMaxWidgetsCellHSpan = a.getInt(R.styleable.CustomizePagedView_widgetCellCountX, 8);
- a.recycle();
-
- mCustomizationType = CustomizationType.WidgetCustomization;
- mWidgetPages = new ArrayList<ArrayList<AppWidgetProviderInfo>>();
- mWorkspaceWidgetLayout = new PagedViewCellLayout(context);
- mInflater = LayoutInflater.from(context);
-
- final Resources r = context.getResources();
- setDragSlopeThreshold(
- r.getInteger(R.integer.config_customizationDrawerDragSlopeThreshold) / 100.0f);
-
- mMaxCellCountY = r.getInteger(R.integer.customization_drawer_contents_maxCellCountY);
-
- setVisibility(View.GONE);
- setSoundEffectsEnabled(false);
- setupWorkspaceLayout();
- }
-
- @Override
- protected void init() {
- super.init();
- mCenterPagesVertically = false;
- }
-
- @Override
- protected void onMeasure(int widthSpec, int heightSpec) {
- // Base the size of this control on the size of the All Apps view.
- final int cellCountX = mAllAppsPagedView.getCellCountX();
- final int cellCountY = Math.min(mAllAppsPagedView.getCellCountY(), mMaxCellCountY);
-
- if (cellCountX != mCellCountX || cellCountY != mCellCountY) {
- mCellCountX = cellCountX;
- mCellCountY = cellCountY;
-
- // Create a dummy page and set it up to determine our size.
- // The size is based on the app shortcuts tab having the same dimensions as All Apps.
- PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
- setupPage(layout);
- mPageContentWidth = layout.getContentWidth();
- mPageContentHeight = layout.getContentHeight();
- mMinPageWidth = layout.getWidthBeforeFirstLayout();
- postInvalidatePageData(true);
- }
- if (mPageContentHeight > 0) {
- // Lock our height to the size of the page content
- final int h = mPageContentHeight + mPageLayoutPaddingTop + mPageLayoutPaddingBottom;
- heightSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY);
- }
- super.onMeasure(widthSpec, heightSpec);
- mFirstMeasure = false;
- }
-
- @Override
- protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
- if (mWaitingToInitPages) {
- mWaitingToInitPages = false;
- postInvalidatePageData(false);
- }
- super.onLayout(changed, left, top, right, bottom);
- mFirstLayout = false;
- }
-
- public void setLauncher(Launcher launcher) {
- Context context = getContext();
- mLauncher = launcher;
- mPackageManager = context.getPackageManager();
- }
-
- public void setAllAppsPagedView(AllAppsPagedView view) {
- mAllAppsPagedView = view;
- }
-
- /**
- * Sets the list of applications that launcher has loaded.
- */
- public void setApps(ArrayList<ApplicationInfo> list) {
- mApps = list;
- Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
-
- // Update the widgets/shortcuts to reflect changes in the set of available apps
- invalidatePageData();
- }
-
- /**
- * Convenience function to add new items to the set of applications that were previously loaded.
- * Called by both updateApps() and setApps().
- */
- private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
- // we add it in place, in alphabetical order
- final int count = list.size();
- for (int i = 0; i < count; ++i) {
- final ApplicationInfo info = list.get(i);
- final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR);
- if (index < 0) {
- mApps.add(-(index + 1), info);
- }
- }
- }
-
- /**
- * Adds new applications to the loaded list, and notifies the paged view to update itself.
- */
- public void addApps(ArrayList<ApplicationInfo> list) {
- addAppsWithoutInvalidate(list);
-
- // Update the widgets/shortcuts to reflect changes in the set of available apps
- invalidatePageData();
- }
-
- /**
- * Convenience function to remove items to the set of applications that were previously loaded.
- * Called by both updateApps() and removeApps().
- */
- private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) {
- // loop through all the apps and remove apps that have the same component
- final int length = list.size();
- for (int i = 0; i < length; ++i) {
- final ApplicationInfo info = list.get(i);
- int removeIndex = findAppByComponent(mApps, info);
- if (removeIndex > -1) {
- mApps.remove(removeIndex);
- }
- }
- }
-
- /**
- * Removes applications from the loaded list, and notifies the paged view to update itself.
- */
- public void removeApps(ArrayList<ApplicationInfo> list) {
- removeAppsWithoutInvalidate(list);
-
- // Update the widgets/shortcuts to reflect changes in the set of available apps
- invalidatePageData();
- }
-
- /**
- * Updates a set of applications from the loaded list, and notifies the paged view to update
- * itself.
- */
- public void updateApps(ArrayList<ApplicationInfo> list) {
- // We remove and re-add the updated applications list because it's properties may have
- // changed (ie. the title), and this will ensure that the items will be in their proper
- // place in the list.
- removeAppsWithoutInvalidate(list);
- addAppsWithoutInvalidate(list);
-
- // Update the widgets/shortcuts to reflect changes in the set of available apps
- invalidatePageData();
- }
-
- /**
- * Convenience function to find matching ApplicationInfos for removal.
- */
- private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) {
- ComponentName removeComponent = item.intent.getComponent();
- final int length = list.size();
- for (int i = 0; i < length; ++i) {
- ApplicationInfo info = list.get(i);
- if (info.intent.getComponent().equals(removeComponent)) {
- return i;
- }
- }
- return -1;
- }
-
- public void update() {
- // get the list of widgets
- mWidgetList = AppWidgetManager.getInstance(mLauncher).getInstalledProviders();
- Collections.sort(mWidgetList, new Comparator<AppWidgetProviderInfo>() {
- @Override
- public int compare(AppWidgetProviderInfo object1, AppWidgetProviderInfo object2) {
- return object1.label.compareTo(object2.label);
- }
- });
-
- LauncherModel.ShortcutNameComparator resolveInfoComparator =
- new LauncherModel.ShortcutNameComparator(mPackageManager);
-
- // get the list of shortcuts
- Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
- mShortcutList = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
- Collections.sort(mShortcutList, resolveInfoComparator);
-
- // get the list of wallpapers
- Intent wallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
- mWallpaperList = mPackageManager.queryIntentActivities(wallpapersIntent,
- PackageManager.GET_META_DATA);
- Collections.sort(mWallpaperList, resolveInfoComparator);
-
- ArrayList<ResolveInfo> retainShortcutList = new ArrayList<ResolveInfo>(mShortcutList);
- retainShortcutList.addAll(mWallpaperList);
- invalidatePageData();
- }
-
- public void setDragController(DragController dragger) {
- mDragController = dragger;
- }
-
- public void setCustomizationFilter(CustomizationType filterType) {
- cancelDragging();
- mCustomizationType = filterType;
- if (getChildCount() > 0) {
- setCurrentPage(0);
- updateCurrentPageScroll();
- invalidatePageData();
-
- // End the current choice mode so that we don't carry selections across tabs
- endChoiceMode();
- }
- }
-
- public CustomizationType getCustomizationFilter() {
- return mCustomizationType;
- }
-
- /**
- * Similar to resetCheckedGrandchildren, but allows us to specify that it's not animated.
- */
- private void resetCheckedItem(boolean animated) {
- final Checkable checkable = getSingleCheckedGrandchild();
- if (checkable != null) {
- if (checkable instanceof PagedViewWidget) {
- ((PagedViewWidget) checkable).setChecked(false, animated);
- } else {
- ((PagedViewIcon) checkable).setChecked(false, animated);
- }
- }
- }
-
- public void onDropCompleted(View target, DragObject d, boolean success) {
- final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
-
- // Create a view, identical to the drag view, that is only used for animating the
- // item onto the home screen (or back to its original position, if the drop failed).
- final int[] pos = mDragController.getDragView().getPosition(null);
- final View animView = dragLayer.createDragView(mDragBitmap, pos[0], pos[1]);
- animView.setVisibility(View.VISIBLE);
-
- if (success) {
- resetCheckedItem(true);
- animateDropOntoScreen(animView, (ItemInfo) d.dragInfo, DROP_ANIM_DURATION, 0);
- } else {
- // Animate the icon/widget back to its original position
- animateIntoPosition(animView, mDragViewOrigin[0], mDragViewOrigin[1], new Runnable() {
- public void run() {
- resetCheckedItem(false);
- dragLayer.removeView(animView);
- }
- });
- }
- mLauncher.getWorkspace().onDragStopped(success);
- mLauncher.unlockScreenOrientation();
- mDragBitmap = null;
- }
-
- @Override
- public void onDragViewVisible() {
- }
-
- /**
- * Animates the given item onto the center of a home screen, and then scales the item to
- * look as though it's disappearing onto that screen.
- */
- private void animateItemOntoScreen(View dragView,
- final CellLayout layout, final ItemInfo info) {
- mTmpFloatPos[0] = layout.getWidth() / 2;
- mTmpFloatPos[1] = layout.getHeight() / 2;
- mLauncher.getWorkspace().mapPointFromChildToSelf(layout, mTmpFloatPos);
-
- int dragViewWidth = dragView.getMeasuredWidth();
- int dragViewHeight = dragView.getMeasuredHeight();
- float heightOffset = 0;
- float widthOffset = 0;
-
- if (dragView instanceof ImageView) {
- Drawable d = ((ImageView) dragView).getDrawable();
- int width = d.getIntrinsicWidth();
- int height = d.getIntrinsicHeight();
-
- if ((1.0 * width / height) >= (1.0f * dragViewWidth) / dragViewHeight) {
- float f = (dragViewWidth / (width * 1.0f));
- heightOffset = ANIMATION_SCALE * (dragViewHeight - f * height) / 2;
- } else {
- float f = (dragViewHeight / (height * 1.0f));
- widthOffset = ANIMATION_SCALE * (dragViewWidth - f * width) / 2;
- }
- }
- final float toX = mTmpFloatPos[0] - dragView.getMeasuredWidth() / 2 + widthOffset;
- final float toY = mTmpFloatPos[1] - dragView.getMeasuredHeight() / 2 + heightOffset;
-
- final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
- final View dragCopy = dragLayer.createDragView(dragView);
- dragCopy.setAlpha(1.0f);
-
- // Translate the item to the center of the appropriate home screen
- animateIntoPosition(dragCopy, toX, toY, null);
-
- // The drop-onto-screen animation begins a bit later, but ends at the same time.
- final int startDelay = TRANSLATE_ANIM_DURATION - DROP_ANIM_DURATION;
-
- // Scale down the icon and fade out the alpha
- animateDropOntoScreen(dragCopy, info, DROP_ANIM_DURATION, startDelay);
- }
-
- /**
- * Animation which scales the view down and animates its alpha, making it appear to disappear
- * onto a home screen.
- */
- private void animateDropOntoScreen(
- final View view, final ItemInfo info, int duration, int delay) {
- final DragLayer dragLayer = (DragLayer) mLauncher.findViewById(R.id.drag_layer);
- final CellLayout layout = mLauncher.getWorkspace().getCurrentDropLayout();
-
- ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
- PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.0f),
- PropertyValuesHolder.ofFloat("scaleX", ANIMATION_SCALE),
- PropertyValuesHolder.ofFloat("scaleY", ANIMATION_SCALE));
- anim.setInterpolator(new LinearInterpolator());
- if (delay > 0) {
- anim.setStartDelay(delay);
- }
- anim.setDuration(duration);
- anim.addListener(new AnimatorListenerAdapter() {
- public void onAnimationEnd(Animator animation) {
- dragLayer.removeView(view);
- mLauncher.addExternalItemToScreen(info, layout);
- info.dropPos = null;
- }
- });
- anim.start();
- }
-
- /**
- * Animates the x,y position of the view, and optionally execute a Runnable on animation end.
- */
- private void animateIntoPosition(
- View view, float toX, float toY, final Runnable endRunnable) {
- ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(view,
- PropertyValuesHolder.ofFloat("x", toX),
- PropertyValuesHolder.ofFloat("y", toY));
- anim.setInterpolator(mQuintEaseOutInterpolator);
- anim.setDuration(TRANSLATE_ANIM_DURATION);
- if (endRunnable != null) {
- anim.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- endRunnable.run();
- }
- });
- }
- anim.start();
- }
-
- @Override
- public void onClick(final View v) {
- // Return early if we are still animating the pages
- if (mNextPage != INVALID_PAGE) return;
-
- // On certain pages, we allow single tap to mark items as selected so that they can be
- // dropped onto the mini workspaces
- boolean enterChoiceMode = false;
- switch (mCustomizationType) {
- case WidgetCustomization:
- mChoiceModeTitleText = R.string.cab_widget_selection_text;
- enterChoiceMode = true;
- break;
- case ApplicationCustomization:
- mChoiceModeTitleText = R.string.cab_app_selection_text;
- enterChoiceMode = true;
- break;
- case ShortcutCustomization:
- mChoiceModeTitleText = R.string.cab_shortcut_selection_text;
- enterChoiceMode = true;
- break;
- default:
- break;
- }
-
- if (enterChoiceMode) {
- final ItemInfo itemInfo = (ItemInfo) v.getTag();
-
- Workspace w = mLauncher.getWorkspace();
- int currentWorkspaceScreen = mLauncher.getCurrentWorkspaceScreen();
- final CellLayout cl = (CellLayout)w.getChildAt(currentWorkspaceScreen);
- final View dragView = getDragView(v);
-
- animateClickFeedback(v, new Runnable() {
- @Override
- public void run() {
- cl.calculateSpans(itemInfo);
- if (cl.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY)) {
- animateItemOntoScreen(dragView, cl, itemInfo);
- } else {
- mLauncher.showOutOfSpaceMessage();
- }
- }
- });
- return;
- }
-
- // Otherwise, we just handle the single click here
- switch (mCustomizationType) {
- case WallpaperCustomization:
- // animate some feedback to the long press
- final View clickView = v;
- animateClickFeedback(v, new Runnable() {
- @Override
- public void run() {
- // add the shortcut
- ResolveInfo info = (ResolveInfo) clickView.getTag();
- Intent createWallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER);
- ComponentName name = new ComponentName(info.activityInfo.packageName,
- info.activityInfo.name);
- createWallpapersIntent.setComponent(name);
- mLauncher.processWallpaper(createWallpapersIntent);
- }
- });
- break;
- default:
- break;
- }
- }
-
- private Bitmap drawableToBitmap(Drawable d, float scaleX, float scaleY) {
- final Rect bounds = d.getBounds();
- final int w = bounds.width();
- final int h = bounds.height();
- Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
- renderDrawableToBitmap(d, b, 0, 0, w, h, scaleX, scaleY);
- return b;
- }
-
- private View getDragView(View v) {
- return (mCustomizationType == CustomizationType.WidgetCustomization) ?
- v.findViewById(R.id.widget_preview) : v;
- }
-
- protected boolean beginDragging(View v) {
- if (!v.isInTouchMode()) return false;
- if (!super.beginDragging(v)) return false;
-
- // End the current choice mode before we start dragging anything
- if (isChoiceMode(CHOICE_MODE_SINGLE)) {
- endChoiceMode();
- }
- final Workspace workspace = mLauncher.getWorkspace();
- boolean result = false;
- mLauncher.lockScreenOrientation();
- switch (mCustomizationType) {
- case WidgetCustomization: {
- if (v instanceof PagedViewWidget) {
- // Get the widget preview as the drag representation
- final LinearLayout l = (LinearLayout) v;
- final ImageView i = (ImageView) l.findViewById(R.id.widget_preview);
-
- // Calculate how much to scale the drag preview
- RectF tmpScaleRect = new RectF(0,0,1,1);
- i.getImageMatrix().mapRect(tmpScaleRect);
-
- mDragBitmap = drawableToBitmap(i.getDrawable(), tmpScaleRect.right,
- tmpScaleRect.bottom);
- i.getLocationOnScreen(mDragViewOrigin);
- PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) v.getTag();
-
- int[] spanXY = CellLayout.rectToCell(getResources(),
- createWidgetInfo.minWidth, createWidgetInfo.minHeight, null);
- createWidgetInfo.spanX = spanXY[0];
- createWidgetInfo.spanY = spanXY[1];
- workspace.onDragStartedWithItemSpans(spanXY[0], spanXY[1], mDragBitmap);
- mDragController.startDrag(i, mDragBitmap, this, createWidgetInfo,
- DragController.DRAG_ACTION_COPY, null);
- result = true;
- }
- break;
- }
- case ShortcutCustomization:
- case ApplicationCustomization: {
- if (v instanceof PagedViewIcon) {
- // get icon (top compound drawable, index is 1)
- final TextView tv = (TextView) v;
- final Drawable icon = tv.getCompoundDrawables()[1];
- mDragBitmap = drawableToBitmap(icon, 1.0f, 1.0f);
-
- Object dragInfo = v.getTag();
- if (mCustomizationType == CustomizationType.ApplicationCustomization) {
- // TODO: Not sure why we have to copy this
- dragInfo = new ApplicationInfo((ApplicationInfo) dragInfo);
- }
- workspace.onDragStartedWithItemSpans(1, 1, mDragBitmap);
-
- // Calculate where to place the drag view in order to align the icon pixels with
- // the original view.
- v.getLocationOnScreen(mDragViewOrigin);
- mDragViewOrigin[0] += (v.getWidth() - icon.getIntrinsicWidth()) / 2;
- mDragViewOrigin[1] += v.getPaddingTop();
-
- mDragController.startDrag(mDragBitmap, mDragViewOrigin[0], mDragViewOrigin[1],
- this, dragInfo, DragController.DRAG_ACTION_COPY);
- result = true;
- }
- break;
- }
- }
-
- // We toggle the checked state _after_ we create the view for the drag in case toggling the
- // checked state changes the view's look
- if (result && (v instanceof Checkable)) {
- // In preparation for drag, we always reset the checked grand children regardless of
- // what choice mode we are in
- resetCheckedGrandchildren();
-
- // Toggle the selection on the dragged app
- Checkable checkable = (Checkable) v;
-
- // Note: we toggle the checkable state to actually cause an alpha fade for the duration
- // of the drag of the item. (The fade-in will occur when all checked states are
- // disabled when dragging ends)
- checkable.toggle();
- }
-
- return result;
- }
-
- /**
- * Pre-processes the layout of the different widget pages.
- * @return the number of pages of widgets that we have
- */
- private int relayoutWidgets() {
- if (mWidgetList.isEmpty()) return 0;
-
- // create a new page for the first set of widgets
- ArrayList<AppWidgetProviderInfo> newPage = new ArrayList<AppWidgetProviderInfo>();
- mWidgetPages.clear();
- mWidgetPages.add(newPage);
-
- // do this until we have no more widgets to lay out
- final int maxNumCellsPerRow = mMaxWidgetsCellHSpan;
- final int widgetCount = mWidgetList.size();
- int numCellsInRow = 0;
- for (int i = 0; i < widgetCount; ++i) {
- final AppWidgetProviderInfo info = mWidgetList.get(i);
-
- // determine the size of the current widget
- int cellSpanX = Math.max(sMinWidgetCellHSpan, Math.min(sMaxWidgetCellHSpan,
- mWorkspaceWidgetLayout.estimateCellHSpan(info.minWidth)));
-
- // create a new page if necessary
- if ((numCellsInRow + cellSpanX) > maxNumCellsPerRow) {
- numCellsInRow = 0;
- newPage = new ArrayList<AppWidgetProviderInfo>();
- mWidgetPages.add(newPage);
- }
-
- // add the item to the current page
- newPage.add(info);
- numCellsInRow += cellSpanX;
- }
-
- return mWidgetPages.size();
- }
-
- /**
- * Helper function to draw a drawable to the specified canvas with the specified bounds.
- */
- private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
- float scaleX, float scaleY) {
- if (bitmap != null) mCanvas.setBitmap(bitmap);
- mCanvas.save();
- mCanvas.scale(scaleX, scaleY);
- final Rect oldBounds = d.copyBounds();
- d.setBounds(x, y, x + w, y + h);
- d.draw(mCanvas);
- d.setBounds(oldBounds); // Restore the bounds
- mCanvas.restore();
- }
-
- /*
- * This method fetches an xml file specified in the manifest identified by
- * WallpaperManager.WALLPAPER_PREVIEW_META_DATA). The xml file specifies
- * an image which will be used as the wallpaper preview for an activity
- * which responds to ACTION_SET_WALLPAPER. This image is returned and used
- * in the customize drawer.
- */
- private Drawable parseWallpaperPreviewXml(ComponentName component, ResolveInfo ri) {
- ActivityInfo activityInfo = ri.activityInfo;
- XmlResourceParser parser = null;
- try {
- parser = activityInfo.loadXmlMetaData(mPackageManager,
- WallpaperManager.WALLPAPER_PREVIEW_META_DATA);
- if (parser == null) {
- Slog.w(TAG, "No " + WallpaperManager.WALLPAPER_PREVIEW_META_DATA + " meta-data for "
- + "wallpaper provider '" + component + '\'');
- return null;
- }
-
- AttributeSet attrs = Xml.asAttributeSet(parser);
-
- int type;
- while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
- && type != XmlPullParser.START_TAG) {
- // drain whitespace, comments, etc.
- }
-
- String nodeName = parser.getName();
- if (!"wallpaper-preview".equals(nodeName)) {
- Slog.w(TAG, "Meta-data does not start with wallpaper-preview tag for "
- + "wallpaper provider '" + component + '\'');
- return null;
- }
-
- // If metaData was null, we would have returned earlier when getting
- // the parser No need to do the check here
- Resources res = mPackageManager.getResourcesForApplication(
- activityInfo.applicationInfo);
-
- TypedArray sa = res.obtainAttributes(attrs,
- com.android.internal.R.styleable.WallpaperPreviewInfo);
-
- TypedValue value = sa.peekValue(
- com.android.internal.R.styleable.WallpaperPreviewInfo_staticWallpaperPreview);
- if (value == null) return null;
-
- return res.getDrawable(value.resourceId);
- } catch (Exception e) {
- Slog.w(TAG, "XML parsing failed for wallpaper provider '" + component + '\'', e);
- return null;
- } finally {
- if (parser != null) parser.close();
- }
- }
-
- /**
- * This method will extract the preview image specified by the wallpaper source provider (if it
- * exists) otherwise, it will try to generate a default image preview.
- */
- private FastBitmapDrawable getWallpaperPreview(ResolveInfo info) {
- // To be implemented later: resolving the up-to-date wallpaper thumbnail
-
- final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1);
- final int dim = mWorkspaceWidgetLayout.estimateCellWidth(mWallpaperCellHSpan);
- Resources resources = mLauncher.getResources();
-
- // Create a new bitmap to hold the widget preview
- int width = (int) (dim * sScaleFactor);
- int height = (int) (dim * sScaleFactor);
- final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
-
- Drawable background = parseWallpaperPreviewXml(
- new ComponentName(info.activityInfo.packageName, info.activityInfo.name), info);
- boolean foundCustomDrawable = background != null;
-
- if (!foundCustomDrawable) {
- background = resources.getDrawable(R.drawable.default_widget_preview);
- }
-
- renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f);
-
- // If we don't have a custom icon, we use the app icon on the default background
- if (!foundCustomDrawable) {
- try {
- final IconCache iconCache =
- ((LauncherApplication) mLauncher.getApplication()).getIconCache();
- Drawable icon = new FastBitmapDrawable(Utilities.createIconBitmap(
- iconCache.getFullResIcon(info, mPackageManager), mContext));
-
- final int iconSize = minDim / 2;
- final int offset = iconSize / 4;
- renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f);
- } catch (Resources.NotFoundException e) {
- // if we can't find the icon, then just don't draw it
- }
- }
-
- FastBitmapDrawable drawable = new FastBitmapDrawable(bitmap);
- drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
- return drawable;
- }
-
- /**
- * This method will extract the preview image specified by the widget developer (if it exists),
- * otherwise, it will try to generate a default image preview with the widget's package icon.
- * @return the drawable that will be used and sized in the ImageView to represent the widget
- */
- private FastBitmapDrawable getWidgetPreview(AppWidgetProviderInfo info) {
- final PackageManager packageManager = mPackageManager;
- String packageName = info.provider.getPackageName();
- Drawable drawable = null;
- FastBitmapDrawable newDrawable = null;
- if (info.previewImage != 0) {
- drawable = packageManager.getDrawable(packageName, info.previewImage, null);
- if (drawable == null) {
- Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon)
- + " for provider: " + info.provider);
- }
- }
-
- // If we don't have a preview image, create a default one
- final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1);
- final int maxDim = mWorkspaceWidgetLayout.estimateCellWidth(3);
- if (drawable == null) {
- Resources resources = mLauncher.getResources();
-
- // Create a new bitmap to hold the widget preview
- int width = (int) (Math.max(minDim, Math.min(maxDim, info.minWidth)) * sScaleFactor);
- int height = (int) (Math.max(minDim, Math.min(maxDim, info.minHeight)) * sScaleFactor);
- final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
- final Drawable background = resources.getDrawable(R.drawable.default_widget_preview);
- renderDrawableToBitmap(background, bitmap, 0, 0, width, height, 1.0f, 1.0f);
-
- // Draw the icon flush left
- try {
- Drawable icon = null;
- if (info.icon > 0) {
- icon = packageManager.getDrawable(packageName, info.icon, null);
- }
- if (icon == null) {
- icon = resources.getDrawable(R.drawable.ic_launcher_application);
- }
-
- final int iconSize = minDim / 2;
- final int offset = iconSize / 4;
- renderDrawableToBitmap(icon, null, offset, offset, iconSize, iconSize, 1.0f, 1.0f);
- } catch (Resources.NotFoundException e) {
- // if we can't find the icon, then just don't draw it
- }
-
- newDrawable = new FastBitmapDrawable(bitmap);
- } else {
- // Scale down the preview if necessary
- final float imageWidth = drawable.getIntrinsicWidth();
- final float imageHeight = drawable.getIntrinsicHeight();
- final float aspect = (float) imageWidth / imageHeight;
- final int scaledWidth =
- (int) (Math.max(minDim, Math.min(maxDim, imageWidth)) * sScaleFactor);
- final int scaledHeight =
- (int) (Math.max(minDim, Math.min(maxDim, imageHeight)) * sScaleFactor);
- int width;
- int height;
- if (aspect >= 1.0f) {
- width = scaledWidth;
- height = (int) (((float) scaledWidth / imageWidth) * imageHeight);
- } else {
- height = scaledHeight;
- width = (int) (((float) scaledHeight / imageHeight) * imageWidth);
- }
-
- final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
- renderDrawableToBitmap(drawable, bitmap, 0, 0, width, height, 1.0f, 1.0f);
-
- newDrawable = new FastBitmapDrawable(bitmap);
- }
- newDrawable.setBounds(0, 0, newDrawable.getIntrinsicWidth(),
- newDrawable.getIntrinsicHeight());
- return newDrawable;
- }
-
- private void setupPage(PagedViewCellLayout layout) {
- layout.setCellCount(mCellCountX, mCellCountY);
- layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight,
- mPageLayoutPaddingBottom);
- layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap);
- }
-
- private void setupWorkspaceLayout() {
- mWorkspaceWidgetLayout.setCellCount(mCellCountX, mCellCountY);
- mWorkspaceWidgetLayout.setPadding(20, 10, 20, 0);
-
- mMaxWidgetWidth = mWorkspaceWidgetLayout.estimateCellWidth(sMaxWidgetCellHSpan);
- }
-
- private void syncWidgetPages() {
- /*
- if (mWidgetList == null) return;
-
- // we need to repopulate with the LinearLayout layout for the widget pages
- removeAllViews();
- int numPages = relayoutWidgets();
- for (int i = 0; i < numPages; ++i) {
- LinearLayout layout = new PagedViewExtendedLayout(getContext());
- layout.setGravity(Gravity.CENTER_HORIZONTAL);
- layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
- mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
-
- addView(layout, new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.MATCH_PARENT));
- }
- */
- }
-
- private void syncWidgetPageItems(int page) {
- /*
- // ensure that we have the right number of items on the pages
- LinearLayout layout = (LinearLayout) getChildAt(page);
- final ArrayList<AppWidgetProviderInfo> list = mWidgetPages.get(page);
- final int count = list.size();
- final int numPages = getPageCount();
- layout.removeAllViews();
- for (int i = 0; i < count; ++i) {
- final AppWidgetProviderInfo info = (AppWidgetProviderInfo) list.get(i);
- final PendingAddWidgetInfo createItemInfo = new PendingAddWidgetInfo(info, null, null);
- final int[] cellSpans = CellLayout.rectToCell(getResources(), info.minWidth,
- info.minHeight, null);
- final FastBitmapDrawable icon = getWidgetPreview(info);
- final boolean createHolographicOutlines = (numPages > 1);
-
- PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
- R.layout.customize_paged_view_widget, layout, false);
-
- l.applyFromAppWidgetProviderInfo(info, icon, mMaxWidgetWidth, cellSpans,
- null, createHolographicOutlines);
- l.setTag(createItemInfo);
- l.setOnClickListener(this);
- l.setOnTouchListener(this);
- l.setOnLongClickListener(this);
-
- layout.addView(l);
- }
- */
- }
-
- private void syncWallpaperPages() {
- /*
- if (mWallpaperList == null) return;
-
- // We need to repopulate the LinearLayout for the wallpaper pages
- removeAllViews();
- int numPages = (int) Math.ceil((float) (mWallpaperList.size() * mWallpaperCellHSpan) /
- mMaxWallpaperCellHSpan);
- for (int i = 0; i < numPages; ++i) {
- LinearLayout layout = new PagedViewExtendedLayout(getContext());
- layout.setGravity(Gravity.CENTER_HORIZONTAL);
- layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop,
- mPageLayoutPaddingRight, mPageLayoutPaddingBottom);
-
- addView(layout, new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.MATCH_PARENT));
- }
- */
- }
-
- private void syncWallpaperPageItems(int page) {
- /*
- // Load the items on to the pages
- LinearLayout layout = (LinearLayout) getChildAt(page);
- layout.removeAllViews();
- final int count = mWallpaperList.size();
- final int numPages = getPageCount();
- final int numItemsPerPage = mMaxWallpaperCellHSpan / mWallpaperCellHSpan;
- final int startIndex = page * numItemsPerPage;
- final int endIndex = Math.min(count, startIndex + numItemsPerPage);
- for (int i = startIndex; i < endIndex; ++i) {
- final ResolveInfo info = mWallpaperList.get(i);
- final FastBitmapDrawable icon = getWallpaperPreview(info);
- final boolean createHolographicOutlines = (numPages > 1);
-
- PagedViewWidget l = (PagedViewWidget) mInflater.inflate(
- R.layout.customize_paged_view_wallpaper, layout, false);
- l.applyFromWallpaperInfo(info, mPackageManager, icon, mMaxWidgetWidth,
- null, createHolographicOutlines);
- l.setTag(info);
- l.setOnClickListener(this);
-
- layout.addView(l);
- }
- */
- }
-
- private void syncListPages(List<ResolveInfo> list) {
- /*
- // we need to repopulate with PagedViewCellLayouts
- removeAllViews();
-
- // ensure that we have the right number of pages
- int numPages = (int) Math.ceil((float) list.size() / (mCellCountX * mCellCountY));
- for (int i = 0; i < numPages; ++i) {
- PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
- setupPage(layout);
- addView(layout);
- }
- */
- }
-
- private void syncListPageItems(int page, List<ResolveInfo> list) {
- /*
- // ensure that we have the right number of items on the pages
- final int numPages = getPageCount();
- final int numCells = mCellCountX * mCellCountY;
- final int startIndex = page * numCells;
- final int endIndex = Math.min(startIndex + numCells, list.size());
- final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
- // TODO: we can optimize by just re-applying to existing views
- layout.removeAllViewsOnPage();
- for (int i = startIndex; i < endIndex; ++i) {
- ResolveInfo info = list.get(i);
- PendingAddItemInfo createItemInfo = new PendingAddItemInfo();
- final boolean createHolographicOutlines = (numPages > 1);
-
- PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
- R.layout.customize_paged_view_item, layout, false);
- icon.applyFromResolveInfo(info, mPackageManager, null,
- ((LauncherApplication) mLauncher.getApplication()).getIconCache(),
- createHolographicOutlines);
- switch (mCustomizationType) {
- case WallpaperCustomization:
- icon.setOnClickListener(this);
- break;
- case ShortcutCustomization:
- createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
- createItemInfo.componentName = new ComponentName(info.activityInfo.packageName,
- info.activityInfo.name);
- icon.setTag(createItemInfo);
- icon.setOnClickListener(this);
- icon.setOnTouchListener(this);
- icon.setOnLongClickListener(this);
- break;
- default:
- break;
- }
-
- final int index = i - startIndex;
- final int x = index % mCellCountX;
- final int y = index / mCellCountX;
- setupPage(layout);
- layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
- }
- */
- }
-
- private void syncAppPages() {
- /*
- if (mApps == null) return;
-
- // We need to repopulate with PagedViewCellLayouts
- removeAllViews();
-
- // Ensure that we have the right number of pages
- int numPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY));
- for (int i = 0; i < numPages; ++i) {
- PagedViewCellLayout layout = new PagedViewCellLayout(getContext());
- setupPage(layout);
- addView(layout);
- }
- */
- }
-
- private void syncAppPageItems(int page) {
- /*
- if (mApps == null) return;
-
- // ensure that we have the right number of items on the pages
- final int numPages = getPageCount();
- final int numCells = mCellCountX * mCellCountY;
- final int startIndex = page * numCells;
- final int endIndex = Math.min(startIndex + numCells, mApps.size());
- final PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page);
- // TODO: we can optimize by just re-applying to existing views
- layout.removeAllViewsOnPage();
- for (int i = startIndex; i < endIndex; ++i) {
- final ApplicationInfo info = mApps.get(i);
- final boolean createHolographicOutlines = (numPages > 1);
- PagedViewIcon icon = (PagedViewIcon) mInflater.inflate(
- R.layout.all_apps_paged_view_application, layout, false);
- icon.applyFromApplicationInfo(
- info, null, true, createHolographicOutlines);
- icon.setOnClickListener(this);
- icon.setOnTouchListener(this);
- icon.setOnLongClickListener(this);
-
- final int index = i - startIndex;
- final int x = index % mCellCountX;
- final int y = index / mCellCountX;
- setupPage(layout);
- layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1));
- }
- */
- }
-
- @Override
- protected void invalidatePageData() {
- if (mWaitingToInitPages || mCellCountX <= 0 || mCellCountY <= 0) {
- // We don't know our size yet, which means we haven't calculated cell count x/y;
- // onMeasure will call us once we figure out our size
- return;
- }
- super.invalidatePageData();
- }
-
- @Override
- public void syncPages() {
- /*
- boolean enforceMinimumPagedWidths = false;
- boolean centerPagedViewCellLayouts = false;
- switch (mCustomizationType) {
- case WidgetCustomization:
- syncWidgetPages();
- enforceMinimumPagedWidths = true;
- break;
- case ShortcutCustomization:
- syncListPages(mShortcutList);
- centerPagedViewCellLayouts = true;
- break;
- case WallpaperCustomization:
- syncWallpaperPages();
- enforceMinimumPagedWidths = true;
- break;
- case ApplicationCustomization:
- syncAppPages();
- centerPagedViewCellLayouts = false;
- break;
- default:
- removeAllViews();
- setCurrentPage(0);
- break;
- }
-
- // only try and center the page if there is one page
- final int childCount = getChildCount();
- if (centerPagedViewCellLayouts) {
- if (childCount == 1) {
- PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(0);
- layout.enableCenteredContent(true);
- } else {
- for (int i = 0; i < childCount; ++i) {
- PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i);
- layout.enableCenteredContent(false);
- }
- }
- }
-
- // Set a min page width for PagedView layout if we have more than a single page
- if (enforceMinimumPagedWidths && childCount > 1) {
- setMinimumWidthOverride(mMinPageWidth);
- } else {
- resetMinimumWidthOverride();
- }
-
- // Bound the current page index
- requestLayout();
- post(new Runnable() {
- @Override
- public void run() {
- setCurrentPage(Math.max(0, Math.min(childCount - 1, getCurrentPage())));
- forceUpdateAdjacentPagesAlpha();
- }
- });
- */
- }
-
- @Override
- public void syncPageItems(int page) {
- /*
- switch (mCustomizationType) {
- case WidgetCustomization:
- syncWidgetPageItems(page);
- break;
- case ShortcutCustomization:
- syncListPageItems(page, mShortcutList);
- break;
- case WallpaperCustomization:
- syncWallpaperPageItems(page);
- break;
- case ApplicationCustomization:
- syncAppPageItems(page);
- break;
- }
- */
- }
-
- int getPageContentWidth() {
- return mPageContentWidth;
- }
-
- @Override
- protected int getAssociatedLowerPageBound(int page) {
- return 0;
- }
- @Override
- protected int getAssociatedUpperPageBound(int page) {
- return getChildCount();
- }
-
- @Override
- public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
- mode.setTitle(mChoiceModeTitleText);
- return true;
- }
-
- @Override
- public boolean onCreateActionMode(ActionMode mode, Menu menu) {
- return true;
- }
-
- @Override
- public void onDestroyActionMode(ActionMode mode) {
- endChoiceMode();
- }
-
- @Override
- public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- return false;
- }
-}
diff --git a/src/com/android/launcher2/CustomizeTrayTabHost.java b/src/com/android/launcher2/CustomizeTrayTabHost.java
deleted file mode 100644
index 5780818..0000000
--- a/src/com/android/launcher2/CustomizeTrayTabHost.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright (C) 2011 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.launcher2;
-
-import java.util.Random;
-
-import android.animation.Animator;
-import android.animation.AnimatorListenerAdapter;
-import android.animation.ObjectAnimator;
-import android.animation.ValueAnimator;
-import android.content.Context;
-import android.content.res.Resources;
-import android.util.AttributeSet;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.TabHost;
-import android.widget.TabWidget;
-import android.widget.TextView;
-
-import com.android.launcher.R;
-import com.android.launcher2.CustomizePagedView.CustomizationType;
-
-public class CustomizeTrayTabHost extends TabHost implements LauncherTransitionable {
- // tags for the customization tabs
- private static final String WIDGETS_TAG = "widgets";
- private static final String APPLICATIONS_TAG = "applications";
- private static final String SHORTCUTS_TAG = "shortcuts";
- private static final String WALLPAPERS_TAG = "wallpapers";
-
- private boolean mFirstLayout = true;
-
- // How much of the vertical space this control should attempt to fill
- private float mVerticalFillPercentage;
-
- private final LayoutInflater mInflater;
- private Context mContext;
-
- private CustomizePagedView mCustomizePagedView;
-
- public CustomizeTrayTabHost(Context context, AttributeSet attrs) {
- super(context, attrs);
- mContext = context;
- mInflater = LayoutInflater.from(context);
- }
-
- @Override
- protected void onFinishInflate() {
- final Resources res = getResources();
-
- setup();
-
- mCustomizePagedView =
- (CustomizePagedView) findViewById(R.id.customization_drawer_tab_contents);
-
- // Configure tabs
- TabContentFactory contentFactory = new TabContentFactory() {
- public View createTabContent(String tag) {
- return mCustomizePagedView;
- }
- };
-
- TextView tabView;
- TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
-
- tabView = (TextView) mInflater.inflate(
- R.layout.customize_tab_widget_indicator, tabWidget, false);
- tabView.setText(mContext.getString(R.string.widgets_tab_label));
- addTab(newTabSpec(WIDGETS_TAG)
- .setIndicator(tabView).setContent(contentFactory));
- tabView = (TextView) mInflater.inflate(
- R.layout.customize_tab_widget_indicator, tabWidget, false);
- tabView.setText(mContext.getString(R.string.all_apps_tab_apps));
- addTab(newTabSpec(APPLICATIONS_TAG)
- .setIndicator(tabView).setContent(contentFactory));
- tabView = (TextView) mInflater.inflate(
- R.layout.customize_tab_widget_indicator, tabWidget, false);
- tabView.setText(mContext.getString(R.string.wallpapers_tab_label));
- addTab(newTabSpec(WALLPAPERS_TAG)
- .setIndicator(tabView).setContent(contentFactory));
- tabView = (TextView) mInflater.inflate(
- R.layout.customize_tab_widget_indicator, tabWidget, false);
- tabView.setText(mContext.getString(R.string.shortcuts_tab_label));
- addTab(newTabSpec(SHORTCUTS_TAG)
- .setIndicator(tabView).setContent(contentFactory));
-
- mVerticalFillPercentage =
- res.getInteger(R.integer.customization_drawer_verticalFillPercentage) / 100f;
-
- setOnTabChangedListener(new OnTabChangeListener() {
- public void onTabChanged(String tabId) {
- final CustomizePagedView.CustomizationType newType =
- getCustomizeFilterForTabTag(tabId);
- if (newType != mCustomizePagedView.getCustomizationFilter()) {
- // animate the changing of the tab content by fading pages in and out
- final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
- final float alpha = mCustomizePagedView.getAlpha();
- ValueAnimator alphaAnim = ObjectAnimator.ofFloat(mCustomizePagedView,
- "alpha", alpha, 0.0f);
- alphaAnim.setDuration(duration);
- alphaAnim.addListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- mCustomizePagedView.setCustomizationFilter(newType);
-
- final float alpha = mCustomizePagedView.getAlpha();
- ValueAnimator alphaAnim = ObjectAnimator.ofFloat(
- mCustomizePagedView, "alpha", alpha, 1.0f);
- alphaAnim.setDuration(duration);
- alphaAnim.start();
- }
- });
- alphaAnim.start();
- }
- }
- });
- }
-
- @Override
- public void onLauncherTransitionStart(Animator animation) {
- if (animation != null) {
- setLayerType(LAYER_TYPE_HARDWARE, null);
- // just a sanity check that we don't build a layer before a call to onLayout
- if (!mFirstLayout) {
- // force building the layer at the beginning of the animation, so you don't get a
- // blip early in the animation
- buildLayer();
- }
- }
- }
-
- @Override
- public void onLauncherTransitionEnd(Animator animation) {
- if (animation != null) {
- setLayerType(LAYER_TYPE_NONE, null);
- }
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
-
- // If there's extra room, try to grow to fill it
- if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) {
- final int availableHeight = MeasureSpec.getSize(heightMeasureSpec);
- final int finalHeight = Math.max(getMeasuredHeight(),
- (int) (availableHeight * mVerticalFillPercentage));
-
- // Measure a second time with EXACTLY so that we get sized correctly
- heightMeasureSpec = MeasureSpec.makeMeasureSpec(finalHeight, MeasureSpec.EXACTLY);
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- }
- }
-
- @Override
- protected void onLayout(boolean changed, int l, int t, int r, int b) {
- if (mFirstLayout) {
- mFirstLayout = false;
-
- final CustomizePagedView customizePagedView =
- (CustomizePagedView) findViewById(R.id.customization_drawer_tab_contents);
- TabWidget tabWidget = (TabWidget) findViewById(com.android.internal.R.id.tabs);
- // Set the width of the tab bar properly
- int pageWidth = customizePagedView.getPageContentWidth();
- TabWidget customizeTabBar = (TabWidget) findViewById(com.android.internal.R.id.tabs);
- if (customizeTabBar == null) throw new Resources.NotFoundException();
- int tabWidgetPadding = 0;
- final int childCount = tabWidget.getChildCount();
- if (childCount > 0) {
- tabWidgetPadding += tabWidget.getChildAt(0).getPaddingLeft() * 2;
- }
- customizeTabBar.getLayoutParams().width = pageWidth + tabWidgetPadding;
- }
- super.onLayout(changed, l, t, r, b);
- }
-
- @Override
- public int getDescendantFocusability() {
- if (getVisibility() != View.VISIBLE) {
- return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
- }
- return super.getDescendantFocusability();
- }
-
- CustomizationType getCustomizeFilterForTabTag(String tag) {
- if (tag.equals(WIDGETS_TAG)) {
- return CustomizationType.WidgetCustomization;
- } else if (tag.equals(APPLICATIONS_TAG)) {
- return CustomizationType.ApplicationCustomization;
- } else if (tag.equals(WALLPAPERS_TAG)) {
- return CustomizePagedView.CustomizationType.WallpaperCustomization;
- } else if (tag.equals(SHORTCUTS_TAG)) {
- return CustomizePagedView.CustomizationType.ShortcutCustomization;
- }
- return CustomizationType.WidgetCustomization;
- }
-}
diff --git a/src/com/android/launcher2/DeleteZone.java b/src/com/android/launcher2/DeleteZone.java
deleted file mode 100644
index 025b292..0000000
--- a/src/com/android/launcher2/DeleteZone.java
+++ /dev/null
@@ -1,270 +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.launcher2;
-
-import android.animation.Animator;
-import android.animation.AnimatorListenerAdapter;
-import android.animation.AnimatorSet;
-import android.animation.ObjectAnimator;
-import android.content.Context;
-import android.content.res.Resources;
-import android.content.res.TypedArray;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.drawable.TransitionDrawable;
-import android.util.AttributeSet;
-import android.view.View;
-import android.view.animation.AccelerateInterpolator;
-
-import com.android.launcher.R;
-
-public class DeleteZone extends IconDropTarget {
- private static final int ORIENTATION_HORIZONTAL = 1;
- private static final int TRANSITION_DURATION = 250;
- private static final int ANIMATION_DURATION = 200;
- private static final int XLARGE_TRANSITION_DURATION = 150;
- private static final int XLARGE_ANIMATION_DURATION = 200;
- private static final int LEFT_DRAWABLE = 0;
-
- private AnimatorSet mInAnimation;
- private AnimatorSet mOutAnimation;
-
- private int mOrientation;
- private DragController mDragController;
-
- private final RectF mRegionF = new RectF();
- private final Rect mRegion = new Rect();
- private TransitionDrawable mTransition;
- private int mTextColor;
- private int mDragTextColor;
-
- public DeleteZone(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public DeleteZone(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
-
- final int srcColor = context.getResources().getColor(R.color.delete_target_hover_tint);
- mHoverPaint.setColorFilter(new PorterDuffColorFilter(srcColor, PorterDuff.Mode.SRC_ATOP));
-
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DeleteZone, defStyle, 0);
- mOrientation = a.getInt(R.styleable.DeleteZone_direction, ORIENTATION_HORIZONTAL);
- a.recycle();
-
- if (LauncherApplication.isScreenLarge()) {
- int tb = getResources().getDimensionPixelSize(
- R.dimen.delete_zone_vertical_drag_padding);
- int lr = getResources().getDimensionPixelSize(
- R.dimen.delete_zone_horizontal_drag_padding);
- setDragPadding(tb, lr, tb, lr);
- }
- }
-
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- mTransition = (TransitionDrawable) getCompoundDrawables()[LEFT_DRAWABLE];
- if (LauncherApplication.isScreenLarge()) {
- mTransition.setCrossFadeEnabled(false);
- }
-
- Resources r = getResources();
- mTextColor = r.getColor(R.color.workspace_all_apps_and_delete_zone_text_color);
- mDragTextColor = r.getColor(R.color.workspace_delete_zone_drag_text_color);
- }
-
- public boolean acceptDrop(DragObject d) {
- return true;
- }
-
- public void onDrop(DragObject d) {
- if (!mDragAndDropEnabled) return;
-
- final ItemInfo item = (ItemInfo) d.dragInfo;
-
- // On x-large screens, you can uninstall an app by dragging from all apps
- if (item instanceof ApplicationInfo && LauncherApplication.isScreenLarge()) {
- mLauncher.startApplicationUninstallActivity((ApplicationInfo) item);
- }
-
- if (item.container == -1) return;
-
- if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
- if (item instanceof LauncherAppWidgetInfo) {
- mLauncher.removeAppWidget((LauncherAppWidgetInfo) item);
- }
- }
-
- if (item instanceof FolderInfo) {
- final FolderInfo folderInfo = (FolderInfo)item;
- LauncherModel.deleteFolderContentsFromDatabase(mLauncher, folderInfo);
- mLauncher.removeFolder(folderInfo);
- } else if (item instanceof LauncherAppWidgetInfo) {
- final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item;
- final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost();
- if (appWidgetHost != null) {
- // Deleting an app widget ID is a void call but writes to disk before returning
- // to the caller...
- new Thread("deleteAppWidgetId") {
- public void run() {
- appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId);
- }
- }.start();
- }
- }
-
- LauncherModel.deleteItemFromDatabase(mLauncher, item);
- }
-
- public void onDragEnter(DragObject d) {
- if (mDragAndDropEnabled) {
- mTransition.reverseTransition(getTransitionAnimationDuration());
- setTextColor(mDragTextColor);
- super.onDragEnter(d);
- }
- }
-
- public void onDragExit(DragObject d) {
- if (mDragAndDropEnabled) {
- mTransition.reverseTransition(getTransitionAnimationDuration());
- setTextColor(mTextColor);
- super.onDragExit(d);
- }
- }
-
- public void onDragStart(DragSource source, Object info, int dragAction) {
- final ItemInfo item = (ItemInfo) info;
- if (item != null && mDragAndDropEnabled) {
- mActive = true;
- getHitRect(mRegion);
- mRegionF.set(mRegion);
-
- if (LauncherApplication.isScreenLarge()) {
- // This region will be a "dead zone" for scrolling; make it extend to the edge of
- // the screen so users don't accidentally trigger a scroll while deleting items
- mRegionF.top = mLauncher.getWorkspace().getTop();
- mRegionF.right = mLauncher.getWorkspace().getRight();
- }
-
- mDragController.setDeleteRegion(mRegionF);
-
- // Make sure the icon is set to the default drawable, not the hover drawable
- mTransition.resetTransition();
-
- createAnimations();
- mInAnimation.start();
- if (mOverlappingViews != null) {
- for (View view : mOverlappingViews) {
- createOutAlphaAnim(view).start();
- }
- }
- setVisibility(VISIBLE);
- }
- }
-
- public void onDragEnd() {
- if (mActive && mDragAndDropEnabled) {
- mActive = false;
- mDragController.setDeleteRegion(null);
-
- mOutAnimation.start();
- if (mOverlappingViews != null) {
- for (View view : mOverlappingViews) {
- createInAlphaAnim(view).start();
- }
- }
- }
- }
-
- private Animator createAlphaAnim(View v, float start, float end) {
- Animator anim = ObjectAnimator.ofFloat(v, "alpha", start, end);
- anim.setDuration(getAnimationDuration());
- return anim;
- }
- private Animator createInAlphaAnim(View v) {
- return createAlphaAnim(v, 0f, 1f);
- }
- private Animator createOutAlphaAnim(View v) {
- return createAlphaAnim(v, 1f, 0f);
- }
-
- private void createAnimations() {
- int duration = getAnimationDuration();
-
- Animator inAlphaAnim = createInAlphaAnim(this);
- if (mInAnimation == null) {
- mInAnimation = new AnimatorSet();
- mInAnimation.setInterpolator(new AccelerateInterpolator());
- mInAnimation.setDuration(duration);
- if (!LauncherApplication.isScreenLarge()) {
- Animator translateAnim;
- if (mOrientation == ORIENTATION_HORIZONTAL) {
- translateAnim = ObjectAnimator.ofFloat(this, "translationY",
- getMeasuredWidth(), 0f);
- } else {
- translateAnim = ObjectAnimator.ofFloat(this, "translationX",
- getMeasuredHeight(), 0f);
- }
- mInAnimation.playTogether(translateAnim, inAlphaAnim);
- } else {
- mInAnimation.play(inAlphaAnim);
- }
- }
-
- Animator outAlphaAnim = createOutAlphaAnim(this);
- if (mOutAnimation == null) {
- mOutAnimation = new AnimatorSet();
- mOutAnimation.setInterpolator(new AccelerateInterpolator());
- mOutAnimation.setDuration(duration);
- if (!LauncherApplication.isScreenLarge()) {
- Animator translateAnim;
- if (mOrientation == ORIENTATION_HORIZONTAL) {
- translateAnim = ObjectAnimator.ofFloat(this, "translationY", 0f,
- getMeasuredWidth());
- } else {
- translateAnim = ObjectAnimator.ofFloat(this, "translationX", 0f,
- getMeasuredHeight());
- }
- mOutAnimation.playTogether(translateAnim, outAlphaAnim);
- } else {
- mOutAnimation.addListener(new AnimatorListenerAdapter() {
- public void onAnimationEnd(Animator animation) {
- setVisibility(GONE);
- }
- });
- mOutAnimation.play(outAlphaAnim);
- }
- }
- }
-
- void setDragController(DragController dragController) {
- mDragController = dragController;
- }
-
- private int getTransitionAnimationDuration() {
- return LauncherApplication.isScreenLarge() ?
- XLARGE_TRANSITION_DURATION : TRANSITION_DURATION;
- }
-
- private int getAnimationDuration() {
- return LauncherApplication.isScreenLarge() ?
- XLARGE_ANIMATION_DURATION : ANIMATION_DURATION;
- }
-}
diff --git a/src/com/android/launcher2/IconDropTarget.java b/src/com/android/launcher2/IconDropTarget.java
deleted file mode 100644
index 202b38d..0000000
--- a/src/com/android/launcher2/IconDropTarget.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2010 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.launcher2;
-
-import android.content.Context;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.TextView;
-
-
-/**
- * Implements a DropTarget which allows applications to be dropped on it,
- * in order to launch the application info for that app.
- */
-public class IconDropTarget extends StrokedTextView implements DropTarget, DragController.DragListener {
- protected Launcher mLauncher;
-
- /**
- * If true, this View responsible for managing its own visibility, and that of its overlapping
- * views. This is generally the case, but it will be set to false when this is part of the
- * Contextual Action Bar.
- */
- protected boolean mDragAndDropEnabled;
-
- /** Whether this drop target is active for the current drag */
- protected boolean mActive;
-
- /** The views that this view should appear in the place of. */
- protected View[] mOverlappingViews = null;
-
- /** The paint applied to the drag view on hover */
- protected final Paint mHoverPaint = new Paint();
-
- /** Drag zone padding [T, R, B, L] */
- protected final int mDragPadding[] = new int[4];
-
- public IconDropTarget(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public IconDropTarget(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- mDragAndDropEnabled = true;
- }
-
- protected void setDragPadding(int t, int r, int b, int l) {
- mDragPadding[0] = t;
- mDragPadding[1] = r;
- mDragPadding[2] = b;
- mDragPadding[3] = l;
- }
-
- void setLauncher(Launcher launcher) {
- mLauncher = launcher;
- }
-
- void setOverlappingView(View view) {
- mOverlappingViews = new View[] { view };
- }
-
- void setOverlappingViews(View[] views) {
- mOverlappingViews = views;
- }
-
- void setDragAndDropEnabled(boolean enabled) {
- mDragAndDropEnabled = enabled;
- }
-
- public boolean acceptDrop(DragObject d) {
- return false;
- }
-
- public void onDrop(DragObject d) {
- // Do nothing
- }
-
- public void onDragEnter(DragObject d) {
- if (mDragAndDropEnabled) {
- d.dragView.setPaint(mHoverPaint);
- }
- }
-
- public void onDragOver(DragObject d) {
- // Do nothing
- }
-
- public void onDragExit(DragObject d) {
- if (mDragAndDropEnabled) {
- d.dragView.setPaint(null);
- }
- }
-
- public void onDragStart(DragSource source, Object info, int dragAction) {
- // Do nothing
- }
-
- public boolean isDropEnabled() {
- return mDragAndDropEnabled && mActive;
- }
-
- public void onDragEnd() {
- // Do nothing
- }
-
- @Override
- public void getHitRect(Rect outRect) {
- super.getHitRect(outRect);
- if (LauncherApplication.isScreenLarge()) {
- outRect.top -= mDragPadding[0];
- outRect.right += mDragPadding[1];
- outRect.bottom += mDragPadding[2];
- outRect.left -= mDragPadding[3];
- }
- }
-
- @Override
- public DropTarget getDropTargetDelegate(DragObject d) {
- return null;
- }
-}
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index b1752a7..f65f458 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -193,7 +193,6 @@ public final class Launcher extends Activity
private FolderInfo mFolderInfo;
- private DeleteZone mDeleteZone;
private ViewGroup mButtonCluster;
private View mAllAppsButton;
private SearchDropTargetBar mSearchDeleteBar;
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index 9991d9d..fa6a570 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -166,7 +166,7 @@ public abstract class PagedView extends ViewGroup {
private static final int sScrollIndicatorFadeOutDuration = 650;
// If set, will defer loading associated pages until the scrolling settles
- private boolean mDeferLoadAssociatedPagesAfterScroll;
+ private boolean mDeferLoadAssociatedPagesUntilScrollCompletes;
public interface PageSwitchListener {
void onPageSwitch(View newPage, int newPageIndex);
@@ -375,9 +375,9 @@ public abstract class PagedView extends ViewGroup {
notifyPageSwitchListener();
// Load the associated pages if necessary
- if (mDeferLoadAssociatedPagesAfterScroll) {
+ if (mDeferLoadAssociatedPagesUntilScrollCompletes) {
loadAssociatedPages(mCurrentPage);
- mDeferLoadAssociatedPagesAfterScroll = false;
+ mDeferLoadAssociatedPagesUntilScrollCompletes = false;
}
// We don't want to trigger a page end moving unless the page has settled
@@ -1390,7 +1390,7 @@ public abstract class PagedView extends ViewGroup {
if (mDeferScrollUpdate) {
loadAssociatedPages(mNextPage);
} else {
- mDeferLoadAssociatedPagesAfterScroll = true;
+ mDeferLoadAssociatedPagesUntilScrollCompletes = true;
}
notifyPageSwitchListener();
invalidate();
diff --git a/src/com/android/launcher2/PagedViewExtendedLayout.java b/src/com/android/launcher2/PagedViewExtendedLayout.java
deleted file mode 100644
index 94890d8..0000000
--- a/src/com/android/launcher2/PagedViewExtendedLayout.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2010 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.launcher2;
-
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.view.View;
-import android.widget.LinearLayout;
-
-/**
- * The linear layout used strictly for the widget/wallpaper tab of the customization tray.
- * To be deprecated.
- */
-public class PagedViewExtendedLayout extends LinearLayout implements Page {
- static final String TAG = "PagedViewExtendedLayout";
-
- public PagedViewExtendedLayout(Context context) {
- this(context, null);
- }
-
- public PagedViewExtendedLayout(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public PagedViewExtendedLayout(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- if (LauncherApplication.isScreenLarge()) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- } else {
- // PagedView currently has issues with different-sized pages since it calculates the
- // offset of each page to scroll to before it updates the actual size of each page
- // (which canchange depending on the content if the contains aren't a fixed size).
- // We work around this by having a minimum size on each widget page).
- int widthSpecSize = Math.max(getSuggestedMinimumWidth(),
- MeasureSpec.getSize(widthMeasureSpec));
- int widthSpecMode = MeasureSpec.AT_MOST;
- super.onMeasure(MeasureSpec.makeMeasureSpec(widthSpecSize, widthSpecMode),
- heightMeasureSpec);
- }
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- // We eat up the touch events here, since the PagedView (which uses the same swiping
- // touch code as Workspace previously) uses onInterceptTouchEvent() to determine when
- // the user is scrolling between pages. This means that if the pages themselves don't
- // handle touch events, it gets forwarded up to PagedView itself, and it's own
- // onTouchEvent() handling will prevent further intercept touch events from being called
- // (it's the same view in that case). This is not ideal, but to prevent more changes,
- // we just always mark the touch event as handled.
- return super.onTouchEvent(event) || true;
- }
-
- @Override
- protected boolean onSetAlpha(int alpha) {
- return true;
- }
-
- @Override
- public void setAlpha(float alpha) {
- setChildrenAlpha(alpha);
- super.setAlpha(alpha);
- }
-
- private void setChildrenAlpha(float alpha) {
- final int childCount = getChildCount();
- for (int i = 0; i < childCount; i++) {
- getChildAt(i).setAlpha(alpha);
- }
- }
-
- @Override
- public void removeAllViewsOnPage() {
- removeAllViews();
- }
-
- @Override
- public void removeViewOnPageAt(int index) {
- removeViewAt(index);
- }
-
- @Override
- public int getPageChildCount() {
- return getChildCount();
- }
-
- @Override
- public View getChildOnPageAt(int i) {
- return getChildAt(i);
- }
-
- @Override
- public int indexOfChildOnPage(View v) {
- return indexOfChild(v);
- }
-
- public static class LayoutParams extends LinearLayout.LayoutParams {
- public LayoutParams() {
- super(LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.MATCH_PARENT);
- }
- }
-}
diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java
index 433a785..d6f6656 100644
--- a/src/com/android/launcher2/PagedViewWidget.java
+++ b/src/com/android/launcher2/PagedViewWidget.java
@@ -140,23 +140,6 @@ public class PagedViewWidget extends LinearLayout implements Checkable {
}
}
- public void applyFromWallpaperInfo(ResolveInfo info, PackageManager packageManager,
- FastBitmapDrawable preview, int maxWidth, HolographicOutlineHelper holoOutlineHelper) {
- mHolographicOutlineHelper = holoOutlineHelper;
- ImageView image = (ImageView) findViewById(R.id.wallpaper_preview);
- image.setMaxWidth(maxWidth);
- image.setImageDrawable(preview);
- mPreviewImageView = image;
- TextView name = (TextView) findViewById(R.id.wallpaper_name);
- name.setText(info.loadLabel(packageManager));
- name.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
-
- // Hide the divider in the Phone UI.
- if (!LauncherApplication.isScreenLarge()) {
- findViewById(R.id.divider).setVisibility(View.GONE);
- }
- }
-
public void setHolographicOutline(Bitmap holoOutline) {
mHolographicOutline = holoOutline;
invalidate();
diff --git a/src/com/android/launcher2/allapps.rs b/src/com/android/launcher2/allapps.rs
deleted file mode 100644
index 4ea1aee..0000000
--- a/src/com/android/launcher2/allapps.rs
+++ /dev/null
@@ -1,385 +0,0 @@
-#pragma version(1)
-
-#pragma rs java_package_name(com.android.launcher2)
-
-#include "rs_graphics.rsh"
-
-#define PI 3.14159f
-
-// Constants from Java
-int COLUMNS_PER_PAGE_PORTRAIT;
-int ROWS_PER_PAGE_PORTRAIT;
-int COLUMNS_PER_PAGE_LANDSCAPE;
-int ROWS_PER_PAGE_LANDSCAPE;
-
-int gIconCount;
-int gSelectedIconIndex = -1;
-rs_allocation gSelectedIconTexture;
-rs_allocation gHomeButton;
-
-rs_program_fragment gPFTexNearest;
-rs_program_fragment gPFTexMip;
-rs_program_fragment gPFTexMipAlpha;
-rs_program_vertex gPVCurve;
-rs_program_store gPS;
-rs_mesh gSMCell;
-
-rs_allocation *gIcons;
-rs_allocation *gLabels;
-
-typedef struct VpConsts {
- rs_matrix4x4 Proj;
- float4 Position;
- float4 ScaleOffset;
- float2 BendPos;
- float2 ImgSize;
-} VpConsts_t;
-VpConsts_t *vpConstants;
-
-// Attraction to center values from page edge to page center.
-static float g_AttractionTable[9] = {20.f, 20.f, 20.f, 10.f, -10.f, -20.f, -20.f, -20.f, -20.f};
-static float g_FrictionTable[9] = {10.f, 10.f, 11.f, 15.f, 15.f, 11.f, 10.f, 10.f, 10.f};
-static float g_PhysicsTableSize = 7;
-
-static float gZoomTarget;
-float gTargetPos;
-static float g_PosPage = 0.f;
-static float g_PosVelocity = 0.f;
-static float g_LastPositionX = 0.f;
-static bool g_LastTouchDown = false;
-static float g_DT;
-static int g_PosMax;
-static float g_Zoom = 0.f;
-static float g_Animation = 1.f;
-static float g_OldPosPage;
-static float g_OldPosVelocity;
-static float g_OldZoom;
-static float g_MoveToTotalTime = 0.2f;
-static float g_MoveToTime = 0.f;
-static float g_MoveToOldPos = 0.f;
-
-static int g_Cols;
-static int g_Rows;
-
-rs_allocation g_VPConstAlloc;
-
-// Drawing constants, should be parameters ======
-#define VIEW_ANGLE 1.28700222f
-
-
-static void updateReadback() {
- if ((g_OldPosPage != g_PosPage) ||
- (g_OldPosVelocity != g_PosVelocity) ||
- (g_OldZoom != g_Zoom)) {
-
- g_OldPosPage = g_PosPage;
- g_OldPosVelocity = g_PosVelocity;
- g_OldZoom = g_Zoom;
-
- int i[3];
- i[0] = g_PosPage * (1 << 16);
- i[1] = g_PosVelocity * (1 << 16);
- i[2] = g_OldZoom * (1 << 16);
- rsSendToClientBlocking(1, &i[0], sizeof(i));
- }
-}
-
-void init() {
-}
-
-void move(float newPos) {
- if (g_LastTouchDown) {
- float dx = -(newPos - g_LastPositionX);
- g_PosVelocity = 0;
- g_PosPage += dx * 5.2f;
-
- float pmin = -0.49f;
- float pmax = g_PosMax + 0.49f;
- g_PosPage = clamp(g_PosPage, pmin, pmax);
- }
- g_LastTouchDown = true;
- g_LastPositionX = newPos;
- g_MoveToTime = 0;
-}
-
-void moveTo(float targetPos) {
- gTargetPos = targetPos;
- g_MoveToTime = g_MoveToTotalTime;
- g_PosVelocity = 0;
- g_MoveToOldPos = g_PosPage;
-}
-
-void setZoom(float z, /*bool*/ int animate) {
- gZoomTarget = z;
- if (gZoomTarget < 0.001f) {
- gZoomTarget = 0;
- }
- if (!animate) {
- g_Zoom = gZoomTarget;
- }
- updateReadback();
-}
-
-void fling(float newPos, float vel) {
- move(newPos);
-
- g_LastTouchDown = false;
- g_PosVelocity = -vel * 4;
- float av = fabs(g_PosVelocity);
- float minVel = 3.5f;
-
- minVel *= 1.f - (fabs(rsFrac(g_PosPage + 0.5f) - 0.5f) * 0.45f);
-
- if (av < minVel && av > 0.2f) {
- if (g_PosVelocity > 0) {
- g_PosVelocity = minVel;
- } else {
- g_PosVelocity = -minVel;
- }
- }
-
- if (g_PosPage <= 0) {
- g_PosVelocity = max(0.f, g_PosVelocity);
- }
- if (g_PosPage > g_PosMax) {
- g_PosVelocity = min(0.f, g_PosVelocity);
- }
-}
-
-// Interpolates values in the range 0..1 to a curve that eases in
-// and out.
-static float getInterpolation(float input) {
- return (cos((input + 1) * PI) * 0.5f) + 0.5f;
-}
-
-
-static void updatePos() {
- if (g_LastTouchDown) {
- return;
- }
-
- float tablePosNorm = rsFrac(g_PosPage + 0.5f);
- float tablePosF = tablePosNorm * g_PhysicsTableSize;
- int tablePosI = tablePosF;
- float tablePosFrac = tablePosF - tablePosI;
- float accel = mix(g_AttractionTable[tablePosI],
- g_AttractionTable[tablePosI + 1],
- tablePosFrac) * g_DT;
- float friction = mix(g_FrictionTable[tablePosI],
- g_FrictionTable[tablePosI + 1],
- tablePosFrac) * g_DT;
-
- if (g_MoveToTime) {
- // New position is old posiition + (total distance) * (interpolated time)
- g_PosPage = g_MoveToOldPos + (gTargetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime);
- g_MoveToTime -= g_DT;
- if (g_MoveToTime <= 0) {
- g_MoveToTime = 0;
- g_PosPage = gTargetPos;
- }
- return;
- }
-
- // If our velocity is low OR acceleration is opposing it, apply it.
- if (fabs(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) {
- g_PosVelocity += accel;
- }
- //RS_DEBUG(g_PosPage);
- //RS_DEBUG(g_PosVelocity);
- //RS_DEBUG(friction);
- //RS_DEBUG(accel);
-
- // Normal physics
- if (g_PosVelocity > 0) {
- g_PosVelocity -= friction;
- g_PosVelocity = max(g_PosVelocity, 0.f);
- } else {
- g_PosVelocity += friction;
- g_PosVelocity = min(g_PosVelocity, 0.f);
- }
-
- if ((friction > fabs(g_PosVelocity)) && (friction > fabs(accel))) {
- // Special get back to center and overcome friction physics.
- float t = tablePosNorm - 0.5f;
- if (fabs(t) < (friction * g_DT)) {
- // really close, just snap
- g_PosPage = round(g_PosPage);
- g_PosVelocity = 0;
- } else {
- if (t > 0) {
- g_PosVelocity = -friction;
- } else {
- g_PosVelocity = friction;
- }
- }
- }
-
- // Check for out of boundry conditions.
- if (g_PosPage < 0 && g_PosVelocity < 0) {
- float damp = 1.0f + (g_PosPage * 4);
- damp = clamp(damp, 0.f, 0.9f);
- g_PosVelocity *= damp;
- }
- if (g_PosPage > g_PosMax && g_PosVelocity > 0) {
- float damp = 1.0f - ((g_PosPage - g_PosMax) * 4);
- damp = clamp(damp, 0.f, 0.9f);
- g_PosVelocity *= damp;
- }
-
- g_PosPage += g_PosVelocity * g_DT;
- g_PosPage = clamp(g_PosPage, -0.49f, g_PosMax + 0.49f);
-}
-
-static void
-draw_home_button()
-{
- rsgBindTexture(gPFTexNearest, 0, gHomeButton);
-
- float w = rsgGetWidth();
- float h = rsgGetHeight();
- float tw = rsAllocationGetDimX(gHomeButton);
- float th = rsAllocationGetDimY(gHomeButton);
-
- float x;
- float y;
- if (w > h) {
- x = w - (tw * (1 - g_Animation)) + 20;
- y = (h - th) * 0.5f;
- } else {
- x = (w - tw) / 2;
- y = -g_Animation * th;
- y -= 30; // move the house to the edge of the screen as it doesn't fill the texture.
- }
-
- rsgDrawSpriteScreenspace(x, y, 0, tw, th);
-}
-
-static void drawFrontGrid(float rowOffset, float p)
-{
- float h = rsgGetHeight();
- float w = rsgGetWidth();
-
- int intRowOffset = rowOffset;
- float rowFrac = rowOffset - intRowOffset;
- float colWidth = 120.f;//w / 4;
- float rowHeight = colWidth + 25.f;
- float yoff = 0.5f * h + 1.5f * rowHeight;
-
- int row, col;
- int colCount = 4;
- if (w > h) {
- colCount = 6;
- rowHeight -= 12.f;
- yoff = 0.47f * h + 1.0f * rowHeight;
- }
-
- int iconNum = (intRowOffset - 5) * colCount;
-
- rsgBindProgramVertex(gPVCurve);
-
- vpConstants->Position.z = p;
-
- for (row = -5; row < 15; row++) {
- float y = yoff - ((-rowFrac + row) * rowHeight);
-
- for (col=0; col < colCount; col++) {
- if (iconNum >= gIconCount) {
- return;
- }
-
- if (iconNum >= 0) {
- float x = colWidth * col + (colWidth / 2);
- vpConstants->Position.x = x + 0.2f;
-
- if (gSelectedIconIndex == iconNum && !p && rsIsObject(gSelectedIconTexture)) {
- rsgBindProgramFragment(gPFTexNearest);
- rsgBindTexture(gPFTexNearest, 0, gSelectedIconTexture);
- vpConstants->ImgSize.x = rsAllocationGetDimX(gSelectedIconTexture);
- vpConstants->ImgSize.y = rsAllocationGetDimY(gSelectedIconTexture);
- vpConstants->Position.y = y - (rsAllocationGetDimY(gSelectedIconTexture)
- - rsAllocationGetDimY(gIcons[iconNum])) * 0.5f;
- rsgAllocationSyncAll(g_VPConstAlloc);
- rsgDrawMesh(gSMCell);
- }
-
- rsgBindProgramFragment(gPFTexMip);
- vpConstants->ImgSize.x = rsAllocationGetDimX(gIcons[iconNum]);
- vpConstants->ImgSize.y = rsAllocationGetDimY(gIcons[iconNum]);
- vpConstants->Position.y = y - 0.2f;
- rsgAllocationSyncAll(g_VPConstAlloc);
- rsgBindTexture(gPFTexMip, 0, gIcons[iconNum]);
- rsgDrawMesh(gSMCell);
-
- rsgBindProgramFragment(gPFTexMipAlpha);
- vpConstants->ImgSize.x = rsAllocationGetDimX(gLabels[iconNum]);
- vpConstants->ImgSize.y = rsAllocationGetDimY(gLabels[iconNum]);
- vpConstants->Position.y = y - 64.f - 0.2f;
- rsgAllocationSyncAll(g_VPConstAlloc);
- rsgBindTexture(gPFTexMipAlpha, 0, gLabels[iconNum]);
- rsgDrawMesh(gSMCell);
- }
- iconNum++;
- }
- }
-}
-
-
-int root()
-{
- // Compute dt in seconds.
- // physics may break if DT is large.
- g_DT = min(rsGetDt(), 0.1f);
- g_VPConstAlloc = rsGetAllocation(vpConstants);
-
- if (g_Zoom != gZoomTarget) {
- float dz = g_DT * 1.7f;
- if (gZoomTarget < 0.5f) {
- dz = -dz;
- }
- if (fabs(g_Zoom - gZoomTarget) < fabs(dz)) {
- g_Zoom = gZoomTarget;
- } else {
- g_Zoom += dz;
- }
- updateReadback();
- }
- g_Animation = pow(1.f - g_Zoom, 3.f);
-
- // Set clear value to dim the background based on the zoom position.
- if ((g_Zoom < 0.001f) && (gZoomTarget < 0.001f)) {
- rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- // When we're zoomed out and not tracking motion events, reset the pos to 0.
- if (!g_LastTouchDown) {
- g_PosPage = 0;
- }
- return 0;
- } else {
- rsgClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
- }
-
- rsgBindProgramStore(gPS);
-
- // icons & labels
- if (rsgGetWidth() > rsgGetHeight()) {
- g_Cols = COLUMNS_PER_PAGE_LANDSCAPE;
- g_Rows = ROWS_PER_PAGE_LANDSCAPE;
- } else {
- g_Cols = COLUMNS_PER_PAGE_PORTRAIT;
- g_Rows = ROWS_PER_PAGE_PORTRAIT;
- }
-
- g_PosMax = ((gIconCount + (g_Cols-1)) / g_Cols) - g_Rows;
- if (g_PosMax < 0) g_PosMax = 0;
-
- updatePos();
- updateReadback();
-
- // Draw the icons ========================================
- drawFrontGrid(g_PosPage, g_Animation);
-
- rsgBindProgramFragment(gPFTexNearest);
- draw_home_button();
- return (g_PosVelocity != 0) || rsFrac(g_PosPage) || g_Zoom != gZoomTarget || (g_MoveToTime != 0);
-}
-
-