Android Open Source - AerisAndroidLibrary Aeris Notification






From Project

Back to project page AerisAndroidLibrary.

License

The source code is released under:

Apache License

If you think the Android project AerisAndroidLibrary listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.demoaerisproject;
//from   ww  w.  jav  a 2  s  .  c om
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;

import com.hamweather.aeris.model.ForecastPeriod;
import com.hamweather.aeris.model.Observation;
import com.hamweather.aeris.response.ForecastsResponse;
import com.hamweather.aeris.response.ObservationResponse;
import com.hamweather.aeris.util.FileUtil;
import com.hamweather.aeris.util.WeatherUtil;

public class AerisNotification {
  private static final int WEATHER_NTF = 100;
  private static NotificationCompat.Builder builder = null;
  private static RemoteViews remoteViews;

  /**
   * Sets the notification for the observation
   * 
   * @param working
   *            true if the progress should show, false otherwise
   * @param title
   *            title to display on the notification
   * @param message
   *            message to display on the notification
   * @param ticker
   *            ticker message to display for the notification
   */
  public static void setCustomNotification(Context context,
      ObservationResponse obResponse, ForecastsResponse fResponse) {

    Intent intent = new Intent(context, DrawerActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    PendingIntent pIntent = PendingIntent
        .getActivity(context, 0, intent, 0);

    if (builder == null) {
      builder = new NotificationCompat.Builder(context)
          // Set Ticker Message
          .setSmallIcon(R.drawable.ic_stat_action_about)
          .setContentIntent(pIntent).setOngoing(true)
          .setPriority(NotificationCompat.PRIORITY_HIGH)
          .setAutoCancel(false);

    }

    if (remoteViews == null) {
      remoteViews = new RemoteViews(context.getPackageName(),
          R.layout.ntf_observation);
      builder.setContent(remoteViews);
    }
    Observation ob = obResponse.getObservation();
    remoteViews.setImageViewResource(R.id.ivNtfIcon,
        FileUtil.getDrawableByName(ob.icon, context));

    remoteViews.setTextViewText(R.id.tvNtfDesc, ob.weather);
    remoteViews.setTextViewText(R.id.tvNtfTemp,
        WeatherUtil.appendDegree(ob.tempF));

    ForecastPeriod period = fResponse.getPeriod(0);
    // reverses orday if isday is not true.
    if (period.isDay) {
      remoteViews.setTextViewText(R.id.tvNtfHigh,
          WeatherUtil.appendDegree(fResponse.getPeriod(0).maxTempF));
      remoteViews.setTextViewText(R.id.tvNtfLow,
          WeatherUtil.appendDegree(fResponse.getPeriod(1).minTempF));

    } else {
      remoteViews.setTextViewText(R.id.tvNtfHigh,
          WeatherUtil.appendDegree(fResponse.getPeriod(1).maxTempF));
      remoteViews.setTextViewText(R.id.tvNtfLow,
          WeatherUtil.appendDegree(fResponse.getPeriod(2).minTempF));
    }

    // Create Notification Manager
    NotificationManager notificationmanager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
    // Build Notification with Notification Manager

    notificationmanager.notify(WEATHER_NTF, builder.build());
  }

  public static void cancelNotification(Context context) {
    // Create Notification Manager
    NotificationManager notificationmanager = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
    // Build Notification with Notification Manager
    notificationmanager.cancel(WEATHER_NTF);
    remoteViews = null;
    builder = null;
  }
}




Java Source Code List

aeris.AerisUnusedStub.java
com.example.customendpoint.CustomEndpointAdapter.java
com.example.customendpoint.CustomMoonModel.java
com.example.customendpoint.CustomSunModel.java
com.example.customendpoint.CustomSunmoonFragment.java
com.example.customendpoint.CustomSunmoonHolder.java
com.example.customendpoint.CustomSunmoonModel.java
com.example.customendpoint.CustomSunmoonResponse.java
com.example.db.MyLocLoader.java
com.example.db.MyPlace.java
com.example.db.MyPlacesDb.java
com.example.db.MyPlacesSubject.java
com.example.db.SimpleCursorLoader.java
com.example.demoaerisproject.AerisDialog.java
com.example.demoaerisproject.AerisNotification.java
com.example.demoaerisproject.BaseApplication.java
com.example.demoaerisproject.DrawerActivity.java
com.example.demoaerisproject.LocationSearchActivity.java
com.example.demoaerisproject.MyLocsActivity.java
com.example.demoaerisproject.SettingsActivity.java
com.example.edithelp.EditTextEnterListener.java
com.example.edithelp.EnterPressedDelegate.java
com.example.fragment.AerisFragment.java
com.example.fragment.AerisPrefFragment.java
com.example.fragment.ExtForecastFragment.java
com.example.fragment.HeadlessFragment.java
com.example.fragment.MapFragment.java
com.example.fragment.NearbyObsFragment.java
com.example.fragment.ObservationFragment.java
com.example.fragment.OverviewFragment.java
com.example.fragment.RecentObsFragment.java
com.example.fragment.RefreshInterface.java
com.example.fragment.SplashFragment.java
com.example.fragment.WeekendFragment.java
com.example.listview.AdapterHolder.java
com.example.listview.DayNightPeriod.java
com.example.listview.ForecastAdapter.java
com.example.listview.ForecastItemHolder.java
com.example.listview.IndexMonitorAdapter.java
com.example.listview.ListAdapter.java
com.example.listview.ObservationAdapter.java
com.example.listview.ObservationItemHolder.java
com.example.listview.ObservationPeriodAdapter.java
com.example.listview.PlacesAdapter.java
com.example.listview.PlacesItemHolder.java
com.example.listview.RecentObsHolder.java
com.example.listview.WeekendAdapter.java
com.example.listview.WeekendItemHolder.java
com.example.menudrawer.HomeFragment.java
com.example.menudrawer.NavDrawerItem.java
com.example.menudrawer.NavDrawerListAdapter.java
com.example.preference.PrefManager.java
com.example.service.NotificationService.java
com.example.service.ScreenOnReceiver.java
com.example.service.ScreenOnService.java
com.example.util.FormatUtil.java
com.example.view.DayNightView.java
com.example.view.SmallForecastView.java
com.example.view.TemperatureInfoData.java
com.example.view.TemperatureWindowAdapter.java
com.example.view.TwoPartView.java