Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.user.aitzik4;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.content.ComponentName;
- import android.content.ContentResolver;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.SharedPreferences;
- import android.content.pm.PackageManager;
- import android.content.res.AssetManager;
- import android.content.res.Resources;
- import android.database.Cursor;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.graphics.Canvas;
- import android.graphics.Matrix;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.os.CancellationSignal;
- import android.os.Environment;
- import android.os.ParcelFileDescriptor;
- import android.os.Parcelable;
- import android.print.PageRange;
- import android.print.PrintAttributes;
- import android.print.PrintDocumentAdapter;
- import android.print.PrintDocumentInfo;
- import android.print.PrintManager;
- import android.provider.MediaStore;
- import android.support.v4.print.PrintHelper;
- import android.telephony.PhoneNumberUtils;
- import android.text.format.DateFormat;
- import android.util.Base64;
- import android.util.Log;
- import android.widget.Button;
- import android.view.View;
- import android.content.Intent;
- import android.net.Uri;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.ProgressBar;
- import android.widget.Toast;
- import java.io.BufferedReader;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Random;
- import java.util.Set;
- import java.util.concurrent.ExecutionException;
- import okhttp3.Call;
- import okhttp3.Callback;
- import okhttp3.FormBody;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- import static android.provider.MediaStore.ACTION_IMAGE_CAPTURE;
- public class MainActivity extends Activity {
- ImageView tv1;
- Button share;
- String lastStamp = null;
- String tempStamp = null;
- String printTime = null;
- String latestFrame;
- String [] getterarray;
- String [] whatsappArray;
- Uri [] emailArray;
- String filePath;
- String [] filePathArray;
- EditText mEdit;
- final int FIRST_PICTURE_TIME=120*1000;
- final int ADDITIONAL_PICTURE_TIME=50*1000;
- EditText mEdit2;
- String number;
- Boolean posting=false;
- ImageView imageView,logo,temp, imageview4, imageview3;
- String emailx;
- final String stampPath="/sdcard/Aitzik4",
- filesInQueue="/sdcard/Aitzik4",
- counterPath="/sdcard/Aitzik4";
- Bitmap merge;
- ProgressBar pb;
- String dummy1="/sdcard/Pictures/Frames/frame5.png",
- dummy2="/sdcard/DCIM/Camera/2018-05-21 23.26.54_0.jpg";
- Uri imageUri;
- String framepath=null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- latestFrame=getNewSaveDefaultArray();
- //latestFrame="sdcard/Pictures/Frames/frame1.png";
- temp = (ImageView) findViewById(R.id.imageView2);
- temp.setImageURI(Uri.parse(latestFrame));
- logo= (ImageView) findViewById(R.id.imageView);
- check_for_updates();
- AssetManager assetManager = getAssets();
- InputStream istr = null;
- try {
- istr = assetManager.open("logo_300x70.png");
- } catch (IOException e) {
- e.printStackTrace();
- }
- logo.setImageBitmap(BitmapFactory.decodeStream(istr));
- pb = (ProgressBar)findViewById(R.id.loading_progress_xml);
- pb.setVisibility(View.INVISIBLE);
- Button share=findViewById(R.id.share);
- Button frames=findViewById(R.id.frame);
- final Button email=findViewById(R.id.email);
- frames.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent i = new Intent(
- Intent.ACTION_PICK,
- android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
- startActivityForResult(i, 1);
- }
- });
- email.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // pb.setVisibility(View.VISIBLE);
- EditText et=(EditText)findViewById(R.id.editText2);
- emailx=et.getText().toString();
- AssetManager assetManager = getAssets();
- InputStream important = null;
- try {
- important = assetManager.open("important.png");
- } catch (IOException e) {
- e.printStackTrace();
- }
- String now = System.currentTimeMillis() + "".trim();
- String myFileName = now;
- String path = "/sdcard/Aitzik4/";
- Bitmap allthree=null;
- if(filePath != null){//one image
- allthree = overlay(BitmapFactory.decodeStream(important),filepathtobitmap(filePath),filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- emailArray=new Uri[1];
- emailArray[0]=bitmapToUriConverter(allthree);
- }else{//multipul
- emailArray=new Uri[filePathArray.length];
- for(int i = 0; i<filePathArray.length; i++){
- allthree = overlay(BitmapFactory.decodeStream(important),filepathtobitmap(filePathArray[i]),filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- emailArray[i]=bitmapToUriConverter(allthree);
- }
- }
- Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
- intent.putExtra(Intent.EXTRA_EMAIL, emailx);
- intent.putExtra(Intent.EXTRA_SUBJECT, "התמונות המגניבות שלכם");
- intent.putExtra(Intent.EXTRA_TEXT, "מקווים שנהנתם!");
- intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<>(Arrays.asList(emailArray)));
- intent.setType("image/png");
- intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
- startActivity(intent);
- //startActivity(Intent.createChooser(intent, "Choice App to send email:"));
- // Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",emailx, null));
- // emailIntent.putExtra(Intent.EXTRA_SUBJECT, "hello there");
- //emailIntent.setType("application/image");
- //emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
- /* ArrayList<Uri> imageUriArray = new ArrayList<Uri>();
- for(int i = 0; i<emailArray.length; i++) {
- imageUriArray.add(Uri.parse(Uri.decode(emailArray[i].trim())));
- //temp[i] = Uri.parse(Uri.decode(picture[i].trim()));
- //Log.d("DEBUG LMAO",temp[i]+"");
- Log.d("DEBUG LMAO",emailArray[i]+"");
- }*/
- // sendIntent.putExtra(Intent.EXTRA_STREAM, temp);
- // emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUriArray);
- // emailIntent.putExtra(Intent.EXTRA_STREAM, "file:///data/data/com.example.user.aitzik4/files/Image-79271305.jpeg");
- // startActivity(Intent.createChooser(emailIntent, "Send email..."));
- //merge=overlay(BitmapFactory.decodeStream(important),filepathtobitmap(filePath),filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- //alert(toRealPath(latestFrame));
- // String disposablef=latestFrame;
- // String disposablei=filePath;
- // merge=null;
- // imageView.setImageBitmap(BitmapFactory.decodeFile(filePath));
- // final String base65=BitmapToString(merge);
- /*
- AsyncTask.execute(new Runnable() {
- @Override
- public void run() {
- if(!posting) {
- posting=true;
- postf(emailx, "email");
- }
- }
- });
- */
- }
- });
- share.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- String now = System.currentTimeMillis() + "".trim();
- String myFileName = now;
- String path = "/sdcard/Aitzik4/";
- AssetManager assetManager = getAssets();
- InputStream important = null;
- try {
- important = assetManager.open("important.png");
- } catch (IOException e) {
- e.printStackTrace();
- }
- if(filePath != null) {
- Bitmap allthree = overlay(BitmapFactory.decodeStream(important), filepathtobitmap(filePath), filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- //stamp wasnt found
- //alert("There is no stamp");
- savePNG(allthree, path, myFileName);
- createHTML(path, myFileName);// if no file is found
- }else{
- Bitmap allthree = overlay(BitmapFactory.decodeStream(important), filepathtobitmap(filePathArray[0]), filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- //stamp wasnt found
- //alert("There is no stamp");
- savePNG(allthree, path, myFileName);
- createHTML(path, myFileName);// if no file is found
- for(int i = 1; i<filePathArray.length; i++){
- allthree = overlay(BitmapFactory.decodeStream(important), filepathtobitmap(filePathArray[i]), filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- savePNG(allthree, path, myFileName+i+"");
- addPictureToTheEndOfAnHtmlFile(myFileName, myFileName+i+"");
- }
- }
- Intent shareIntent = new Intent();
- shareIntent.setAction(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_TEXT,"file:///"+path+myFileName+".html");
- shareIntent.setType("text/plain");
- shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- shareIntent.setClassName("com.happy2print.premium", "com.dynamixsoftware.printhand.ui.phone.ActivityDetails");
- //startActivity(Intent.createChooser(shareIntent, "Share images..."));
- startActivity(shareIntent);
- /*
- // Bitmap allthree=overlay(filepathtobitmap(filePath),filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- //readStampFileOrCreateNewIfNotExists();
- // String myFileName = lastStamp;
- // String path = "/sdcard/Aitzik4/";
- // savePNG(allthree,path,myFileName);
- if(IsPrintTime()){
- //stamp is found
- lastStamp = readStampFileOrCreateNewIfNotExists();
- tempStamp = readTempStampFileOrCreateNewIfNotExists();
- String myFileName = lastStamp;
- String path = "/sdcard/Aitzik4/";
- //alert("#aa12eas: stampNowTimeDifference is "+stampNowTimeDifference());
- if(stampNowTimeDifference()>calculateLastQueue()) {
- //enough time has passed and printer is not busy
- //alert("Printer should not be busy right now");
- //alert("1534013579: "+stampNowTimeDifference() + " difference "+ calculateLastQueue());
- deletePrintTime();
- printTime = readPrintTimeFileOrCreateNewIfNotExists();
- addOnetoCounter();
- deleteStamp();
- makeTempStampNotTemp();
- saveToLastQueue();
- deleteCounter();
- myFileName = now;
- //saveDataToStampFile(myFileName);
- //lastStamp = myFileName;
- lastStamp = tempStamp;
- savePNG(allthree,path,myFileName);
- addPictureToTheEndOfAnHtmlFile(lastStamp,now);
- Intent shareIntent1 = new Intent();
- shareIntent1.setAction(Intent.ACTION_SEND);
- shareIntent1.putExtra(Intent.EXTRA_TEXT,"file:///"+"/sdcard/AItzik4/"+lastStamp+".html");
- shareIntent1.setType("text/plain");
- shareIntent1.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- startActivity(Intent.createChooser(shareIntent1, "Share images..."));
- }else{
- alert("המדפסת עסוקה, הקובץ נוסף לתור");
- if(!waitingForPrint()){
- //no files in queue for printing
- lastStamp = updateStamp();
- tempStamp = readTempStampFileOrCreateNewIfNotExists();
- //alert("This is the first file in queue");
- savePNG(allthree,path,tempStamp);
- createHTML(path,tempStamp);
- addOnetoCounter();
- }else{
- //alert("We have some files who are wating for be printed");
- String stamp = tempStamp;
- savePNG(allthree,path,now);
- myFileName = now;
- addPictureToTheEndOfAnHtmlFile(stamp,myFileName);
- try{
- addOnetoCounter();
- }catch (Exception e){
- alert("Error while trying to addOnetoCounter. error #1534033234");
- alert(e.getMessage());
- }
- }
- }
- }else{
- //stamp wasnt found
- //alert("There is no stamp");
- printTime = readPrintTimeFileOrCreateNewIfNotExists();
- lastStamp = readStampFileOrCreateNewIfNotExists();
- //alert("1534072710 lastStamp is:"+lastStamp);
- String myFileName = lastStamp;
- String path = "/sdcard/Aitzik4/";
- savePNG(allthree,path,myFileName);
- createHTML(path,myFileName);// if no file is found
- Intent shareIntent = new Intent();
- shareIntent.setAction(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_TEXT,"file:///"+path+myFileName+".html");
- shareIntent.setType("text/plain");
- shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- startActivity(Intent.createChooser(shareIntent, "Share images..."));
- }
- }
- */
- }
- });
- /*
- share.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- String now = System.currentTimeMillis() + "".trim();
- ;
- AssetManager assetManager = getAssets();
- InputStream important = null;
- try {
- important = assetManager.open("important.png");
- } catch (IOException e) {
- e.printStackTrace();
- }
- Bitmap allthree = overlay(BitmapFactory.decodeStream(important), filepathtobitmap(filePath), filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- //stamp wasnt found
- //alert("There is no stamp");
- String myFileName = now;
- String path = "/sdcard/Aitzik4/";
- savePNG(allthree,path,myFileName);
- createHTML(path,myFileName);// if no file is found
- Intent shareIntent = new Intent();
- shareIntent.setAction(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_TEXT,"file:///"+path+myFileName+".html");
- shareIntent.setType("text/plain");
- shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- startActivity(Intent.createChooser(shareIntent, "Share images..."));
- /*
- // Bitmap allthree=overlay(filepathtobitmap(filePath),filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- //readStampFileOrCreateNewIfNotExists();
- // String myFileName = lastStamp;
- // String path = "/sdcard/Aitzik4/";
- // savePNG(allthree,path,myFileName);
- if(IsPrintTime()){
- //stamp is found
- lastStamp = readStampFileOrCreateNewIfNotExists();
- tempStamp = readTempStampFileOrCreateNewIfNotExists();
- String myFileName = lastStamp;
- String path = "/sdcard/Aitzik4/";
- //alert("#aa12eas: stampNowTimeDifference is "+stampNowTimeDifference());
- if(stampNowTimeDifference()>calculateLastQueue()) {
- //enough time has passed and printer is not busy
- //alert("Printer should not be busy right now");
- //alert("1534013579: "+stampNowTimeDifference() + " difference "+ calculateLastQueue());
- deletePrintTime();
- printTime = readPrintTimeFileOrCreateNewIfNotExists();
- addOnetoCounter();
- deleteStamp();
- makeTempStampNotTemp();
- saveToLastQueue();
- deleteCounter();
- myFileName = now;
- //saveDataToStampFile(myFileName);
- //lastStamp = myFileName;
- lastStamp = tempStamp;
- savePNG(allthree,path,myFileName);
- addPictureToTheEndOfAnHtmlFile(lastStamp,now);
- Intent shareIntent1 = new Intent();
- shareIntent1.setAction(Intent.ACTION_SEND);
- shareIntent1.putExtra(Intent.EXTRA_TEXT,"file:///"+"/sdcard/AItzik4/"+lastStamp+".html");
- shareIntent1.setType("text/plain");
- shareIntent1.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- startActivity(Intent.createChooser(shareIntent1, "Share images..."));
- }else{
- alert("המדפסת עסוקה, הקובץ נוסף לתור");
- if(!waitingForPrint()){
- //no files in queue for printing
- lastStamp = updateStamp();
- tempStamp = readTempStampFileOrCreateNewIfNotExists();
- //alert("This is the first file in queue");
- savePNG(allthree,path,tempStamp);
- createHTML(path,tempStamp);
- addOnetoCounter();
- }else{
- //alert("We have some files who are wating for be printed");
- String stamp = tempStamp;
- savePNG(allthree,path,now);
- myFileName = now;
- addPictureToTheEndOfAnHtmlFile(stamp,myFileName);
- try{
- addOnetoCounter();
- }catch (Exception e){
- alert("Error while trying to addOnetoCounter. error #1534033234");
- alert(e.getMessage());
- }
- }
- }
- }else{
- //stamp wasnt found
- //alert("There is no stamp");
- printTime = readPrintTimeFileOrCreateNewIfNotExists();
- lastStamp = readStampFileOrCreateNewIfNotExists();
- //alert("1534072710 lastStamp is:"+lastStamp);
- String myFileName = lastStamp;
- String path = "/sdcard/Aitzik4/";
- savePNG(allthree,path,myFileName);
- createHTML(path,myFileName);// if no file is found
- Intent shareIntent = new Intent();
- shareIntent.setAction(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_TEXT,"file:///"+path+myFileName+".html");
- shareIntent.setType("text/plain");
- shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- startActivity(Intent.createChooser(shareIntent, "Share images..."));
- }
- }
- *//*
- }
- });
- */
- final Button button = findViewById(R.id.whatsapp);
- button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- // pb.setVisibility(View.VISIBLE);
- mEdit = (EditText)findViewById(R.id.editText);
- number=mEdit.getText().toString();
- AssetManager assetManager = getAssets();
- InputStream important = null;
- try {
- important = assetManager.open("important.png");
- } catch (IOException e) {
- e.printStackTrace();
- }
- String now = System.currentTimeMillis() + "".trim();
- String myFileName = now;
- String path = "/sdcard/Aitzik4/";
- if(filePath != null) {
- Bitmap allthree = overlay(BitmapFactory.decodeStream(important), filepathtobitmap(filePath), filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- //stamp wasnt found
- //alert("There is no stamp");
- // convertFileToContentUri
- //savePNG(allthree, path, myFileName);
- //Log.d("DEBUG K", path+myFileName);
- //Uri myUri = Uri.fromFile(new File(path+myFileName+".png"));
- // Log.d("DEBUG K", myUri+"");
- whatsappArray=new String[1];
- whatsappArray[0]=bitmapToUriConverter(allthree)+"";
- }else{
- whatsappArray=new String[filePathArray.length];
- for(int i = 0; i<filePathArray.length; i++){
- Bitmap allthree = overlay(BitmapFactory.decodeStream(important), filepathtobitmap(filePathArray[i]), filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- whatsappArray[i]=bitmapToUriConverter(allthree)+"";
- }
- }
- // merge=overlay(BitmapFactory.decodeStream(important),filepathtobitmap(filePath),filepathtobitmap(toRealPath(getNewSaveDefaultArray())));
- AsyncTask.execute(new Runnable() {
- @Override
- public void run() {
- if(!posting) {
- //posting=true;
- openWhatsApp(number,whatsappArray);
- //postf(number, "number");
- }
- }
- });
- }
- });
- Intent intent = getIntent();
- String action = intent.getAction();
- String type = intent.getType();
- if ((Intent.ACTION_SEND.equals(action)||Intent.ACTION_SEND_MULTIPLE.equals(action)) && type != null) {
- if ("text/plain".equals(type)) {
- handleSendText(intent); // Handle text being sent
- } else if (type.startsWith("image/")) {
- handleSendImage(intent);
- // Handle single image being sent
- }
- } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
- if (type.startsWith("image/")) {
- // handleSendMultipleImages(intent); // Handle multiple images being sent
- }
- } else {
- // Handle other intents, such as being started from the home screen
- }
- }
- private void deleteCounter() {
- //("delete counter");
- File file=new File("/sdcard/Aitzik4/counter.txt");
- file.delete();
- }
- private void deleteStamp() {
- lastStamp = null;
- File file=new File("/sdcard/Aitzik4/stamp.txt");
- file.delete();
- }
- private void deletePrintTime() {
- printTime = null;
- File file=new File("/sdcard/Aitzik4/printTime.txt");
- file.delete();
- }
- private void deleteTempStamp() {
- lastStamp = null;
- File file=new File("/sdcard/Aitzik4/tempStamp.txt");
- file.delete();
- }
- private boolean IsStamp() {
- File dir = new File(stampPath+"/stamp.txt");
- if(dir.exists()) {
- return true;
- }
- return false;
- }
- private boolean IsPrintTime() {
- File dir = new File(stampPath+"/printTime.txt");
- if(dir.exists()) {
- return true;
- }
- return false;
- }
- void handleSendText(Intent intent) {
- String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
- if (sharedText != null) {
- // Update UI to reflect text being shared
- }
- }
- /*
- void handleSendImage(Intent intent) {
- imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
- if (imageUri != null) {
- filePath = null;
- if (imageUri != null && "content".equals(imageUri.getScheme())) {
- Cursor cursor = this.getContentResolver().query(imageUri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
- cursor.moveToFirst();
- filePath = cursor.getString(0);
- cursor.close();
- } else {
- filePath = imageUri.getPath();
- }
- //buildPrintImage();
- imageView = (ImageView) findViewById(R.id.imageView5);
- imageView.setImageBitmap(BitmapFactory.decodeFile(filePath));
- }
- }
- */
- void handleSendImage(Intent intent) {
- //printExtras(intent.getExtras());
- //alert(getExtraArray(intent.getExtras()));
- if(getExtraArray(intent.getExtras()).toLowerCase().contains("[")){
- /* Uri imageUriArray = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
- alert(imageUriArray.getClass().getName());
- */
- //alert("array");
- String tempArrString = getExtraArray(intent.getExtras()).substring(1,getExtraArray(intent.getExtras()).length() - 1);
- String[] pathArray = tempArrString.split(",");
- for(int i=0; i<pathArray.length; i++){
- pathArray[i]=pathArray[i].trim();
- }
- String msg = "";
- filePathArray = new String [pathArray.length];
- for(int i = 0; i<pathArray.length; i++){
- msg += pathArray[i]+"\n";
- //imageUri = Uri.parse(Uri.decode(pathArray[i].substring(7)));
- imageUri = Uri.parse(Uri.decode(pathArray[i]));
- Log.d("3",imageUri+"" +" to string");
- //alert(imageUri.getPath() +" get path");
- // alert(imageUri.getClass().getName() +" get type");
- if (imageUri != null) {
- filePath = null;
- if (imageUri != null && "content".equals(imageUri.getScheme())) {
- Cursor cursor = this.getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
- cursor.moveToFirst();
- filePath = cursor.getString(0);
- cursor.close();
- } else {
- filePath = imageUri.getPath();
- }
- // alert(imageUri.toString()+" ==> "+filePath);
- //buildPrintImage();
- imageView = (ImageView) findViewById(R.id.imageView5);
- imageView.setImageURI(Uri.parse(filePath));
- }
- filePathArray[i] = filePath;
- }
- filePath = null;
- //alert(msg);
- /*
- ArrayList<Uri> imgList = new ArrayList<Uri>();
- intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imgList);
- for (Uri object: imgList) {
- String filePath = imgList.getEncodedPath();
- alert(imgList.toString);
- imageUri = object;
- if (imageUri != null) {
- filePath = null;
- if (imageUri != null && "content".equals(imageUri.getScheme())) {
- Cursor cursor = this.getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
- cursor.moveToFirst();
- filePath = cursor.getString(0);
- cursor.close();
- } else {
- filePath = imageUri.getPath();
- }
- //buildPrintImage();
- imageView = (ImageView) findViewById(R.id.imageView5);
- imageView.setImageBitmap(BitmapFactory.decodeFile(filePath));
- }
- }
- */
- }else{
- //alert(Intent.EXTRA_STREAM);
- imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
- // alert(imageUri.getClass().getName());
- if (imageUri != null) {
- filePath = null;
- if (imageUri != null && "content".equals(imageUri.getScheme())) {
- Cursor cursor = this.getContentResolver().query(imageUri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
- cursor.moveToFirst();
- filePath = cursor.getString(0);
- cursor.close();
- } else {
- filePath = imageUri.getPath();
- }
- //alert(imageUri.toString()+" ==> "+filePath);
- //buildPrintImage();
- imageView = (ImageView) findViewById(R.id.imageView5);
- imageView.setImageBitmap(BitmapFactory.decodeFile(filePath));
- }
- }
- }
- public void printExtras(Bundle extras) {
- String msg="";
- for(String extraKey : extras.keySet()) {
- msg += "Extra: " + extraKey + ": " + extras.get(extraKey)+"\n";
- }
- alert(msg);
- }
- public String getExtraArray(Bundle extras) {
- String msg="";
- int counter = 0;
- for(String extraKey : extras.keySet()) {
- if(counter==0)
- msg = extras.get(extraKey)+"";
- counter++;
- }
- return msg;
- }
- public Bitmap overlay(Bitmap bmp1, Bitmap bmp2,Bitmap bm3) {// big picture frame
- Bitmap bmOverlay=null;
- //ssssssssssssss
- try {
- bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
- Canvas canvas = new Canvas(bmOverlay);
- canvas.drawBitmap(bmp1, new Matrix(), null);
- canvas.drawBitmap(bmp2, 2, 21, null); // the image
- canvas.drawBitmap(bm3, 0, 10, null); // the frame
- //bmOverlay = rotateImage(bmOverlay,180);
- return bmOverlay;
- }catch (Exception e){
- alert("לא בחרת מסגרת");
- }
- return bmOverlay;
- }
- public Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {// big picture frame
- Bitmap bmOverlay=null;
- try {
- bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
- Canvas canvas = new Canvas(bmOverlay);
- canvas.drawBitmap(bmp1, new Matrix(), null);
- canvas.drawBitmap(bmp2, 0, 0, null);
- return bmOverlay;
- }catch (Exception e){
- reset();
- }
- return bmOverlay;
- }
- public static String BitmapToString(Bitmap bitmap) {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
- byte[] b = baos.toByteArray();
- String temp = Base64.encodeToString(b, Base64.DEFAULT);
- return temp;
- } catch (NullPointerException e) {
- return null;
- } catch (OutOfMemoryError e) {
- return null;
- }
- }
- public void alert(String message){
- AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
- alertDialog.setTitle("Alert");
- alertDialog.setMessage(message+"");
- alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- dialog.dismiss();
- }
- });
- alertDialog.show();
- }
- public Uri bitmapToUriConverter(Bitmap mBitmap) {
- Uri uri = null;
- try {
- final BitmapFactory.Options options = new BitmapFactory.Options();
- // Calculate inSampleSize
- options.inSampleSize =1;
- // Decode bitmap with inSampleSize set
- options.inJustDecodeBounds = false;
- Bitmap newBitmap = Bitmap.createScaledBitmap(mBitmap, mBitmap.getWidth(), mBitmap.getHeight(),
- true);
- File file = new File(MainActivity.this
- .getFilesDir(), "Image"
- + new Random().nextInt() + ".jpeg");
- FileOutputStream out = MainActivity.this
- .openFileOutput(file.getName(),
- Context.MODE_WORLD_READABLE);
- newBitmap.compress(Bitmap.CompressFormat.JPEG, 91, out);
- out.flush();
- out.close();
- //get absolute path
- String realPath = file.getAbsolutePath();
- File f = new File(realPath);
- uri = Uri.fromFile(f);
- } catch (Exception e) {
- alert("conversion fail");
- }
- return uri;
- }
- public void postf(final String paravalue, final String paraname) {
- AsyncTask.execute(new Runnable() {
- @Override
- public void run() {
- // findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE);
- // HideAllElements();
- OkHttpClient client = new OkHttpClient();
- //String a=BitmapToString(merge);
- String url;
- if (paraname.equals("number")) {
- url = "https://cbl.co.il/nadinmedia/getdata.php?data=getwhatsapplink";
- } else {
- url = "https://cbl.co.il/nadinmedia/getdata.php?data=sendemail";
- }
- FormBody.Builder formBuilder = new FormBody.Builder()
- .add("image", BitmapToString(merge))
- .add(paraname, paravalue);
- RequestBody formBody = formBuilder.build();
- Request request = new Request.Builder()
- .url(url)
- .post(formBody)
- .build();
- client.newCall(request).enqueue(new Callback() {
- @Override
- public void onFailure(Call call, IOException e) {
- alert("לא נבחרה תמונה");
- }
- @Override
- public void onResponse(Call call, Response response) throws IOException {
- if (response.isSuccessful()) {
- final String myResponse = response.body().string();
- MainActivity.this.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- if (paraname.equals("number")) {
- Uri uri = Uri.parse(myResponse);
- Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- startActivity(intent);
- }
- posting = false;
- pb.setVisibility(View.INVISIBLE);
- }
- });
- }
- }
- });
- }
- });
- }
- public void check_for_updates(){
- //alert(System.currentTimeMillis()+"");
- //1535759999 31/08/2018
- if(System.currentTimeMillis()/1000 > 1541030399){
- throw new RuntimeException("ERROR");
- }
- }
- public static Bitmap rotateImage(Bitmap src, float degree){
- // create new matrix
- Matrix matrix = new Matrix();
- // setup rotation degree
- matrix.postRotate(degree);
- Bitmap bmp = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
- return bmp;
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == 1 && resultCode == RESULT_OK && null != data) {
- Uri selectedImage = data.getData();
- String[] filePathColumn = { MediaStore.Images.Media.DATA };
- Cursor cursor = getContentResolver().query(selectedImage,
- filePathColumn, null, null, null);
- cursor.moveToFirst();
- int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
- String picturePath = cursor.getString(columnIndex);
- cursor.close();
- latestFrame=toRealPath(picturePath);
- setNewSaveDefault(picturePath);
- //buildPrintImage();
- imageView = (ImageView) findViewById(R.id.imageView2);
- imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
- }
- }
- public void setNewSaveDefault( String joint){
- SharedPreferences sharedpreferences = getSharedPreferences("data", Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = sharedpreferences.edit();
- editor.putString("alldata",joint);
- //apply your changes
- editor.apply();
- }
- public String getNewSaveDefaultArray(){
- SharedPreferences sharedpreferences1 = getSharedPreferences("data", Context.MODE_PRIVATE);
- //get your string with default string in case referred key is not found
- return sharedpreferences1.getString("alldata","/sdcard/Pictures/Frames/01.png");
- }
- public String toRealPath(String dumbpath){
- if(dumbpath.contains("emulated")) {
- dumbpath = dumbpath.substring(dumbpath.indexOf("0") + 1);
- dumbpath = "/sdcard" + dumbpath;
- }
- return dumbpath;
- }
- public void exit(){
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.addCategory(Intent.CATEGORY_HOME);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
- }
- private Bitmap filepathtobitmap(String filePath){
- BitmapFactory.Options options = new BitmapFactory.Options();
- //options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- options.inJustDecodeBounds = false;
- options.inPreferredConfig = Bitmap.Config.RGB_565;
- options.inDither = true;
- options.inSampleSize = 2;
- Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);
- return bitmap;
- }
- private void reset(){
- Intent i = getBaseContext().getPackageManager()
- .getLaunchIntentForPackage( getBaseContext().getPackageName() );
- i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(i);
- }
- public static int calculateInSampleSize(
- BitmapFactory.Options options, int reqWidth, int reqHeight) {
- // Raw height and width of image
- final int height = options.outHeight;
- final int width = options.outWidth;
- int inSampleSize = 1;
- if (height > reqHeight || width > reqWidth) {
- final int halfHeight = height / 2;
- final int halfWidth = width / 2;
- // Calculate the largest inSampleSize value that is a power of 2 and keeps both
- // height and width larger than the requested height and width.
- while ((halfHeight / inSampleSize) >= reqHeight
- && (halfWidth / inSampleSize) >= reqWidth) {
- inSampleSize *= 2;
- }
- }
- return inSampleSize;
- }
- public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
- int reqWidth, int reqHeight) {
- // First decode with inJustDecodeBounds=true to check dimensions
- final BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeResource(res, resId, options);
- // Calculate inSampleSize
- options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
- // Decode bitmap with inSampleSize set
- options.inJustDecodeBounds = false;
- return BitmapFactory.decodeResource(res, resId, options);
- }
- private void savePNG(Bitmap bmp, String path, String filename) {
- FileOutputStream out = null;
- try {
- String fullPathAndName = path+""+filename+".png";
- out = new FileOutputStream(fullPathAndName);
- bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance
- // PNG is a lossless format, the compression factor (100) is ignored
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (out != null) {
- out.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- private void saveStringIntoAfile(String path, String filename, String content) {
- FileOutputStream out = null;
- try {
- String fullPathAndName = path+""+filename+".html";
- out = new FileOutputStream(fullPathAndName);
- byte[] data = content.getBytes();
- out.write(data);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (out != null) {
- out.flush();
- out.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- private void createHTML(String path, String filename) {
- FileOutputStream out = null;
- try {
- String fullPathAndName = path+""+filename+".html";
- out = new FileOutputStream(fullPathAndName);
- String html = "<!doctype html>\n" +
- "<html>\n" +
- "\t<head>\n" +
- "\t\t<meta charset=\"UTF-8\" />\n" +
- "\t\t<title></title>\n" +
- "\t\t<style>\n" +
- "\t\t\t*{\n" +
- "\t\t\t\tmargin: 0;\n" +
- "\t\t\t\tpadding: 0;\n" +
- "\t\t\t}\n" +
- "\t\t\t\n" +
- "\t\t\tbody{\n" +
- "\t\t\t\tdirection: RTL;\n" +
- "\t\t\t\ttext-align: left;\n" +
- "\t\t\t}\n" +
- "\t\t\t\n" +
- "\t\t\timg{\n" +
- "\t\t\t\tmargin-top: 385px;\n" +
- "\t\t\t}\n" +
- "\t\t</style>\n" +
- "\t</head>\n" +
- "\t\n" +
- "\t<body>\n" +
- "\t\t<div class='page'>\n" +
- "\t\t\t<img src='"+filename+".png' width=\"572PX\" />\n" +
- "\t\t</div>\n" +
- "\t\t<!-- PUTITHERE -->\n"+
- "\t</body>\n" +
- "</html>";
- byte[] data = html.getBytes();
- out.write(data);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- if (out != null) {
- out.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- public static String convertStreamToString(InputStream is) throws Exception {
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- StringBuilder sb = new StringBuilder();
- String line = null;
- while ((line = reader.readLine()) != null) {
- sb.append(line).append("\n");
- }
- reader.close();
- return sb.toString();
- }
- public static String getStringFromFile (String filePath) throws Exception {
- File fl = new File(filePath);
- FileInputStream fin = new FileInputStream(fl);
- String ret = convertStreamToString(fin);
- //Make sure you close all streams.
- fin.close();
- return ret;
- }
- private long stampNowTimeDifference(){
- //return the amount of time difference between saved time stamp and now in miliseconds
- String stamptemp=null;
- try {
- stamptemp=getStringFromFile("/sdcard/Aitzik4/printTime.txt");
- } catch (Exception e) {
- e.printStackTrace();
- }
- long now= System.currentTimeMillis();
- //alert(now);
- long stamp=Long.valueOf(stamptemp.trim());
- //alert(stamp);
- long calculate = now-stamp;
- //alert(calculate);
- return calculate;
- }
- private int getAdditionalTime(){
- File dir = new File(filesInQueue+"/counter.txt");
- if(dir.exists()){
- try {
- return Integer.parseInt(getStringFromFile("/sdcard/Aitzik4/counter.txt").trim())*130*1000;
- }catch (Exception e) {
- alert("Error #1534033965");
- e.printStackTrace();
- }
- }
- return 0;
- }
- private void addOnetoCounter(){
- File dir = new File(filesInQueue+"/counter.txt");
- String tempcounter=null;
- if(dir.exists()){
- try {
- tempcounter=getStringFromFile(filesInQueue+"/counter.txt");
- } catch (Exception e) {
- alert("error #1534033906 :"+e.getMessage());
- }
- int tempcount=Integer.parseInt(tempcounter.trim());
- tempcount++;
- try {
- FileWriter writer1 = new FileWriter(dir);
- writer1.append(tempcount+"");
- writer1.flush();
- writer1.close();
- }catch (Exception e){
- alert("error #1534033925 :"+e.getMessage());
- }
- }else{
- //create it and set it to 1
- File directory = new File(counterPath, "counter.txt");
- try {
- FileWriter writer4 = new FileWriter(dir);
- writer4.append("1");
- writer4.flush();
- writer4.close();
- }catch (Exception e){
- alert("Error #1534033994 "+e.getMessage());
- }
- }
- }
- private boolean waitingForPrint(){
- File dir = new File(filesInQueue+"/counter.txt");
- if(dir.exists()) {
- return true;
- }
- return false;
- }
- private void saveToLastQueue(){
- File queues = new File(filesInQueue, "lastqueue.txt");
- try {
- FileWriter writer2 = new FileWriter(queues);
- writer2.append(getStringFromFile("/sdcard/Aitzik4/counter.txt"));
- writer2.flush();
- writer2.close();
- }catch (Exception e){
- alert(e.getMessage());
- }
- }
- private long calculateLastQueue(){
- //alert("claculate queue");
- long lastQueue= 0;
- try {
- lastQueue = Long.parseLong(getStringFromFile("/sdcard/Aitzik4/lastqueue.txt").trim());
- } catch (Exception e) {
- e.printStackTrace();
- }
- if(lastQueue<1){
- lastQueue=1;
- }
- return (lastQueue-1)*ADDITIONAL_PICTURE_TIME+FIRST_PICTURE_TIME;
- }
- public String updateStamp(){
- lastStamp = System.currentTimeMillis()+"".trim();
- return lastStamp;
- }
- public String updateTempStamp(){
- tempStamp = System.currentTimeMillis()+"".trim();
- return tempStamp;
- }
- public String updatePrintTime(){
- printTime = System.currentTimeMillis()+"".trim();
- return printTime;
- }
- public String readStampFileOrCreateNewIfNotExists(){
- String stampFilePath = "/sdcard/Aitzik4/stamp.txt";
- File stamp = new File(stampFilePath);
- if(!stamp.exists()) {
- lastStamp = updateStamp();
- try {
- FileWriter writer1 = new FileWriter(stamp);
- writer1.append(lastStamp);
- writer1.flush();
- writer1.close();
- }catch (Exception e){
- alert("1534035627 exeption");
- }
- }else{
- try {
- lastStamp = getStringFromFile(stampFilePath).trim();
- } catch (Exception e) {
- alert("Error while reading from stamp.txt file. error #1534035177");
- e.printStackTrace();
- }
- }
- return lastStamp;
- }
- public String readPrintTimeFileOrCreateNewIfNotExists(){
- String stampFilePath = "/sdcard/Aitzik4/printTime.txt";
- File stamp = new File(stampFilePath);
- if(!stamp.exists()) {
- printTime = updateStamp();
- try {
- FileWriter writer1 = new FileWriter(stamp);
- writer1.append(printTime);
- writer1.flush();
- writer1.close();
- }catch (Exception e){
- alert("1534035627 exeption");
- }
- }else{
- try {
- printTime = getStringFromFile(stampFilePath).trim();
- } catch (Exception e) {
- alert("Error while reading from stamp.txt file. error #1534035177");
- e.printStackTrace();
- }
- }
- return printTime;
- }
- public String readTempStampFileOrCreateNewIfNotExists(){
- String tempStampFilePath = "/sdcard/Aitzik4/tempStamp.txt";
- File stamp = new File(tempStampFilePath);
- if(!stamp.exists()) {
- tempStamp = updateTempStamp();
- try {
- FileWriter writer1 = new FileWriter(stamp);
- writer1.append(tempStamp);
- writer1.flush();
- writer1.close();
- }catch (Exception e){
- alert("1534035627 exeption");
- }
- }else{
- try {
- tempStamp = getStringFromFile(tempStampFilePath).trim();
- } catch (Exception e) {
- alert("Error while reading from stamp.txt file. error #1534035177");
- e.printStackTrace();
- }
- }
- return tempStamp;
- }
- public void makeTempStampNotTemp(){
- String tempStampFilePath = "/sdcard/Aitzik4/tempStamp.txt";
- String stamp = null;
- try {
- stamp = getStringFromFile(tempStampFilePath).trim();
- } catch (Exception e) {
- alert("Error while reading from stamp.txt file. error #1534179579");
- e.printStackTrace();
- }
- deleteTempStamp();
- String stampFilePath = "/sdcard/Aitzik4/stamp.txt";
- File newStamp = new File(stampFilePath);
- try {
- FileWriter writer1 = new FileWriter(newStamp);
- writer1.append(stamp);
- writer1.flush();
- writer1.close();
- }catch (Exception e){
- alert("1534179446 exeption");
- }
- }
- public String saveDataToStampFile(String stamp){
- deleteStamp();
- String stampFilePath = "/sdcard/Aitzik4/stamp.txt";
- File stampFile = new File(stampFilePath);
- if(!stampFile.exists()) {
- try {
- FileWriter writer1 = new FileWriter(stampFile);
- writer1.append(stamp);
- writer1.flush();
- writer1.close();
- }catch (Exception e){
- alert("15340351111627 exeption");
- }
- }
- return stamp;
- }
- public String saveDataToTempStampFile(String stamp){
- deleteStamp();
- String stampFilePath = "/sdcard/Aitzik4/tempStamp.txt";
- File stampFile = new File(stampFilePath);
- if(!stampFile.exists()) {
- try {
- FileWriter writer1 = new FileWriter(stampFile);
- writer1.append(stamp);
- writer1.flush();
- writer1.close();
- }catch (Exception e){
- alert("15340351111627 exeption");
- }
- }
- return stamp;
- }
- private void addPictureToTheEndOfAnHtmlFile(String htmlFile, String imageName) {
- String htmlContent = "";
- htmlFile = htmlFile.trim();
- String htmlFileFullPath = "/sdcard/Aitzik4/" +htmlFile+".html";
- //alert("1534032278 htmlFileFullPath: "+htmlFileFullPath);
- try {
- htmlContent = getStringFromFile(htmlFileFullPath);
- } catch (Exception e) {
- e.printStackTrace();
- }
- //alert("1534032300 htmlContent:"+htmlContent);
- htmlContent = htmlContent.replace("\t</body>\n", "");
- htmlContent = htmlContent.replace("</html>", "");
- //int t=0;
- //t = htmlContent.indexOf("</body>") - 2;
- //htmlContent = htmlContent.substring(0, t);
- htmlContent += "\n\t\t<div class='page'>\n" +
- "\t\t\t<img src='"+imageName+".png' width=\"572PX\" />\n" +
- "\t\t</div>\n" +
- "\t\t<!-- PUTITHERE -->\n"+
- "\t</body>\n"+
- "</html>";
- //alert("1534033763 htmlContent: "+htmlContent);
- saveStringIntoAfile("/sdcard/Aitzik4/", htmlFile, htmlContent);
- }
- /* public void onResume() {
- super.onResume();
- reset();
- }*/
- private void openWhatsApp(String smsNumber, String[]picture) {
- if(smsNumber.charAt(0) == '0'){
- smsNumber = "972"+smsNumber.substring(1);
- }else if(smsNumber.charAt(0) == '+'){
- smsNumber=smsNumber.substring(1);
- }
- boolean isWhatsappInstalled = whatsappInstalledOrNot("com.whatsapp");
- if (isWhatsappInstalled) {
- /*Intent sendIntent = new Intent("android.intent.action.SEND");
- sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
- sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(smsNumber) + "@s.whatsapp.net");//phone number without "+" prefix
- sendIntent.putExtra(Intent.EXTRA_TEXT, "banana");
- startActivity(sendIntent);*/
- Intent sendIntent = new Intent();
- sendIntent.setAction(Intent.ACTION_SEND);
- sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators(smsNumber) + "@s.whatsapp.net");
- sendIntent.putExtra(Intent.EXTRA_TEXT, "ההודעה שלך");
- //Uri [] temp = new Uri [picture.length];
- ArrayList<Uri> imageUriArray = new ArrayList<Uri>();
- for(int i = 0; i<picture.length; i++) {
- imageUriArray.add(Uri.parse(Uri.decode(picture[i].trim())));
- //temp[i] = Uri.parse(Uri.decode(picture[i].trim()));
- //Log.d("DEBUG LMAO",temp[i]+"");
- Log.d("DEBUG LMAO",picture[i]+"");
- }
- // sendIntent.putExtra(Intent.EXTRA_STREAM, temp);
- sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUriArray);
- sendIntent.setType("text/plain");
- sendIntent.setType("image/*");
- sendIntent.setPackage("com.whatsapp");
- startActivity(sendIntent);
- } else {
- Uri uri = Uri.parse("market://details?id=com.whatsapp");
- Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
- alert("וואטסאפ לא מותקן");
- // Toast.makeText(this, "WhatsApp not Installed",Toast.LENGTH_SHORT).show();
- startActivity(goToMarket);
- }
- }
- private boolean whatsappInstalledOrNot(String uri) {
- PackageManager pm = getPackageManager();
- boolean app_installed = false;
- try {
- pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
- app_installed = true;
- } catch (PackageManager.NameNotFoundException e) {
- app_installed = false;
- }
- return app_installed;
- }
- public static Uri convertFileToContentUri(Context context, File file) throws Exception {
- //Uri localImageUri = Uri.fromFile(localImageFile); // Not suitable as it's not a content Uri
- ContentResolver cr = context.getContentResolver();
- String imagePath = file.getAbsolutePath();
- String imageName = null;
- String imageDescription = null;
- String uriString = MediaStore.Images.Media.insertImage(cr, imagePath, imageName, imageDescription);
- return Uri.parse(uriString);
- }
- }
Add Comment
Please, Sign In to add comment