/* 
 * 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.
 */
/** 
	 * Pegar.java
	 * Autor: Alberto Población Navarro
	 * Añadido al proyecto en la version v0.2.2
	 * Añadido a:
	 		* Proyecto original: http://code.google.com/p/android-vnc-viewer/
	 		* Release: 39
	 */
package android.androidVNC;

import java.io.IOException;

import android.app.AlertDialog;
import android.content.Context;
import android.text.ClipboardManager;
import android.view.KeyEvent;

public class Pegar {
	/**
	 * Funcion que actualiza el clipboard remoto con la información del portapapeles local
	 * @param context Contexto de ejecución del programa
	 * @param vncCanvas Lienzo que maneja los eventos de teclado
	 */
	static public void pegar(Context context, VncCanvas vncCanvas){
		//Obtneemos el servicio de clipboard
		ClipboardManager portapapeles = (ClipboardManager)context.getSystemService("clipboard");
		try {
			//Mandamos al servidor la información del portapapeles
			vncCanvas.rfb.writeClientCutText(portapapeles.getText().toString());
		} catch (IOException e) {
			//En caso de error mostramos cuadro de diálogo con la causa 
			new AlertDialog.Builder(context)
	          .setTitle(context.getString(R.string.no_paste))
	          .setMessage(context.getString(R.string.cause)+": "+e.toString())
	          .setIcon(android.R.drawable.ic_dialog_alert)
	          .setPositiveButton(android.R.string.ok, null)
	          .show();
			
		}
		//Mandamos el Control+V al remoto para que lo pueda pegar automaticamente
		vncCanvas.processLocalKeyEvent(KeyEvent.KEYCODE_V,	new KeyEvent(0,0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_V, 0, KeyEvent.META_SYM_ON));
		//Mostramos en la barra de estado una notificación
		Notificacion.Instancia(context).notificar(context.getString(R.string.paste),context.getString(R.string.clipboard_update));
	}

}
