Merge "Add a dynamically-revealed view to the drag demo" into honeycomb
This commit is contained in:
committed by
Android (Google) Code Review
commit
560094efef
@@ -62,6 +62,18 @@
|
|||||||
dot:anr="drop"
|
dot:anr="drop"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<com.example.android.apis.view.DraggableDot
|
||||||
|
android:id="@+id/drag_dot_hidden"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
dot:radius="64dp"
|
||||||
|
android:padding="15dp"
|
||||||
|
android:layout_toRightOf="@id/drag_dot_3"
|
||||||
|
android:layout_alignTop="@id/drag_dot_3"
|
||||||
|
android:visibility="invisible"
|
||||||
|
dot:legend="Surprise!"
|
||||||
|
/>
|
||||||
|
|
||||||
<TextView android:id="@+id/drag_result_text"
|
<TextView android:id="@+id/drag_result_text"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
public class DragAndDropDemo extends Activity {
|
public class DragAndDropDemo extends Activity {
|
||||||
TextView mResultText;
|
TextView mResultText;
|
||||||
|
DraggableDot mHiddenDot;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -40,14 +41,30 @@ public class DragAndDropDemo extends Activity {
|
|||||||
dot = (DraggableDot) findViewById(R.id.drag_dot_3);
|
dot = (DraggableDot) findViewById(R.id.drag_dot_3);
|
||||||
dot.setReportView(text);
|
dot.setReportView(text);
|
||||||
|
|
||||||
|
mHiddenDot = (DraggableDot) findViewById(R.id.drag_dot_hidden);
|
||||||
|
mHiddenDot.setReportView(text);
|
||||||
|
|
||||||
mResultText = (TextView) findViewById(R.id.drag_result_text);
|
mResultText = (TextView) findViewById(R.id.drag_result_text);
|
||||||
mResultText.setOnDragListener(new View.OnDragListener() {
|
mResultText.setOnDragListener(new View.OnDragListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onDrag(View v, DragEvent event) {
|
public boolean onDrag(View v, DragEvent event) {
|
||||||
final int action = event.getAction();
|
final int action = event.getAction();
|
||||||
if (action == DragEvent.ACTION_DRAG_ENDED) {
|
switch (action) {
|
||||||
final boolean dropped = event.getResult();
|
case DragEvent.ACTION_DRAG_STARTED: {
|
||||||
mResultText.setText(dropped ? "Dropped!" : "No drop");
|
// Bring up a fourth draggable dot on the fly. Note that it
|
||||||
|
// is properly notified about the ongoing drag, and lights up
|
||||||
|
// to indicate that it can handle the current content.
|
||||||
|
mHiddenDot.setVisibility(View.VISIBLE);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case DragEvent.ACTION_DRAG_ENDED: {
|
||||||
|
// Hide the surprise again
|
||||||
|
mHiddenDot.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
// Report the drop/no-drop result to the user
|
||||||
|
final boolean dropped = event.getResult();
|
||||||
|
mResultText.setText(dropped ? "Dropped!" : "No drop");
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user