From 8f96a63ebeae772fb4eee5e80cc5b64b88df0c2d Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Fri, 13 May 2011 21:38:05 -0700 Subject: Use method invoke to work around SetForeground not being in API 11+ --- src/org/connectbot/service/ConnectionNotifier.java | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/org/connectbot/service/ConnectionNotifier.java b/src/org/connectbot/service/ConnectionNotifier.java index a9c054d..ffe2230 100644 --- a/src/org/connectbot/service/ConnectionNotifier.java +++ b/src/org/connectbot/service/ConnectionNotifier.java @@ -17,6 +17,9 @@ package org.connectbot.service; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + import org.connectbot.ConsoleActivity; import org.connectbot.R; import org.connectbot.bean.HostBean; @@ -128,19 +131,41 @@ public abstract class ConnectionNotifier { public abstract void hideRunningNotification(Service context); private static class PreEclair extends ConnectionNotifier { + private static final Class[] setForegroundSignature = new Class[] {boolean.class}; + private Method setForeground = null; + private static class Holder { private static final PreEclair sInstance = new PreEclair(); } + public PreEclair() { + try { + setForeground = Service.class.getMethod("setForeground", setForegroundSignature); + } catch (Exception e) { + } + } + @Override public void showRunningNotification(Service context) { - context.setForeground(true); + Object[] setForegroundArgs = new Object[1]; + setForegroundArgs[0] = Boolean.TRUE; + try { + setForeground.invoke(context, setForegroundArgs); + } catch (InvocationTargetException e) { + } catch (IllegalAccessException e) { + } getNotificationManager(context).notify(ONLINE_NOTIFICATION, newRunningNotification(context)); } @Override public void hideRunningNotification(Service context) { - context.setForeground(false); + Object[] setForegroundArgs = new Object[1]; + setForegroundArgs[0] = Boolean.FALSE; + try { + setForeground.invoke(context, setForegroundArgs); + } catch (InvocationTargetException e) { + } catch (IllegalAccessException e) { + } getNotificationManager(context).cancel(ONLINE_NOTIFICATION); } } -- cgit v1.2.3 From 05824e5335d6032d1202d87fce6e147a0ffd8a21 Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Fri, 13 May 2011 22:01:36 -0700 Subject: Add stubs for API 11 SharedPreferences interface methods --- src/org/connectbot/HostEditorActivity.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/org/connectbot/HostEditorActivity.java b/src/org/connectbot/HostEditorActivity.java index a994b1b..4e8427f 100644 --- a/src/org/connectbot/HostEditorActivity.java +++ b/src/org/connectbot/HostEditorActivity.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Map.Entry; import org.connectbot.bean.HostBean; @@ -162,6 +163,10 @@ public class HostEditorActivity extends PreferenceActivity implements OnSharedPr update.remove(key); return this; } + + public android.content.SharedPreferences.Editor putStringSet(String key, Set value) { + throw new UnsupportedOperationException("HostEditor Prefs do not support Set"); + } } @@ -197,6 +202,10 @@ public class HostEditorActivity extends PreferenceActivity implements OnSharedPr return values.get(key); } + public Set getStringSet(String key, Set defValue) { + throw new ClassCastException("HostEditor Prefs do not support Set"); + } + protected List listeners = new LinkedList(); public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) { -- cgit v1.2.3 From e56f341c53ab0114aa53fc2b4ebcc96a4c045a36 Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Fri, 13 May 2011 22:28:52 -0700 Subject: Update API version to 11 --- default.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default.properties b/default.properties index 76c9984..af73ae7 100644 --- a/default.properties +++ b/default.properties @@ -11,4 +11,4 @@ split.density=false # Project target. -target=android-9 +target=android-11 -- cgit v1.2.3 From 4a8327b6799df44681c7118e7f5202acbf74be1d Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Wed, 18 May 2011 01:00:23 -0700 Subject: Update the manifest for API 11 --- AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 205f0f6..88a1823 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -5,7 +5,7 @@ android:versionCode="347" android:installLocation="auto"> - + Date: Wed, 18 May 2011 02:40:43 -0700 Subject: Add title bar to ConsoleActivity so menu is accessible --- res/values-v11/styles.xml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 res/values-v11/styles.xml diff --git a/res/values-v11/styles.xml b/res/values-v11/styles.xml new file mode 100644 index 0000000..cf9636b --- /dev/null +++ b/res/values-v11/styles.xml @@ -0,0 +1,24 @@ + + + + + -- cgit v1.2.3 From f328e7f8acccca78cd0e7559b6cbcd17d56844e6 Mon Sep 17 00:00:00 2001 From: Hans Nielsen Date: Wed, 25 May 2011 18:32:43 -0700 Subject: Avoid null-pointer exception in ConnectionNotifier --- src/org/connectbot/service/ConnectionNotifier.java | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/org/connectbot/service/ConnectionNotifier.java b/src/org/connectbot/service/ConnectionNotifier.java index ffe2230..d276761 100644 --- a/src/org/connectbot/service/ConnectionNotifier.java +++ b/src/org/connectbot/service/ConnectionNotifier.java @@ -147,26 +147,30 @@ public abstract class ConnectionNotifier { @Override public void showRunningNotification(Service context) { - Object[] setForegroundArgs = new Object[1]; - setForegroundArgs[0] = Boolean.TRUE; - try { - setForeground.invoke(context, setForegroundArgs); - } catch (InvocationTargetException e) { - } catch (IllegalAccessException e) { - } - getNotificationManager(context).notify(ONLINE_NOTIFICATION, newRunningNotification(context)); + if (setForeground != null) { + Object[] setForegroundArgs = new Object[1]; + setForegroundArgs[0] = Boolean.TRUE; + try { + setForeground.invoke(context, setForegroundArgs); + } catch (InvocationTargetException e) { + } catch (IllegalAccessException e) { + } + getNotificationManager(context).notify(ONLINE_NOTIFICATION, newRunningNotification(context)); + } } @Override public void hideRunningNotification(Service context) { - Object[] setForegroundArgs = new Object[1]; - setForegroundArgs[0] = Boolean.FALSE; - try { - setForeground.invoke(context, setForegroundArgs); - } catch (InvocationTargetException e) { - } catch (IllegalAccessException e) { - } - getNotificationManager(context).cancel(ONLINE_NOTIFICATION); + if (setForeground != null) { + Object[] setForegroundArgs = new Object[1]; + setForegroundArgs[0] = Boolean.FALSE; + try { + setForeground.invoke(context, setForegroundArgs); + } catch (InvocationTargetException e) { + } catch (IllegalAccessException e) { + } + getNotificationManager(context).cancel(ONLINE_NOTIFICATION); + } } } -- cgit v1.2.3