From: gu.martinm@gmail.com Date: Tue, 23 Sep 2014 18:15:53 +0000 (+0200) Subject: WeatherInformation: custom notification city/country X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=b9af8e78e07461fde505ec153e9850076ce37870;p=JavaForFun WeatherInformation: custom notification city/country --- 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)