Skip to content

Commit

Permalink
Merge "Initial changes for new clings. (Bug 11142616)" into jb-ub-now…
Browse files Browse the repository at this point in the history
…-indigo-rose
  • Loading branch information
Winson Chung authored and Android (Google) Code Review committed Oct 10, 2013
2 parents bb6fda6 + 3a6e7f3 commit d1e474a
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 48 deletions.
60 changes: 49 additions & 11 deletions res/layout-port/workspace_cling.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:layout_marginTop="310dp">
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:layout_marginTop="30dp"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/cling_arrow_up" />
<LinearLayout
android:paddingLeft="20dp"
android:paddingRight="20dp"
Expand All @@ -56,14 +51,57 @@
android:layout_height="wrap_content"
android:text="@string/workspace_cling_move_item" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/cling_arrow_down" />
</LinearLayout>

<LinearLayout
android:id="@+id/focused_hotseat_app_bubble"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="25dp"
android:layout_marginBottom="100dp"
android:orientation="vertical"
android:visibility="gone">
<LinearLayout
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/cling">
<TextView
android:id="@+id/focused_hotseat_app_title"
style="@style/ClingTitleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/focused_hotseat_app_description"
style="@style/ClingText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="80dp"
android:src="@drawable/cling_arrow_down" />
</LinearLayout>
</FrameLayout>

<Button
style="@style/ClingButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginEnd="20dp"
android:layout_gravity="bottom|end"
android:layout_marginStart="20dp"
android:layout_gravity="bottom|start"
android:onClick="dismissWorkspaceCling" />
</com.android.launcher3.Cling>
1 change: 0 additions & 1 deletion res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">24sp</item>
<item name="android:textColor">#49C0EC</item>
<item name="android:fontFamily">sans-serif-condensed</item>
</style>
<style name="ClingText">
<item name="android:layout_width">wrap_content</item>
Expand Down
34 changes: 11 additions & 23 deletions src/com/android/launcher3/CellLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public class CellLayout extends ViewGroup {
private static final int INVALID_DIRECTION = -100;
private DropTarget.DragEnforcer mDragEnforcer;

private Rect mTempRect = new Rect();

private final static PorterDuffXfermode sAddBlendMode =
new PorterDuffXfermode(PorterDuff.Mode.ADD);
private final static Paint sPaint = new Paint();
Expand Down Expand Up @@ -397,25 +399,6 @@ protected void resetOverscrollTransforms() {
}
}

public void scaleRect(Rect r, float scale) {
if (scale != 1.0f) {
r.left = (int) (r.left * scale + 0.5f);
r.top = (int) (r.top * scale + 0.5f);
r.right = (int) (r.right * scale + 0.5f);
r.bottom = (int) (r.bottom * scale + 0.5f);
}
}

Rect temp = new Rect();
void scaleRectAboutCenter(Rect in, Rect out, float scale) {
int cx = in.centerX();
int cy = in.centerY();
out.set(in);
out.offset(-cx, -cy);
scaleRect(out, scale);
out.offset(cx, cy);
}

