Didn't test on ICS or lower, getDrawable isn't supported until Jellybean

This commit is contained in:
Joe Bowser 2014-01-16 13:55:53 -08:00
parent 736c8ddec0
commit 0ce0eed585

View File

@ -27,7 +27,6 @@ import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.util.Log; import android.util.Log;
@ -254,16 +253,11 @@ public class InAppBrowser extends CordovaPlugin {
scriptToInject = source; scriptToInject = source;
} }
final String finalScriptToInject = scriptToInject; final String finalScriptToInject = scriptToInject;
// This action will have the side-effect of blurring the currently focused element
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(new Runnable() {
@SuppressLint("NewApi")
@Override @Override
public void run() { public void run() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { inAppWebView.loadUrl("javascript:" + finalScriptToInject);
// This action will have the side-effect of blurring the currently focused element
inAppWebView.loadUrl("javascript:" + finalScriptToInject);
} else {
inAppWebView.evaluateJavascript(finalScriptToInject, null);
}
} }
}); });
} }
@ -491,7 +485,14 @@ public class InAppBrowser extends CordovaPlugin {
Resources activityRes = cordova.getActivity().getResources(); Resources activityRes = cordova.getActivity().getResources();
int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName());
Drawable backIcon = activityRes.getDrawable(backResId); Drawable backIcon = activityRes.getDrawable(backResId);
back.setBackground(backIcon); if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
back.setBackgroundDrawable(backIcon);
}
else
{
back.setBackground(backIcon);
}
back.setOnClickListener(new View.OnClickListener() { back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
goBack(); goBack();
@ -508,7 +509,14 @@ public class InAppBrowser extends CordovaPlugin {
//forward.setText(">"); //forward.setText(">");
int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
Drawable fwdIcon = activityRes.getDrawable(fwdResId); Drawable fwdIcon = activityRes.getDrawable(fwdResId);
forward.setBackground(fwdIcon); if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
forward.setBackgroundDrawable(fwdIcon);
}
else
{
forward.setBackground(fwdIcon);
}
forward.setOnClickListener(new View.OnClickListener() { forward.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
goForward(); goForward();
@ -548,7 +556,14 @@ public class InAppBrowser extends CordovaPlugin {
//close.setText(buttonLabel); //close.setText(buttonLabel);
int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
Drawable closeIcon = activityRes.getDrawable(closeResId); Drawable closeIcon = activityRes.getDrawable(closeResId);
close.setBackground(closeIcon); if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
{
close.setBackgroundDrawable(closeIcon);
}
else
{
close.setBackground(closeIcon);
}
close.setOnClickListener(new View.OnClickListener() { close.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
closeDialog(); closeDialog();