AI2 Component  (Version nb184)
TableArrangement.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2009-2011 Google, All Rights reserved
3 // Copyright 2011-2012 MIT, All rights reserved
4 // Released under the Apache License, Version 2.0
5 // http://www.apache.org/licenses/LICENSE-2.0
6 
7 package com.google.appinventor.components.runtime;
8 
17 
18 import android.app.Activity;
19 import android.view.View;
20 
45 @DesignerComponent(version = YaVersion.TABLEARRANGEMENT_COMPONENT_VERSION,
46  description = "<p>A formatting element in which to place components " +
47  "that should be displayed in tabular form.</p>",
48  category = ComponentCategory.LAYOUT)
49 @SimpleObject
51  implements Component, ComponentContainer {
52  private final Activity context;
53 
54  // Layout
55  private final TableLayout viewLayout;
56 
63  super(container);
64  context = container.$context();
65 
66  viewLayout = new TableLayout(context, 2, 2);
67 
68  container.$add(this);
69  }
70 
76  @SimpleProperty(userVisible = false)
77  public int Columns() {
78  return viewLayout.getNumColumns();
79  }
80 
87  defaultValue = "2")
88  @SimpleProperty(userVisible = false)
89  public void Columns(int numColumns) {
90  viewLayout.setNumColumns(numColumns);
91  }
92 
98  @SimpleProperty(userVisible = false)
99  public int Rows() {
100  return viewLayout.getNumRows();
101  }
102 
109  defaultValue = "2")
110  @SimpleProperty(userVisible = false)
111  public void Rows(int numRows) {
112  viewLayout.setNumRows(numRows);
113  }
114 
115  // ComponentContainer implementation
116 
117  @Override
118  public Activity $context() {
119  return context;
120  }
121 
122  @Override
123  public Form $form() {
124  return container.$form();
125  }
126 
127  @Override
128  public void $add(AndroidViewComponent component) {
129  viewLayout.add(component);
130  }
131 
132  @Override
133  public void setChildWidth(AndroidViewComponent component, int width) {
134 
135  System.err.println("TableArrangment.setChildWidth: width = " + width + " component = " + component);
136  if (width <= LENGTH_PERCENT_TAG) {
137 
138  int cWidth = container.$form().Width();
139 
140  if ((cWidth > LENGTH_PERCENT_TAG) && (cWidth <= 0)) {
141  // FILL_PARENT OR LENGTH_PREFERRED
142  width = LENGTH_PREFERRED;
143  } else {
144  System.err.println("%%TableArrangement.setChildWidth(): width = " + width + " parent Width = " + cWidth + " child = " + component);
145  width = cWidth * (- (width - LENGTH_PERCENT_TAG)) / 100;
146  }
147  }
148 
149  component.setLastWidth(width);
150 
151  ViewUtil.setChildWidthForTableLayout(component.getView(), width);
152  }
153 
154  @Override
155  public void setChildHeight(AndroidViewComponent component, int height) {
156  if (height <= LENGTH_PERCENT_TAG) {
157  int cHeight = container.$form().Height();
158 
159  if ((cHeight > LENGTH_PERCENT_TAG) && (cHeight <= 0)) {
160  // FILL_PARENT OR LENGTH_PREFERRED
161  height = LENGTH_PREFERRED;
162  } else {
163  height = cHeight * (- (height - LENGTH_PERCENT_TAG)) / 100;
164  }
165  }
166 
167  component.setLastHeight(height);
168 
169  ViewUtil.setChildHeightForTableLayout(component.getView(), height);
170 
171  }
172 
173  // AndroidViewComponent implementation
174 
175  @Override
176  public View getView() {
177  return viewLayout.getLayoutManager();
178  }
179 }
com.google.appinventor.components.runtime.AndroidViewComponent.setLastHeight
void setLastHeight(int height)
Definition: AndroidViewComponent.java:143
com.google.appinventor.components.runtime.TableArrangement.getView
View getView()
Definition: TableArrangement.java:176
com.google.appinventor.components.runtime.util
-*- mode: java; c-basic-offset: 2; -*-
Definition: AccountChooser.java:7
com.google.appinventor.components.runtime.TableArrangement.TableArrangement
TableArrangement(ComponentContainer container)
Definition: TableArrangement.java:62
com.google.appinventor.components.common.YaVersion
Definition: YaVersion.java:14
com.google.appinventor.components.annotations.DesignerProperty
Definition: DesignerProperty.java:25
com.google.appinventor.components.runtime.TableArrangement.$context
Activity $context()
Definition: TableArrangement.java:118
com.google.appinventor.components
com.google.appinventor.components.common.PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER
static final String PROPERTY_TYPE_NON_NEGATIVE_INTEGER
Definition: PropertyTypeConstants.java:206
com.google.appinventor.components.runtime.TableArrangement.setChildHeight
void setChildHeight(AndroidViewComponent component, int height)
Definition: TableArrangement.java:155
com.google.appinventor.components.annotations.DesignerComponent
Definition: DesignerComponent.java:22
com.google.appinventor.components.runtime.AndroidViewComponent.setLastWidth
void setLastWidth(int width)
Definition: AndroidViewComponent.java:129
com.google.appinventor.components.runtime.TableArrangement.Rows
int Rows()
Definition: TableArrangement.java:99
com.google.appinventor.components.runtime.Component.LENGTH_PERCENT_TAG
static final int LENGTH_PERCENT_TAG
Definition: Component.java:123
com.google.appinventor.components.runtime.ComponentContainer.$add
void $add(AndroidViewComponent component)
com.google.appinventor.components.runtime.util.ViewUtil.setChildHeightForTableLayout
static void setChildHeightForTableLayout(View view, int height)
Definition: ViewUtil.java:160
com.google.appinventor.components.runtime.TableArrangement.setChildWidth
void setChildWidth(AndroidViewComponent component, int width)
Definition: TableArrangement.java:133
com.google.appinventor.components.runtime.TableArrangement.Columns
int Columns()
Definition: TableArrangement.java:77
com.google.appinventor.components.annotations.SimpleProperty
Definition: SimpleProperty.java:23
com.google.appinventor.components.runtime.TableLayout
Definition: TableLayout.java:26
com.google.appinventor.components.runtime.TableLayout.getLayoutManager
ViewGroup getLayoutManager()
Definition: TableLayout.java:105
com.google.appinventor.components.runtime.Component.LENGTH_PREFERRED
static final int LENGTH_PREFERRED
Definition: Component.java:118
com.google.appinventor.components.runtime.Form.Height
int Height()
Definition: Form.java:1948
com.google.appinventor.components.runtime.ComponentContainer
Definition: ComponentContainer.java:16
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.runtime.Form.Width
int Width()
Definition: Form.java:1936
com.google.appinventor.components.runtime.Component
Definition: Component.java:17
com.google.appinventor.components.common
Definition: ComponentCategory.java:7
com.google.appinventor.components.common.ComponentCategory
Definition: ComponentCategory.java:48
com.google.appinventor.components.annotations.SimpleObject
Definition: SimpleObject.java:23
com.google.appinventor.components.runtime.AndroidViewComponent.getView
abstract View getView()
com.google.appinventor.components.runtime.AndroidViewComponent.container
final ComponentContainer container
Definition: AndroidViewComponent.java:29
com.google.appinventor.components.runtime.util.ViewUtil.setChildWidthForTableLayout
static void setChildWidthForTableLayout(View view, int width)
Definition: ViewUtil.java:139
com.google
com
com.google.appinventor.components.runtime.TableArrangement.$form
Form $form()
Definition: TableArrangement.java:123
com.google.appinventor.components.runtime.ComponentContainer.$form
Form $form()
com.google.appinventor.components.runtime.TableArrangement
Definition: TableArrangement.java:50
com.google.appinventor.components.runtime.ComponentContainer.$context
Activity $context()
com.google.appinventor.components.runtime.TableArrangement.$add
void $add(AndroidViewComponent component)
Definition: TableArrangement.java:128
com.google.appinventor.components.runtime.AndroidViewComponent
Definition: AndroidViewComponent.java:27
com.google.appinventor.components.runtime.TableLayout.add
void add(AndroidViewComponent child)
Definition: TableLayout.java:109
com.google.appinventor.components.runtime.Form
Definition: Form.java:126
com.google.appinventor.components.common.PropertyTypeConstants
Definition: PropertyTypeConstants.java:14
com.google.appinventor.components.annotations
com.google.appinventor
com.google.appinventor.components.runtime.util.ViewUtil
Definition: ViewUtil.java:22