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.server.wm.dndtargetappsdk23; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.server.wm.TestLogClient; 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 private static final String RESULT_KEY_DRAG_STARTED = "DRAG_STARTED"; 32 private static final String RESULT_KEY_DROP_RESULT = "DROP"; 33 34 public static final String RESULT_OK = "OK"; 35 36 private TextView mTextView; 37 private TestLogClient mLogClient; 38 39 @Override onCreate(Bundle savedInstanceState)40 public void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 43 View view = getLayoutInflater().inflate(R.layout.target_activity, null); 44 setContentView(view); 45 46 mTextView = (TextView) findViewById(R.id.drag_target); 47 mTextView.setOnDragListener(new OnDragListener()); 48 49 mLogClient = new TestLogClient(this, getIntent().getStringExtra("logtag")); 50 } 51 logResult(String key, String value)52 private void logResult(String key, String value) { 53 mLogClient.record(key, value); 54 mTextView.setText(key + "=" + value); 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