1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.wm.cts.dndtargetappsdk23;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.util.Log;
22 import android.view.DragEvent;
23 import android.view.View;
24 import android.widget.TextView;
25 
26 /**
27  * This application is compiled against SDK 23 and used to verify that apps targeting SDK 23 and
28  * below do not receive global drags.
29  */
30 public class DropTarget extends Activity {
31     public static final String LOG_TAG = "DropTarget";
32 
33     private static final String RESULT_KEY_DRAG_STARTED = "DRAG_STARTED";
34     private static final String RESULT_KEY_DROP_RESULT = "DROP";
35 
36     public static final String RESULT_OK = "OK";
37 
38     private TextView mTextView;
39 
40     @Override
onCreate(Bundle savedInstanceState)41     public void onCreate(Bundle savedInstanceState) {
42         super.onCreate(savedInstanceState);
43 
44         View view = getLayoutInflater().inflate(R.layout.target_activity, null);
45         setContentView(view);
46 
47         mTextView = (TextView) findViewById(R.id.drag_target);
48         mTextView.setOnDragListener(new OnDragListener());
49     }
50 
logResult(String key, String value)51     private void logResult(String key, String value) {
52         String result = key + "=" + value;
53         Log.i(LOG_TAG, result);
54         mTextView.setText(result);
55     }
56 
57     private class OnDragListener implements View.OnDragListener {
58         @Override
onDrag(View v, DragEvent event)59         public boolean onDrag(View v, DragEvent event) {
60             switch (event.getAction()) {
61                 case DragEvent.ACTION_DRAG_STARTED:
62                     logResult(RESULT_KEY_DRAG_STARTED, RESULT_OK);
63                     return true;
64 
65                 case DragEvent.ACTION_DRAG_ENTERED:
66                     return true;
67 
68                 case DragEvent.ACTION_DRAG_LOCATION:
69                     return true;
70 
71                 case DragEvent.ACTION_DRAG_EXITED:
72                     return true;
73 
74                 case DragEvent.ACTION_DROP:
75                     logResult(RESULT_KEY_DROP_RESULT, RESULT_OK);
76                     return true;
77 
78                 case DragEvent.ACTION_DRAG_ENDED:
79                     return true;
80 
81                 default:
82                     return false;
83             }
84         }
85     }
86 }
87