1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php 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 package com.android.ide.common.layout; 17 18 import com.android.annotations.NonNull; 19 import com.android.annotations.Nullable; 20 import com.android.ide.common.api.DrawingStyle; 21 import com.android.ide.common.api.DropFeedback; 22 import com.android.ide.common.api.IDragElement; 23 import com.android.ide.common.api.IFeedbackPainter; 24 import com.android.ide.common.api.IGraphics; 25 import com.android.ide.common.api.INode; 26 import com.android.ide.common.api.Point; 27 import com.android.ide.common.api.Rect; 28 29 /** Rule for AdapterView subclasses that don't have more specific rules */ 30 public class AdapterViewRule extends BaseLayoutRule { 31 @Override onDropEnter(@onNull INode targetNode, @Nullable Object targetView, @Nullable IDragElement[] elements)32 public DropFeedback onDropEnter(@NonNull INode targetNode, @Nullable Object targetView, 33 @Nullable IDragElement[] elements) { 34 // You are not allowed to insert children into AdapterViews; you must 35 // use the dedicated addView methods etc dynamically 36 DropFeedback dropFeedback = new DropFeedback(null, new IFeedbackPainter() { 37 @Override 38 public void paint(@NonNull IGraphics gc, @NonNull INode node, 39 @NonNull DropFeedback feedback) { 40 Rect b = node.getBounds(); 41 if (b.isValid()) { 42 gc.useStyle(DrawingStyle.DROP_RECIPIENT); 43 gc.drawRect(b); 44 } 45 } 46 }); 47 String fqcn = targetNode.getFqcn(); 48 String name = fqcn.substring(fqcn.lastIndexOf('.') +1); 49 dropFeedback.errorMessage = String.format( 50 "%s cannot be configured via XML; add content to the AdapterView using Java code", 51 name); 52 dropFeedback.invalidTarget = true; 53 return dropFeedback; 54 } 55 56 @Override onDropMove(@onNull INode targetNode, @NonNull IDragElement[] elements, @Nullable DropFeedback feedback, @NonNull Point p)57 public DropFeedback onDropMove(@NonNull INode targetNode, @NonNull IDragElement[] elements, 58 @Nullable DropFeedback feedback, @NonNull Point p) { 59 feedback.invalidTarget = true; 60 return feedback; 61 } 62 } 63