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