AI2 Component  (Version nb184)
EclairUtil.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 package com.google.appinventor.components.runtime.util;
7 
9 
10 import android.app.Activity;
11 import android.app.AlertDialog;
12 import android.content.Context;
13 import android.content.DialogInterface;
14 
15 import android.text.InputType;
16 import android.view.MotionEvent;
17 import android.view.View;
18 import android.webkit.GeolocationPermissions;
19 import android.webkit.GeolocationPermissions.Callback;
20 import android.webkit.WebView;
21 import android.webkit.WebViewClient;
22 import android.webkit.WebChromeClient;
23 import android.widget.EditText;
24 
31 public class EclairUtil {
32 
33  private EclairUtil() {
34  }
35 
44  public static void overridePendingTransitions(Activity activity, int enterAnim, int exitAnim) {
45  activity.overridePendingTransition(enterAnim, exitAnim);
46  }
47 
56  public static void setupWebViewGeoLoc(final WebViewer caller, WebView webview, final Activity activity) {
57  webview.getSettings().setGeolocationDatabasePath(activity.getFilesDir().getAbsolutePath());
58  webview.getSettings().setDatabaseEnabled(true);
59  webview.setWebChromeClient(new WebChromeClient() {
60  @Override
61  public void onGeolocationPermissionsShowPrompt(String origin,
62  Callback callback) {
63  final Callback theCallback = callback;
64  final String theOrigin = origin;
65  if (!caller.PromptforPermission()) { // Don't prompt, assume permission
66  callback.invoke(origin, true, true);
67  return;
68  }
69  AlertDialog alertDialog = new AlertDialog.Builder(activity).create();
70  alertDialog.setTitle("Permission Request");
71  if (origin.equals("file://"))
72  origin = "This Application";
73  alertDialog.setMessage(origin + " would like to access your location.");
74  alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Allow",
75  new DialogInterface.OnClickListener() {
76  public void onClick(DialogInterface dialog, int which) {
77  theCallback.invoke(theOrigin, true, true);
78  }
79  });
80  alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Refuse",
81  new DialogInterface.OnClickListener() {
82  public void onClick(DialogInterface dialog, int which) {
83  theCallback.invoke(theOrigin, false, true);
84  }
85  });
86  alertDialog.show();
87  }
88  });
89  }
90 
100  public static void clearWebViewGeoLoc() {
101  GeolocationPermissions permissions = GeolocationPermissions.getInstance();
102  permissions.clearAll();
103  }
104 
105  public static String getInstallerPackageName(String pname, Activity form) {
106  return form.getPackageManager().getInstallerPackageName(pname);
107  }
108 
117  public static void disableSuggestions(EditText textview) {
118  textview.setInputType(textview.getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
119  }
120 
121 }
com.google.appinventor.components.runtime.util.EclairUtil.overridePendingTransitions
static void overridePendingTransitions(Activity activity, int enterAnim, int exitAnim)
Definition: EclairUtil.java:44
com.google.appinventor.components.runtime.util.EclairUtil.disableSuggestions
static void disableSuggestions(EditText textview)
Definition: EclairUtil.java:117
com.google.appinventor.components.runtime.util.EclairUtil.setupWebViewGeoLoc
static void setupWebViewGeoLoc(final WebViewer caller, WebView webview, final Activity activity)
Definition: EclairUtil.java:56
com.google.appinventor.components
com.google.appinventor.components.runtime.WebViewer.PromptforPermission
boolean PromptforPermission()
Definition: WebViewer.java:482
com.google.appinventor.components.runtime.WebViewer
Definition: WebViewer.java:107
com.google.appinventor.components.runtime.util.EclairUtil.clearWebViewGeoLoc
static void clearWebViewGeoLoc()
Definition: EclairUtil.java:100
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.runtime.util.EclairUtil.getInstallerPackageName
static String getInstallerPackageName(String pname, Activity form)
Definition: EclairUtil.java:105
com.google
com
com.google.appinventor.components.runtime.util.EclairUtil
Definition: EclairUtil.java:31
com.google.appinventor