am a6abce84: Improve previews display and allow to jump directly to any screen.
Merge commit 'a6abce8464b57ce91e8f083951ad263370fc2da8' into eclair-mr2 * commit 'a6abce8464b57ce91e8f083951ad263370fc2da8': Improve previews display and allow to jump directly to any screen.
This commit is contained in:
@@ -21,6 +21,7 @@ import android.content.res.TypedArray;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
|
import android.graphics.Canvas;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -104,6 +105,11 @@ public class CellLayout extends ViewGroup {
|
|||||||
mWallpaperManager = WallpaperManager.getInstance(getContext());
|
mWallpaperManager = WallpaperManager.getInstance(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatchDraw(Canvas canvas) {
|
||||||
|
super.dispatchDraw(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelLongPress() {
|
public void cancelLongPress() {
|
||||||
super.cancelLongPress();
|
super.cancelLongPress();
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import android.content.res.Resources;
|
|||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.Matrix;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -84,7 +84,7 @@ import java.io.DataInputStream;
|
|||||||
* Default launcher application.
|
* Default launcher application.
|
||||||
*/
|
*/
|
||||||
public final class Launcher extends Activity
|
public final class Launcher extends Activity
|
||||||
implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, View.OnTouchListener, View.OnKeyListener {
|
implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks {
|
||||||
static final String LOG_TAG = "Launcher";
|
static final String LOG_TAG = "Launcher";
|
||||||
static final String TAG = LOG_TAG;
|
static final String TAG = LOG_TAG;
|
||||||
static final boolean LOGD = false;
|
static final boolean LOGD = false;
|
||||||
@@ -567,11 +567,7 @@ public final class Launcher extends Activity
|
|||||||
mWorkspace.setIndicators(previous, next);
|
mWorkspace.setIndicators(previous, next);
|
||||||
|
|
||||||
mPreviousView.setOnLongClickListener(this);
|
mPreviousView.setOnLongClickListener(this);
|
||||||
mPreviousView.setOnTouchListener(this);
|
|
||||||
mPreviousView.setOnKeyListener(this);
|
|
||||||
mNextView.setOnLongClickListener(this);
|
mNextView.setOnLongClickListener(this);
|
||||||
mNextView.setOnTouchListener(this);
|
|
||||||
mNextView.setOnKeyListener(this);
|
|
||||||
|
|
||||||
workspace.setOnLongClickListener(this);
|
workspace.setOnLongClickListener(this);
|
||||||
workspace.setDragController(dragController);
|
workspace.setDragController(dragController);
|
||||||
@@ -1333,6 +1329,8 @@ public final class Launcher extends Activity
|
|||||||
} else {
|
} else {
|
||||||
closeFolder();
|
closeFolder();
|
||||||
}
|
}
|
||||||
|
dismissPreview(mPreviousView);
|
||||||
|
dismissPreview(mNextView);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case KeyEvent.KEYCODE_HOME:
|
case KeyEvent.KEYCODE_HOME:
|
||||||
@@ -1512,23 +1510,10 @@ public final class Launcher extends Activity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
||||||
if (event.getAction() == KeyEvent.ACTION_UP) {
|
|
||||||
dismissPreview(v);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
|
||||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
|
||||||
dismissPreview(v);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dismissPreview(View v) {
|
private void dismissPreview(View v) {
|
||||||
PopupWindow window = (PopupWindow) v.getTag();
|
PopupWindow window = (PopupWindow) v.getTag();
|
||||||
if (window != null) {
|
if (window != null) {
|
||||||
|
window.setOnDismissListener(null);
|
||||||
window.dismiss();
|
window.dismiss();
|
||||||
((ImageView) v.getTag(R.id.workspace)).setImageBitmap(null);
|
((ImageView) v.getTag(R.id.workspace)).setImageBitmap(null);
|
||||||
((Bitmap) v.getTag(R.id.icon)).recycle();
|
((Bitmap) v.getTag(R.id.icon)).recycle();
|
||||||
@@ -1543,67 +1528,132 @@ public final class Launcher extends Activity
|
|||||||
int current = mWorkspace.getCurrentScreen();
|
int current = mWorkspace.getCurrentScreen();
|
||||||
if (current <= 0) return;
|
if (current <= 0) return;
|
||||||
|
|
||||||
View previous = mWorkspace.getChildAt(current - 1);
|
showPreviews(anchor, 0, current);
|
||||||
showPreview(anchor, previous);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showNextPreview(View anchor) {
|
private void showNextPreview(View anchor) {
|
||||||
int current = mWorkspace.getCurrentScreen();
|
int current = mWorkspace.getCurrentScreen();
|
||||||
if (current >= mWorkspace.getChildCount() - 1) return;
|
if (current >= mWorkspace.getChildCount() - 1) return;
|
||||||
|
|
||||||
View next = mWorkspace.getChildAt(current + 1);
|
showPreviews(anchor, current + 1, mWorkspace.getChildCount());
|
||||||
showPreview(anchor, next);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPreview(View anchor, View source) {
|
@Override
|
||||||
boolean cacheEnabled = source.isDrawingCacheEnabled();
|
public void onWindowFocusChanged(boolean hasFocus) {
|
||||||
source.setDrawingCacheEnabled(true);
|
super.onWindowFocusChanged(hasFocus);
|
||||||
source.buildDrawingCache();
|
|
||||||
|
|
||||||
Bitmap cache = source.getDrawingCache();
|
if (!hasFocus) {
|
||||||
if (cache == null) return;
|
dismissPreview(mPreviousView);
|
||||||
|
dismissPreview(mNextView);
|
||||||
int width = cache.getWidth();
|
}
|
||||||
int height = cache.getHeight();
|
}
|
||||||
float sx = (int) (width / 2.5f) / (float) width;
|
|
||||||
float sy = (int) (height / 2.5f) / (float) height;
|
|
||||||
|
|
||||||
Matrix m = new Matrix();
|
|
||||||
m.setScale(sx, sy);
|
|
||||||
|
|
||||||
CellLayout cell = ((CellLayout) source);
|
|
||||||
int x = cell.getLeftPadding();
|
|
||||||
int y = cell.getTopPadding();
|
|
||||||
width -= (x + cell.getRightPadding());
|
|
||||||
height -= (y + cell.getBottomPadding());
|
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(cache, x, y, width, height, m, true);
|
|
||||||
|
|
||||||
|
private void showPreviews(final View anchor, int start, int end) {
|
||||||
ImageView preview = new ImageView(this);
|
ImageView preview = new ImageView(this);
|
||||||
preview.setImageBitmap(bitmap);
|
preview.requestFocus();
|
||||||
|
|
||||||
Drawable d = getResources().getDrawable(R.drawable.preview_popup);
|
Drawable d = getResources().getDrawable(R.drawable.preview_popup);
|
||||||
preview.setBackgroundDrawable(d);
|
|
||||||
|
|
||||||
Rect r = new Rect();
|
Rect r = new Rect();
|
||||||
d.getPadding(r);
|
d.getPadding(r);
|
||||||
int extraW = r.left + r.right;
|
int extraW = r.left + r.right;
|
||||||
int extraH = r.top + r.bottom;
|
int extraH = r.top + r.bottom;
|
||||||
|
|
||||||
PopupWindow p = new PopupWindow(preview, bitmap.getWidth() + extraW,
|
Workspace workspace = mWorkspace;
|
||||||
bitmap.getHeight() + extraH);
|
CellLayout cell = ((CellLayout) workspace.getChildAt(start));
|
||||||
p.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
float max = workspace.getChildCount() - 1;
|
||||||
|
|
||||||
|
int aW = cell.getWidth() - extraW;
|
||||||
|
float w = aW / max;
|
||||||
|
|
||||||
|
int width = cell.getWidth();
|
||||||
|
int height = cell.getHeight();
|
||||||
|
int x = cell.getLeftPadding();
|
||||||
|
int y = cell.getTopPadding();
|
||||||
|
width -= (x + cell.getRightPadding());
|
||||||
|
height -= (y + cell.getBottomPadding());
|
||||||
|
|
||||||
|
float scale = w / width;
|
||||||
|
|
||||||
|
int count = end - start;
|
||||||
|
|
||||||
|
final float sWidth = width * scale;
|
||||||
|
float sHeight = height * scale;
|
||||||
|
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap((int) (sWidth * count),
|
||||||
|
(int) sHeight, Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
|
PopupWindow p = new PopupWindow(this);
|
||||||
|
p.setContentView(preview);
|
||||||
|
p.setWidth(bitmap.getWidth() + extraW);
|
||||||
|
p.setHeight(bitmap.getHeight() + extraH);
|
||||||
p.setAnimationStyle(R.style.AnimationPreview);
|
p.setAnimationStyle(R.style.AnimationPreview);
|
||||||
|
p.setOutsideTouchable(true);
|
||||||
|
p.setBackgroundDrawable(d);
|
||||||
p.showAsDropDown(anchor, 0, 0);
|
p.showAsDropDown(anchor, 0, 0);
|
||||||
|
|
||||||
source.destroyDrawingCache();
|
Canvas c = new Canvas(bitmap);
|
||||||
if (!cacheEnabled) source.setDrawingCacheEnabled(cacheEnabled);
|
|
||||||
|
for (int i = start; i < end; i++) {
|
||||||
|
cell = (CellLayout) workspace.getChildAt(i);
|
||||||
|
|
||||||
|
c.save();
|
||||||
|
c.scale(scale, scale);
|
||||||
|
c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
|
||||||
|
cell.dispatchDraw(c);
|
||||||
|
c.restore();
|
||||||
|
|
||||||
|
c.translate(sWidth, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
preview.setImageBitmap(bitmap);
|
||||||
|
|
||||||
|
PreviewTouchHandler handler = new PreviewTouchHandler(anchor, sWidth);
|
||||||
|
preview.setOnClickListener(handler);
|
||||||
|
preview.setOnTouchListener(handler);
|
||||||
|
p.setOnDismissListener(handler);
|
||||||
|
|
||||||
anchor.setTag(p);
|
anchor.setTag(p);
|
||||||
anchor.setTag(R.id.workspace, preview);
|
anchor.setTag(R.id.workspace, preview);
|
||||||
anchor.setTag(R.id.icon, bitmap);
|
anchor.setTag(R.id.icon, bitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PreviewTouchHandler implements View.OnTouchListener, View.OnClickListener,
|
||||||
|
PopupWindow.OnDismissListener {
|
||||||
|
|
||||||
|
private final View mAnchor;
|
||||||
|
private final float mWidth;
|
||||||
|
private float mTouchX;
|
||||||
|
|
||||||
|
public PreviewTouchHandler(View anchor, float width) {
|
||||||
|
mAnchor = anchor;
|
||||||
|
mWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
|
mTouchX = event.getX();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClick(View v) {
|
||||||
|
int screen = 0;
|
||||||
|
if (mAnchor == mNextView) {
|
||||||
|
screen = mWorkspace.getCurrentScreen() + (int) (mTouchX / mWidth) + 1;
|
||||||
|
} else if (mAnchor == mPreviousView) {
|
||||||
|
screen = (int) (mTouchX / mWidth);
|
||||||
|
}
|
||||||
|
mWorkspace.snapToScreen(screen);
|
||||||
|
dismissPreview(mAnchor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDismiss() {
|
||||||
|
dismissPreview(mAnchor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
View getDrawerHandle() {
|
View getDrawerHandle() {
|
||||||
return mHandleView;
|
return mHandleView;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user