diff options
| -rw-r--r-- | main/res/layout/main.xml | 22 | ||||
| -rw-r--r-- | main/res/layout/status.xml | 22 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/StatusFragment.java | 110 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeo.java | 70 |
4 files changed, 135 insertions, 89 deletions
diff --git a/main/res/layout/main.xml b/main/res/layout/main.xml index 1341821..575fe1f 100644 --- a/main/res/layout/main.xml +++ b/main/res/layout/main.xml @@ -17,31 +17,15 @@ android:src="@drawable/actionbar_manual" android:onClick="goManual" /> </LinearLayout> - <RelativeLayout android:id="@+id/status" - android:visibility="gone" + <fragment android:id="@+id/status" + android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="16dip" android:layout_marginRight="16dip" android:layout_marginTop="60dip" - android:background="@drawable/helper_bcg" > - <ImageView android:id="@+id/status_icon" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_alignParentLeft="true" - android:layout_centerVertical="true" - android:layout_margin="4dip" /> - <TextView android:id="@+id/status_message" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:layout_toRightOf="@id/status_icon" - android:layout_centerVertical="true" - android:gravity="center" - android:padding="4dip" - android:textSize="14dip" - android:textColor="@color/text_icon" /> - </RelativeLayout> + android:name="cgeo.geocaching.StatusFragment" /> <!-- ** --> <LinearLayout android:layout_width="fill_parent" diff --git a/main/res/layout/status.xml b/main/res/layout/status.xml new file mode 100644 index 0000000..6d9aba3 --- /dev/null +++ b/main/res/layout/status.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> + +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/status" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="@drawable/helper_bcg" > + <ImageView android:id="@+id/status_icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_centerVertical="true" + android:layout_margin="4dip" /> + <TextView android:id="@+id/status_message" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_toRightOf="@id/status_icon" + android:layout_centerVertical="true" + android:gravity="center" + android:padding="4dip" + android:textSize="14dip" + android:textColor="@color/text_icon" /> +</RelativeLayout>
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/StatusFragment.java b/main/src/cgeo/geocaching/StatusFragment.java new file mode 100644 index 0000000..5a9a5b4 --- /dev/null +++ b/main/src/cgeo/geocaching/StatusFragment.java @@ -0,0 +1,110 @@ +package cgeo.geocaching; + +import cgeo.geocaching.network.StatusUpdater.Status; +import cgeo.geocaching.utils.IObserver; +import cgeo.geocaching.utils.Log; + +import android.content.Intent; +import android.content.res.Resources; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +public class StatusFragment extends Fragment { + + private ViewGroup status; + private ImageView statusIcon; + private TextView statusMessage; + + final private StatusHandler statusHandler = new StatusHandler(); + + @Override + public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + status = (ViewGroup) inflater.inflate(R.layout.status, container, false); + statusIcon = (ImageView) status.findViewById(R.id.status_icon); + statusMessage = (TextView) status.findViewById(R.id.status_message); + return status; + } + + @Override + public void onResume() { + super.onResume(); + cgeoapplication.getInstance().getStatusUpdater().addObserver(statusHandler); + } + + @Override + public void onPause() { + cgeoapplication.getInstance().getStatusUpdater().deleteObserver(statusHandler); + super.onPause(); + } + + 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 : null); + } + + private void updateDisplay(final Status data) { + + if (data == null) { + status.setVisibility(View.INVISIBLE); + return; + } + + final Resources res = getResources(); + final String packageName = getActivity().getPackageName(); + + if (data.icon != null) { + final int iconId = res.getIdentifier(data.icon, "drawable", packageName); + if (iconId != 0) { + statusIcon.setImageResource(iconId); + statusIcon.setVisibility(View.VISIBLE); + } else { + Log.w("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", packageName); + 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); + } + } + + } +} diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java index cb2de66..29c287a 100644 --- a/main/src/cgeo/geocaching/cgeo.java +++ b/main/src/cgeo/geocaching/cgeo.java @@ -8,10 +8,8 @@ import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Units; import cgeo.geocaching.maps.CGeoMap; -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.RunnableWithArgument; import cgeo.geocaching.utils.Version; @@ -29,7 +27,6 @@ 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; @@ -38,8 +35,6 @@ import android.view.MenuInflater; 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; @@ -174,69 +169,6 @@ 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 : null); - } - - 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"); } @@ -291,7 +223,6 @@ public class cgeo extends AbstractActivity { @Override public void onResume() { super.onResume(); - app.getStatusUpdater().addObserver(statusHandler); locationUpdater.startGeo(); satellitesHandler.startGeo(); updateUserInfoHandler.sendEmptyMessage(-1); @@ -315,7 +246,6 @@ public class cgeo extends AbstractActivity { @Override public void onPause() { initialized = false; - app.getStatusUpdater().deleteObserver(statusHandler); locationUpdater.stopGeo(); satellitesHandler.stopGeo(); super.onPause(); |
