Example usage for android.content Context LOCATION_SERVICE

List of usage examples for android.content Context LOCATION_SERVICE

Introduction

In this page you can find the example usage for android.content Context LOCATION_SERVICE.

Prototype

String LOCATION_SERVICE

To view the source code for android.content Context LOCATION_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.location.LocationManager for controlling location updates.

Usage

From source file:com.scoreflex.Scoreflex.java

/**
 * Returns the Location as set in {@link setLocation(Location)} or the best
 * last known location of the {@link LocationManager} or null if permission
 * was not given./*from ww w. ja v a 2 s.  c o  m*/
 */

public static Location getLocation() {
    if (null != sLocation)
        return sLocation;

    Context applicationContext = getApplicationContext();

    if (applicationContext == null)
        return null;

    LocationManager locationManager = (LocationManager) applicationContext
            .getSystemService(Context.LOCATION_SERVICE);
    try {
        Location locations[] = { locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER),
                locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER),
                locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER), };

        Location best = null;
        for (int i = 0; i < locations.length; i++) {

            // If this location is null, discard
            if (null == locations[i])
                continue;

            // If we have no best yet, use this first location
            if (null == best) {
                best = locations[i];
                continue;
            }

            // If this location is significantly older, discard
            long timeDelta = locations[i].getTime() - best.getTime();
            if (timeDelta < -1000 * 60 * 2)
                continue;

            // If we have no accuracy, discard
            if (0 == locations[i].getAccuracy())
                continue;

            // If this location is less accurate, discard
            if (best.getAccuracy() < locations[i].getAccuracy())
                continue;

            best = locations[i];
        }

        return best;
    } catch (java.lang.SecurityException e) {
        // Missing permission;
        return null;
    }
}

From source file:com.thomasokken.free42.Free42Activity.java

public int shell_get_location(DoubleHolder lat, DoubleHolder lon, DoubleHolder lat_lon_acc, DoubleHolder elev,
        DoubleHolder elev_acc) {/*from  ww  w  .j  a  va 2s  . co  m*/
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        locat_inited = false;
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
        return 0;
    }
    if (!locat_inited) {
        locat_inited = true;
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Criteria cr = new Criteria();
        cr.setAccuracy(Criteria.ACCURACY_FINE);
        String provider = lm.getBestProvider(cr, true);
        if (provider == null) {
            locat_exists = false;
            return 0;
        }
        LocationListener ll = new LocationListener() {
            public void onLocationChanged(Location location) {
                // TODO: Verify units etc.
                locat_lat = location.getLatitude();
                locat_lon = location.getLongitude();
                locat_lat_lon_acc = location.getAccuracy();
                locat_elev = location.getAltitude();
                locat_elev_acc = location.hasAltitude() ? locat_lat_lon_acc : -1;
            }

            public void onProviderDisabled(String provider) {
                // Ignore
            }

            public void onProviderEnabled(String provider) {
                // Ignore
            }

            public void onStatusChanged(String provider, int status, Bundle extras) {
                // Ignore
            }
        };
        try {
            lm.requestLocationUpdates(provider, 60000, 1, ll, Looper.getMainLooper());
        } catch (IllegalArgumentException e) {
            return 0;
        } catch (SecurityException e) {
            return 0;
        }
        locat_exists = true;
    }

    if (locat_exists) {
        lat.value = locat_lat;
        lon.value = locat_lon;
        lat_lon_acc.value = locat_lat_lon_acc;
        elev.value = locat_elev;
        elev_acc.value = locat_elev_acc;
        return 1;
    } else
        return 0;
}

From source file:com.plusot.senselib.SenseMain.java

private void checkGPS() {
    if (PreferenceKey.GPSON.isTrue()) {
        final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            startUpDialogs("checkGPS.providerEnabled");
            return;
        }/*from  ww  w . java  2 s.  c o m*/
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.dialog_gps_on).setCancelable(true)
                .setPositiveButton(R.string.button_yes, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                RESULT_GPS);
                    }
                }).setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        //dialog.cancel();
                        startUpDialogs("checkGPS.dialog.negativeButton");
                    }
                }).setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface arg0) {
                        startUpDialogs("checkGPS.dialog.cancel");
                    }
                });
        final AlertDialog alert = builder.create();
        alert.show();
    } else
        startUpDialogs("checkGPS.gpsOff");
}

