android-ibc-forum

Unnamed repository; edit this file 'description' to name the repository.
git clone http://git.code.weiherhei.de/android-ibc-forum.git
Log | Files | Refs

IBCApplication.java (3363B)


      1 /**
      2  * 
      3  */
      4 package de.mtbnews.android;
      5 
      6 import java.lang.ref.SoftReference;
      7 import java.util.List;
      8 
      9 import org.mcsoxford.rss.RSSFeed;
     10 
     11 import android.app.Application;
     12 import android.content.Intent;
     13 import android.content.SharedPreferences;
     14 import android.preference.PreferenceManager;
     15 import android.util.Log;
     16 import de.mtbnews.android.service.SubscriptionService;
     17 import de.mtbnews.android.tapatalk.TapatalkClient;
     18 import de.mtbnews.android.tapatalk.wrapper.Forum;
     19 import de.mtbnews.android.util.IBC;
     20 
     21 /**
     22  * IBC-Application. Diese Klasse dient als anwendungsweite (und damit
     23  * Activity-übergreifende) Ablage für Informationen.
     24  * 
     25  * @author dankert
     26  * 
     27  */
     28 public class IBCApplication extends Application
     29 {
     30 	/**
     31 	 * Speichert eine Referenz auf den Tapatalk-Client. Dieser Client kann vom
     32 	 * GC jederzeit entfernt werden, wenn der Speicherverbrauch zu hoch ist.
     33 	 */
     34 	private SoftReference<TapatalkClient> tapatalkClientRef = new SoftReference<TapatalkClient>(null);
     35 
     36 	/**
     37 	 * Speichert eine Referenz auf den RSSFeed. Dieser Feed kann vom GC
     38 	 * jederzeit entfernt werden, wenn der Speicherverbrauch zu hoch ist.
     39 	 */
     40 	private SoftReference<RSSFeed> newsFeedRef = new SoftReference<RSSFeed>(null);
     41 	/**
     42 	 * Speichert eine Referenz auf die Forum-Liste. Diese Liste kann vom GC
     43 	 * jederzeit entfernt werden, wenn der Speicherverbrauch zu hoch ist.
     44 	 */
     45 	private SoftReference<List<Forum>> listForumRef = new SoftReference<List<Forum>>(null);;
     46 
     47 	public SharedPreferences prefs;
     48 
     49 	public int themeResId;
     50 
     51 	/**
     52 	 * {@inheritDoc}
     53 	 * 
     54 	 * @see android.app.Application#onCreate()
     55 	 */
     56 	@Override
     57 	public void onCreate()
     58 	{
     59 		Log.d(IBC.TAG, "starting main application");
     60 		prefs = PreferenceManager.getDefaultSharedPreferences(this);
     61 
     62 		themeResId = (prefs.getBoolean("ibc_theme", true)) ? R.style.IBC : R.style.Default;
     63 
     64 		if (prefs.getBoolean("autostart_subscription_service", false))
     65 		{
     66 			startService(new Intent(getApplicationContext(), SubscriptionService.class));
     67 		}
     68 
     69 		super.onCreate();
     70 	}
     71 
     72 	/**
     73 	 * {@inheritDoc}
     74 	 * 
     75 	 * @see android.app.Application#onLowMemory()
     76 	 */
     77 	@Override
     78 	public void onLowMemory()
     79 	{
     80 		Log.d(IBC.TAG, "Low memory detected...");
     81 		super.onLowMemory();
     82 	}
     83 
     84 	/**
     85 	 * {@inheritDoc}
     86 	 * 
     87 	 * @see android.app.Application#onTerminate()
     88 	 */
     89 	@Override
     90 	public void onTerminate()
     91 	{
     92 		Log.d(IBC.TAG, "terminating application");
     93 		super.onTerminate();
     94 	}
     95 
     96 	/**
     97 	 * Liefert den Tapatalk-Client. Der Client wird zwar gecacht, kann jedoch,
     98 	 * falls der bisherige durch den GC weggeräumt wurde, auch ein neuer Client
     99 	 * ohne bestehendes Login sein!
    100 	 * 
    101 	 * @return
    102 	 */
    103 	public TapatalkClient getTapatalkClient()
    104 	{
    105 		TapatalkClient client = tapatalkClientRef.get();
    106 		if (client != null)
    107 		{
    108 			return client;
    109 		}
    110 		else
    111 		{
    112 			Log.d(IBC.TAG, "Creating a new tapatalk client");
    113 
    114 			client = new TapatalkClient(IBC.IBC_FORUM_CONNECTOR_URL);
    115 			client.setUserAgent("Mozilla/5.0 (compatible; Android)");
    116 			tapatalkClientRef = new SoftReference<TapatalkClient>(client);
    117 			return client;
    118 		}
    119 	}
    120 
    121 	public RSSFeed getNewsFeed()
    122 	{
    123 		return newsFeedRef.get();
    124 	}
    125 
    126 	public void setNewsFeed(RSSFeed feed)
    127 	{
    128 		newsFeedRef = new SoftReference<RSSFeed>(feed);
    129 	}
    130 
    131 	public List<Forum> getForumList()
    132 	{
    133 		return listForumRef.get();
    134 	}
    135 
    136 	public void setForumList(List<Forum> feed)
    137 	{
    138 		listForumRef = new SoftReference<List<Forum>>(feed);
    139 	}
    140 }