Example usage for android.app ProgressDialog show

List of usage examples for android.app ProgressDialog show

Introduction

In this page you can find the example usage for android.app ProgressDialog show.

Prototype

public static ProgressDialog show(Context context, CharSequence title, CharSequence message,
        boolean indeterminate) 

Source Link

Document

Creates and shows a ProgressDialog.

Usage

From source file:com.piggate.sdk.Piggate.java

public boolean validateCard(String cardNumber, int cardExpMonth, int cardExpYear, String cardCVC, String token,
        Context context, String title, String msg) {

    final PiggateCard creditCard = new PiggateCard(cardNumber, cardCVC, cardExpMonth, cardExpYear);
    Card card = new Card(cardNumber, cardExpMonth, cardExpYear, cardCVC); //Create the Card object
    if (card.validateCard()) { //Validate the credit card
        final ProgressDialog loadingDialog = ProgressDialog.show(context, title, msg, true);
        //Create the Stripe token
        new Stripe().createToken(card, token, new TokenCallback() {
            public void onSuccess(Token token) { //If create the token successfully
                creditCard.setTokenID(token.getId()); //Set the token ID in the PiggateCard object
                addCreditCard(creditCard); //Add the credit card to the ArrayList
                loadingDialog.dismiss();
            }// w  w w  .  j  a v a  2 s. com

            public void onError(Exception error) { //If there's an error creating the token
                //Handle the error
                loadingDialog.dismiss();
            }
        });
        return true; //Return true if card is validated
    } else
        return false; //Return false if card is not validated
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void endshiftCode() {
    pdialog = ProgressDialog.show(HomeScreen.this, "Please wait", "Ending shift ...", true);

    //send end shift code
    send_event("93");

    ToastMessage.displayToastFromResource(HomeScreen.this, 5, Gravity.CENTER,
            (ViewGroup) findViewById(R.id.toast_layout_root));

    //if tour module installed then clear out any current tour
    if (GTConstants.isTour) {
        //if tour started but not completed write to the trp file
        //touritemNumber > 0 indicates that at least one tag has been scanned
        if (GTConstants.trpfilename.length() > 1 && touritemNumber >= 0)
            endtrpFile(false);//from w  w w  .  j a va  2  s.co  m
        else
            cleantourInfo();
    }

    //write to dar, transfer file to send directory
    Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.darfileName,
            "End shift;" + GTConstants.currentBatteryPercent + ";" + Utility.getLocalTime() + ";"
                    + Utility.getLocalDate() + "\r\n",
            true);

    //write the event 19 information to the file
    String GM = Utility.getHeaderMessage("$GM") + ",19," + getCellID();
    Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.darfileName,
            GM + "\r\n", true);

    //give time for file write before moving file
    Utility.initializeGeneralTimer(2000);
    do {
        Utility.Sleep(1000);
    } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag());

    //move the dar file to the send file folder 
    File from = new File(GTConstants.dardestinationFolder, GTConstants.darfileName);

    //change the file name to match the $GM time and date
    String parse[] = GM.split(",");
    String newFile = GTConstants.LICENSE_ID.substring(7) + "_" + parse[10] + "_" + parse[2] + ".dar";

    File to = new File(GTConstants.sendfileFolder, newFile);
    from.renameTo(to);

    //write to srp file
    if (GTConstants.srpfileName.length() > 1) {
        Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.srpfileName,
                "End account;" + GTConstants.accountName + ";" + Utility.getLocalTime() + ";"
                        + Utility.getLocalDate() + "\r\n",
                true);

        //write the event 19 information to the file
        GM = Utility.getHeaderMessage("$GM") + ",19," + getCellID();
        Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.srpfileName,
                GM + "\r\n", true);

        //give time for file write before moving file
        Utility.initializeGeneralTimer(2000);
        do {
            Utility.Sleep(100);
        } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag());

        //move the srp file to the send file folder 
        from = new File(GTConstants.dardestinationFolder, GTConstants.srpfileName);

        //change the file name to match the $GM time and date
        String _parse[] = GM.split(",");
        newFile = GTConstants.LICENSE_ID.substring(7) + "_" + _parse[10] + "_" + _parse[2] + "_srp.srp";

        to = new File(GTConstants.sendfileFolder, newFile);
        from.renameTo(to);

        //end account
        GTConstants.srpfileName = " ";
        GTConstants.accountID = "";
        GTConstants.accountName = "";
    }
    //set flag for sending
    Utility.setUploadAvailable();

    //pause the GPS location service after ending a shift
    MainService.pauseLocationListener();

    //wait for end shift string to reach server (or timeout occurs) before dismissing wait dialog
    new CountDownTimer(5000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            if (!GTConstants.sendData) {
                //pdialog.dismiss();
            }
        }

        @Override
        public void onFinish() {
            if (!(pdialog == null)) {
                pdialog.dismiss();

                //set spinner back to start shift
                spinner.setSelection(0);

                //clear the warning text window
                setwarningText("");

                //set the current state
                Utility.setcurrentState(GTConstants.offShift);
                setuserBanner();

                btn_send.setEnabled(true);

                if (Utility.getpostorderAvailable()) {
                    restartsyncTimer = true;
                    showAlert("Sync Update", "Update of sync file required", true);
                }
            }
        }
    }.start();
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

