android:layout_gravity="center"
tools:context="de.example.exampletdd.MapActivity" >
- <TextView
- android:id="@+id/weather_map_city"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="City"
- android:layout_alignParentTop="true"
- android:layout_alignParentStart="true"
- android:textAlignment="textStart"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:textIsSelectable="false"
- android:textStyle="bold|normal" />
- <TextView
- android:id="@+id/weather_map_country"
- android:layout_width="wrap_content"
+ <LinearLayout
+ android:id="@+id/weather_map_citycountry_container"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
- android:layout_alignParentEnd="true"
- android:paddingStart="5dp"
- android:paddingEnd="5dp"
- android:text="country"
- android:textAlignment="textEnd"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:textIsSelectable="false"
- android:textStyle="bold|normal" />
-
+ android:layout_alignParentStart="true" >
+ <LinearLayout
+ android:id="@+id/weather_map_city_container"
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:layout_height="wrap_content">
+ <TextView
+ android:id="@+id/weather_map_city"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="City"
+ android:layout_gravity="center"
+ android:textAlignment="center"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textIsSelectable="false"
+ android:textStyle="bold|normal" />
+ </LinearLayout>
+
+ <ProgressBar
+ android:id="@+id/weather_map_progress"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:layout_weight="1"
+ android:indeterminateBehavior="repeat"
+ android:indeterminateDuration="3500"
+ android:indeterminateOnly="true"
+ android:visibility="gone" />
+
+ <LinearLayout
+ android:id="@+id/weather_map_country_container"
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:layout_gravity="center"
+ android:gravity="center"
+ android:layout_height="wrap_content" >
+ <TextView
+ android:id="@+id/weather_map_country"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="Country"
+ android:layout_gravity="center"
+ android:textAlignment="center"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textIsSelectable="false"
+ android:textStyle="bold|normal" />
+ </LinearLayout>
+ </LinearLayout>
<fragment
- android:id="@+id/map"
+ android:id="@+id/weather_map_fragment_map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_below="@+id/weather_map_country"
+ android:layout_below="@+id/weather_map_citycountry_container"
android:layout_above="@+id/weather_map_button_savelocation" />
import android.util.Log;
import android.view.View;
import android.widget.Button;
+import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.model.MarkerOptions;
import de.example.exampletdd.fragment.ErrorDialogFragment;
-import de.example.exampletdd.fragment.ProgressDialogFragment;
import de.example.exampletdd.gms.GPlayServicesErrorDialogFragment;
import de.example.exampletdd.model.DatabaseQueries;
import de.example.exampletdd.model.WeatherLocation;
private GoogleMap mMap;
// TODO: read and store from different threads? Hopefully always from UI thread.
private Marker mMarker;
+ private ProgressBar mActivityIndicator;
// Google Play Services Location
private GoogleApiClient mGoogleApiClient;
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
+ .enableAutoManage(this, this)
+ .useDefaultAccount()
.build();
// Google Play Services Map
final MapFragment mapFragment = (MapFragment) this.getFragmentManager()
- .findFragmentById(R.id.map);
+ .findFragmentById(R.id.weather_map_fragment_map);
this.mMap = mapFragment.getMap();
this.mMap.setMyLocationEnabled(false);
this.mMap.getUiSettings().setCompassEnabled(false);
this.mMap.setOnMapLongClickListener(new MapActivityOnMapLongClickListener(this));
+ this.mActivityIndicator = (ProgressBar) this.findViewById(R.id.weather_map_progress);
}
@Override
private static final String TAG = "GetAddressTask";
// Store the context passed to the AsyncTask when the system instantiates it.
private final Context localContext;
- // TODO: siempre tuve problemas usando fragmentos y recreando activities (rotar, volver a activity, etc, etc)
- private final DialogFragment newFragment;
private GetAddressTask(final Context context) {
- this.localContext = context;
- this.newFragment = ProgressDialogFragment.newInstance(
- R.string.progress_dialog_get_remote_data,
- this.localContext.getString(R.string.progress_dialog_generic_message));
+ this.localContext = context;
}
@Override
protected void onPreExecute() {
// TODO: The same with Overview and Current? I guess so...
- final FragmentActivity activity = (FragmentActivity) this.localContext;
- this.newFragment.show(activity.getSupportFragmentManager(), "progressDialog");
+ // Show the activity indicator
+ final MapActivity activity = (MapActivity) this.localContext;
+ activity.mActivityIndicator.setVisibility(View.VISIBLE);
}
@Override
@Override
protected void onPostExecute(final WeatherLocation weatherLocation) {
- this.newFragment.dismiss();
+ final MapActivity activity = (MapActivity) this.localContext;
+ activity.mActivityIndicator.setVisibility(View.GONE);
// TODO: Is AsyncTask calling this method even when RunTimeException in doInBackground method?
// I hope so, otherwise I must catch(Throwable) in doInBackground method :(
if (weatherLocation == null) {
- final FragmentActivity activity = (FragmentActivity) this.localContext;
// TODO: if user changed activity, where is this going to appear?
final DialogFragment newFragment = ErrorDialogFragment.newInstance(R.string.error_dialog_location_error);
newFragment.show(activity.getSupportFragmentManager(), "errorDialog");
return;
}
- final MapActivity activity = (MapActivity) this.localContext;
activity.updateUI(weatherLocation);
}
// Disconnecting the client invalidates it.
// After disconnect() is called, the client is considered "dead".
+ mGoogleApiClient.unregisterConnectionCallbacks(this);
+ mGoogleApiClient.unregisterConnectionFailedListener(this);
mGoogleApiClient.disconnect();
super.onStop();
Log.d(TAG, "Received an unknown activity request code onActivityResult. Request code: " + requestCode);
break;
}
+
+ // TODO: documentation says I must call its parent's onActivityResult
+ // see: https://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.Builder.html#enableAutoManage(android.support.v4.app.FragmentActivity, com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener)
+ super.onActivityResult(requestCode, resultCode, intent);
}
private void showErrorDialog(final int errorCode) {