Back to project page gatoloco.
The source code is released under:
GNU General Public License
If you think the Android project gatoloco listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.grumpycat; /* www . ja v a 2 s. c o m*/ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import com.grumpycat.utils.FileUtils; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.ResolveInfo; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.os.Parcelable; import android.util.Log; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; public class SaveActivity extends Activity { final Context context = this; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_save); ImageView imgCenter = (ImageView) findViewById(R.id.imgCenter); BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options(); bmpFactoryOptions.inSampleSize = 8; Bitmap bmp = BitmapFactory.decodeFile(Config.OUTPUT_FILENAME, bmpFactoryOptions); imgCenter.setImageBitmap(bmp); /****************************** Guardar Imagen *************************/ ImageButton btnSave = (ImageButton) findViewById(R.id.btnSave); btnSave.setOnClickListener(new OnClickListener() { public void onClick(View v) { try { // File inputFile = new File(Config.OUTPUT_FILENAME); // File outputFile = new File(String.format( // Config.OUTPUT_FILENAME_GALLERY, // System.currentTimeMillis())); // InputStream in = new FileInputStream(inputFile); // OutputStream out = new FileOutputStream(outputFile); // byte[] buffer = new byte[1024]; // int read; // while ((read = in.read(buffer)) != -1) { // out.write(buffer, 0, read); // } // in.close(); // in = null; // out.flush(); // out.close(); // out = null; FileUtils.copyFile(Config.OUTPUT_FILENAME,Config.OUTPUT_FILENAME_GALLERY); // Dialogo final Dialog dialog = new Dialog(context, R.style.DialogTheme); dialog.setContentView(R.layout.dialog_save_save); dialog.setTitle("Congratulations!"); ImageButton dialogButton = (ImageButton) dialog .findViewById(R.id.dialogButtonOK); dialogButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } catch (IOException e) { Log.e(Config.LOG_NAME, "Failed to copy asset file: " + Config.OUTPUT_FILENAME, e); } } }); /****************************** Compartir Imagen ***********************/ ImageButton btnShare = (ImageButton) findViewById(R.id.btnShare); btnShare.setOnClickListener(new OnClickListener() { public void onClick(View v) { final Dialog dialog = new Dialog(context, R.style.DialogTheme); dialog.setContentView(R.layout.dialog_save_share); ImageButton btnEmail = (ImageButton) dialog .findViewById(R.id.dialogButtonEmail); btnEmail.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { shareSpecificSocialNetwork("mail", Config.APP_NAME, "Powered by " + Config.APP_NAME, Config.OUTPUT_FILENAME); dialog.dismiss(); } }); ImageButton btnFacebook = (ImageButton) dialog .findViewById(R.id.dialogButtonFacebook); btnFacebook.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { shareSpecificSocialNetwork("com.facebook.katana", Config.APP_NAME, "Powered by " + Config.APP_NAME, Config.OUTPUT_FILENAME); dialog.dismiss(); } }); ImageButton btnTwitter = (ImageButton) dialog .findViewById(R.id.dialogButtonTwitter); btnTwitter.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { shareSpecificSocialNetwork("com.twitter.android", Config.APP_NAME, "Powered by " + Config.APP_NAME, Config.OUTPUT_FILENAME); dialog.dismiss(); } }); ImageButton btnInstagram = (ImageButton) dialog .findViewById(R.id.dialogButtonInstagram); btnInstagram.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // mms : com.android.mms shareSpecificSocialNetwork("instagram", Config.APP_NAME, "Powered by " + Config.APP_NAME, Config.OUTPUT_FILENAME); dialog.dismiss(); } }); ImageButton btnCancel = (ImageButton) dialog .findViewById(R.id.dialogButtonCancel); btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } }); /****************************** Mensaje de Texto ***********************/ /****************************** Back ***********************************/ ImageButton btnBack = (ImageButton) findViewById(R.id.btnBack); btnBack.setOnClickListener(new OnClickListener() { public void onClick(View v) { onBackPressed(); } }); } public void sendMail(String to, String subject, String message, String filename) { Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_EMAIL, new String[] { to }); email.putExtra(Intent.EXTRA_SUBJECT, subject); email.putExtra(Intent.EXTRA_TEXT, message); email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filename))); // need this to prompts email client only // email.setType("text/plain"); startActivity(Intent.createChooser(email, "Choose an Email client :")); } public void shareSocialNetwork(String title, String extraTitle, String filename) { Intent share = new Intent(Intent.ACTION_SEND); // email.putExtra(Intent.EXTRA_EMAIL, new String[] { to }); // email.putExtra(Intent.EXTRA_SUBJECT, ""); // email.putExtra(Intent.EXTRA_TEXT, ""); share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filename))); share.putExtra(Intent.EXTRA_TITLE, extraTitle); share.putExtra(Intent.EXTRA_SUBJECT, extraTitle); // need this to prompts email client only // share.setType("image/png"); startActivity(Intent.createChooser(share, title)); } // facebook = com.facebook.katana twitter = com.twitter.android void shareSpecificSocialNetwork(String nameApp, String title, String extraTitle, String filename) { try { List<Intent> targetedShareIntents = new ArrayList<Intent>(); Intent share = new Intent(android.content.Intent.ACTION_SEND); share.setType("image/jpeg"); List<ResolveInfo> resInfo = getPackageManager() .queryIntentActivities(share, 0); if (!resInfo.isEmpty()) { for (ResolveInfo info : resInfo) { Intent targetedShare = new Intent( android.content.Intent.ACTION_SEND); targetedShare.setType("image/jpeg"); // put here your mime // type Log.i(Config.LOG_NAME, info.activityInfo.packageName); if (info.activityInfo.packageName.toLowerCase().contains( nameApp) || info.activityInfo.name.toLowerCase().contains( nameApp)) { targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Sample Photo"); targetedShare.putExtra(Intent.EXTRA_TEXT, extraTitle); targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filename))); targetedShare.setPackage(info.activityInfo.packageName); targetedShareIntents.add(targetedShare); } } Intent chooserIntent = Intent.createChooser( targetedShareIntents.remove(0), title); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[] {})); startActivity(chooserIntent); } } catch (Exception e) { Log.v(Config.LOG_NAME, "Exception while sending image on" + nameApp + " " + e.getMessage()); } } }