From 5d8faed24eb6c22845c371fbd1b67a9021b883dc Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Fri, 26 Sep 2014 04:39:00 +0200 Subject: [PATCH] WeatherInformation: widget does not spawn Server --- Android/WeatherInformation/AndroidManifest.xml | 24 +-- .../WeatherInformation/res/layout/appwidget.xml | 1 + .../widget/WeatherInformationWidgetProvider.java | 202 ++++++++++++++++++++- 3 files changed, 214 insertions(+), 13 deletions(-) diff --git a/Android/WeatherInformation/AndroidManifest.xml b/Android/WeatherInformation/AndroidManifest.xml index e5d1bbf..8cfc5c5 100644 --- a/Android/WeatherInformation/AndroidManifest.xml +++ b/Android/WeatherInformation/AndroidManifest.xml @@ -34,17 +34,15 @@ - - @@ -54,8 +52,7 @@ - @@ -63,8 +60,7 @@ - @@ -72,8 +68,7 @@ - @@ -102,11 +97,16 @@ android:resource="@xml/appwidget_provider" /> - + + + + 0) + && (current.getWeather().get(0).getIcon() != null) + && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) { + final String icon = current.getWeather().get(0).getIcon(); + picture = BitmapFactory.decodeResource(this.getResources(), IconsList.getIcon(icon) + .getResourceDrawable()); + } else { + 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.appwidget); + remoteView.setImageViewBitmap(R.id.weather_appwidget_image, picture); + remoteView.setTextViewText(R.id.weather_appwidget_temperature_max, tempMax); + remoteView.setTextViewText(R.id.weather_appwidget_temperature_min, tempMin); + remoteView.setTextViewText(R.id.weather_appwidget_city, city); + remoteView.setTextViewText(R.id.weather_appwidget_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( +// this.getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); + // The stack builder object will contain an artificial back stack for the started Activity. + // This ensures that navigating backward from the Activity leads out of + // your application to the Home screen. + final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); + // Adds the back stack for the Intent (but not the Intent itself) + stackBuilder.addParentStack(WeatherTabsActivity.class); + // Adds the Intent that starts the Activity to the top of the stack + stackBuilder.addNextIntent(resultIntent); + final PendingIntent resultPendingIntent = + stackBuilder.getPendingIntent( + 0, + PendingIntent.FLAG_UPDATE_CURRENT + ); + remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent); + + + // Push update for this widget to the home screen + final AppWidgetManager manager = AppWidgetManager.getInstance(this); + manager.updateAppWidget(appWidgetId, remoteView); + + Log.i("WordWidget.UpdateService", "widget updated"); + } + } } -- 2.1.4