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(-) (limited to 'src') 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(+) (limited to 'src') 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 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(-) (limited to 'src') 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