aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/cgeo.java
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-05-29 20:03:00 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-05-30 00:36:14 +0200
commit67da8b62ff0f414eb5dbde10fddb78a9ae4c208e (patch)
tree6b3faa3f6f7b462b66b78746be5a76c665c75a1d /main/src/cgeo/geocaching/cgeo.java
parentd900291f83928f8929608eaa3b4d87faff258458 (diff)
downloadcgeo-67da8b62ff0f414eb5dbde10fddb78a9ae4c208e.zip
cgeo-67da8b62ff0f414eb5dbde10fddb78a9ae4c208e.tar.gz
cgeo-67da8b62ff0f414eb5dbde10fddb78a9ae4c208e.tar.bz2
Get message from the notification server
Diffstat (limited to 'main/src/cgeo/geocaching/cgeo.java')
-rw-r--r--main/src/cgeo/geocaching/cgeo.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java
index f1535c5..a23e232 100644
--- a/main/src/cgeo/geocaching/cgeo.java
+++ b/main/src/cgeo/geocaching/cgeo.java
@@ -9,8 +9,11 @@ import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.HumanDistance;
import cgeo.geocaching.geopoint.IConversion;
import cgeo.geocaching.maps.CGeoMap;
+import cgeo.geocaching.network.StatusUpdater;
+import cgeo.geocaching.network.StatusUpdater.Status;
import cgeo.geocaching.ui.Formatter;
import cgeo.geocaching.utils.GeoDirHandler;
+import cgeo.geocaching.utils.IObserver;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.Version;
@@ -26,6 +29,7 @@ import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.location.Address;
import android.location.Geocoder;
+import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -34,6 +38,8 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
@@ -173,6 +179,69 @@ public class cgeo extends AbstractActivity {
}
};
+ private class StatusHandler extends Handler implements IObserver<Status> {
+
+ @Override
+ public void update(final Status data) {
+ obtainMessage(0, data).sendToTarget();
+ }
+
+ @Override
+ public void handleMessage(final Message msg) {
+ final Status data = (Status) msg.obj;
+ updateDisplay(data != null && data.message != null ? data : StatusUpdater.defaultStatus());
+ }
+
+ private void updateDisplay(final Status data) {
+ final ViewGroup status = (ViewGroup) findViewById(R.id.status);
+ final ImageView statusIcon = (ImageView) findViewById(R.id.status_icon);
+ final TextView statusMessage = (TextView) findViewById(R.id.status_message);
+
+ if (data == null) {
+ status.setVisibility(View.GONE);
+ return;
+ }
+
+ if (data.icon != null) {
+ final int iconId = res.getIdentifier(data.icon, "drawable", getPackageName());
+ if (iconId != 0) {
+ statusIcon.setImageResource(iconId);
+ statusIcon.setVisibility(View.VISIBLE);
+ } else {
+ Log.e("StatusHandler: could not find icon corresponding to @drawable/" + data.icon);
+ statusIcon.setVisibility(View.GONE);
+ }
+ } else {
+ statusIcon.setVisibility(View.GONE);
+ }
+
+ String message = data.message;
+ if (data.messageId != null) {
+ final int messageId = res.getIdentifier(data.messageId, "string", getPackageName());
+ if (messageId != 0) {
+ message = res.getString(messageId);
+ }
+ }
+
+ statusMessage.setText(message);
+ status.setVisibility(View.VISIBLE);
+
+ if (data.url != null) {
+ status.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(data.url)));
+ }
+ });
+ } else {
+ status.setClickable(false);
+ }
+ }
+
+ }
+
+ private StatusHandler statusHandler = new StatusHandler();
+
public cgeo() {
super("c:geo-main-screen");
}
@@ -224,6 +293,7 @@ public class cgeo extends AbstractActivity {
@Override
public void onResume() {
super.onResume();
+ app.getStatusUpdater().addObserver(statusHandler);
locationUpdater.startGeo();
satellitesHandler.startGeo();
updateUserInfoHandler.sendEmptyMessage(-1);
@@ -247,6 +317,7 @@ public class cgeo extends AbstractActivity {
@Override
public void onPause() {
initialized = false;
+ app.getStatusUpdater().deleteObserver(statusHandler);
locationUpdater.stopGeo();
satellitesHandler.stopGeo();
super.onPause();