<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_gravity="center_horizontal"
- android:orientation="horizontal"
- android:padding="5dp" >
+ android:layout_gravity="fill"
+ android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
+
+
<LinearLayout
- android:layout_width="0dp"
- android:layout_weight="1"
- android:layout_height="match_parent"
- android:gravity="center"
- android:layout_gravity="center"
- android:orientation="vertical" >
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:layout_weight="2"
+ android:gravity="center"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/weather_notification_city"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="Morata de Tajuña"
+ android:textAlignment="center"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="@color/weather_time_of_day_color_title"
+ android:textStyle="bold" />
<TextView
+ android:id="@+id/weather_notification_country"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="Spain"
+ android:textAlignment="center"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="@color/weather_time_of_day_color_title"
+ android:textStyle="normal" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:layout_weight="1"
+ android:gravity="center"
+ android:orientation="vertical" >
+
+ <TextView
android:id="@+id/weather_notification_temperature_max"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/weather_time_of_day_color_title"
android:textStyle="normal" />
-
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
- android:orientation="vertical"
- android:padding="5dp" >
+ android:orientation="vertical" >
<ImageView
android:id="@+id/weather_notification_image"
}
@Override
- public int onStartCommand(final Intent intent, final int flags, final int startId) {
- Log.i(TAG, "onStartCommand");
-
- return super.onStartCommand(intent, flags, startId);
- }
-
- @Override
protected void onHandleIntent(final Intent intent) {
-
- Log.i(TAG, "onHandleIntent");
-
final DatabaseQueries query = new DatabaseQueries(this.getApplicationContext());
final WeatherLocation weatherLocation = query.queryDataBase();
if (weatherLocation != null) {
- Log.i(TAG, "onHandleIntent, weatherLocation not null");
final ServiceParser weatherService = new ServiceParser(new JPOSWeatherParser());
final CustomHTTPClient HTTPClient = new CustomHTTPClient(
- AndroidHttpClient.newInstance("Android Weather Information Agent"));
+ AndroidHttpClient.newInstance("Android 4.3 WeatherInformation Agent"));
Current current = null;
try {
HTTPClient.close();
}
- this.showNotification(current);
+ if (current != null) {
+ this.showNotification(current, weatherLocation);
+ }
}
}
return current;
}
- private void showNotification(final Current current) {
+ private void showNotification(final Current current, final WeatherLocation weatherLocation) {
final SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(this.getApplicationContext());
tempFormatter.applyPattern("#####.#####");
- // 3. Prepare data for UI.
+ // 3. Prepare data for RemoteViews.
String tempMax = "";
if (current.getMain().getTemp_max() != null) {
double conversion = (Double) current.getMain().getTemp_max();
conversion = conversion - tempUnits;
tempMin = tempFormatter.format(conversion) + symbol;
}
- // TODO: static resource
- String description = "no description available";
- if (current.getWeather().size() > 0) {
- description = current.getWeather().get(0).getDescription();
- }
Bitmap picture;
if ((current.getWeather().size() > 0)
&& (current.getWeather().get(0).getIcon() != null)
picture = BitmapFactory.decodeResource(this.getResources(),
R.drawable.weather_severe_alert);
}
+ final String city = weatherLocation.getCity();
+ final String country = weatherLocation.getCountry();
+ // 4. Insert data in RemoteViews.
final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.notification);
remoteView.setImageViewBitmap(R.id.weather_notification_image, picture);
remoteView.setTextViewText(R.id.weather_notification_temperature_max, tempMax);
remoteView.setTextViewText(R.id.weather_notification_temperature_min, tempMin);
+ remoteView.setTextViewText(R.id.weather_notification_city, city);
+ remoteView.setTextViewText(R.id.weather_notification_country, country);
+ // 5. Activity launcher.
final Intent resultIntent = new Intent(this.getApplicationContext(), WeatherTabsActivity.class);
// The PendingIntent to launch our activity if the user selects this notification
// final PendingIntent contentIntent = PendingIntent.getActivity(
NotificationManagerCompat.from(this.getApplicationContext());
+ // 6. Create notification.
final NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this.getApplicationContext())
.setContent(remoteView)