Home | History | Annotate | Download | only in layout
      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
     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             public void paint(IGraphics gc, INode node, DropFeedback feedback) {
     35                 Rect b = node.getBounds();
     36                 if (b.isValid()) {
     37                     gc.useStyle(DrawingStyle.DROP_RECIPIENT);
     38                     gc.drawRect(b);
     39                 }
     40             }
     41         });
     42         String fqcn = targetNode.getFqcn();
     43         String name = fqcn.substring(fqcn.lastIndexOf('.') +1);
     44         dropFeedback.errorMessage = String.format(
     45                 "%s cannot be configured via XML; add content to the AdapterView using Java code",
     46                 name);
     47         dropFeedback.invalidTarget = true;
     48         return dropFeedback;
     49     }
     50 
     51     @Override
     52     public DropFeedback onDropMove(INode targetNode, IDragElement[] elements,
     53             DropFeedback feedback, Point p) {
     54         feedback.invalidTarget = true;
     55         return feedback;
     56     }
     57 }
     58