• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.ide.common.api.DrawingStyle;
19 import com.android.ide.common.api.DropFeedback;
20 import com.android.ide.common.api.IDragElement;
21 import com.android.ide.common.api.IFeedbackPainter;
22 import com.android.ide.common.api.IGraphics;
23 import com.android.ide.common.api.INode;
24 import com.android.ide.common.api.Point;
25 import com.android.ide.common.api.Rect;
26 
27 /** Rule for AdapterView subclasses that don't have more specific rules */
28 public class AdapterViewRule extends BaseLayoutRule {
29     @Override
onDropEnter(INode targetNode, Object targetView, IDragElement[] elements)30     public DropFeedback onDropEnter(INode targetNode, Object targetView, IDragElement[] elements) {
31         // You are not allowed to insert children into AdapterViews; you must
32         // use the dedicated addView methods etc dynamically
33         DropFeedback dropFeedback = new DropFeedback(null,  new IFeedbackPainter() {
34             @Override
35             public void paint(IGraphics gc, INode node, DropFeedback feedback) {
36                 Rect b = node.getBounds();
37                 if (b.isValid()) {
38                     gc.useStyle(DrawingStyle.DROP_RECIPIENT);
39                     gc.drawRect(b);
40                 }
41             }
42         });
43         String fqcn = targetNode.getFqcn();
44         String name = fqcn.substring(fqcn.lastIndexOf('.') +1);
45         dropFeedback.errorMessage = String.format(
46                 "%s cannot be configured via XML; add content to the AdapterView using Java code",
47                 name);
48         dropFeedback.invalidTarget = true;
49         return dropFeedback;
50     }
51 
52     @Override
onDropMove(INode targetNode, IDragElement[] elements, DropFeedback feedback, Point p)53     public DropFeedback onDropMove(INode targetNode, IDragElement[] elements,
54             DropFeedback feedback, Point p) {
55         feedback.invalidTarget = true;
56         return feedback;
57     }
58 }
59