@Override
protected void onDraw(Canvas canvas) {
// When we're large, we are either drawn in a "hover" state (ie when dragging an item to
Expand Down Expand Up @@ -443,10 +426,11 @@ protected void onDraw(Canvas canvas) {
final float alpha = mDragOutlineAlphas[i];
if (alpha > 0) {
final Rect r = mDragOutlines[i];
scaleRectAboutCenter(r, temp, getChildrenScale());
mTempRect.set(r);
Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
paint.setAlpha((int)(alpha + .5f));
canvas.drawBitmap(b, null, temp, paint);
canvas.drawBitmap(b, null, mTempRect, paint);
}
}

Expand All @@ -456,9 +440,13 @@ protected void onDraw(Canvas canvas) {
final int padding = mPressedOrFocusedIcon.getPressedOrFocusedBackgroundPadding();
final Bitmap b = mPressedOrFocusedIcon.getPressedOrFocusedBackground();
if (b != null) {
int offset = getMeasuredWidth() - getPaddingLeft() - getPaddingRight() -
(mCountX * mCellWidth);
int left = getPaddingLeft() + (int) Math.ceil(offset / 2f);
int top = getPaddingTop();
canvas.drawBitmap(b,
mPressedOrFocusedIcon.getLeft() + getPaddingLeft() - padding,
mPressedOrFocusedIcon.getTop() + getPaddingTop() - padding,
mPressedOrFocusedIcon.getLeft() + left - padding,
mPressedOrFocusedIcon.getTop() + top - padding,
null);
}
}
Expand Down
100 changes: 90 additions & 10 deletions src/com/android/launcher3/Cling.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.ComponentName;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.*;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
Expand All @@ -37,8 +33,10 @@
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.TextView;

public class Cling extends FrameLayout implements Insettable, View.OnLongClickListener {
public class Cling extends FrameLayout implements Insettable, View.OnClickListener,
View.OnLongClickListener, View.OnTouchListener {

static final String FIRST_RUN_CLING_DISMISSED_KEY = "cling_gel.first_run.dismissed";
static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed";
Expand Down Expand Up @@ -66,6 +64,12 @@ public class Cling extends FrameLayout implements Insettable, View.OnLongClickLi
private String mDrawIdentifier;
private Drawable mBackground;

private int[] mTouchDownPt = new int[2];

private Drawable mFocusedHotseatApp;
private ComponentName mFocusedHotseatAppComponent;
private Rect mFocusedHotseatAppBounds;

private Paint mErasePaint;
private Paint mBubblePaint;
private Paint mDotPaint;
Expand Down Expand Up @@ -100,6 +104,8 @@ void init(Launcher l, View scrim) {
mScrimView = scrim;
mBackgroundColor = 0xdd000000;
setOnLongClickListener(this);
setOnClickListener(this);
setOnTouchListener(this);

mErasePaint = new Paint();
mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
Expand All @@ -121,6 +127,46 @@ void init(Launcher l, View scrim) {
}
}

void setFocusedHotseatApp(int drawableId, int appRank, ComponentName cn, String title,
String description) {
// Get the app to draw
Resources r = getResources();
int appIconId = drawableId;
Hotseat hotseat = mLauncher.getHotseat();
if (hotseat != null && appIconId > -1 && appRank > -1 && !title.isEmpty() &&
!description.isEmpty()) {
// Set the app bounds
int x = hotseat.getCellXFromOrder(appRank);
int y = hotseat.getCellYFromOrder(appRank);
Rect pos = hotseat.getCellCoordinates(x, y);
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
mFocusedHotseatApp = getResources().getDrawable(appIconId);
mFocusedHotseatAppComponent = cn;
mFocusedHotseatAppBounds = new Rect(pos.left, pos.top,
pos.left + Utilities.sIconTextureWidth,
pos.top + Utilities.sIconTextureHeight);
Utilities.scaleRectAboutCenter(mFocusedHotseatAppBounds,
(grid.hotseatIconSize / grid.iconSize));

// Set the title
TextView v = (TextView) findViewById(R.id.focused_hotseat_app_title);
if (v != null) {
v.setText(title);
}

// Set the description
v = (TextView) findViewById(R.id.focused_hotseat_app_description);
if (v != null) {
v.setText(description);
}

// Show the bubble
View bubble = findViewById(R.id.focused_hotseat_app_bubble);
bubble.setVisibility(View.VISIBLE);
}
}

void show(boolean animate, int duration) {
setVisibility(View.VISIBLE);
setLayerType(View.LAYER_TYPE_HARDWARE, null);
Expand Down Expand Up @@ -274,6 +320,32 @@ public boolean onTouchEvent(android.view.MotionEvent event) {
return super.onTouchEvent(event);
};

@Override
public boolean onTouch(View v, MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
mTouchDownPt[0] = (int) ev.getX();
mTouchDownPt[1] = (int) ev.getY();
}
return false;
}

@Override
public void onClick(View v) {
if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) ||
mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) ||
mDrawIdentifier.equals(WORKSPACE_LARGE)) {
if (mFocusedHotseatAppBounds != null &&
mFocusedHotseatAppBounds.contains(mTouchDownPt[0], mTouchDownPt[1])) {
// Launch the activity that is being highlighted
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(mFocusedHotseatAppComponent);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
mLauncher.startActivity(intent, null);
mLauncher.dismissWorkspaceCling(this);
}
}
}

@Override
public boolean onLongClick(View v) {
if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) ||
Expand Down Expand Up @@ -354,8 +426,16 @@ protected void dispatchDraw(Canvas canvas) {
canvas.drawBitmap(eraseBg, 0, 0, null);
eraseCanvas.setBitmap(null);
eraseBg = null;
}

// Draw the focused hotseat app icon
if (mFocusedHotseatAppBounds != null && mFocusedHotseatApp != null) {
mFocusedHotseatApp.setBounds(mFocusedHotseatAppBounds.left,
mFocusedHotseatAppBounds.top, mFocusedHotseatAppBounds.right,
mFocusedHotseatAppBounds.bottom);
mFocusedHotseatApp.setAlpha((int) (255 * alpha));
mFocusedHotseatApp.draw(canvas);
}
}

canvas.restore();
}
Expand Down
22 changes: 20 additions & 2 deletions src/com/android/launcher3/Hotseat.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -102,6 +101,25 @@ public boolean isAllAppsButtonRank(int rank) {
}
}

/** This returns the coordinates of an app in a given cell, relative to the DragLayer */
Rect getCellCoordinates(int cellX, int cellY) {
Rect coords = new Rect();
mContent.cellToRect(cellX, cellY, 1, 1, coords);
int[] hotseatInParent = new int[2];
Utilities.getDescendantCoordRelativeToParent(this, mLauncher.getDragLayer(),
hotseatInParent, false);
coords.offset(hotseatInParent[0], hotseatInParent[1]);

// Center the icon
int cWidth = mContent.getShortcutsAndWidgets().getCellContentWidth();
int cHeight = mContent.getShortcutsAndWidgets().getCellContentHeight();
int cellPaddingX = (int) Math.max(0, ((coords.width() - cWidth) / 2f));
int cellPaddingY = (int) Math.max(0, ((coords.height() - cHeight) / 2f));
coords.offset(cellPaddingX, cellPaddingY);

return coords;
}

@Override
protected void onFinishInflate() {
super.onFinishInflate();
Expand Down
Loading

0 comments on commit d1e474a

Please sign in to comment.