/* 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */
/** 
	 * mContentProvider.java
	 * Autor: Alberto Población Navarro
	 * Añadido al proyecto en la version v0.2.8
	 * Añadido a:
	 		* Proyecto original: http://code.google.com/p/android-vnc-viewer/
	 		* Release: 39
*/
package android.androidVNC;

import java.io.File;
import java.io.FileNotFoundException;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;

public class mContentProvider extends ContentProvider{

	/**
	 * Automaticamente se llama a esta funcion cuando se intenta abrir un archivo mediante 
	 * el "protocolo" content://.
	 * En nuestro caso siempre vamos a intentar abrir el mismo archivo por lo que los parametros
	 * pasados en la llamada no nos interesan.
	 *   
	 */
	@Override
	public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
		//URI uri_ = URI.create("file:///sdcard/androidVNC.html");
		File file;
		String sdcard_status = Environment.getExternalStorageState();
		//Comprobamos si hay un medio extraible y creamos el archivo en la tarjeta si es posible
        if(sdcard_status.equals(Environment.MEDIA_REMOVED)){
        	file = new File("/data/data/android.androidVNC/androidVNC.html");
        }else file = new File("/sdcard/androidVNC.html"); 
		ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);  
		return parcel;
			  
	} 
	@Override
	public int delete(Uri uri, String selection, String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String getType(Uri uri) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Uri insert(Uri uri, ContentValues values) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean onCreate() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int update(Uri uri, ContentValues values, String selection,
			String[] selectionArgs) {
		// TODO Auto-generated method stub
		return 0;
	}
	

}
