Revert "Revert "Fix make file by adding google analytics back Update uses of deprecated APIs""

This reverts commit 5e8e11042a0f525f9129809cd0e1398682999e38.

Conflicts:
	Tools/sl4a/ScriptingLayerForAndroid/Android.mk

Change-Id: Ieee7f1660fc4d837a6fc305ae2e8a78748a9281c
diff --git a/Common/src/com/googlecode/android_scripting/facade/SettingsFacade.java b/Common/src/com/googlecode/android_scripting/facade/SettingsFacade.java
index a21b389..ade3c27 100644
--- a/Common/src/com/googlecode/android_scripting/facade/SettingsFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/SettingsFacade.java
@@ -64,7 +64,8 @@
     mConnect = (ConnectivityManager) mService.getSystemService(Context.CONNECTIVITY_SERVICE);
   }
 
-  @Rpc(description = "Sets the screen timeout to this number of seconds.", returns = "The original screen timeout.")
+  @Rpc(description = "Sets the screen timeout to this number of seconds.",
+       returns = "The original screen timeout.")
   public Integer setScreenTimeout(@RpcParameter(name = "value") Integer value) {
     Integer oldValue = getScreenTimeout();
     android.provider.Settings.System.putInt(mService.getContentResolver(),
@@ -72,7 +73,8 @@
     return oldValue;
   }
 
-  @Rpc(description = "Returns the current screen timeout in seconds.", returns = "the current screen timeout in seconds.")
+  @Rpc(description = "Returns the current screen timeout in seconds.",
+       returns = "the current screen timeout in seconds.")
   public Integer getScreenTimeout() {
     try {
       return android.provider.Settings.System.getInt(mService.getContentResolver(),
@@ -82,7 +84,8 @@
     }
   }
 
-  @Rpc(description = "Checks the airplane mode setting.", returns = "True if airplane mode is enabled.")
+  @Rpc(description = "Checks the airplane mode setting.",
+       returns = "True if airplane mode is enabled.")
   public Boolean checkAirplaneMode() {
     try {
       return android.provider.Settings.System.getInt(mService.getContentResolver(),
@@ -92,7 +95,8 @@
     }
   }
 
-  @Rpc(description = "Toggles airplane mode on and off.", returns = "True if airplane mode is enabled.")
+  @Rpc(description = "Toggles airplane mode on and off.",
+       returns = "True if airplane mode is enabled.")
   public void toggleAirplaneMode(@RpcParameter(name = "enabled") @RpcOptional Boolean enabled) {
     if (enabled == null) {
       enabled = !checkAirplaneMode();
@@ -100,13 +104,16 @@
     mConnect.setAirplaneMode(enabled);
   }
 
-  @Rpc(description = "Checks the ringer silent mode setting.", returns = "True if ringer silent mode is enabled.")
+  @Rpc(description = "Checks the ringer silent mode setting.",
+       returns = "True if ringer silent mode is enabled.")
   public Boolean checkRingerSilentMode() {
     return mAudio.getRingerMode() == AudioManager.RINGER_MODE_SILENT;
   }
 
-  @Rpc(description = "Toggles ringer silent mode on and off.", returns = "True if ringer silent mode is enabled.")
-  public Boolean toggleRingerSilentMode(@RpcParameter(name = "enabled") @RpcOptional Boolean enabled) {
+  @Rpc(description = "Toggles ringer silent mode on and off.",
+       returns = "True if ringer silent mode is enabled.")
+  public Boolean toggleRingerSilentMode(@RpcParameter(name = "enabled")
+                                        @RpcOptional Boolean enabled) {
     if (enabled == null) {
       enabled = !checkRingerSilentMode();
     }
@@ -115,19 +122,19 @@
     return enabled;
   }
 
-  @Rpc(description = "Toggles vibrate mode on and off. If ringer=true then set Ringer setting, else set Notification setting", returns = "True if vibrate mode is enabled.")
-  public Boolean toggleVibrateMode(@RpcParameter(name = "enabled") @RpcOptional Boolean enabled,
-      @RpcParameter(name = "ringer") @RpcOptional Boolean ringer) {
-    int atype = ringer ? AudioManager.VIBRATE_TYPE_RINGER : AudioManager.VIBRATE_TYPE_NOTIFICATION;
-    int asetting = enabled ? AudioManager.VIBRATE_SETTING_ON : AudioManager.VIBRATE_SETTING_OFF;
-    mAudio.setVibrateSetting(atype, asetting);
-    return enabled;
+  @Rpc(description = "Set the ringer to a specified mode")
+  public void setRingerMode(@RpcParameter(name = "mode") Integer mode) throws Exception {
+    if(AudioManager.isValidRingerMode(mode)) {
+      mAudio.setRingerMode(mode);
+    } else {
+      throw new Exception("Ringer mode " + mode + " does not exist.");
+    }
   }
 
-  @Rpc(description = "Checks Vibration setting. If ringer=true then query Ringer setting, else query Notification setting", returns = "True if vibrate mode is enabled.")
-  public Boolean getVibrateMode(@RpcParameter(name = "ringer") @RpcOptional Boolean ringer) {
-    int atype = ringer ? AudioManager.VIBRATE_TYPE_RINGER : AudioManager.VIBRATE_TYPE_NOTIFICATION;
-    return mAudio.shouldVibrate(atype);
+  @Rpc(description = "Returns the current ringtone mode.",
+       returns = "An integer representing the current ringer mode")
+  public Integer getRingerMode() {
+    return mAudio.getRingerMode();
   }
 
   @Rpc(description = "Returns the maximum ringer volume.")
@@ -160,7 +167,8 @@
     mAudio.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
   }
 
-  @Rpc(description = "Returns the screen backlight brightness.", returns = "the current screen brightness between 0 and 255")
+  @Rpc(description = "Returns the screen backlight brightness.",
+       returns = "the current screen brightness between 0 and 255")
   public Integer getScreenBrightness() {
     try {
       return android.provider.Settings.System.getInt(mService.getContentResolver(),
@@ -170,9 +178,11 @@
     }
   }
 
-  @Rpc(description = "Sets the the screen backlight brightness.", returns = "the original screen brightness.")
+  @Rpc(description = "Sets the the screen backlight brightness.",
+       returns = "the original screen brightness.")
   public Integer setScreenBrightness(
-      @RpcParameter(name = "value", description = "brightness value between 0 and 255") Integer value) {
+      @RpcParameter(name = "value", description = "brightness value between 0 and 255")
+      Integer value) {
     if (value < 0) {
       value = 0;
     } else if (value > 255) {
@@ -202,7 +212,8 @@
     return oldValue;
   }
 
-  @Rpc(description = "Checks if the screen is on or off (requires API level 7).", returns = "True if the screen is currently on.")
+  @Rpc(description = "Checks if the screen is on or off (requires API level 7).",
+       returns = "True if the screen is currently on.")
   public Boolean checkScreenOn() throws Exception {
     Class<?> powerManagerClass = mPower.getClass();
     Boolean result = null;
diff --git a/Common/src/com/googlecode/android_scripting/interpreter/html/HtmlActivityTask.java b/Common/src/com/googlecode/android_scripting/interpreter/html/HtmlActivityTask.java
index cd83bec..56c351b 100644
--- a/Common/src/com/googlecode/android_scripting/interpreter/html/HtmlActivityTask.java
+++ b/Common/src/com/googlecode/android_scripting/interpreter/html/HtmlActivityTask.java
@@ -112,8 +112,10 @@
     @Override
     public boolean shouldOverrideUrlLoading(WebView view, String url) {
       /*
-       * if (Uri.parse(url).getHost().equals("www.example.com")) { // This is my web site, so do not
-       * override; let my WebView load the page return false; } // Otherwise, the link is not for a
+       * if (Uri.parse(url).getHost().equals("www.example.com")) { 
+       * // This is my web site, so do not
+       * override; let my WebView load the page return false; }
+       * // Otherwise, the link is not for a
        * page on my site, so launch another Activity that handles URLs Intent intent = new
        * Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent);
        */
@@ -301,7 +303,8 @@
     @Override
     public void onReceivedIcon(WebView view, Bitmap icon) {
       mActivity.getWindow().requestFeature(Window.FEATURE_RIGHT_ICON);
-      mActivity.getWindow().setFeatureDrawable(Window.FEATURE_RIGHT_ICON, new BitmapDrawable(icon));
+      mActivity.getWindow().setFeatureDrawable(Window.FEATURE_RIGHT_ICON,
+                                               new BitmapDrawable(mActivity.getResources(), icon));
     }
 
     @Override
diff --git a/ScriptingLayerForAndroid/Android.mk b/ScriptingLayerForAndroid/Android.mk
index 824f6a7..c85ad8d 100644
--- a/ScriptingLayerForAndroid/Android.mk
+++ b/ScriptingLayerForAndroid/Android.mk
@@ -15,9 +15,7 @@
 
 LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libGoogleAnalytics:../Common/libs/libGoogleAnalytics.jar
 
-
-LOCAL_STATIC_JAVA_LIBRARIES := guava android-common libGoogleAnalytics locale_platform
-#LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4
+LOCAL_STATIC_JAVA_LIBRARIES := guava android-common locale_platform GoogleAnalytics
 LOCAL_STATIC_JAVA_LIBRARIES += sl4a.Utils sl4a.Common sl4a.BluetoothFacade
 LOCAL_STATIC_JAVA_LIBRARIES += sl4a.SignalStrengthFacade sl4a.TextToSpeechFacade sl4a.WebCamFacade
 LOCAL_STATIC_JAVA_LIBRARIES += sl4a.InterpreterForAndroid sl4a.ScriptingLayer sl4a.QuickAction
diff --git a/Utils/src/com/googlecode/android_scripting/Log.java b/Utils/src/com/googlecode/android_scripting/Log.java
index 097d540..06b2fa9 100644
--- a/Utils/src/com/googlecode/android_scripting/Log.java
+++ b/Utils/src/com/googlecode/android_scripting/Log.java
@@ -48,9 +48,14 @@
     int iconId = context.getResources().getIdentifier("stat_sys_warning", "drawable", packageName);
     NotificationManager notificationManager =
         (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
-    Notification note = new Notification(iconId > 0 ? iconId : -1, title, 0);
-    note.setLatestEventInfo(context, contentTitle, message, PendingIntent.getService(context, 0,
-        null, 0));
+    Notification.Builder builder = new Notification.Builder(context);
+    builder.setSmallIcon(iconId > 0 ? iconId : -1)
+           .setTicker(title)
+           .setWhen(0)
+           .setContentTitle(contentTitle)
+           .setContentText(message)
+           .setContentIntent(PendingIntent.getService(context, 0, null, 0));
+    Notification note = builder.build();
     note.contentView.getLayoutId();
     notificationManager.notify(NotificationIdFactory.create(), note);
   }