AI2 Component  (Version nb184)
EmailPicker.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-2018 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 
15 
16 import android.Manifest;
17 import android.widget.AutoCompleteTextView;
18 
37 @DesignerComponent(version = YaVersion.EMAILPICKER_COMPONENT_VERSION,
38  description = "An EmailPicker is a kind of text box. " +
39  "If the user begins entering the name " +
40  "or email address of a contact, the phone will show a dropdown menu of " +
41  "choices that complete the entry. If there are many contacts, the " +
42  "dropdown can take several seconds to appear, and can show intermediate results " +
43  "while the matches are being computed. <p>The initial contents " +
44  "of the text box and the contents< after user entry is in the <code>Text</code> " +
45  "property. If the <code>Text</code> property is initially empty, " +
46  "the contents of the <code>Hint</code> property will be faintly shown " +
47  "in the text box as a hint to the user.</p>\n " +
48  "<p>Other properties affect the appearance of the text box " +
49  "(<code>TextAlignment</code>, <code>BackgroundColor</code>, etc.) and " +
50  "whether it can be used (<code>Enabled</code>).</p>\n" +
51  "<p>Text boxes like this are usually used with <code>Button</code> " +
52  "components, with the user clicking on the button when text entry is " +
53  "complete.",
54  category = ComponentCategory.SOCIAL)
55 @SimpleObject
56 @UsesPermissions(permissionNames = "android.permission.READ_CONTACTS")
57 public class EmailPicker extends TextBoxBase {
58 
59  private final EmailAddressAdapter addressAdapter;
60 
66  public EmailPicker(ComponentContainer container) {
67  super(container, new AutoCompleteTextView(container.$context()));
68  addressAdapter = new EmailAddressAdapter(container.$context());
69  }
70 
71  @SuppressWarnings("unused") // Will be called from Scheme
72  public void Initialize() {
73  container.$form().askPermission(Manifest.permission.READ_CONTACTS, new PermissionResultHandler() {
74  @Override
75  public void HandlePermissionResponse(String permission, boolean granted) {
76  if (granted) {
77  ((AutoCompleteTextView) view).setAdapter(addressAdapter);
78  } else {
79  container.$form().dispatchPermissionDeniedEvent(EmailPicker.this, "Initialize", permission);
80  }
81  }
82  });
83  }
84 
90  @Override
91  public void GotFocus() {
92 
93 // Note(halabelson): I am commenting out this test. Android provider.Constacts was
94 // deprecated in Donut, but email picking still seems to work on newer versions of the SDK.
95 // If there's a phone where it does not work, we'll get the error at PuntContactSelection
96 // Note that there is still a general problem with contact picking on Motoblur.
97 //
98 // if (SdkLevel.getLevel() > SdkLevel.LEVEL_DONUT) {
99 // container.$form().dispatchErrorOccurredEvent(this, "EmailAddress",
100 // ErrorMessages.ERROR_FUNCTIONALITY_NOT_SUPPORTED_EMAIL_PICKER);
101 // }
102 
103  EventDispatcher.dispatchEvent(this, "GotFocus");
104  }
105 }
com.google.appinventor.components.runtime.EventDispatcher
Definition: EventDispatcher.java:22
com.google.appinventor.components.common.YaVersion
Definition: YaVersion.java:14
com.google.appinventor.components.runtime.EmailAddressAdapter
Definition: EmailAddressAdapter.java:36
com.google.appinventor.components
com.google.appinventor.components.runtime.EmailPicker.GotFocus
void GotFocus()
Definition: EmailPicker.java:91
com.google.appinventor.components.annotations.DesignerComponent
Definition: DesignerComponent.java:22
com.google.appinventor.components.annotations.SimpleEvent
Definition: SimpleEvent.java:20
com.google.appinventor.components.runtime.EmailPicker.EmailPicker
EmailPicker(ComponentContainer container)
Definition: EmailPicker.java:66
com.google.appinventor.components.runtime.TextBoxBase
Definition: TextBoxBase.java:37
com.google.appinventor.components.annotations.UsesPermissions
Definition: UsesPermissions.java:21
com.google.appinventor.components.runtime.PermissionResultHandler
Definition: PermissionResultHandler.java:15
com.google.appinventor.components.runtime.EventDispatcher.dispatchEvent
static boolean dispatchEvent(Component component, String eventName, Object...args)
Definition: EventDispatcher.java:188
com.google.appinventor.components.runtime.EmailPicker
Definition: EmailPicker.java:57
com.google.appinventor.components.runtime.ComponentContainer
Definition: ComponentContainer.java:16
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
com
com.google.appinventor.components.runtime.ComponentContainer.$context
Activity $context()
com.google.appinventor.components.annotations
com.google.appinventor