From source file:com.example.sensingapp.SensingApp.java

public void show_screen2() {
    int i;/*from   w ww .  jav  a  2s. c  o m*/
    Location location = null;

    setContentView(R.layout.screen_2_sensors);

    m_chkAccl = (CheckBox) findViewById(R.id.chkAccl);
    m_chkLinearAccl = (CheckBox) findViewById(R.id.chkLinearAccl);
    m_chkGravity = (CheckBox) findViewById(R.id.chkGravity);
    m_chkGyro = (CheckBox) findViewById(R.id.chkGyro);
    m_chkOrient = (CheckBox) findViewById(R.id.chkOrient);
    m_chkMagnet = (CheckBox) findViewById(R.id.chkMagnetic);
    m_chkLight = (CheckBox) findViewById(R.id.chkLight);
    m_chkBarometer = (CheckBox) findViewById(R.id.chkBarometer);

    m_chkMic = (CheckBox) findViewById(R.id.chkMic);
    m_chkCellular = (CheckBox) findViewById(R.id.chkCellular);

    m_chkGPS = (CheckBox) findViewById(R.id.chkGPS);
    m_chkWifi = (CheckBox) findViewById(R.id.chkWifi);

    m_chkAccl.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkLinearAccl.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkGravity.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkGyro.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkOrient.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkMagnet.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkLight.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkBarometer.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkMic.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkCellular.setOnCheckedChangeListener(m_chkSensorEnableListener);

    m_chkGPS.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkWifi.setOnCheckedChangeListener(m_chkSensorEnableListener);

    m_spnScreen2_WiFiScanSpeed = (Spinner) findViewById(R.id.Screen2_spnWiFiScanSpeed);

    m_adpWiFiScanSpeed = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            m_arrsWiFiScanSpeed);
    m_adpWiFiScanSpeed.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    m_spnScreen2_WiFiScanSpeed.setAdapter(m_adpWiFiScanSpeed);
    m_spnScreen2_WiFiScanSpeed.setSelection(m_nWifiScanSpeedIndex);

    m_rdgpSensor = (RadioGroup) findViewById(R.id.RdGpSensor);
    m_rdSensorAccl = (RadioButton) findViewById(R.id.RdSensor_Accl);
    m_rdSensorLinearAccl = (RadioButton) findViewById(R.id.RdSensor_LinearAccl);
    m_rdSensorGravity = (RadioButton) findViewById(R.id.RdSensor_Gravity);
    m_rdSensorGyro = (RadioButton) findViewById(R.id.RdSensor_Gyro);
    m_rdSensorOrient = (RadioButton) findViewById(R.id.RdSensor_Orient);
    m_rdSensorMagnet = (RadioButton) findViewById(R.id.RdSensor_Magnetic);
    m_rdSensorLight = (RadioButton) findViewById(R.id.RdSensor_Light);
    m_rdSensorBarometer = (RadioButton) findViewById(R.id.RdSensor_Barometer);

    m_rdgpSensorMode = (RadioGroup) findViewById(R.id.RdGpSensorMode);
    m_rdSensorModeFastest = (RadioButton) findViewById(R.id.RdSensorMode_Fastest);
    m_rdSensorModeGame = (RadioButton) findViewById(R.id.RdSensorMode_Game);
    m_rdSensorModeNormal = (RadioButton) findViewById(R.id.RdSensorMode_Normal);
    m_rdSensorModeUI = (RadioButton) findViewById(R.id.RdSensorMode_UI);

    m_rdgpSensor.setOnCheckedChangeListener(m_rdgpSensorListener);
    m_rdgpSensorMode.setOnCheckedChangeListener(m_rdgpSensorModeListener);

    configSensorOptionStatus();

    m_mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (m_mainWifi.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
        m_blnWifiSignalEnabled = true;
    } else {
        m_blnWifiSignalEnabled = false;
        m_chkWifi.setEnabled(false);
    }

    this.registerReceiver(m_brcvWifiStateChangedReceiver,
            new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));

    m_locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    m_blnGPSSignalEnabled = m_locManager.isProviderEnabled(m_sGPSProvider);

    if ((m_locManager != null) && (m_blnGPSSignalEnabled == true)) {
        location = m_locManager.getLastKnownLocation(m_sGPSProvider);
        if (location != null) {
            float fLat = (float) (location.getLatitude());
            float fLng = (float) (location.getLongitude());
            if (location.hasAltitude()) {
                float fAlt = (float) (location.getAltitude());
            }
        }
    }

    m_btnScreen2_Back = (Button) findViewById(R.id.btScreen2_Back);
    m_btnScreen2_Back.setOnClickListener(m_btnScreen2_Back_Listener);
    m_btnScreen2_Next = (Button) findViewById(R.id.btScreen2_Next);
    m_btnScreen2_Next.setOnClickListener(m_btnScreen2_Next_Listener);

    /* No sensor is installed, disable other widgets and show information to user */
    if ((m_blnOrientPresent == false) && (m_blnGyroPresent == false) && (m_blnAcclPresent == false)
            && (m_blnLinearAcclPresent == false) && (m_blnGravityPresent == false)
            && (m_blnMagnetPresent == false) && (m_blnLightPresent == false)
            && (m_blnBarometerPresent == false)) {

        m_rdSensorModeFastest.setEnabled(false);
        m_rdSensorModeGame.setEnabled(false);
        m_rdSensorModeNormal.setEnabled(false);
        m_rdSensorModeUI.setEnabled(false);

    }

    if (m_blnAcclEnabled == true) {
        m_chkAccl.setChecked(true);
    }

    if (m_blnLinearAcclEnabled == true) {
        m_chkLinearAccl.setChecked(true);
    }

    if (m_blnGravityEnabled == true) {
        m_chkGravity.setChecked(true);
    }

    if (m_blnGyroEnabled == true) {
        m_chkGyro.setChecked(true);
    }

    if (m_blnOrientEnabled == true) {
        m_chkOrient.setChecked(true);
    }

    if (m_blnMagnetEnabled == true) {
        m_chkMagnet.setChecked(true);
    }

    if (m_blnLightEnabled == true) {
        m_chkLight.setChecked(true);
    }

    if (m_blnBarometerEnabled == true) {
        m_chkBarometer.setChecked(true);
    }

    if (m_blnMicEnabled == true) {
        m_chkMic.setChecked(true);
    }

    if (m_blnCellularEnabled == true) {
        m_chkCellular.setChecked(true);
    }

    if (m_blnGPSEnabled == true) {
        m_chkGPS.setChecked(true);
    }

    if (m_blnWifiEnabled == true) {
        m_chkWifi.setChecked(true);
    }

    Settings.System.putInt(getContentResolver(), Settings.System.WIFI_SLEEP_POLICY,
            Settings.System.WIFI_SLEEP_POLICY_NEVER);

}

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

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.icn_message_send:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        String message = messageText.getText().toString();
        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.mensajeId = id;/*from  w w  w .j a v  a2 s  .  c  o  m*/
        msjNew.emisor = u.id;
        msjNew.receptor = contact.idContacto;
        msjNew.mensaje = message;
        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_TEXT));
        if (tiempoMensaje)
            msjNew.delay = temporizadorSeek.getValue();
        else
            msjNew.delay = 0;
        msjNew.translation = translate;
        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 = msjNew.mensaje;
            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 = msjNew.mensaje;
            chat.save();
        }
        messageText.setText("");
        showNewMessage(msjNew);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        tiempoMensaje = false;
        break;
    case R.id.message_text:
        SharedPreferences settings = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings.getInt("INPUTKEY", 0) == 0) {
            customKeyboardLayout.setVisibility(View.GONE);
            customKeyboardAudio.setVisibility(View.GONE);
            keyboardLayout.setVisibility(View.GONE);
            isShowCustomKeyboard = false;
            if (tiempoMensaje) {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
            } else {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
            }
            isShowKeyboard = true;
        } else {
            if (!isShowKeyboard) {
                if (!isShowCustomKeyboard) {
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                } else {
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                }
            }
        }
        break;
    case R.id.icn_message_translate:
        translate = !translate;
        if (translate)
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_red));
        else
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_gray));
        break;
    case R.id.icn_message_clock:
        tiempoMensaje = false;
        temporizadorAcept.setVisibility(View.INVISIBLE);
        temporizadorSeek.setInitPosition(0);
        SharedPreferences settings1 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings1.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardAudio.setVisibility(View.GONE);
            if (!customKeyboardLayout.isShown()) {
                customKeyboardLayout.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
                tiempoMensaje = false;
                if (tiempoMensaje) {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
            }
        }
        break;
    case R.id.temporizador_cancel:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        temporizadorSeek.setInitPosition(0);
        isShowCustomKeyboard = false;
        tiempoMensaje = false;
        break;
    case R.id.temporizador_acept:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        isShowCustomKeyboard = false;
        tiempoMensaje = true;
        if (!isShowKeyboard) {
            if (!isShowCustomKeyboard) {
                messagesListScroll.setVerticalScrollBarEnabled(false);
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                ((MainActivity) activity).setOnBackPressedListener(null);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            } else {
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                ((MainActivity) activity).setOnBackPressedListener(null);
                messagesListScroll.setVerticalScrollBarEnabled(false);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id._1:
        temporizadorSeek.setInitPosition(15);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._2:
        temporizadorSeek.setInitPosition(30);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._3:
        temporizadorSeek.setInitPosition(45);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._4:
        temporizadorSeek.setInitPosition(60);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._5:
        temporizadorSeek.setInitPosition(75);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._6:
        temporizadorSeek.setInitPosition(90);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._7:
        temporizadorSeek.setInitPosition(105);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._8:
        temporizadorSeek.setInitPosition(120);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._9:
        temporizadorSeek.setInitPosition(135);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._10:
        temporizadorSeek.setInitPosition(150);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._11:
        temporizadorSeek.setInitPosition(165);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._12:
        temporizadorSeek.setInitPosition(180);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id.adjunt_image:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, 1);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_contact:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(i, 34);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_audio:
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        SharedPreferences settings2 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings2.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set4 = new AnimatorSet();
                set4.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set4.setDuration(220).start();
                set4.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set5 = new AnimatorSet();
                set5.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set5.setDuration(220).start();
                set5.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardLayout.setVisibility(View.GONE);
            if (!customKeyboardAudio.isShown()) {
                customKeyboardAudio.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id.add_to_contacts:
        try {
            JSONArray jsonArr = new JSONArray();
            JSONObject jsonObj = new JSONObject();
            jsonObj.put(C.c_id_contact, contact.idContacto);
            RequestParams params = new RequestParams();
            params.put("contacts", jsonArr.put(jsonObj));
            addToContacts(params);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        break;
    case R.id.adjunt_photo:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        File imagesFolder = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
        imagesFolder.mkdirs();
        adjuntLayout.setVisibility(View.GONE);
        dateToCamera = Calendar.getInstance().getTimeInMillis();
        File image = new File(imagesFolder, dateToCamera + ".png");
        Uri uriSavedImage = Uri.fromFile(image);
        Intent pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
        startActivityForResult(pictureActionIntent, 23);
        break;
    case R.id.adjunt_video:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent videoPickerIntent = new Intent(Intent.ACTION_PICK);
        videoPickerIntent.setType("video/*");
        startActivityForResult(videoPickerIntent, 18);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_location:
        adjuntLayout.setVisibility(View.GONE);
        hideKeyBoard();
        menuAdjunt = false;
        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);
        break;
    }
}

