/* Tibisay Movil Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz (jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e Investigacion en Tecnologias Libres - CENDITEL. La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o modificar este programa, reconociendo el derecho que la humanidad posee al libre acceso al conocimiento, bajo los términos de la licencia de software GPL versión 2.0 de la Free Software Foundation. Este programa se distribuye con la esperanza de que sea util, pero SIN NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o ADECUACION A UN PROPOSITO PARTICULAR. Para mayor información sobre los términos de la licencia ver el archivo llamado "gpl-2.0.txt" en ingles. */ package ve.gob.cenditel.tibisaymovil; import java.io.File; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.webkit.MimeTypeMap; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class DecryptionResultActivity extends Activity{ private String fileToDecrypt; private String decryptedFile; private String recipient; private String pathFileSigned; private LinearLayout button_share; private LinearLayout button_finish; @Override protected void onCreate(Bundle savedInstanceState) { //Capturando archivo original fileToDecrypt = getIntent().getExtras().getString("fileToDecrypt"); //Capturando archivo cifrado decryptedFile = getIntent().getExtras().getString("decryptedFile"); //Capturando destinatario //recipient = getIntent().getExtras().getString("recipient"); //Estilando la barra de titulo final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.activity_decryption_result); //Estilando Barra de titulo if(customTitleSupported) getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); TextView archivo_original_a_descifrar = (TextView) this.findViewById(R.id.archivo_original_pdf); TextView archivo_descifrado = (TextView) this.findViewById(R.id.archivo_descifrado); //TextView destinatario = (TextView) this.findViewById(R.id.destinatario); archivo_original_a_descifrar.setText(fileToDecrypt); archivo_descifrado.setText(decryptedFile); LinearLayout layoutDecryptedFileAndArror = (LinearLayout) this.findViewById(R.id.layout_decrypted_file_and_arrow); OnClickListener decryptedFileListener = new OnClickListener() { public void onClick(View v) { // do something when the button is clicked //Toast.makeText(getApplicationContext(), "**CLICK SOBRE EL TEXTVIEW***", Toast.LENGTH_LONG).show(); openIt(decryptedFile, getMimeType(decryptedFile)); } }; layoutDecryptedFileAndArror.setOnClickListener(decryptedFileListener); button_share = (LinearLayout) this.findViewById(R.id.button_remove_certificate_zone); button_finish = (LinearLayout) this.findViewById(R.id.button_add_certificate_zone); button_finish.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent oIntent = new Intent(DecryptionResultActivity.this, TibisayMovilActivity.class); oIntent.setAction(Intent.ACTION_VIEW); oIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(oIntent); finish(); } }); button_share.setOnClickListener(new OnClickListener() { public void onClick(View v) { shareIt(); } }); } // funcion para compartir el documento private void shareIt() { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); File file = new File(decryptedFile); Uri uri = Uri.fromFile(file); Log.i("DEBUG", file.getPath()); //Log.d("******", getMimeType(file.getPath())); //shareIntent.setDataAndType(uri, getMimeType(file.getPath())); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("application/*"); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_it_using))); } // funcion para obtener el tipo mime de un archivo public static String getMimeType(String url) { String extension = url.substring(url.lastIndexOf(".")); String mimeTypeMap = MimeTypeMap.getFileExtensionFromUrl(extension); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap); return mimeType; } // funcion para lanzar un intent que abra un archivo private void openIt(String decryptedFile, String mimeType) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_VIEW); File file = new File(decryptedFile); Uri uri = Uri.fromFile(file); Log.i("DEBUG", file.getPath()); shareIntent.setDataAndType(uri, mimeType); startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.open_it_using))); } /** * Crea un dialogo con el titulo y mensaje como argumentos y lo despliega * * @return void */ public void showDialog(String title, String msg) { // 1. Instantiate an AlertDialog.Builder with its constructor AlertDialog.Builder builder = new AlertDialog.Builder(DecryptionResultActivity.this); // 2. Chain together various setter methods to set the dialog characteristics builder.setMessage(msg) .setTitle(title); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User clicked OK button Toast.makeText(getApplicationContext(), "User clicked OK button", Toast.LENGTH_LONG).show(); } }); // 3. Get the AlertDialog from create() AlertDialog dialog = builder.create(); dialog.show(); } }