public void promptImageName(final Activity activity, String hd) {
    final String hd_string = hd;
    final AlertDialog alertDialog;
    alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle("Image Name");

    RelativeLayout mLayout = new RelativeLayout(this);
    mLayout.setId(12222);/* w  w w .  j  a v a2 s  .c  o m*/

    EditText imageNameView = new EditText(activity);
    imageNameView.setEnabled(true);
    imageNameView.setVisibility(View.VISIBLE);
    imageNameView.setId(201012010);
    imageNameView.setSingleLine();
    RelativeLayout.LayoutParams searchViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    mLayout.addView(imageNameView, searchViewParams);

    final Spinner size = new Spinner(this);
    RelativeLayout.LayoutParams setPlusParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    size.setId(201012044);

    String[] arraySpinner = new String[7];
    for (int i = 0; i < arraySpinner.length; i++) {

        if (i < 5) {
            arraySpinner[i] = (i + 1) + " GB";
        }

    }
    arraySpinner[5] = "10 GB";
    arraySpinner[6] = "20 GB";

    ArrayAdapter sizeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, arraySpinner);
    sizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    size.setAdapter(sizeAdapter);
    setPlusParams.addRule(RelativeLayout.BELOW, imageNameView.getId());
    mLayout.addView(size, setPlusParams);

    // TODO: Not working for now
    // final TextView preallocText = new TextView(this);
    // preallocText.setText("Preallocate? ");
    // preallocText.setTextSize(15);
    // RelativeLayout.LayoutParams preallocTParams = new
    // RelativeLayout.LayoutParams(
    // RelativeLayout.LayoutParams.WRAP_CONTENT,
    // RelativeLayout.LayoutParams.WRAP_CONTENT);
    // preallocTParams.addRule(RelativeLayout.BELOW, size.getId());
    // mLayout.addView(preallocText, preallocTParams);
    // preallocText.setId(64512044);
    //
    // final CheckBox prealloc = new CheckBox(this);
    // RelativeLayout.LayoutParams preallocParams = new
    // RelativeLayout.LayoutParams(
    // RelativeLayout.LayoutParams.WRAP_CONTENT,
    // RelativeLayout.LayoutParams.WRAP_CONTENT);
    // preallocParams.addRule(RelativeLayout.BELOW, size.getId());
    // preallocParams.addRule(RelativeLayout.RIGHT_OF,
    // preallocText.getId());
    // preallocParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,
    // preallocText.getId());
    // mLayout.addView(prealloc, preallocParams);
    // prealloc.setId(64512344);

    alertDialog.setView(mLayout);

    final Handler handler = this.handler;

    // alertDialog.setMessage(body);
    alertDialog.setButton("Create", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            int sizeSel = size.getSelectedItemPosition();
            String templateImage = "hd1g.qcow2";
            if (sizeSel < 5) {
                templateImage = "hd" + (sizeSel + 1) + "g.qcow2";
            } else if (sizeSel == 5) {
                templateImage = "hd10g.qcow2";
            } else if (sizeSel == 6) {
                templateImage = "hd20g.qcow2";
            }

            // UIUtils.log("Searching...");
            EditText a = (EditText) alertDialog.findViewById(201012010);
            progDialog = ProgressDialog.show(activity, "Please Wait", "Creating HD Image...", true);
            // CreateImage createImg = new
            // CreateImage(a.getText().toString(),
            // hd_string, sizeInt, prealloc.isChecked());
            //            CreateImage createImg = new CreateImage(a.getText().toString(),
            //                  hd_string, sizeInt, false);
            //            createImg.execute();

            String image = a.getText().toString();
            if (!image.endsWith(".qcow2")) {
                image += ".qcow2";
            }
            createImg(templateImage, image, hd_string);

        }
    });
    alertDialog.show();

}

From source file:cgeo.geocaching.CacheDetailActivity.java

/**
 * A dialog to allow the user to select reseting coordinates local/remote/both.
 *//*  www . j av a 2 s  .co  m*/