From source file:com.linkbubble.ui.ContentView.java

void showAllowLocationDialog(final String origin, final WebRenderer.GetGeolocationCallback callback) {

    LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
    if (locationManager == null || locationManager.getAllProviders() == null
            || locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER) == false) {
        return;//from  w w  w.  j  a  v a  2 s.  co m
    }

    String originCopy = origin.replace("http://", "").replace("https://", "");
    String messageText = String.format(getResources().getString(R.string.requesting_location_message),
            originCopy);
    mRequestLocationTextView.setText(messageText);
    mRequestLocationContainer.setVisibility(View.VISIBLE);
    mRequestLocationShadow.setVisibility(View.VISIBLE);
    mRequestLocationYesButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            callback.onAllow();
            hideAllowLocationDialog();
        }
    });
}

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

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.icn_message_send:
        String message = messageText.getText().toString();
        MsgGroups msgGroup = new MsgGroups();
        try {//from w  w w.ja  v a 2  s  . co m
            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);
                            }
                        }
                    }
                }
            }
            msgGroup.grupoId = grupo.grupoId;
            msgGroup.mensajeId = u.id + grupo.grupoId + fecha.getTimeInMillis()
                    + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
            msgGroup.emisor = u.id;
            msgGroup.receptores = targets.toString();
            msgGroup.mensaje = message;
            msgGroup.emisorEmail = u.email;
            msgGroup.emisorLang = u.lang;
            msgGroup.translation = translate;
            msgGroup.emitedAt = fecha.getTimeInMillis();
            msgGroup.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_TEXT));
            if (tiempoMensaje) {
                msgGroup.delay = temporizadorSeek.getValue();
            } else {
                msgGroup.delay = 0;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        msgGroup.save();
        messageText.setText("");
        showNewMessage(msgGroup);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        tiempoMensaje = false;
        break;
    case R.id.message_text:
        SharedPreferences settings = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings.getInt("INPUTKEY", 0) == 0) {
            customKeyboardLayout.setVisibility(View.GONE);
            customKeyboardAudio.setVisibility(View.GONE);
            keyboardLayout.setVisibility(View.GONE);
            isShowCustomKeyboard = false;
            if (tiempoMensaje) {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
            } else {
                messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
            }
            isShowKeyboard = true;
        } else {
            if (!isShowKeyboard) {
                if (!isShowCustomKeyboard) {
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                } else {
                    keyboardLayout.setVisibility(View.GONE);
                    AnimatorSet set = new AnimatorSet();
                    set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                    set.setDuration(220).start();
                    set.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            keyboardLayout.setVisibility(View.VISIBLE);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {

                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {

                        }
                    });
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    messagesListScroll.setVerticalScrollBarEnabled(false);
                    if (tiempoMensaje) {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    } else {
                        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    }
                    final InputMethodManager imm = (InputMethodManager) activity
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(messageText, 0);
                    keyboardLayout
                            .setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                    isShowKeyboard = true;
                    customKeyboardLayout.setVisibility(View.GONE);
                    customKeyboardAudio.setVisibility(View.GONE);
                    isShowCustomKeyboard = false;
                }
            }
        }
        break;
    case R.id.icn_message_translate:
        if (translate)
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_red));
        else
            messageTranslate.setTextColor(getResources().getColor(R.color.speak_all_gray));
        //initAdapter();
        break;
    case R.id.icn_message_clock:
        tiempoMensaje = false;
        temporizadorAcept.setVisibility(View.INVISIBLE);
        temporizadorSeek.setInitPosition(0);
        SharedPreferences settings1 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings1.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                }
                customKeyboardLayout.setVisibility(View.VISIBLE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardAudio.setVisibility(View.GONE);
            if (!customKeyboardLayout.isShown()) {
                customKeyboardLayout.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
                tiempoMensaje = false;
                if (tiempoMensaje) {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
            }
        }
        break;
    case R.id.temporizador_cancel:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        temporizadorSeek.setInitPosition(0);
        isShowCustomKeyboard = false;
        tiempoMensaje = false;
        break;
    case R.id.temporizador_acept:
        temporizadorAcept.setVisibility(View.INVISIBLE);
        messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
        messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
        keyboardLayout.setVisibility(View.GONE);
        customKeyboardLayout.setVisibility(View.GONE);
        customKeyboardAudio.setVisibility(View.GONE);
        temporizadorSeek.setInitPosition(15);
        isShowCustomKeyboard = false;
        tiempoMensaje = true;
        if (!isShowKeyboard) {
            if (!isShowCustomKeyboard) {
                messagesListScroll.setVerticalScrollBarEnabled(false);
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                ((MainActivity) activity).setOnBackPressedListener(null);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            } else {
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set = new AnimatorSet();
                set.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set.setDuration(220).start();
                set.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                ((MainActivity) activity).setOnBackPressedListener(null);
                messagesListScroll.setVerticalScrollBarEnabled(false);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
                final InputMethodManager imm = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(messageText, 0);
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                isShowKeyboard = true;
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id._1:
        temporizadorSeek.setInitPosition(15);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._2:
        temporizadorSeek.setInitPosition(30);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._3:
        temporizadorSeek.setInitPosition(45);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._4:
        temporizadorSeek.setInitPosition(60);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._5:
        temporizadorSeek.setInitPosition(75);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._6:
        temporizadorSeek.setInitPosition(90);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._7:
        temporizadorSeek.setInitPosition(105);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._8:
        temporizadorSeek.setInitPosition(120);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._9:
        temporizadorSeek.setInitPosition(135);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._10:
        temporizadorSeek.setInitPosition(150);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._11:
        temporizadorSeek.setInitPosition(165);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id._12:
        temporizadorSeek.setInitPosition(180);
        temporizadorAcept.setVisibility(View.VISIBLE);
        break;
    case R.id.adjunt_image:
        System.gc();
        getFragmentManager().beginTransaction().replace(R.id.container3, CreatePollFragment.newInstance(grupo))
                .addToBackStack(null).commit();
        ((MainActivity) activity).setOnBackPressedListener(null);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_contact:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent i = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
        startActivityForResult(i, 34);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_audio:
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        AnimatorSet set3 = new AnimatorSet();
        set3.playTogether(ObjectAnimator.ofFloat(adjuntLayout, "alpha", 1, 0));
        set3.setDuration(200).start();
        SharedPreferences settings2 = getActivity().getSharedPreferences(Finder.STRING.APP_PREF.toString(),
                Context.MODE_PRIVATE);
        if (settings2.getInt("INPUTKEY", 0) != 0) {
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
        }
        if (!isShowCustomKeyboard) {
            if (!isShowKeyboard) {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set4 = new AnimatorSet();
                set4.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set4.setDuration(220).start();
                set4.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            } else {
                keyboardLayout.setBackgroundColor(getResources().getColor(R.color.speak_all_ligh_gray_plus));
                keyboardLayout.setVisibility(View.GONE);
                AnimatorSet set5 = new AnimatorSet();
                set5.playTogether(ObjectAnimator.ofFloat(keyboardLayout, "alpha", 0, 1));
                set5.setDuration(220).start();
                set5.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        keyboardLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
                hideKeyBoard();
                ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) {
                    @Override
                    public void doBack() {
                        if (tiempoMensaje) {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                        } else {
                            messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                            messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                        }
                        keyboardLayout.setVisibility(View.GONE);
                        customKeyboardLayout.setVisibility(View.GONE);
                        customKeyboardAudio.setVisibility(View.GONE);
                        isShowCustomKeyboard = false;
                        ((MainActivity) activity).setOnBackPressedListener(null);
                    }
                });
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                }
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.VISIBLE);
                isShowCustomKeyboard = true;
                isShowKeyboard = false;
            }
        } else {
            customKeyboardLayout.setVisibility(View.GONE);
            if (!customKeyboardAudio.isShown()) {
                customKeyboardAudio.setVisibility(View.VISIBLE);
                if (tiempoMensaje) {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER_FILL.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_red));
                } else {
                    messageClock.setText(Finder.STRING.ICN_TEMPORIZER.toString());
                    messageClock.setTextColor(getResources().getColor(R.color.speak_all_gray));
                }
            } else {
                temporizadorAcept.setVisibility(View.INVISIBLE);
                keyboardLayout.setVisibility(View.GONE);
                customKeyboardLayout.setVisibility(View.GONE);
                customKeyboardAudio.setVisibility(View.GONE);
                isShowCustomKeyboard = false;
            }
        }
        break;
    case R.id.adjunt_photo:
        System.gc();
        choosePicture();
        break;
    case R.id.adjunt_video:
        System.gc();
        dontClose = true;
        ((MainActivity) activity).dontClose = true;
        hideKeyBoard();
        Intent videoPickerIntent = new Intent(Intent.ACTION_PICK);
        videoPickerIntent.setType("video/*");
        startActivityForResult(videoPickerIntent, 18);
        menuAdjunt = false;
        adjuntLayout.setVisibility(View.GONE);
        break;
    case R.id.adjunt_location:
        adjuntLayout.setVisibility(View.GONE);
        hideKeyBoard();
        menuAdjunt = false;
        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);
        break;
    }
}

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();/* www  . j a v  a 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();/* ww  w  . j a va2s.  co  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);
    }

}