development
Revision | 86e2451d1c49263bd3a761fe16ab2769d7d634bb (tree) |
---|---|
Time | 2011-01-15 05:40:37 |
Author | Christopher Tate <ctate@goog...> |
Commiter | Android Git Automerger |
am eb3c9bb4: am 560094ef: Merge "Add a dynamically-revealed view to the drag demo" into honeycomb
* commit 'eb3c9bb439166ef17450e4e9fb4d8fa2d96b6ef3':
@@ -62,6 +62,18 @@ | ||
62 | 62 | dot:anr="drop" |
63 | 63 | /> |
64 | 64 | |
65 | + <com.example.android.apis.view.DraggableDot | |
66 | + android:id="@+id/drag_dot_hidden" | |
67 | + android:layout_width="wrap_content" | |
68 | + android:layout_height="wrap_content" | |
69 | + dot:radius="64dp" | |
70 | + android:padding="15dp" | |
71 | + android:layout_toRightOf="@id/drag_dot_3" | |
72 | + android:layout_alignTop="@id/drag_dot_3" | |
73 | + android:visibility="invisible" | |
74 | + dot:legend="Surprise!" | |
75 | + /> | |
76 | + | |
65 | 77 | <TextView android:id="@+id/drag_result_text" |
66 | 78 | android:layout_width="fill_parent" |
67 | 79 | android:layout_height="wrap_content" |
@@ -26,6 +26,7 @@ import android.widget.TextView; | ||
26 | 26 | |
27 | 27 | public class DragAndDropDemo extends Activity { |
28 | 28 | TextView mResultText; |
29 | + DraggableDot mHiddenDot; | |
29 | 30 | |
30 | 31 | @Override |
31 | 32 | protected void onCreate(Bundle savedInstanceState) { |
@@ -40,14 +41,30 @@ public class DragAndDropDemo extends Activity { | ||
40 | 41 | dot = (DraggableDot) findViewById(R.id.drag_dot_3); |
41 | 42 | dot.setReportView(text); |
42 | 43 | |
44 | + mHiddenDot = (DraggableDot) findViewById(R.id.drag_dot_hidden); | |
45 | + mHiddenDot.setReportView(text); | |
46 | + | |
43 | 47 | mResultText = (TextView) findViewById(R.id.drag_result_text); |
44 | 48 | mResultText.setOnDragListener(new View.OnDragListener() { |
45 | 49 | @Override |
46 | 50 | public boolean onDrag(View v, DragEvent event) { |
47 | 51 | final int action = event.getAction(); |
48 | - if (action == DragEvent.ACTION_DRAG_ENDED) { | |
49 | - final boolean dropped = event.getResult(); | |
50 | - mResultText.setText(dropped ? "Dropped!" : "No drop"); | |
52 | + switch (action) { | |
53 | + case DragEvent.ACTION_DRAG_STARTED: { | |
54 | + // Bring up a fourth draggable dot on the fly. Note that it | |
55 | + // is properly notified about the ongoing drag, and lights up | |
56 | + // to indicate that it can handle the current content. | |
57 | + mHiddenDot.setVisibility(View.VISIBLE); | |
58 | + } break; | |
59 | + | |
60 | + case DragEvent.ACTION_DRAG_ENDED: { | |
61 | + // Hide the surprise again | |
62 | + mHiddenDot.setVisibility(View.INVISIBLE); | |
63 | + | |
64 | + // Report the drop/no-drop result to the user | |
65 | + final boolean dropped = event.getResult(); | |
66 | + mResultText.setText(dropped ? "Dropped!" : "No drop"); | |
67 | + } break; | |
51 | 68 | } |
52 | 69 | return false; |
53 | 70 | } |