From ab360fbd55a54ad759ee7c0777d3d9e4b5a49cca Mon Sep 17 00:00:00 2001 From: miqmago Date: Thu, 4 Sep 2014 18:41:38 +0200 Subject: [PATCH] Support for Android old devices < API 11 for AlertDialog.Builder < API 14 for ProgressDialog --- src/android/Notification.java | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/android/Notification.java b/src/android/Notification.java index 456a9bfb..96d2d53c 100755 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -25,6 +25,8 @@ Licensed to the Apache Software Foundation (ASF) under one import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; + +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; @@ -151,7 +153,7 @@ public synchronized void alert(final String message, final String title, final S Runnable runnable = new Runnable() { public void run() { - AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); + AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(true); @@ -192,7 +194,7 @@ public synchronized void confirm(final String message, final String title, final Runnable runnable = new Runnable() { public void run() { - AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); + AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(true); @@ -270,7 +272,7 @@ public synchronized void prompt(final String message, final String title, final public void run() { final EditText promptInput = new EditText(cordova.getActivity()); promptInput.setHint(defaultText); - AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); + AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(true); @@ -398,7 +400,7 @@ public synchronized void progressStart(final String title, final String message) final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { - notification.progressDialog = new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); + notification.progressDialog = createProgressDialog(cordova); // new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); notification.progressDialog.setTitle(title); notification.progressDialog.setMessage(message); @@ -437,4 +439,24 @@ public synchronized void progressStop() { this.progressDialog = null; } } + + @SuppressLint("NewApi") + private AlertDialog.Builder createDialog(CordovaInterface cordova) { + int currentapiVersion = android.os.Build.VERSION.SDK_INT; + if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { + return new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); + } else { + return new AlertDialog.Builder(cordova.getActivity()); + } + } + + @SuppressLint("InlinedApi") + private ProgressDialog createProgressDialog(CordovaInterface cordova) { + int currentapiVersion = android.os.Build.VERSION.SDK_INT; + if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + return new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); + } else { + return new ProgressDialog(cordova.getActivity()); + } + } }