private AlertDialog createResetCacheCoordinatesDialog(final Waypoint wpt) {

    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.waypoint_reset_cache_coords);

    final String[] items = { res.getString(R.string.waypoint_localy_reset_cache_coords),
            res.getString(R.string.waypoint_reset_local_and_remote_cache_coords) };
    builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            dialog.dismiss();
            final ProgressDialog progressDialog = ProgressDialog.show(CacheDetailActivity.this,
                    getString(R.string.cache), getString(R.string.waypoint_reset), true);
            final HandlerResetCoordinates handler = new HandlerResetCoordinates(CacheDetailActivity.this,
                    progressDialog, which == 1);
            resetCoords(cache, handler, wpt, which == 0 || which == 1, which == 1, progressDialog);
        }
    });
    return builder.create();
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    System.gc();/*from   w  w w  . j  ava 2s  .  co m*/
    if (requestCode == 18 && resultCode == Activity.RESULT_OK && null != data) {
        final ProgressDialog dialogLoader = ProgressDialog.show(activity, "",
                Finder.STRING.CONTACT_PROGRESS.toString(), true);
        Uri selectedVideo = data.getData();
        String[] filePathColumn = { MediaStore.Video.Media.DATA };
        final Cursor cursor = activity.getContentResolver().query(selectedVideo, filePathColumn, null, null,
                null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        final String videoPath = cursor.getString(columnIndex);
        cursor.close();
        System.gc();
        final File fileVideo = new File(videoPath);
        Calendar fecha = Calendar.getInstance();
        final long fechaInMillis = fecha.getTimeInMillis();
        File pathImage = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Video/Sent");
        pathImage.mkdirs();
        final File file = new File(pathImage, +fechaInMillis + ".mp4");
        cursor.close();
        //runTranscodingUsingLoader(fileVideo.getAbsolutePath(), file.getAbsolutePath());
        new Thread(new Runnable() {
            @Override
            public void run() {
                Bitmap thumbnailVideo = ThumbnailUtils.createVideoThumbnail(videoPath,
                        MediaStore.Video.Thumbnails.MICRO_KIND);
                Bitmap toUpload = scaleDownLargeImageWithAspectRatio(thumbnailVideo, 1280);
                Bitmap binaryData = toUpload;
                Bitmap binaryData2 = BlurImage(toUpload);
                try {
                    FileInputStream inStream = new FileInputStream(fileVideo);
                    FileOutputStream outStream = new FileOutputStream(file);

                    byte[] buffer = new byte[1024];

                    int length;
                    //copy the file content in bytes
                    while ((length = inStream.read(buffer)) > 0) {

                        outStream.write(buffer, 0, length);

                    }

                    inStream.close();
                    outStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                final Message msjVideo = new Message();
                try {
                    String id = u.id + contact.idContacto + fechaInMillis + Settings.Secure
                            .getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);

                    msjVideo.mensajeId = id;
                    msjVideo.emisor = u.id;
                    msjVideo.receptor = contact.idContacto;
                    msjVideo.emisorEmail = u.email;
                    msjVideo.receptorEmail = contact.email;
                    msjVideo.emisorLang = u.lang;
                    msjVideo.receptorLang = contact.lang;
                    msjVideo.emitedAt = fechaInMillis;
                    msjVideo.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_VIDEO));
                    if (tiempoMensaje)
                        msjVideo.delay = temporizadorSeek.getValue();
                    else
                        msjVideo.delay = 0;
                    msjVideo.videoName = file.getAbsolutePath();

                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                    byte[] byteArray = stream.toByteArray();
                    msjVideo.photo = byteArray;

                    ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                    binaryData2.compress(Bitmap.CompressFormat.JPEG, 60, stream2);
                    byte[] byteArray2 = stream2.toByteArray();
                    msjVideo.photoBlur = byteArray2;
                    if (SpeakSocket.mSocket != null)
                        if (SpeakSocket.mSocket.connected()) {
                            msjVideo.status = 1;
                        } else {
                            msjVideo.status = -1;
                        }
                    msjVideo.fileUploaded = false;
                    msjVideo.save();

                    Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjVideo.receptor)
                            .executeSingle();
                    if (chat == null) {
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", msjVideo.receptor).executeSingle();
                        Chats newChat = new Chats();
                        newChat.mensajeId = msjVideo.mensajeId;
                        newChat.idContacto = msjVideo.receptor;
                        newChat.isLockedConversation = false;
                        newChat.lastStatus = msjVideo.status;
                        newChat.email = msjVideo.receptorEmail;
                        if (contact != null) {
                            newChat.photo = contact.photo;
                            newChat.fullName = contact.fullName;
                            newChat.lang = contact.lang;
                            newChat.screenName = contact.screenName;
                            newChat.photoload = true;
                            newChat.phone = contact.phone;
                        } else {
                            newChat.photo = null;
                            newChat.photoload = false;
                            newChat.fullName = msjVideo.receptorEmail;
                            newChat.lang = msjVideo.receptorLang;
                            newChat.screenName = msjVideo.receptorEmail;
                            newChat.phone = null;
                        }
                        newChat.emitedAt = msjVideo.emitedAt;
                        newChat.notRead = 0;
                        newChat.lastMessage = "send Video";
                        newChat.show = true;
                        newChat.save();
                    } else {
                        if (!chat.photoload) {
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", msjVideo.emisor).executeSingle();
                            if (contact != null) {
                                chat.photo = contact.photo;
                                chat.photoload = true;
                            } else {
                                chat.photo = null;
                                chat.photoload = false;
                            }
                        }
                        chat.mensajeId = msjVideo.mensajeId;
                        chat.lastStatus = msjVideo.status;
                        chat.emitedAt = msjVideo.emitedAt;
                        chat.notRead = 0;
                        chat.lastMessage = "send Video";
                        chat.save();
                    }
                    showNewMessage(msjVideo);
                    dialogLoader.dismiss();
                } catch (Exception e) {
                }
                System.gc();
            }
        }).start();

    }

    if (requestCode == 45) {
        milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        List<String> allProviders = milocManager.getAllProviders();
        boolean gpsProvider = false;
        boolean netProvider = false;
        for (String providerName : allProviders) {
            if (providerName.equals(LocationManager.GPS_PROVIDER)) {
                gpsProvider = true;
            }
            if (providerName.equals(LocationManager.NETWORK_PROVIDER)) {
                netProvider = true;
            }
        }
        checkCountryLocation(gpsProvider, netProvider);
    }

    if (requestCode == 34) {
        if (resultCode == activity.RESULT_OK) {
            Uri contactUri = data.getData();
            try {
                //contactPic.setImageBitmap(getPhoto(contactUri));
                JSONObject contacto = new JSONObject();
                contacto.put("nombre", getName(contactUri));
                contacto.put("telefono", getPhone(contactUri));
                Message msjNew = new Message();
                Calendar fecha = Calendar.getInstance();
                String id = u.id + contact.idContacto + fecha.getTimeInMillis()
                        + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                msjNew.translation = true;
                msjNew.mensajeId = id;
                msjNew.emisor = u.id;
                msjNew.receptor = contact.idContacto;
                msjNew.mensaje = contacto.toString();
                msjNew.emisorEmail = u.email;
                msjNew.receptorEmail = contact.email;
                msjNew.emisorLang = u.lang;
                msjNew.receptorLang = contact.lang;
                msjNew.emitedAt = fecha.getTimeInMillis();
                msjNew.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_CONTACT));
                msjNew.delay = 0;
                if (SpeakSocket.mSocket != null)
                    if (SpeakSocket.mSocket.connected()) {
                        msjNew.status = 1;
                    } else {
                        msjNew.status = -1;
                    }
                msjNew.save();
                Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjNew.receptor)
                        .executeSingle();
                if (chat == null) {
                    Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.receptor)
                            .executeSingle();
                    Chats newChat = new Chats();
                    newChat.mensajeId = msjNew.mensajeId;
                    newChat.idContacto = msjNew.receptor;
                    newChat.isLockedConversation = false;
                    newChat.lastStatus = msjNew.status;
                    newChat.email = msjNew.receptorEmail;
                    if (contact != null) {
                        newChat.photo = contact.photo;
                        newChat.fullName = contact.fullName;
                        newChat.lang = contact.lang;
                        newChat.screenName = contact.screenName;
                        newChat.photoload = true;
                        newChat.phone = contact.phone;
                    } else {
                        newChat.photo = null;
                        newChat.photoload = false;
                        newChat.fullName = msjNew.receptorEmail;
                        newChat.lang = msjNew.receptorLang;
                        newChat.screenName = msjNew.receptorEmail;
                        newChat.phone = null;
                    }
                    newChat.emitedAt = msjNew.emitedAt;
                    newChat.notRead = 0;
                    newChat.lastMessage = "send Contact";
                    newChat.show = true;
                    newChat.save();
                } else {
                    if (!chat.photoload) {
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", msjNew.emisor).executeSingle();
                        if (contact != null) {
                            chat.photo = contact.photo;
                            chat.photoload = true;
                        } else {
                            chat.photo = null;
                            chat.photoload = false;
                        }
                    }
                    chat.mensajeId = msjNew.mensajeId;
                    chat.lastStatus = msjNew.status;
                    chat.emitedAt = msjNew.emitedAt;
                    chat.notRead = 0;
                    chat.lastMessage = "send Contact";
                    chat.save();
                }
                showNewMessage(msjNew);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        System.gc();
    }
    if (requestCode == 1 && null != data) {
        Uri selectedImage = data.getData();
        InputStream imageStream = null;
        try {
            imageStream = activity.getContentResolver().openInputStream(selectedImage);
        } catch (FileNotFoundException e) {
        }
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = activity.getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        Bitmap bitmapRotate = C.rotateBitmapAndScale(picturePath);
        cursor.close();
        System.gc();
        Calendar fecha = Calendar.getInstance();
        long fechaInMillis = fecha.getTimeInMillis();
        File pathImage = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
        pathImage.mkdirs();
        Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280);
        System.gc();
        Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500);
        System.gc();
        Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400));
        System.gc();
        File file = new File(pathImage, +fechaInMillis + ".png");
        OutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(file);
            toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
            outputStream.flush();
            outputStream.close();
            System.gc();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            final Message msjPhoto = new Message();
            String id = u.id + contact.idContacto + fechaInMillis
                    + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
            msjPhoto.mensajeId = id;
            msjPhoto.emisor = u.id;
            msjPhoto.receptor = contact.idContacto;
            msjPhoto.emisorEmail = u.email;
            msjPhoto.receptorEmail = contact.email;
            msjPhoto.emisorLang = u.lang;
            msjPhoto.receptorLang = contact.lang;
            msjPhoto.emitedAt = fechaInMillis;
            msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_PHOTO));
            if (tiempoMensaje)
                msjPhoto.delay = temporizadorSeek.getValue();
            else
                msjPhoto.delay = 0;
            msjPhoto.photoName = file.getAbsolutePath();

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
            byte[] byteArray = stream.toByteArray();
            msjPhoto.photo = byteArray;

            ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
            binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2);
            byte[] byteArray2 = stream2.toByteArray();
            msjPhoto.photoBlur = byteArray2;
            if (SpeakSocket.mSocket != null)
                if (SpeakSocket.mSocket.connected()) {
                    msjPhoto.status = 1;
                } else {
                    msjPhoto.status = -1;
                }
            msjPhoto.fileUploaded = false;
            msjPhoto.save();
            Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjPhoto.receptor)
                    .executeSingle();
            if (chat == null) {
                Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjPhoto.receptor)
                        .executeSingle();
                Chats newChat = new Chats();
                newChat.mensajeId = msjPhoto.mensajeId;
                newChat.idContacto = msjPhoto.receptor;
                newChat.isLockedConversation = false;
                newChat.lastStatus = msjPhoto.status;
                newChat.email = msjPhoto.receptorEmail;
                if (contact != null) {
                    newChat.photo = contact.photo;
                    newChat.fullName = contact.fullName;
                    newChat.lang = contact.lang;
                    newChat.screenName = contact.screenName;
                    newChat.photoload = true;
                    newChat.phone = contact.phone;
                } else {
                    newChat.photo = null;
                    newChat.photoload = false;
                    newChat.fullName = msjPhoto.receptorEmail;
                    newChat.lang = msjPhoto.receptorLang;
                    newChat.screenName = msjPhoto.receptorEmail;
                    newChat.phone = null;
                }
                newChat.emitedAt = msjPhoto.emitedAt;
                newChat.notRead = 0;
                newChat.lastMessage = "send Image";
                newChat.show = true;
                newChat.save();
            } else {
                if (!chat.photoload) {
                    Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjPhoto.emisor)
                            .executeSingle();
                    if (contact != null) {
                        chat.photo = contact.photo;
                        chat.photoload = true;
                    } else {
                        chat.photo = null;
                        chat.photoload = false;
                    }
                }
                chat.mensajeId = msjPhoto.mensajeId;
                chat.lastStatus = msjPhoto.status;
                chat.emitedAt = msjPhoto.emitedAt;
                chat.notRead = 0;
                chat.lastMessage = "send Image";
                chat.save();
            }
            showNewMessage(msjPhoto);

        } catch (Exception e) {
        }
        System.gc();
    }
    if (requestCode == 23) {
        if (resultCode == Activity.RESULT_OK) {
            Bitmap bitmapRotate = C
                    .rotateBitmapAndScale(Environment.getExternalStorageDirectory().getAbsolutePath()
                            + "/SpeakOn/Image/Sent/" + dateToCamera + ".png");
            System.gc();
            Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280);
            System.gc();
            Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500);
            System.gc();
            Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400));
            System.gc();
            File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                    + "/SpeakOn/Image/Sent/" + dateToCamera + ".png");
            OutputStream outputStream = null;
            try {
                outputStream = new FileOutputStream(file);
                toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
                outputStream.flush();
                outputStream.close();
                System.gc();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                final Message msjPhoto = new Message();
                String id = u.id + contact.idContacto + dateToCamera
                        + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                msjPhoto.mensajeId = id;
                msjPhoto.emisor = u.id;
                msjPhoto.receptor = contact.idContacto;
                msjPhoto.emisorEmail = u.email;
                msjPhoto.receptorEmail = contact.email;
                msjPhoto.emisorLang = u.lang;
                msjPhoto.receptorLang = contact.lang;
                msjPhoto.emitedAt = dateToCamera;
                msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_PHOTO));
                if (tiempoMensaje)
                    msjPhoto.delay = temporizadorSeek.getValue();
                else
                    msjPhoto.delay = 0;
                msjPhoto.photoName = file.getAbsolutePath();

                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                byte[] byteArray = stream.toByteArray();
                msjPhoto.photo = byteArray;

                ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2);
                byte[] byteArray2 = stream2.toByteArray();
                msjPhoto.photoBlur = byteArray2;
                if (SpeakSocket.mSocket != null)
                    if (SpeakSocket.mSocket.connected()) {
                        msjPhoto.status = 1;
                    } else {
                        msjPhoto.status = -1;
                    }
                msjPhoto.fileUploaded = false;
                msjPhoto.save();
                Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjPhoto.receptor)
                        .executeSingle();
                if (chat == null) {
                    Contact contact = new Select().from(Contact.class)
                            .where("id_contact = ?", msjPhoto.receptor).executeSingle();
                    Chats newChat = new Chats();
                    newChat.mensajeId = msjPhoto.mensajeId;
                    newChat.idContacto = msjPhoto.receptor;
                    newChat.isLockedConversation = false;
                    newChat.lastStatus = msjPhoto.status;
                    newChat.email = msjPhoto.receptorEmail;
                    if (contact != null) {
                        newChat.photo = contact.photo;
                        newChat.fullName = contact.fullName;
                        newChat.lang = contact.lang;
                        newChat.screenName = contact.screenName;
                        newChat.photoload = true;
                        newChat.phone = contact.phone;
                    } else {
                        newChat.photo = null;
                        newChat.photoload = false;
                        newChat.fullName = msjPhoto.receptorEmail;
                        newChat.lang = msjPhoto.receptorLang;
                        newChat.screenName = msjPhoto.receptorEmail;
                        newChat.phone = null;
                    }
                    newChat.emitedAt = msjPhoto.emitedAt;
                    newChat.notRead = 0;
                    newChat.lastMessage = "send Image";
                    newChat.show = true;
                    newChat.save();
                } else {
                    if (!chat.photoload) {
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", msjPhoto.emisor).executeSingle();
                        if (contact != null) {
                            chat.photo = contact.photo;
                            chat.photoload = true;
                        } else {
                            chat.photo = null;
                            chat.photoload = false;
                        }
                    }
                    chat.mensajeId = msjPhoto.mensajeId;
                    chat.lastStatus = msjPhoto.status;
                    chat.emitedAt = msjPhoto.emitedAt;
                    chat.notRead = 0;
                    chat.lastMessage = "send Image";
                    chat.save();
                }
                showNewMessage(msjPhoto);
            } catch (Exception e) {
            }
            System.gc();
        }
    }
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    System.gc();// www.ja v a2s . c  o  m
    if (requestCode == 34) {
        if (resultCode == activity.RESULT_OK) {
            Uri contactUri = data.getData();
            try {
                //contactPic.setImageBitmap(getPhoto(contactUri));
                JSONObject contactoSend = new JSONObject();
                contactoSend.put("nombre", getName(contactUri));
                contactoSend.put("telefono", getPhone(contactUri));
                MsgGroups msjNew = new MsgGroups();
                Calendar fecha = Calendar.getInstance();
                JSONArray targets = new JSONArray();
                JSONArray contactos = new JSONArray(grupo.targets);
                String contactosId = null;
                if (SpeakSocket.mSocket != null) {
                    if (SpeakSocket.mSocket.connected()) {
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            JSONObject newContact = new JSONObject();
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", contacto.getString("name")).executeSingle();
                            if (contact != null) {
                                if (!contact.idContacto.equals(u.id)) {
                                    if (translate)
                                        newContact.put("lang", contact.lang);
                                    else
                                        newContact.put("lang", u.lang);
                                    newContact.put("name", contact.idContacto);
                                    newContact.put("screen_name", contact.screenName);
                                    newContact.put("status", 1);
                                    contactosId += contact.idContacto;
                                    targets.put(targets.length(), newContact);
                                }
                            }
                        }
                    } else {
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            JSONObject newContact = new JSONObject();
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", contacto.getString("name")).executeSingle();
                            if (contact != null) {
                                if (!contact.idContacto.equals(u.id)) {
                                    if (translate)
                                        newContact.put("lang", contact.lang);
                                    else
                                        newContact.put("lang", u.lang);
                                    newContact.put("name", contact.idContacto);
                                    newContact.put("screen_name", contact.screenName);
                                    newContact.put("status", -1);
                                    contactosId += contact.idContacto;
                                    targets.put(targets.length(), newContact);
                                }
                            }
                        }
                    }
                }
                msjNew.grupoId = grupo.grupoId;
                msjNew.mensajeId = u.id + grupo.grupoId + fecha.getTimeInMillis()
                        + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                msjNew.emisor = u.id;
                msjNew.receptores = targets.toString();
                msjNew.mensaje = contactoSend.toString();
                msjNew.emisorEmail = u.email;
                msjNew.emisorLang = u.lang;
                msjNew.translation = false;
                msjNew.emitedAt = fecha.getTimeInMillis();
                msjNew.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_CONTACT));
                msjNew.delay = 0;
                msjNew.save();
                showNewMessage(msjNew);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        System.gc();
    }

    if (requestCode == 1 && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = activity.getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        Bitmap bitmapRotate = C.rotateBitmapAndScale(picturePath);
        cursor.close();
        System.gc();
        Calendar fecha = Calendar.getInstance();
        long fechaInMillis = fecha.getTimeInMillis();
        File pathImage = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
        pathImage.mkdirs();
        Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280);
        System.gc();
        Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500);
        System.gc();
        Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400));
        System.gc();
        File file = new File(pathImage, +fechaInMillis + ".png");
        OutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(file);
            toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
            outputStream.flush();
            outputStream.close();
            System.gc();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            final MsgGroups msjPhoto = new MsgGroups();
            JSONArray targets = new JSONArray();
            JSONArray contactos = new JSONArray(grupo.targets);
            String contactosId = null;
            if (SpeakSocket.mSocket != null) {
                if (SpeakSocket.mSocket.connected()) {
                    for (int i = 0; i < contactos.length(); i++) {
                        JSONObject contacto = contactos.getJSONObject(i);
                        JSONObject newContact = new JSONObject();
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", contacto.getString("name")).executeSingle();
                        if (contact != null) {
                            if (!contact.idContacto.equals(u.id)) {
                                if (translate)
                                    newContact.put("lang", contact.lang);
                                else
                                    newContact.put("lang", u.lang);
                                newContact.put("name", contact.idContacto);
                                newContact.put("screen_name", contact.screenName);
                                newContact.put("status", 1);
                                contactosId += contact.idContacto;
                                targets.put(targets.length(), newContact);
                            }
                        }
                    }
                } else {
                    for (int i = 0; i < contactos.length(); i++) {
                        JSONObject contacto = contactos.getJSONObject(i);
                        JSONObject newContact = new JSONObject();
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", contacto.getString("name")).executeSingle();
                        if (contact != null) {
                            if (!contact.idContacto.equals(u.id)) {
                                if (translate)
                                    newContact.put("lang", contact.lang);
                                else
                                    newContact.put("lang", u.lang);
                                newContact.put("name", contact.idContacto);
                                newContact.put("screen_name", contact.screenName);
                                newContact.put("status", -1);
                                contactosId += contact.idContacto;
                                targets.put(targets.length(), newContact);
                            }
                        }
                    }
                }
            }
            msjPhoto.grupoId = grupo.grupoId;
            msjPhoto.mensajeId = u.id + grupo.grupoId + fechaInMillis
                    + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
            msjPhoto.emisor = u.id;
            msjPhoto.receptores = targets.toString();
            msjPhoto.mensaje = "send Image";
            msjPhoto.emisorEmail = u.email;
            msjPhoto.emisorLang = u.lang;
            msjPhoto.translation = false;
            msjPhoto.emitedAt = fechaInMillis;
            msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_PHOTO));
            msjPhoto.delay = 0;
            msjPhoto.photoName = file.getAbsolutePath();
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
            byte[] byteArray = stream.toByteArray();
            msjPhoto.photo = byteArray;

            ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
            binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2);
            byte[] byteArray2 = stream2.toByteArray();
            msjPhoto.photoBlur = byteArray2;
            msjPhoto.fileUploaded = false;
            msjPhoto.save();
            showNewMessage(msjPhoto);
        } catch (Exception e) {
        }
        System.gc();
    }

    if (requestCode == 23) {
        if (resultCode == Activity.RESULT_OK) {
            Bitmap bitmapRotate = C
                    .rotateBitmapAndScale(Environment.getExternalStorageDirectory().getAbsolutePath()
                            + "/SpeakOn/Image/Sent/" + dateToCamera + ".png");
            System.gc();
            Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280);
            System.gc();
            Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500);
            System.gc();
            Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400));
            System.gc();
            File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                    + "/SpeakOn/Image/Sent/" + dateToCamera + ".png");
            OutputStream outputStream = null;
            try {
                outputStream = new FileOutputStream(file);
                toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
                outputStream.flush();
                outputStream.close();
                System.gc();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                final MsgGroups msjPhoto = new MsgGroups();
                JSONArray targets = new JSONArray();
                JSONArray contactos = new JSONArray(grupo.targets);
                String contactosId = null;
                if (SpeakSocket.mSocket != null) {
                    if (SpeakSocket.mSocket.connected()) {
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            JSONObject newContact = new JSONObject();
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", contacto.getString("name")).executeSingle();
                            if (contact != null) {
                                if (!contact.idContacto.equals(u.id)) {
                                    if (translate)
                                        newContact.put("lang", contact.lang);
                                    else
                                        newContact.put("lang", u.lang);
                                    newContact.put("name", contact.idContacto);
                                    newContact.put("screen_name", contact.screenName);
                                    newContact.put("status", 1);
                                    contactosId += contact.idContacto;
                                    targets.put(targets.length(), newContact);
                                }
                            }
                        }
                    } else {
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            JSONObject newContact = new JSONObject();
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", contacto.getString("name")).executeSingle();
                            if (contact != null) {
                                if (!contact.idContacto.equals(u.id)) {
                                    if (translate)
                                        newContact.put("lang", contact.lang);
                                    else
                                        newContact.put("lang", u.lang);
                                    newContact.put("name", contact.idContacto);
                                    newContact.put("screen_name", contact.screenName);
                                    newContact.put("status", -1);
                                    contactosId += contact.idContacto;
                                    targets.put(targets.length(), newContact);
                                }
                            }
                        }
                    }
                }
                msjPhoto.grupoId = grupo.grupoId;
                msjPhoto.mensajeId = u.id + grupo.grupoId + dateToCamera
                        + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                msjPhoto.emisor = u.id;
                msjPhoto.receptores = targets.toString();
                msjPhoto.mensaje = "send Image";
                msjPhoto.emisorEmail = u.email;
                msjPhoto.emisorLang = u.lang;
                msjPhoto.translation = false;
                msjPhoto.emitedAt = dateToCamera;
                msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_PHOTO));
                msjPhoto.delay = 0;
                msjPhoto.photoName = file.getAbsolutePath();
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                byte[] byteArray = stream.toByteArray();
                msjPhoto.photo = byteArray;

                ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2);
                byte[] byteArray2 = stream2.toByteArray();
                msjPhoto.photoBlur = byteArray2;
                msjPhoto.fileUploaded = false;
                msjPhoto.save();
                showNewMessage(msjPhoto);
            } catch (Exception e) {
            }
            System.gc();
        }
    }

    System.gc();
    if (requestCode == 18 && resultCode == Activity.RESULT_OK && null != data) {
        final ProgressDialog dialogLoader = ProgressDialog.show(activity, "",
                Finder.STRING.CONTACT_PROGRESS.toString(), true);
        Uri selectedVideo = data.getData();
        String[] filePathColumn = { MediaStore.Video.Media.DATA };
        final Cursor cursor = activity.getContentResolver().query(selectedVideo, filePathColumn, null, null,
                null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        final String videoPath = cursor.getString(columnIndex);
        cursor.close();
        System.gc();
        final File fileVideo = new File(videoPath);
        Calendar fecha = Calendar.getInstance();
        final long fechaInMillis = fecha.getTimeInMillis();
        File pathImage = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Video/Sent");
        pathImage.mkdirs();
        final File file = new File(pathImage, +fechaInMillis + ".mp4");
        cursor.close();
        //runTranscodingUsingLoader(fileVideo.getAbsolutePath(), file.getAbsolutePath());
        new Thread(new Runnable() {
            @Override
            public void run() {
                Bitmap thumbnailVideo = ThumbnailUtils.createVideoThumbnail(videoPath,
                        MediaStore.Video.Thumbnails.MICRO_KIND);
                Bitmap toUpload = scaleDownLargeImageWithAspectRatio(thumbnailVideo, 1280);
                Bitmap binaryData = toUpload;
                Bitmap binaryData2 = BlurImage(toUpload);
                try {
                    FileInputStream inStream = new FileInputStream(fileVideo);
                    FileOutputStream outStream = new FileOutputStream(file);

                    byte[] buffer = new byte[1024];

                    int length;
                    //copy the file content in bytes
                    while ((length = inStream.read(buffer)) > 0) {

                        outStream.write(buffer, 0, length);

                    }

                    inStream.close();
                    outStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                try {
                    final MsgGroups msjVideo = new MsgGroups();
                    JSONArray targets = new JSONArray();
                    JSONArray contactos = new JSONArray(grupo.targets);
                    String contactosId = null;
                    if (SpeakSocket.mSocket != null) {
                        if (SpeakSocket.mSocket.connected()) {
                            for (int i = 0; i < contactos.length(); i++) {
                                JSONObject contacto = contactos.getJSONObject(i);
                                JSONObject newContact = new JSONObject();
                                Contact contact = new Select().from(Contact.class)
                                        .where("id_contact = ?", contacto.getString("name")).executeSingle();
                                if (contact != null) {
                                    if (!contact.idContacto.equals(u.id)) {
                                        if (translate)
                                            newContact.put("lang", contact.lang);
                                        else
                                            newContact.put("lang", u.lang);
                                        newContact.put("name", contact.idContacto);
                                        newContact.put("screen_name", contact.screenName);
                                        newContact.put("status", 1);
                                        contactosId += contact.idContacto;
                                        targets.put(targets.length(), newContact);
                                    }
                                }
                            }
                        } else {
                            for (int i = 0; i < contactos.length(); i++) {
                                JSONObject contacto = contactos.getJSONObject(i);
                                JSONObject newContact = new JSONObject();
                                Contact contact = new Select().from(Contact.class)
                                        .where("id_contact = ?", contacto.getString("name")).executeSingle();
                                if (contact != null) {
                                    if (!contact.idContacto.equals(u.id)) {
                                        if (translate)
                                            newContact.put("lang", contact.lang);
                                        else
                                            newContact.put("lang", u.lang);
                                        newContact.put("name", contact.idContacto);
                                        newContact.put("screen_name", contact.screenName);
                                        newContact.put("status", -1);
                                        contactosId += contact.idContacto;
                                        targets.put(targets.length(), newContact);
                                    }
                                }
                            }
                        }
                    }
                    msjVideo.grupoId = grupo.grupoId;
                    msjVideo.mensajeId = u.id + grupo.grupoId + fechaInMillis + Settings.Secure
                            .getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                    msjVideo.emisor = u.id;
                    msjVideo.receptores = targets.toString();
                    msjVideo.mensaje = "send Video";
                    msjVideo.emisorEmail = u.email;
                    msjVideo.emisorLang = u.lang;
                    msjVideo.translation = false;
                    msjVideo.emitedAt = fechaInMillis;
                    msjVideo.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_VIDEO));
                    msjVideo.delay = 0;
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                    byte[] byteArray = stream.toByteArray();
                    msjVideo.photo = byteArray;
                    ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                    binaryData2.compress(Bitmap.CompressFormat.JPEG, 60, stream2);
                    byte[] byteArray2 = stream2.toByteArray();
                    msjVideo.photoBlur = byteArray2;
                    msjVideo.fileUploaded = false;
                    msjVideo.videoName = file.getAbsolutePath();
                    msjVideo.save();
                    showNewMessage(msjVideo);
                    dialogLoader.dismiss();
                } catch (Exception e) {
                }
                System.gc();
            }
        }).start();

    }

    if (requestCode == 45) {
        milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        List<String> allProviders = milocManager.getAllProviders();
        boolean gpsProvider = false;
        boolean netProvider = false;
        for (String providerName : allProviders) {
            if (providerName.equals(LocationManager.GPS_PROVIDER)) {
                gpsProvider = true;
            }
            if (providerName.equals(LocationManager.NETWORK_PROVIDER)) {
                netProvider = true;
            }
        }
        checkCountryLocation(gpsProvider, netProvider);
    }

}