Home | History | Annotate | Download | only in layout
      1 /*
      2  * Copyright (C) 2011 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 static com.android.SdkConstants.ATTR_CONTENT;
     19 import static com.android.SdkConstants.ATTR_HANDLE;
     20 import static com.android.SdkConstants.ATTR_ID;
     21 import static com.android.SdkConstants.ATTR_LAYOUT_HEIGHT;
     22 import static com.android.SdkConstants.ATTR_LAYOUT_WIDTH;
     23 import static com.android.SdkConstants.ATTR_TEXT;
     24 
     25 
     26 import com.android.SdkConstants;
     27 import static com.android.SdkConstants.ANDROID_URI;
     28 import com.android.annotations.NonNull;
     29 import com.android.ide.common.api.INode;
     30 import com.android.ide.common.api.IViewRule;
     31 import com.android.ide.common.api.InsertType;
     32 
     33 /**
     34  * An {@link IViewRule} for android.widget.SlidingDrawerRule which initializes new sliding
     35  * drawers with their mandatory children and default sizing attributes
     36  */
     37 public class SlidingDrawerRule extends BaseLayoutRule {
     38 
     39     @Override
     40     public void onCreate(@NonNull INode node, @NonNull INode parent,
     41             @NonNull InsertType insertType) {
     42         super.onCreate(node, parent, insertType);
     43 
     44         if (insertType.isCreate()) {
     45             String matchParent = getFillParentValueName();
     46             node.setAttribute(ANDROID_URI, ATTR_LAYOUT_WIDTH, matchParent);
     47             node.setAttribute(ANDROID_URI, ATTR_LAYOUT_HEIGHT, matchParent);
     48 
     49             // Create mandatory children and reference them from the handle and content
     50             // attributes of the sliding drawer
     51             String handleId = "@+id/handle";    //$NON-NLS-1$
     52             String contentId = "@+id/content";  //$NON-NLS-1$
     53             node.setAttribute(ANDROID_URI, ATTR_HANDLE, handleId);
     54             node.setAttribute(ANDROID_URI, ATTR_CONTENT, contentId);
     55 
     56             // Handle
     57             INode handle = node.appendChild(SdkConstants.FQCN_BUTTON);
     58             handle.setAttribute(ANDROID_URI, ATTR_TEXT, "Handle");
     59             handle.setAttribute(ANDROID_URI, ATTR_ID, handleId);
     60 
     61             // Content
     62             INode content = node.appendChild(SdkConstants.FQCN_LINEAR_LAYOUT);
     63             content.setAttribute(ANDROID_URI, ATTR_ID, contentId);
     64             content.setAttribute(ANDROID_URI, ATTR_LAYOUT_WIDTH, matchParent);
     65             content.setAttribute(ANDROID_URI, ATTR_LAYOUT_HEIGHT, matchParent);
     66         }
     67     }
     68 }
     69