7 package com.google.appinventor.components.runtime.util;
9 import android.app.Activity;
10 import android.content.Context;
11 import android.graphics.Bitmap;
12 import android.media.AudioManager;
13 import android.net.http.SslError;
14 import android.view.Display;
15 import android.webkit.SslErrorHandler;
16 import android.webkit.WebView;
17 import android.webkit.WebViewClient;
42 return display.getRotation();
52 return (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
61 Object afChangeListener = (android.media.AudioManager.OnAudioFocusChangeListener)
new android
62 .media.AudioManager.OnAudioFocusChangeListener() {
63 private boolean playbackFlag =
false;
71 public void onAudioFocusChange(
int focusChange) {
73 case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
74 case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
81 case AudioManager.AUDIOFOCUS_LOSS:
84 player.OtherPlayerStarted();
86 case AudioManager.AUDIOFOCUS_GAIN:
96 return afChangeListener;
106 int result = am.requestAudioFocus((AudioManager.OnAudioFocusChangeListener) afChangeListener,
107 AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
108 return result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
116 public static void abandonFocus(AudioManager am, Object afChangeListener) {
117 am.abandonAudioFocus((AudioManager.OnAudioFocusChangeListener) afChangeListener);
129 final boolean followLinks,
final Form form,
final Component component) {
130 return new WebViewClient() {
132 public boolean shouldOverrideUrlLoading(WebView view, String url) {
137 public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
148 public void onPageStarted(WebView view, String url, Bitmap favicon) {
153 public void onPageFinished(WebView view, String url) {
158 public void onReceivedError(WebView view,
final int errorCode,
final String description,
final String failingUrl) {
159 form.runOnUiThread(
new Runnable() {