List of usage examples for android.location LocationManager NETWORK_PROVIDER
String NETWORK_PROVIDER
To view the source code for android.location LocationManager NETWORK_PROVIDER.
Click Source Link
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 ww.j a va2 s . c o 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.ConversationGroupFragment.java
public void checkCountryLocation(final boolean gpsProvider, final boolean netProvider) { getActivity().runOnUiThread(new Runnable() { @Override/*from w w w . j av a2 s .c o m*/ public void run() { boolean gpsEnabled = false; boolean networkEnabled = false; if (gpsProvider) { gpsEnabled = milocManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } if (netProvider) { networkEnabled = milocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); } if (gpsProvider && netProvider) { if (!gpsEnabled && !networkEnabled) { LayoutInflater dialogInflater = (LayoutInflater) activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialogView = dialogInflater.inflate(R.layout.null_contact_dialog, null); TextView mensaje = (TextView) dialogView.findViewById(R.id.dialog_add_contact); mensaje.setText(getString(R.string.location_services)); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity) .setView(dialogView).setCancelable(true) .setPositiveButton(R.string.add_contact_yes, null) .setNegativeButton(R.string.add_contact_no, null); finderDialog = dialogBuilder.show(); finderDialog.setCanceledOnTouchOutside(true); finderDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finderDialog.dismiss(); System.gc(); dontClose = true; ((MainActivity) activity).dontClose = true; Intent intent = new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 45); } }); finderDialog.getButton(DialogInterface.BUTTON_NEGATIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finderDialog.dismiss(); } }); } else { milocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ConversationGroupFragment.this); milocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ConversationGroupFragment.this); } } } }); }
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();/* ww w .j av 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();/*from ww w . j a v a 2s. c o m*/ if (requestCode == 34) { if (resultCode == activity.RESULT_OK) { Uri contactUri = data.getData(); try { //contactPic.setImageBitmap(getPhoto(contactUri)); JSONObject contactoSend = new JSONObject(); contactoSend.put("nombre", getName(contactUri)); contactoSend.put("telefono", getPhone(contactUri)); MsgGroups msjNew = new MsgGroups(); Calendar fecha = Calendar.getInstance(); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); String contactosId = null; if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } } msjNew.grupoId = grupo.grupoId; msjNew.mensajeId = u.id + grupo.grupoId + fecha.getTimeInMillis() + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID); msjNew.emisor = u.id; msjNew.receptores = targets.toString(); msjNew.mensaje = contactoSend.toString(); msjNew.emisorEmail = u.email; msjNew.emisorLang = u.lang; msjNew.translation = false; msjNew.emitedAt = fecha.getTimeInMillis(); msjNew.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_CONTACT)); msjNew.delay = 0; msjNew.save(); showNewMessage(msjNew); } catch (JSONException e) { e.printStackTrace(); } } System.gc(); } if (requestCode == 1 && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); Bitmap bitmapRotate = C.rotateBitmapAndScale(picturePath); cursor.close(); System.gc(); Calendar fecha = Calendar.getInstance(); long fechaInMillis = fecha.getTimeInMillis(); File pathImage = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent"); pathImage.mkdirs(); Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280); System.gc(); Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500); System.gc(); Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400)); System.gc(); File file = new File(pathImage, +fechaInMillis + ".png"); OutputStream outputStream = null; try { outputStream = new FileOutputStream(file); toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream); outputStream.flush(); outputStream.close(); System.gc(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { final MsgGroups msjPhoto = new MsgGroups(); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); String contactosId = null; if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } } msjPhoto.grupoId = grupo.grupoId; msjPhoto.mensajeId = u.id + grupo.grupoId + fechaInMillis + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID); msjPhoto.emisor = u.id; msjPhoto.receptores = targets.toString(); msjPhoto.mensaje = "send Image"; msjPhoto.emisorEmail = u.email; msjPhoto.emisorLang = u.lang; msjPhoto.translation = false; msjPhoto.emitedAt = fechaInMillis; msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_PHOTO)); msjPhoto.delay = 0; msjPhoto.photoName = file.getAbsolutePath(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream); byte[] byteArray = stream.toByteArray(); msjPhoto.photo = byteArray; ByteArrayOutputStream stream2 = new ByteArrayOutputStream(); binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2); byte[] byteArray2 = stream2.toByteArray(); msjPhoto.photoBlur = byteArray2; msjPhoto.fileUploaded = false; msjPhoto.save(); showNewMessage(msjPhoto); } catch (Exception e) { } System.gc(); } if (requestCode == 23) { if (resultCode == Activity.RESULT_OK) { Bitmap bitmapRotate = C .rotateBitmapAndScale(Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent/" + dateToCamera + ".png"); System.gc(); Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280); System.gc(); Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500); System.gc(); Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400)); System.gc(); File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent/" + dateToCamera + ".png"); OutputStream outputStream = null; try { outputStream = new FileOutputStream(file); toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream); outputStream.flush(); outputStream.close(); System.gc(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { final MsgGroups msjPhoto = new MsgGroups(); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); String contactosId = null; if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } } msjPhoto.grupoId = grupo.grupoId; msjPhoto.mensajeId = u.id + grupo.grupoId + dateToCamera + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID); msjPhoto.emisor = u.id; msjPhoto.receptores = targets.toString(); msjPhoto.mensaje = "send Image"; msjPhoto.emisorEmail = u.email; msjPhoto.emisorLang = u.lang; msjPhoto.translation = false; msjPhoto.emitedAt = dateToCamera; msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_PHOTO)); msjPhoto.delay = 0; msjPhoto.photoName = file.getAbsolutePath(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream); byte[] byteArray = stream.toByteArray(); msjPhoto.photo = byteArray; ByteArrayOutputStream stream2 = new ByteArrayOutputStream(); binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2); byte[] byteArray2 = stream2.toByteArray(); msjPhoto.photoBlur = byteArray2; msjPhoto.fileUploaded = false; msjPhoto.save(); showNewMessage(msjPhoto); } catch (Exception e) { } System.gc(); } } System.gc(); if (requestCode == 18 && resultCode == Activity.RESULT_OK && null != data) { final ProgressDialog dialogLoader = ProgressDialog.show(activity, "", Finder.STRING.CONTACT_PROGRESS.toString(), true); Uri selectedVideo = data.getData(); String[] filePathColumn = { MediaStore.Video.Media.DATA }; final Cursor cursor = activity.getContentResolver().query(selectedVideo, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); final String videoPath = cursor.getString(columnIndex); cursor.close(); System.gc(); final File fileVideo = new File(videoPath); Calendar fecha = Calendar.getInstance(); final long fechaInMillis = fecha.getTimeInMillis(); File pathImage = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Video/Sent"); pathImage.mkdirs(); final File file = new File(pathImage, +fechaInMillis + ".mp4"); cursor.close(); //runTranscodingUsingLoader(fileVideo.getAbsolutePath(), file.getAbsolutePath()); new Thread(new Runnable() { @Override public void run() { Bitmap thumbnailVideo = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Video.Thumbnails.MICRO_KIND); Bitmap toUpload = scaleDownLargeImageWithAspectRatio(thumbnailVideo, 1280); Bitmap binaryData = toUpload; Bitmap binaryData2 = BlurImage(toUpload); try { FileInputStream inStream = new FileInputStream(fileVideo); FileOutputStream outStream = new FileOutputStream(file); byte[] buffer = new byte[1024]; int length; //copy the file content in bytes while ((length = inStream.read(buffer)) > 0) { outStream.write(buffer, 0, length); } inStream.close(); outStream.close(); } catch (IOException e) { e.printStackTrace(); } try { final MsgGroups msjVideo = new MsgGroups(); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); String contactosId = null; if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (translate) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); contactosId += contact.idContacto; targets.put(targets.length(), newContact); } } } } } msjVideo.grupoId = grupo.grupoId; msjVideo.mensajeId = u.id + grupo.grupoId + fechaInMillis + Settings.Secure .getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID); msjVideo.emisor = u.id; msjVideo.receptores = targets.toString(); msjVideo.mensaje = "send Video"; msjVideo.emisorEmail = u.email; msjVideo.emisorLang = u.lang; msjVideo.translation = false; msjVideo.emitedAt = fechaInMillis; msjVideo.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_VIDEO)); msjVideo.delay = 0; ByteArrayOutputStream stream = new ByteArrayOutputStream(); binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream); byte[] byteArray = stream.toByteArray(); msjVideo.photo = byteArray; ByteArrayOutputStream stream2 = new ByteArrayOutputStream(); binaryData2.compress(Bitmap.CompressFormat.JPEG, 60, stream2); byte[] byteArray2 = stream2.toByteArray(); msjVideo.photoBlur = byteArray2; msjVideo.fileUploaded = false; msjVideo.videoName = file.getAbsolutePath(); msjVideo.save(); showNewMessage(msjVideo); dialogLoader.dismiss(); } catch (Exception e) { } System.gc(); } }).start(); } if (requestCode == 45) { milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); List<String> allProviders = milocManager.getAllProviders(); boolean gpsProvider = false; boolean netProvider = false; for (String providerName : allProviders) { if (providerName.equals(LocationManager.GPS_PROVIDER)) { gpsProvider = true; } if (providerName.equals(LocationManager.NETWORK_PROVIDER)) { netProvider = true; } } checkCountryLocation(gpsProvider, netProvider); } }