Skip to content

Commit 06e8d66

Browse files
Jim MillerAndroid (Google) Code Review
authored andcommitted
Merge "Fix 6397736: Swipe up to search layout fixes" into jb-dev
2 parents 476b03b + 354619c commit 06e8d66

File tree

22 files changed

+243
-86
lines changed

22 files changed

+243
-86
lines changed

core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java

Lines changed: 80 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.util.AttributeSet;
3333
import android.util.Log;
3434
import android.util.TypedValue;
35+
import android.view.Gravity;
3536
import android.view.MotionEvent;
3637
import android.view.View;
3738
import android.view.accessibility.AccessibilityEvent;
@@ -99,8 +100,11 @@ public interface OnTriggerListener {
99100
private float mTapRadius;
100101
private float mWaveCenterX;
101102
private float mWaveCenterY;
102-
private float mVerticalOffset;
103+
private int mMaxTargetHeight;
104+
private int mMaxTargetWidth;
103105
private float mHorizontalOffset;
106+
private float mVerticalOffset;
107+
104108
private float mOuterRadius = 0.0f;
105109
private float mHitRadius = 0.0f;
106110
private float mSnapMargin = 0.0f;
@@ -142,6 +146,9 @@ public void onAnimationEnd(Animator animator) {
142146
private int mTargetDescriptionsResourceId;
143147
private int mDirectionDescriptionsResourceId;
144148
private boolean mAlwaysTrackFinger;
149+
private int mHorizontalInset;
150+
private int mVerticalInset;
151+
private int mGravity = Gravity.TOP;
145152

146153
public MultiWaveView(Context context) {
147154
this(context, null);
@@ -153,10 +160,9 @@ public MultiWaveView(Context context, AttributeSet attrs) {
153160

154161
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiWaveView);
155162
mOuterRadius = a.getDimension(R.styleable.MultiWaveView_outerRadius, mOuterRadius);
156-
mHorizontalOffset = a.getDimension(R.styleable.MultiWaveView_horizontalOffset,
157-
mHorizontalOffset);
158-
mVerticalOffset = a.getDimension(R.styleable.MultiWaveView_verticalOffset,
159-
mVerticalOffset);
163+
// mHorizontalOffset = a.getDimension(R.styleable.MultiWaveView_horizontalOffset,
164+
// mHorizontalOffset);
165+
// mVerticalOffset = a.getDimension(R.styleable.MultiWaveView_verticalOffset, mVerticalOffset);
160166
mHitRadius = a.getDimension(R.styleable.MultiWaveView_hitRadius, mHitRadius);
161167
mSnapMargin = a.getDimension(R.styleable.MultiWaveView_snapMargin, mSnapMargin);
162168
mVibrationDuration = a.getInt(R.styleable.MultiWaveView_vibrationDuration,
@@ -169,6 +175,7 @@ public MultiWaveView(Context context, AttributeSet attrs) {
169175
mOuterRing = new TargetDrawable(res,
170176
a.peekValue(R.styleable.MultiWaveView_waveDrawable).resourceId);
171177
mAlwaysTrackFinger = a.getBoolean(R.styleable.MultiWaveView_alwaysTrackFinger, false);
178+
mGravity = a.getInt(R.styleable.MultiWaveView_gravity, Gravity.TOP);
172179

173180
// Read chevron animation drawables
174181
final int chevrons[] = { R.styleable.MultiWaveView_leftChevronDrawable,
@@ -231,16 +238,16 @@ private void dump() {
231238

232239
@Override
233240
protected int getSuggestedMinimumWidth() {
234-
// View should be large enough to contain the background + target drawable on either edge
235-
return mOuterRing.getWidth()
236-
+ (mTargetDrawables.size() > 0 ? (mTargetDrawables.get(0).getWidth()/2) : 0);
241+
// View should be large enough to contain the background + handle and
242+
// target drawable on either edge.
243+
return mOuterRing.getWidth() + mMaxTargetWidth;
237244
}
238245

239246
@Override
240247
protected int getSuggestedMinimumHeight() {
241-
// View should be large enough to contain the unlock ring + target drawable on either edge
242-
return mOuterRing.getHeight()
243-
+ (mTargetDrawables.size() > 0 ? (mTargetDrawables.get(0).getHeight()/2) : 0);
248+
// View should be large enough to contain the unlock ring + target and
249+
// target drawable on either edge
250+
return mOuterRing.getHeight() + mMaxTargetHeight;
244251
}
245252

246253
private int resolveMeasured(int measureSpec, int desired)
@@ -265,9 +272,10 @@ private int resolveMeasured(int measureSpec, int desired)
265272
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
266273
final int minimumWidth = getSuggestedMinimumWidth();
267274
final int minimumHeight = getSuggestedMinimumHeight();
268-
int viewWidth = resolveMeasured(widthMeasureSpec, minimumWidth);
269-
int viewHeight = resolveMeasured(heightMeasureSpec, minimumHeight);
270-
setMeasuredDimension(viewWidth, viewHeight);
275+
int computedWidth = resolveMeasured(widthMeasureSpec, minimumWidth);
276+
int computedHeight = resolveMeasured(heightMeasureSpec, minimumHeight);
277+
setupGravity((computedWidth - minimumWidth), (computedHeight - minimumHeight));
278+
setMeasuredDimension(computedWidth, computedHeight);
271279
}
272280

273281
private void switchToState(int state, float x, float y) {
@@ -521,14 +529,25 @@ private void internalSetTargetResources(int resourceId) {
521529
TypedArray array = res.obtainTypedArray(resourceId);
522530
int count = array.length();
523531
ArrayList<TargetDrawable> targetDrawables = new ArrayList<TargetDrawable>(count);
532+
int maxWidth = mHandleDrawable.getWidth();
533+
int maxHeight = mHandleDrawable.getHeight();
524534
for (int i = 0; i < count; i++) {
525535
TypedValue value = array.peekValue(i);
526-
targetDrawables.add(new TargetDrawable(res, value != null ? value.resourceId : 0));
536+
TargetDrawable target= new TargetDrawable(res, value != null ? value.resourceId : 0);
537+
targetDrawables.add(target);
538+
maxWidth = Math.max(maxWidth, target.getWidth());
539+
maxHeight = Math.max(maxHeight, target.getHeight());
540+
}
541+
if (mMaxTargetWidth != maxWidth || mMaxTargetHeight != maxHeight) {
542+
mMaxTargetWidth = maxWidth;
543+
mMaxTargetHeight = maxHeight;
544+
requestLayout(); // required to resize layout and call updateTargetPositions()
545+
} else {
546+
updateTargetPositions();
527547
}
528548
array.recycle();
529549
mTargetResourceId = resourceId;
530550
mTargetDrawables = targetDrawables;
531-
updateTargetPositions();
532551
}
533552

534553
/**
@@ -638,23 +657,27 @@ public boolean onTouchEvent(MotionEvent event) {
638657
boolean handled = false;
639658
switch (action) {
640659
case MotionEvent.ACTION_DOWN:
660+
if (DEBUG) Log.v(TAG, "*** DOWN ***");
641661
handleDown(event);
642662
handled = true;
643663
break;
644664

645665
case MotionEvent.ACTION_MOVE:
666+
if (DEBUG) Log.v(TAG, "*** MOVE ***");
646667
handleMove(event);
647668
handled = true;
648669
break;
649670

650671
case MotionEvent.ACTION_UP:
672+
if (DEBUG) Log.v(TAG, "*** UP ***");
651673
handleMove(event);
652674
handleUp(event);
653675
handled = true;
654676
break;
655677

656678
case MotionEvent.ACTION_CANCEL:
657-
handleMove(event);
679+
if (DEBUG) Log.v(TAG, "*** CANCEL ***");
680+
// handleMove(event);
658681
handleCancel(event);
659682
handled = true;
660683
break;
@@ -795,6 +818,11 @@ private void setGrabbedState(int newState) {
795818
}
796819
mGrabbedState = newState;
797820
if (mOnTriggerListener != null) {
821+
if (newState == OnTriggerListener.NO_HANDLE) {
822+
mOnTriggerListener.onReleased(this, OnTriggerListener.CENTER_HANDLE);
823+
} else {
824+
mOnTriggerListener.onGrabbed(this, OnTriggerListener.CENTER_HANDLE);
825+
}
798826
mOnTriggerListener.onGrabbedStateChange(this, mGrabbedState);
799827
}
800828
}
@@ -832,13 +860,45 @@ private void performInitialLayout(float centerX, float centerY) {
832860
moveHandleTo(centerX, centerY, false);
833861
}
834862

863+
private void setupGravity(int dx, int dy) {
864+
final int layoutDirection = getResolvedLayoutDirection();
865+
final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
866+
867+
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
868+
case Gravity.LEFT:
869+
mHorizontalInset = 0;
870+
break;
871+
case Gravity.RIGHT:
872+
mHorizontalInset = dx;
873+
break;
874+
case Gravity.CENTER_HORIZONTAL:
875+
default:
876+
mHorizontalInset = dx / 2;
877+
break;
878+
}
879+
switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) {
880+
case Gravity.TOP:
881+
mVerticalInset = 0;
882+
break;
883+
case Gravity.BOTTOM:
884+
mVerticalInset = dy;
885+
break;
886+
case Gravity.CENTER_VERTICAL:
887+
default:
888+
mVerticalInset = dy / 2;
889+
break;
890+
}
891+
}
892+
835893
@Override
836894
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
837895
super.onLayout(changed, left, top, right, bottom);
838896
final int width = right - left;
839897
final int height = bottom - top;
840-
float newWaveCenterX = mHorizontalOffset + Math.max(width, mOuterRing.getWidth() ) / 2;
841-
float newWaveCenterY = mVerticalOffset + Math.max(height, mOuterRing.getHeight()) / 2;
898+
float newWaveCenterX = mHorizontalOffset + mHorizontalInset
899+
+ Math.max(width, mMaxTargetWidth + mOuterRing.getWidth()) / 2;
900+
float newWaveCenterY = mVerticalOffset + mVerticalInset
901+
+ Math.max(height, + mMaxTargetHeight + mOuterRing.getHeight()) / 2;
842902
if (newWaveCenterX != mWaveCenterX || newWaveCenterY != mWaveCenterY) {
843903
if (mWaveCenterX == 0 && mWaveCenterY == 0) {
844904
performInitialLayout(newWaveCenterX, newWaveCenterY);
@@ -848,9 +908,8 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
848908

849909
mOuterRing.setX(mWaveCenterX);
850910
mOuterRing.setY(Math.max(mWaveCenterY, mWaveCenterY));
851-
852-
updateTargetPositions();
853911
}
912+
updateTargetPositions();
854913
if (DEBUG) dump();
855914
}
856915

core/res/res/layout-sw600dp/keyguard_screen_tab_unlock.xml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@
8585
<com.android.internal.widget.multiwaveview.MultiWaveView
8686
android:id="@+id/unlock_widget"
8787
android:orientation="horizontal"
88-
android:layout_width="match_parent"
89-
android:layout_height="match_parent"
90-
android:layout_alignParentBottom="true"
88+
android:layout_width="wrap_content"
89+
android:layout_height="wrap_content"
9190
android:layout_gravity="center"
91+
android:gravity="center"
9292

9393
android:targetDrawables="@array/lockscreen_targets_with_camera"
9494
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
@@ -99,8 +99,6 @@
9999
android:snapMargin="@dimen/multiwaveview_snap_margin"
100100
android:hitRadius="@dimen/multiwaveview_hit_radius"
101101
android:rightChevronDrawable="@drawable/ic_lockscreen_chevron_right"
102-
android:horizontalOffset="0dip"
103-
android:verticalOffset="60dip"
104102
android:feedbackCount="3"
105103
android:vibrationDuration="20"
106104
/>

core/res/res/layout-sw600dp/keyguard_screen_tab_unlock_land.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@
8484

8585
<com.android.internal.widget.multiwaveview.MultiWaveView
8686
android:id="@+id/unlock_widget"
87-
android:layout_width="match_parent"
88-
android:layout_height="match_parent"
87+
android:layout_width="wrap_content"
88+
android:layout_height="wrap_content"
8989
android:layout_rowSpan="7"
9090
android:layout_gravity="center_vertical|center_horizontal"
91+
android:gravity="center"
9192

9293
android:targetDrawables="@array/lockscreen_targets_with_camera"
9394
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
@@ -100,8 +101,6 @@
100101
android:rightChevronDrawable="@drawable/ic_lockscreen_chevron_right"
101102
android:feedbackCount="3"
102103
android:vibrationDuration="20"
103-
android:horizontalOffset="0dip"
104-
android:verticalOffset="0dip"
105104
/>
106105

107106
<!-- emergency call button shown when sim is PUKd and tab_selector is hidden -->

core/res/res/layout/keyguard_screen_tab_unlock.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
android:layout_width="match_parent"
130130
android:layout_height="match_parent"
131131
android:layout_alignParentBottom="true"
132+
android:gravity="top"
132133

133134
android:targetDrawables="@array/lockscreen_targets_with_camera"
134135
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
@@ -139,8 +140,6 @@
139140
android:snapMargin="@dimen/multiwaveview_snap_margin"
140141
android:hitRadius="@dimen/multiwaveview_hit_radius"
141142
android:rightChevronDrawable="@drawable/ic_lockscreen_chevron_right"
142-
android:horizontalOffset="0dip"
143-
android:verticalOffset="60dip"
144143
android:feedbackCount="3"
145144
android:vibrationDuration="20"
146145
/>

core/res/res/layout/keyguard_screen_tab_unlock_land.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@
131131
<!-- Column 2 -->
132132
<com.android.internal.widget.multiwaveview.MultiWaveView
133133
android:id="@+id/unlock_widget"
134-
android:layout_width="200dip"
134+
android:layout_width="302dip"
135135
android:layout_height="match_parent"
136136
android:layout_rowSpan="7"
137+
android:gravity="center"
137138

138139
android:targetDrawables="@array/lockscreen_targets_with_camera"
139140
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
@@ -146,8 +147,6 @@
146147
android:topChevronDrawable="@drawable/ic_lockscreen_chevron_up"
147148
android:feedbackCount="3"
148149
android:vibrationDuration="20"
149-
android:horizontalOffset="0dip"
150-
android:verticalOffset="0dip"
151150
/>
152151

153152
<!-- Music transport control -->

core/res/res/values-sw600dp-land/arrays.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757

5858
<array name="lockscreen_targets_with_camera">
5959
<item>@drawable/ic_lockscreen_unlock</item>
60-
<item>@null</item>
60+
<item>@drawable/ic_lockscreen_search</item>
6161
<item>@drawable/ic_lockscreen_camera</item>
6262
<item>@null</item>
6363
</array>
6464

6565
<array name="lockscreen_target_descriptions_with_camera">
6666
<item>@string/description_target_unlock</item>
67-
<item>@null</item>
67+
<item>@string/description_target_search</item>
6868
<item>@string/description_target_camera</item>
6969
<item>@null</item>
7070
</array>

core/res/res/values/attrs.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3107,7 +3107,7 @@
31073107
<attr name="singleLine" format="boolean" />
31083108
<!-- Specifies whether the widget is enabled. The interpretation of the enabled state varies by subclass.
31093109
For example, a non-enabled EditText prevents the user from editing the contained text, and
3110-
a non-enabled Button prevents the user from tapping the button.
3110+
a non-enabled Button prevents the user from tapping the button.
31113111
The appearance of enabled and non-enabled widgets may differ, if the drawables referenced
31123112
from evaluating state_enabled differ. -->
31133113
<attr name="enabled" format="boolean" />
@@ -5378,12 +5378,17 @@
53785378
<!-- Number of waves/chevrons to show in animation. -->
53795379
<attr name="feedbackCount" format="integer" />
53805380

5381-
<!-- Used to shift center of pattern vertically. -->
5381+
<!-- {@deprecated Not used by the framework. Use android:gravity instead}
5382+
Used to shift center of pattern vertically. -->
53825383
<attr name="verticalOffset" format="dimension" />
53835384

5384-
<!-- Used to shift center of pattern horizontally. -->
5385+
<!-- {@deprecated Not used by the framework. Use android:gravity instead}
5386+
Used to shift center of pattern horizontally. -->
53855387
<attr name="horizontalOffset" format="dimension" />
53865388

5389+
<!-- How the items in this layout should be positioned -->
5390+
<attr name="gravity" />
5391+
53875392
<!-- Used when the handle shouldn't wait to be hit before following the finger -->
53885393
<attr name="alwaysTrackFinger" format="boolean" />
53895394
</declare-styleable>
21.4 KB
Loading
10.7 KB
Loading
34.1 KB
Loading

0 commit comments

Comments
 (0)