
it.tidalwave.bluebill.mobile.android.news.AndroidNewsService Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - Android - open source birding
* Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* WWW: http://bluebill.tidalwave.it/mobile
* SCM: https://kenai.com/hg/bluebill~android-src
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.news;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.android.util.Analytics;
import it.tidalwave.bluebill.mobile.network.DefaultNetworkingPreferences;
import it.tidalwave.bluebill.mobile.news.DefaultNewsService;
import it.tidalwave.netbeans.util.Locator;
import java.io.IOException;
import java.net.URL;
import javax.annotation.Nonnull;
import org.openide.util.lookup.ServiceProvider;
import static org.openide.util.NbBundle.*;
/***********************************************************************************************************************
*
* @stereotype Service
*
* @author Fabrizio Giudici
* @version $Id$
*
**********************************************************************************************************************/
@ServiceProvider(service=AndroidNewsService.class, supersedes={"it.tidalwave.bluebill.mobile.news.DefaultNewsService"})
public class AndroidNewsService extends DefaultNewsService
{
private static final Class _ = DefaultNewsService.class;
public static final int NEWS_NOTIFICATION_ID = 999;
@Nonnull
private final SharedPreferences sharedPreferences = Locator.find(SharedPreferences.class);
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
private final OnSharedPreferenceChangeListener preferencesListener = new OnSharedPreferenceChangeListener()
{
public void onSharedPreferenceChanged (final @Nonnull SharedPreferences sharedPreferences,
final @Nonnull String preferenceName)
{
if (DefaultNetworkingPreferences.PREF_NETWORK_CONNECTION_ALLOWED.equals(preferenceName))
{
start();
}
}
};
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public AndroidNewsService()
throws IOException
{
sharedPreferences.registerOnSharedPreferenceChangeListener(preferencesListener);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override
protected void postUnreadNewsNotification()
{
final String title = getMessage(_, "unreadNewsTitle");
final String message = getMessage(_, "unreadNewsMessage");
final Context context = Locator.find(Context.class);
final NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.bluebill_notification, title, System.currentTimeMillis());
final Intent notificationIntent = new Intent(context, NewsActivity.class);
final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, contentIntent);
notificationManager.notify(NEWS_NOTIFICATION_ID, notification);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull @Override
protected URL createUrl (final String string)
throws IOException
{
return Analytics.createURL(string);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy