package com.upc.pbe.upcnews;

import android.app.Application;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;

//Instanciacio de la nostra aplicacio
public class UpcApp extends Application implements
		OnSharedPreferenceChangeListener {

	final static String TAG = "Aplicacio";
	private SharedPreferences prefs; // Conjunt de preferencies de l'aplicacio
	private String url = null;
	private final static String localPath = Environment.getExternalStorageDirectory().getPath() + "/UPC NEWS/";
	private HLS h;
	private int quality;
	
	public int getQuality(){
		quality = (int) Integer.parseInt(prefs.getString("selector", "0"));
		return quality;
	}

	public String getLocalPath() {
		return localPath;
	}

	public HLS getHLS() {
		return h;
	}

	public void setHLS(HLS h) {
		this.h = h;
	}

	public String getUrl() {
		url = "http://"
				+ prefs.getString("server", getString(R.string.defaultURL));
		return url;
	}

	public void onCreate() {
		super.onCreate();
		// Prefs
		prefs = PreferenceManager.getDefaultSharedPreferences(this);
		prefs.registerOnSharedPreferenceChangeListener(this);
		this.getUrl();
		Log.d(TAG, "onCreated");
	}

	public SharedPreferences getPrefs() {
		return prefs;
	}

	public void onSharedPreferenceChanged(SharedPreferences arg0, String key) {
		Log.d(TAG, "onSharedPreferenceChanged for key: " + key);
	}
}