From b9af8e78e07461fde505ec153e9850076ce37870 Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Tue, 23 Sep 2014 20:15:53 +0200 Subject: [PATCH] WeatherInformation: custom notification city/country --- .../WeatherInformation/res/layout/notification.xml | 55 +++++++++++++++++----- .../exampletdd/WeatherInformationBatch.java | 33 +++++-------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/Android/WeatherInformation/res/layout/notification.xml b/Android/WeatherInformation/res/layout/notification.xml index ce08934..b471e61 100644 --- a/Android/WeatherInformation/res/layout/notification.xml +++ b/Android/WeatherInformation/res/layout/notification.xml @@ -1,11 +1,9 @@ + android:layout_gravity="fill" + android:orientation="horizontal" > + + + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_gravity="center" + android:layout_weight="2" + android:gravity="center" + android:orientation="vertical" > + + + + + + + - + android:orientation="vertical" > 0) { - description = current.getWeather().get(0).getDescription(); - } Bitmap picture; if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null) @@ -162,12 +148,18 @@ public class WeatherInformationBatch extends IntentService { 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( @@ -190,6 +182,7 @@ public class WeatherInformationBatch extends IntentService { NotificationManagerCompat.from(this.getApplicationContext()); + // 6. Create notification. final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this.getApplicationContext()) .setContent(remoteView) -- 2.1.4