7 package com.google.appinventor.components.runtime;
23 import android.app.Activity;
24 import android.content.Intent;
25 import android.view.WindowManager;
42 @DesignerComponent(version = YaVersion.LISTPICKER_COMPONENT_VERSION,
43 category = ComponentCategory.USERINTERFACE,
44 description =
"<p>A button that, when clicked on, displays a list of " +
45 "texts for the user to choose among. The texts can be specified through " +
46 "the Designer or Blocks Editor by setting the " +
47 "<code>ElementsFromString</code> property to their string-separated " +
48 "concatenation (for example, <em>choice 1, choice 2, choice 3</em>) or " +
49 "by setting the <code>Elements</code> property to a List in the Blocks " +
51 "<p>Setting property ShowFilterBar to true, will make the list searchable. " +
52 "Other properties affect the appearance of the button " +
53 "(<code>TextAlignment</code>, <code>BackgroundColor</code>, etc.) and " +
54 "whether it can be clicked on (<code>Enabled</code>).</p>")
56 @UsesActivities(activities = {
57 @ActivityElement(name =
"com.google.appinventor.components.runtime.ListPickerActivity",
58 configChanges =
"orientation|keyboardHidden",
59 screenOrientation =
"behind")
64 static final String LIST_ACTIVITY_ARG_NAME = LIST_ACTIVITY_CLASS +
".list";
65 static final String LIST_ACTIVITY_RESULT_NAME = LIST_ACTIVITY_CLASS +
".selection";
66 static final String LIST_ACTIVITY_RESULT_INDEX = LIST_ACTIVITY_CLASS +
".index";
67 static final String LIST_ACTIVITY_ANIM_TYPE = LIST_ACTIVITY_CLASS +
".anim";
68 static final String LIST_ACTIVITY_SHOW_SEARCH_BAR = LIST_ACTIVITY_CLASS +
".search";
69 static final String LIST_ACTIVITY_TITLE = LIST_ACTIVITY_CLASS +
".title";
70 static final String LIST_ACTIVITY_ORIENTATION_TYPE = LIST_ACTIVITY_CLASS +
".orientation";
71 static final String LIST_ACTIVITY_ITEM_TEXT_COLOR = LIST_ACTIVITY_CLASS +
".itemtextcolor";
72 static final String LIST_ACTIVITY_BACKGROUND_COLOR = LIST_ACTIVITY_CLASS +
".backgroundcolor";
75 private String selection;
76 private int selectionIndex;
77 private boolean showFilter =
false;
78 private static final boolean DEFAULT_ENABLED =
false;
79 private String title =
"";
81 private boolean resumedFromListFlag =
false;
83 private int itemTextColor;
84 private int itemBackgroundColor;
98 itemTextColor = DEFAULT_ITEM_TEXT_COLOR;
99 itemBackgroundColor = DEFAULT_ITEM_BACKGROUND_COLOR;
106 if (resumedFromListFlag) {
107 container.$form().getWindow().setSoftInputMode(
108 WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
110 resumedFromListFlag =
false;
120 description =
"The selected item. When directly changed by the " +
121 "programmer, the SelectionIndex property is also changed to the first " +
122 "item in the ListPicker with the given value. If the value does not " +
123 "appear, SelectionIndex will be set to 0.",
125 public String Selection() {
145 defaultValue = DEFAULT_ENABLED ?
"True" :
"False")
148 this.showFilter = showFilter;
155 description =
"Returns current state of ShowFilterBar indicating if " +
156 "Search Filter Bar will be displayed on ListPicker or not")
157 public
boolean ShowFilterBar() {
165 this.itemTextColor = argb;
168 @
SimpleProperty(description =
"The text color of the ListPicker items.",
172 return this.itemTextColor;
179 this.itemBackgroundColor = argb;
185 @
SimpleProperty(description =
"The background color of the ListPicker items.",
189 return this.itemBackgroundColor;
196 description =
"The index of the currently selected item, starting at " +
197 "1. If no item is selected, the value will be 0. If an attempt is " +
198 "made to set this to a number less than 1 or greater than the number " +
199 "of items in the ListPicker, SelectionIndex will be set to 0, and " +
200 "Selection will be set to the empty text.",
202 public
int SelectionIndex() {
203 return selectionIndex;
253 public
void ElementsFromString(String itemstring) {
266 description =
"Optional title displayed at the top of the list of choices.")
267 public String Title() {
287 Intent intent =
new Intent();
288 intent.setClassName(container.$context(), LIST_ACTIVITY_CLASS);
289 intent.putExtra(LIST_ACTIVITY_ARG_NAME, items.
toStringArray());
290 intent.putExtra(LIST_ACTIVITY_SHOW_SEARCH_BAR, String.valueOf(showFilter));
291 if (!title.equals(
"")) {
292 intent.putExtra(LIST_ACTIVITY_TITLE, title);
297 String openAnim = container.$form().getOpenAnimType();
298 intent.putExtra(LIST_ACTIVITY_ANIM_TYPE, openAnim);
299 intent.putExtra(LIST_ACTIVITY_ORIENTATION_TYPE,container.$form().ScreenOrientation());
300 intent.putExtra(LIST_ACTIVITY_ITEM_TEXT_COLOR, itemTextColor);
301 intent.putExtra(LIST_ACTIVITY_BACKGROUND_COLOR, itemBackgroundColor);
318 if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) {
319 if (data.hasExtra(LIST_ACTIVITY_RESULT_NAME)) {
320 selection = data.getStringExtra(LIST_ACTIVITY_RESULT_NAME);
324 selectionIndex = data.getIntExtra(LIST_ACTIVITY_RESULT_INDEX, 0);
329 resumedFromListFlag =
true;
337 container.$form().unregisterForActivityResult(
this);