List of usage examples for android.content Intent setClassName
public @NonNull Intent setClassName(@NonNull String packageName, @NonNull String className)
From source file:android.app.Activity.java
/** * Called when the activity is starting. This is where most initialization * should go: calling {@link #setContentView(int)} to inflate the * activity's UI, using {@link #findViewById} to programmatically interact * with widgets in the UI, calling//from w ww.j av a 2 s . c o m * {@link #managedQuery(android.net.Uri , String[], String, String[], String)} to retrieve * cursors for data being displayed, etc. * * <p>You can call {@link #finish} from within this function, in * which case onDestroy() will be immediately called without any of the rest * of the activity lifecycle ({@link #onStart}, {@link #onResume}, * {@link #onPause}, etc) executing. * * <p><em>Derived classes must call through to the super class's * implementation of this method. If they do not, an exception will be * thrown.</em></p> * * @param savedInstanceState If the activity is being re-initialized after * previously being shut down then this Bundle contains the data it most * recently supplied in {@link #onSaveInstanceState}. <b><i>Note: Otherwise it is null.</i></b> * * @see #onStart * @see #onSaveInstanceState * @see #onRestoreInstanceState * @see #onPostCreate */ protected void onCreate(Bundle savedInstanceState) { if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState); if (mLastNonConfigurationInstances != null) { mAllLoaderManagers = mLastNonConfigurationInstances.loaders; } if (mActivityInfo.parentActivityName != null) { if (mActionBar == null) { mEnableDefaultActionBarUp = true; } else { mActionBar.setDefaultDisplayHomeAsUpEnabled(true); } } if (isAvailable()) { /* if this device can use the platform */ Log.w("MIGRATOR", "This is " + getLocalClassName()); Intent intent = getIntent(); Bundle tmpBundle = intent.getBundleExtra("MIGRATED"); ArrayList<Bundle> stacked = intent.getParcelableArrayListExtra("MIGRATED STACK"); if (tmpBundle != null) { /* true if this Activity was migrated */ if (stacked != null) { /* true if this Activity called next Activity */ Intent next = new Intent(); Bundle nextBundle = stacked.get(0); next.setClassName(nextBundle.getString("MIGRATED PNAME"), nextBundle.getString("MIGRATED CNAME")); next.putExtra("MIGRATED", nextBundle); stacked.remove(0); int code = tmpBundle.getInt("MIGRATED REQUEST CODE"); Bundle option = nextBundle.getBundle("MIGRATED REQUEST OPTIONS"); if (!stacked.isEmpty()) { /* store for next Activity */ next.putParcelableArrayListExtra("MIGRATED STACK", stacked); } Log.w("MIGRATOR", "Start ForResult: code=" + code); mReceiverStackFlag = true; mStackedNextIntent = next; mStackedNextCode = code; mStackedNextOption = option; } else { /* for debug */ Log.w("MIGRATOR", "stack is null"); } savedInstanceState = null; mMigFlag = true; migratedState = tmpBundle; Intent tmpIntent = tmpBundle.getParcelable("MIGRATED_INTENT"); if (tmpIntent != null) { tmpIntent.setAction(Intent.ACTION_MIGRATE); setIntent(tmpIntent); } /* File handling */ ArrayList<String> tmpNames = tmpBundle.getStringArrayList("TARGET_FILE_NAME"); if (tmpNames != null) { FileWorker fw = new FileWorker(tmpNames.toArray(new String[tmpNames.size()]), FileWorker.WRITE_MODE); fw.start(); tmpNames = null; } Log.w("MIGRATOR", "successed migaration: " + tmpBundle.toString()); tmpBundle = null; } else { /* for debug */ Log.w("MIGRATOR", "tmpBundle is null"); } } if (savedInstanceState != null) { Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); mFragments.restoreAllState(p, mLastNonConfigurationInstances != null ? mLastNonConfigurationInstances.fragments : null); } mFragments.dispatchCreate(); getApplication().dispatchActivityCreated(this, savedInstanceState); mCalled = true; }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private void forwardMessage(final MessageItem msgItem) { mTempThreadId = 0;/*from w ww . j ava 2 s .co m*/ // The user wants to forward the message. If the message is an mms message, we need to // persist the pdu to disk. This is done in a background task. // If the task takes longer than a half second, a progress dialog is displayed. // Once the PDU persisting is done, another runnable on the UI thread get executed to start // the ForwardMessageActivity. getAsyncDialog().runAsync(new Runnable() { @Override public void run() { // This runnable gets run in a background thread. if (msgItem.mType.equals("mms")) { SendReq sendReq = new SendReq(); String subject = getString(R.string.forward_prefix); if (msgItem.mSubject != null) { subject += msgItem.mSubject; } sendReq.setSubject(new EncodedStringValue(subject)); sendReq.setBody(msgItem.mSlideshow.makeCopy()); mTempMmsUri = null; try { PduPersister persister = PduPersister.getPduPersister(ComposeMessageActivity.this); // Copy the parts of the message here. mTempMmsUri = persister.persist(sendReq, Mms.Draft.CONTENT_URI, true, MessagingPreferenceActivity.getIsGroupMmsEnabled(ComposeMessageActivity.this), null); mTempThreadId = MessagingNotification.getThreadId(ComposeMessageActivity.this, mTempMmsUri); } catch (MmsException e) { Log.e(TAG, "Failed to copy message: " + msgItem.mMessageUri); Toast.makeText(ComposeMessageActivity.this, R.string.cannot_save_message, Toast.LENGTH_SHORT).show(); return; } } } }, new Runnable() { @Override public void run() { // Once the above background thread is complete, this runnable is run // on the UI thread. Intent intent = createIntent(ComposeMessageActivity.this, 0); intent.putExtra(KEY_EXIT_ON_SENT, true); intent.putExtra(KEY_FORWARDED_MESSAGE, true); if (mTempThreadId > 0) { intent.putExtra(THREAD_ID, mTempThreadId); } if (msgItem.mType.equals("sms")) { intent.putExtra("sms_body", msgItem.mBody); } else { intent.putExtra("msg_uri", mTempMmsUri); String subject = getString(R.string.forward_prefix); if (msgItem.mSubject != null) { subject += msgItem.mSubject; } intent.putExtra("subject", subject); String[] numbers = mConversation.getRecipients().getNumbers(); if (numbers != null) { intent.putExtra("msg_recipient", numbers[0]); } } // ForwardMessageActivity is simply an alias in the manifest for // ComposeMessageActivity. We have to make an alias because ComposeMessageActivity // launch flags specify singleTop. When we forward a message, we want to start a // separate ComposeMessageActivity. The only way to do that is to override the // singleTop flag, which is impossible to do in code. By creating an alias to the // activity, without the singleTop flag, we can launch a separate // ComposeMessageActivity to edit the forward message. intent.setClassName(ComposeMessageActivity.this, "com.android.mms.ui.ForwardMessageActivity"); startActivity(intent); } }, R.string.building_slideshow_title); }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
public void showMensajeLocation(int position, Context context, final MsgGroups message, View rowView, TextView icnMessageArrow) {//from w w w . j a v a2 s .c o m final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageTime = (TextView) rowView.findViewById(R.id.message_time); final TextView icnMesajeTempo = (TextView) rowView.findViewById(R.id.icn_message_tempo); final View icnMensajeTempoDivider = (View) rowView.findViewById(R.id.icn_message_tempo_divider); final TextView icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy); final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back); final ImageView messageContent = (ImageView) rowView.findViewById(R.id.message_content); TextView messageStatus = (TextView) rowView.findViewById(R.id.message_status); final LinearLayout messageMenu = (LinearLayout) rowView.findViewById(R.id.messages_menu_layout); final LinearLayout mensajeLayout = (LinearLayout) rowView.findViewById(R.id.mensaje_layout); TextView messageDate = (TextView) rowView.findViewById(R.id.message_date); TextView messageLocationText = (TextView) rowView.findViewById(R.id.message_location_text); TextView messageLocationIcon = (TextView) rowView.findViewById(R.id.message_location_icon); final CircleImageView imageUser = (CircleImageView) rowView.findViewById(R.id.chat_row_user_pic); final TextView userName = (TextView) rowView.findViewById(R.id.username_text); TFCache.apply(context, messageTime, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, icnMesajeTempo, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeCopy, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageLocationIcon, TFCache.TF_SPEAKALL); TFCache.apply(context, messageDate, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageLocationText, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, userName, TFCache.TF_WHITNEY_MEDIUM); if (position == 0) { if (mensajesTotal > mensajesOffset) { prevMessages.setVisibility(View.VISIBLE); prevMessages.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { prevMessages.setVisibility(View.GONE); if (mensajesTotal - mensajesOffset >= 10) { mensajesLimit = 10; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } else { mensajesLimit = mensajesTotal - mensajesOffset; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } } }); } } double latitud = 0; double longitud = 0; try { JSONObject locationData = new JSONObject(message.mensaje); messageLocationText.setText(locationData.getString("direccion")); latitud = Double.parseDouble(locationData.getString("latitud")); longitud = Double.parseDouble(locationData.getString("longitud")); } catch (JSONException e) { e.printStackTrace(); } DateFormat dateDay = new SimpleDateFormat("d"); DateFormat dateDayText = new SimpleDateFormat("EEEE"); DateFormat dateMonth = new SimpleDateFormat("MMMM"); DateFormat dateYear = new SimpleDateFormat("yyyy"); DateFormat timeFormat = new SimpleDateFormat("h:mm a"); Calendar fechamsj = Calendar.getInstance(); fechamsj.setTimeInMillis(message.emitedAt); String time = timeFormat.format(fechamsj.getTime()); String dayMessage = dateDay.format(fechamsj.getTime()); String monthMessage = dateMonth.format(fechamsj.getTime()); String yearMessage = dateYear.format(fechamsj.getTime()); String dayMessageText = dateDayText.format(fechamsj.getTime()); char[] caracteres = dayMessageText.toCharArray(); caracteres[0] = Character.toUpperCase(caracteres[0]); dayMessageText = new String(caracteres); Calendar fechaActual = Calendar.getInstance(); String dayActual = dateDay.format(fechaActual.getTime()); String monthActual = dateMonth.format(fechaActual.getTime()); String yearActual = dateYear.format(fechaActual.getTime()); String fechaMostrar = ""; if (dayMessage.equals(dayActual) && monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { fechaMostrar = getString(R.string.messages_today); } else if (monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { int days = Integer.parseInt(dayActual) - Integer.parseInt(dayMessage); if (days < 7) { switch (days) { case 1: fechaMostrar = getString(R.string.messages_yesterday); break; default: fechaMostrar = dayMessageText; break; } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } messageDate.setText(fechaMostrar); if (position != -1) { if (itemAnterior != null) { if (!fechaMostrar.equals(fechaAnterior)) { itemAnterior.findViewById(R.id.message_date).setVisibility(View.VISIBLE); } else { itemAnterior.findViewById(R.id.message_date).setVisibility(View.GONE); } } itemAnterior = rowView; fechaAnterior = fechaMostrar; } else { View v = messagesList.getChildAt(messagesList.getChildCount() - 1); if (v != null) { TextView tv = (TextView) v.findViewById(R.id.message_date); if (tv.getText().toString().equals(fechaMostrar)) { messageDate.setVisibility(View.GONE); } else { messageDate.setVisibility(View.VISIBLE); } } } messageTime.setText(time); if (message.emisor.equals(u.id)) { int status = 0; try { JSONArray contactos = new JSONArray(message.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); Log.w("STATUS", contacto.getInt("status") + contacto.getString("name")); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } if (status != -1) { rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(30); MsgGroups mensaje = new Select().from(MsgGroups.class) .where("mensajeId = ?", message.mensajeId).executeSingle(); int status = 0; try { JSONArray contactos = new JSONArray(mensaje.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } if (status != 4) { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } else { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } return false; } }); } if (status == 1) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(getResources().getColor(R.color.speak_all_disable_red)); messageStatus.setTextColor(getResources().getColor(R.color.speak_all_ligh_gray)); messageStatus.setText(Finder.STRING.ICN_MSJ_SENDING.toString()); ValueAnimator colorAnim = ObjectAnimator.ofFloat(messageStatus, "alpha", 1, 0); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.setDuration(1000).start(); animaciones.put(message.mensajeId, colorAnim); JSONObject data = new JSONObject(); try { data.put("type", message.tipo); data.put("group_id", message.grupoId); data.put("group_name", grupo.nombreGrupo); data.put("source", message.emisor); data.put("source_lang", message.emisorLang); data.put("source_email", message.emisorEmail); data.put("message", message.mensaje); data.put("translation_required", message.translation); data.put("message_id", message.mensajeId); data.put("delay", message.delay); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); 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 (message.translation) 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); targets.put(targets.length(), newContact); } } } data.put("targets", targets); message.receptores = targets.toString(); message.save(); SpeakSocket.mSocket.emit("message", data); } 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 (message.translation) 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); targets.put(targets.length(), newContact); } } } message.receptores = targets.toString(); message.save(); } changeStatus(message.mensajeId); } } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } } if (status == -1) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString()); } if (status == 3) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString()); } if (status == 2) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString()); } if (status == 4) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_OPENED.toString()); } } else { final Contact contacto = new Select().from(Contact.class).where(" id_contact= ?", message.emisor) .executeSingle(); if (contacto != null) { new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { if (contacto.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(contacto.photo, 0, contacto.photo.length); imageUser.setImageBitmap(bmp); userName.setText(contacto.fullName); } } }); } }).start(); } rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(20); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", -100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", -150, 0)); set.setDuration(200).start(); return false; } }); } icnMesajeBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (message.emisor.equals(u.id)) { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensaje)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } else { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensajeTrad)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } } }); final double finalLatitud = latitud; final double finalLongitud = longitud; rowView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MsgGroups mensaje = new Select().from(MsgGroups.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); int status = 0; try { JSONArray contactos = new JSONArray(mensaje.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); if (!messageSelected.equals(message.mensajeId)) { vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } else { if (status != -1) { dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + finalLatitud + "," + finalLongitud)); i.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(i); } } if (status == -1) { JSONObject data = new JSONObject(); try { data.put("type", mensaje.tipo); data.put("group_id", mensaje.grupoId); data.put("group_name", grupo.nombreGrupo); data.put("source", mensaje.emisor); data.put("source_lang", mensaje.emisorLang); data.put("source_email", mensaje.emisorEmail); data.put("message", mensaje.mensaje); data.put("translation_required", mensaje.translation); data.put("message_id", mensaje.mensajeId); data.put("delay", mensaje.delay); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); 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 (mensaje.translation) 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); targets.put(targets.length(), newContact); } } } data.put("targets", targets); mensaje.receptores = targets.toString(); mensaje.save(); SpeakSocket.mSocket.emit("message", data); } 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 (mensaje.translation) 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); targets.put(targets.length(), newContact); } } } mensaje.receptores = targets.toString(); mensaje.save(); } changeStatus(mensaje.mensajeId); } } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } } } }); }
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
public void showMensajeLocation(int position, Context context, final Message message, View rowView, TextView icnMessageArrow) {/* w w w . j a va2 s .c o m*/ final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageTime = (TextView) rowView.findViewById(R.id.message_time); final TextView icnMesajeTempo = (TextView) rowView.findViewById(R.id.icn_message_tempo); final View icnMensajeTempoDivider = (View) rowView.findViewById(R.id.icn_message_tempo_divider); final TextView icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy); final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back); final ImageView messageContent = (ImageView) rowView.findViewById(R.id.message_content); TextView messageStatus = (TextView) rowView.findViewById(R.id.message_status); final LinearLayout messageMenu = (LinearLayout) rowView.findViewById(R.id.messages_menu_layout); final LinearLayout mensajeLayout = (LinearLayout) rowView.findViewById(R.id.mensaje_layout); TextView messageDate = (TextView) rowView.findViewById(R.id.message_date); TextView messageLocationText = (TextView) rowView.findViewById(R.id.message_location_text); TextView messageLocationIcon = (TextView) rowView.findViewById(R.id.message_location_icon); TFCache.apply(context, messageTime, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, icnMesajeTempo, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeCopy, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageLocationIcon, TFCache.TF_SPEAKALL); TFCache.apply(context, messageDate, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageLocationText, TFCache.TF_WHITNEY_MEDIUM); if (position == 0) { if (mensajesTotal > mensajesOffset) { prevMessages.setVisibility(View.VISIBLE); prevMessages.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { prevMessages.setVisibility(View.GONE); if (mensajesTotal - mensajesOffset >= 10) { mensajesLimit = 10; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } else { mensajesLimit = mensajesTotal - mensajesOffset; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } } }); } } double latitud = 0; double longitud = 0; try { JSONObject locationData = new JSONObject(message.mensaje); messageLocationText.setText(locationData.getString("direccion")); latitud = Double.parseDouble(locationData.getString("latitud")); longitud = Double.parseDouble(locationData.getString("longitud")); } catch (JSONException e) { e.printStackTrace(); } DateFormat dateDay = new SimpleDateFormat("d"); DateFormat dateDayText = new SimpleDateFormat("EEEE"); DateFormat dateMonth = new SimpleDateFormat("MMMM"); DateFormat dateYear = new SimpleDateFormat("yyyy"); DateFormat timeFormat = new SimpleDateFormat("h:mm a"); Calendar fechamsj = Calendar.getInstance(); fechamsj.setTimeInMillis(message.emitedAt); String time = timeFormat.format(fechamsj.getTime()); String dayMessage = dateDay.format(fechamsj.getTime()); String monthMessage = dateMonth.format(fechamsj.getTime()); String yearMessage = dateYear.format(fechamsj.getTime()); String dayMessageText = dateDayText.format(fechamsj.getTime()); char[] caracteres = dayMessageText.toCharArray(); caracteres[0] = Character.toUpperCase(caracteres[0]); dayMessageText = new String(caracteres); Calendar fechaActual = Calendar.getInstance(); String dayActual = dateDay.format(fechaActual.getTime()); String monthActual = dateMonth.format(fechaActual.getTime()); String yearActual = dateYear.format(fechaActual.getTime()); String fechaMostrar = ""; if (dayMessage.equals(dayActual) && monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { fechaMostrar = getString(R.string.messages_today); } else if (monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { int days = Integer.parseInt(dayActual) - Integer.parseInt(dayMessage); if (days < 7) { switch (days) { case 1: fechaMostrar = getString(R.string.messages_yesterday); break; default: fechaMostrar = dayMessageText; break; } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } messageDate.setText(fechaMostrar); if (position != -1) { if (itemAnterior != null) { if (!fechaMostrar.equals(fechaAnterior)) { itemAnterior.findViewById(R.id.message_date).setVisibility(View.VISIBLE); } else { itemAnterior.findViewById(R.id.message_date).setVisibility(View.GONE); } } itemAnterior = rowView; fechaAnterior = fechaMostrar; } else { View v = messagesList.getChildAt(messagesList.getChildCount() - 1); if (v != null) { TextView tv = (TextView) v.findViewById(R.id.message_date); if (tv.getText().toString().equals(fechaMostrar)) { messageDate.setVisibility(View.GONE); } else { messageDate.setVisibility(View.VISIBLE); } } } messageTime.setText(time); if (message.emisor.equals(u.id)) { if (message.status != -1) { rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(30); Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { icnMesajeTempo.setVisibility(View.VISIBLE); icnMensajeTempoDivider.setVisibility(View.VISIBLE); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeTempo, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeTempo, "translationX", 150, 0), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } else { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } return false; } }); } if (message.status == 1) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setTextColor(getResources().getColor(R.color.speak_all_ligh_gray)); messageStatus.setText(Finder.STRING.ICN_MSJ_SENDING.toString()); ValueAnimator colorAnim = ObjectAnimator.ofFloat(messageStatus, "alpha", 1, 0); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.setDuration(1000).start(); animaciones.put(message.mensajeId, colorAnim); JSONObject data = new JSONObject(); try { data.put("message_id", message.mensajeId); data.put("source", message.emisor); data.put("source_email", message.emisorEmail); data.put("target_email", message.receptorEmail); data.put("target", message.receptor); data.put("message", message.mensaje); data.put("source_lang", message.emisorLang); data.put("delay", message.delay); data.put("type", message.tipo); } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { message.status = 1; SpeakSocket.mSocket.emit("message", data); } else { message.status = -1; } } if (message.status == -1) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString()); } if (message.status == 3) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString()); } if (message.status == 2) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString()); } if (message.status == 4) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_OPENED.toString()); icnMensajeTempoDivider.setVisibility(View.GONE); icnMesajeTempo.setVisibility(View.GONE); } else { icnMensajeTempoDivider.setVisibility(View.INVISIBLE); icnMesajeTempo.setVisibility(View.INVISIBLE); } } else { mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getFriendBalloon(activity)); if (message.tipo == Integer.parseInt(getString(R.string.MSG_TYPE_BROADCAST_PHOTO))) { messageStatus.setTextSize(15); messageStatus.setText(Finder.STRING.ICN_BROADCAST_FILL.toString()); } //messageContent.setText(message.mensajeTrad); icnMesajeTempo.setVisibility(View.GONE); rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(20); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", -100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", -150, 0)); set.setDuration(200).start(); return false; } }); } icnMesajeTempo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { JSONObject notifyMessage = new JSONObject(); try { Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { notifyMessage.put("type", mensaje.tipo); notifyMessage.put("message_id", mensaje.mensajeId); notifyMessage.put("source", mensaje.receptor); notifyMessage.put("status", 5); SpeakSocket.mSocket.emit("message-status", notifyMessage); } new Delete().from(Message.class).where("mensajeId = ?", mensaje.mensajeId).execute(); Message message = null; if (mensaje.emisor.equals(u.id)) { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.receptor, mensaje.receptor) .orderBy("emitedAt DESC").executeSingle(); } else { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.emisor, mensaje.emisor) .orderBy("emitedAt DESC").executeSingle(); } if (message != null) { Chats chat = null; if (mensaje.emisor.equals(u.id)) { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.receptor) .executeSingle(); } else { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.emisor) .executeSingle(); } if (chat != null) { chat.mensajeId = message.mensajeId; chat.lastStatus = message.status; chat.emitedAt = message.emitedAt; chat.lang = message.emisorLang; chat.notRead = 0; if (chat.idContacto.equals(message.emisor)) chat.lastMessage = message.mensajeTrad; else chat.lastMessage = message.mensaje; chat.save(); } } else { if (mensaje.emisor.equals(u.id)) { new Delete().from(Chats.class).where("idContacto = ?", mensaje.receptor).execute(); } else { new Delete().from(Chats.class).where("idContacto = ?", mensaje.emisor).execute(); } } View delete = messagesList.findViewWithTag(mensaje.mensajeId); if (delete != null) messagesList.removeView(delete); messageSelected = null; ((MainActivity) activity).setOnBackPressedListener(null); } catch (JSONException e) { e.printStackTrace(); } } } ); icnMesajeCopy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*ClipData clip = ClipData.newPlainText("text", messageContent.getText().toString()); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(clip); Toast.makeText(activity, "Copiado", Toast.LENGTH_SHORT).show();*/ } } ); icnMesajeBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (message.emisor.equals(u.id)) { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensaje)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } else { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensajeTrad)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } } } ); final double finalLatitud = latitud; final double finalLongitud = longitud; rowView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); if (!messageSelected.equals(message.mensajeId)) { vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } else { if (mensaje.status != -1) { dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + finalLatitud + "," + finalLongitud)); i.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(i); } } if (mensaje.status == -1) { JSONObject data = new JSONObject(); try { data.put("message_id", mensaje.mensajeId); data.put("source", mensaje.emisor); data.put("source_email", mensaje.emisorEmail); data.put("target_email", mensaje.receptorEmail); data.put("target", mensaje.receptor); data.put("message", message.mensaje); data.put("source_lang", mensaje.emisorLang); data.put("delay", mensaje.delay); data.put("type", mensaje.tipo); } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { mensaje.status = 1; SpeakSocket.mSocket.emit("message", data); } else { mensaje.status = -1; } changeStatus(mensaje.mensajeId, mensaje.status); } } } ); }
From source file:com.zoffcc.applications.zanavi.Navit.java
@SuppressLint("NewApi") public boolean onOptionsItemSelected_wrapper(int id) { // Handle item selection switch (id) { case 1:/* ww w. j a v a 2 s . co m*/ // zoom in Message msg = new Message(); Bundle b = new Bundle(); b.putInt("Callback", 1); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); // if we zoom, hide the bubble if (N_NavitGraphics.NavitAOverlay != null) { N_NavitGraphics.NavitAOverlay.hide_bubble(); } Log.e("Navit", "onOptionsItemSelected -> zoom in"); break; case 2: // zoom out msg = new Message(); b = new Bundle(); b.putInt("Callback", 2); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); // if we zoom, hide the bubble if (N_NavitGraphics.NavitAOverlay != null) { N_NavitGraphics.NavitAOverlay.hide_bubble(); } Log.e("Navit", "onOptionsItemSelected -> zoom out"); break; case 3: // map download menu Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class); this.startActivityForResult(map_download_list_activity, Navit.NavitDownloaderPriSelectMap_id); break; case 5: toggle_poi_pref(); set_poi_layers(); draw_map(); break; case 6: // ok startup address search activity (online google maps search) Navit.use_index_search = false; Intent search_intent = new Intent(this, NavitAddressSearchActivity.class); search_intent.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS search_intent.putExtra("address_string", Navit_last_address_search_string); //search_intent.putExtra("hn_string", Navit_last_address_hn_string); search_intent.putExtra("type", "online"); String pm_temp = "0"; if (Navit_last_address_partial_match) { pm_temp = "1"; } search_intent.putExtra("partial_match", pm_temp); this.startActivityForResult(search_intent, NavitAddressSearch_id_online); break; case 7: // ok startup address search activity (offline binfile search) Navit.use_index_search = Navit.allow_use_index_search(); Intent search_intent2 = new Intent(this, NavitAddressSearchActivity.class); search_intent2.putExtra("title", Navit.get_text("Enter: City and Street")); //TRANS search_intent2.putExtra("address_string", Navit_last_address_search_string); search_intent2.putExtra("hn_string", Navit_last_address_hn_string); search_intent2.putExtra("type", "offline"); search_intent2.putExtra("search_country_id", Navit_last_address_search_country_id); String pm_temp2 = "0"; if (Navit_last_address_partial_match) { pm_temp2 = "1"; } search_intent2.putExtra("partial_match", pm_temp2); this.startActivityForResult(search_intent2, NavitAddressSearch_id_offline); break; case 8: // map delete menu Intent map_delete_list_activity2 = new Intent(this, NavitDeleteSelectMapActivity.class); this.startActivityForResult(map_delete_list_activity2, Navit.NavitDeleteSecSelectMap_id); break; case 9: // stop navigation (this menu should only appear when navigation is actually on!) Message msg2 = new Message(); Bundle b2 = new Bundle(); b2.putInt("Callback", 7); msg2.setData(b2); NavitGraphics.callback_handler.sendMessage(msg2); Log.e("Navit", "stop navigation"); break; case 10: // open settings menu Intent settingsActivity = new Intent(getBaseContext(), NavitPreferences.class); startActivity(settingsActivity); break; case 11: //zoom_to_route zoom_to_route(); break; case 12: // --------- make app crash --------- // --------- make app crash --------- // --------- make app crash --------- // ** // DEBUG // ** // crash_app_java(1); // ** // DEBUG // ** // crash_app_C(); // --------- make app crash --------- // --------- make app crash --------- // --------- make app crash --------- // announcer off Navit_Announcer = false; msg = new Message(); b = new Bundle(); b.putInt("Callback", 34); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); try { invalidateOptionsMenu(); } catch (Exception e) { } break; case 13: // announcer on Navit_Announcer = true; msg = new Message(); b = new Bundle(); b.putInt("Callback", 35); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); try { invalidateOptionsMenu(); } catch (Exception e) { } break; case 14: // show recent destination list Intent i2 = new Intent(this, NavitRecentDestinationActivity.class); this.startActivityForResult(i2, Navit.NavitRecentDest_id); break; case 15: // show current target on googlemaps String current_target_string = NavitGraphics.CallbackGeoCalc(4, 1, 1); // Log.e("Navit", "got target 1: "+current_target_string); if (current_target_string.equals("x:x")) { Log.e("Navit", "no target set!"); } else { try { String tmp[] = current_target_string.split(":", 2); googlemaps_show(tmp[0], tmp[1], "ZANavi Target"); } catch (Exception e) { e.printStackTrace(); Log.e("Navit", "problem with target!"); } } break; case 16: // show online manual Log.e("Navit", "user wants online help, show the website lang=" + NavitTextTranslations.main_language.toLowerCase()); // URL to ZANavi Manual (in english language) String url = "http://zanavi.cc/index.php/Manual"; if (FDBL) { url = "http://fd.zanavi.cc/manual"; } if (NavitTextTranslations.main_language.toLowerCase().equals("de")) { // show german manual url = "http://zanavi.cc/index.php/Manual/de"; if (FDBL) { url = "http://fd.zanavi.cc/manualde"; } } Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); break; case 17: // show age of maps (online) Intent i3 = new Intent(Intent.ACTION_VIEW); i3.setData(Uri.parse(NavitMapDownloader.ZANAVI_MAPS_AGE_URL)); startActivity(i3); break; case 18: Intent intent_latlon = new Intent(Intent.ACTION_MAIN); //intent_latlon.setAction("android.intent.action.POINTPICK"); intent_latlon.setPackage("com.cruthu.latlongcalc1"); intent_latlon.setClassName("com.cruthu.latlongcalc1", "com.cruthu.latlongcalc1.LatLongMain"); //intent_latlon.setClassName("com.cruthu.latlongcalc1", "com.cruthu.latlongcalc1.LatLongPointPick"); try { startActivity(intent_latlon); } catch (Exception e88) { e88.printStackTrace(); // show install page try { // String urlx = "http://market.android.com/details?id=com.cruthu.latlongcalc1"; String urlx = "market://details?id=com.cruthu.latlongcalc1"; Intent ix = new Intent(Intent.ACTION_VIEW); ix.setData(Uri.parse(urlx)); startActivity(ix); } catch (Exception ex) { ex.printStackTrace(); } } break; case 19: // GeoCoordEnterDialog Intent it001 = new Intent(this, GeoCoordEnterDialog.class); this.startActivityForResult(it001, Navit.NavitGeoCoordEnter_id); break; case 20: // convert GPX file Intent intent77 = new Intent(getBaseContext(), FileDialog.class); File a = new File(p.PREF_last_selected_dir_gpxfiles); try { // convert the "/../" in the path to normal absolut dir intent77.putExtra(FileDialog.START_PATH, a.getCanonicalPath()); //can user select directories or not intent77.putExtra(FileDialog.CAN_SELECT_DIR, false); // disable the "new" button intent77.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN); //alternatively you can set file filter //intent.putExtra(FileDialog.FORMAT_FILTER, new String[] { "gpx" }); startActivityForResult(intent77, Navit.NavitGPXConvChooser_id); } catch (IOException e1) { e1.printStackTrace(); } break; case 21: // add traffic block (like blocked road, or construction site) at current location of crosshair try { String traffic = ""; if (Navit.GFX_OVERSPILL) { traffic = NavitGraphics.CallbackGeoCalc(7, (int) (NavitGraphics.Global_dpi_factor * (NavitGraphics.mCanvasWidth / 2 + NavitGraphics.mCanvasWidth_overspill)), (int) (NavitGraphics.Global_dpi_factor * (NavitGraphics.mCanvasHeight / 2 + NavitGraphics.mCanvasHeight_overspill))); } else { traffic = NavitGraphics.CallbackGeoCalc(7, (int) (NavitGraphics.Global_dpi_factor * NavitGraphics.mCanvasWidth / 2), (int) (NavitGraphics.Global_dpi_factor * NavitGraphics.mCanvasHeight / 2)); } // System.out.println("traffic=" + traffic); File traffic_file_dir = new File(MAP_FILENAME_PATH); traffic_file_dir.mkdirs(); File traffic_file = new File(MAP_FILENAME_PATH + "/traffic.txt"); FileOutputStream fOut = null; OutputStreamWriter osw = null; try { fOut = new FileOutputStream(traffic_file, true); osw = new OutputStreamWriter(fOut); osw.write("type=traffic_distortion maxspeed=0" + "\n"); // item header osw.write(traffic); // item coordinates osw.close(); fOut.close(); } catch (Exception ef) { ef.printStackTrace(); } // update route, if a route is set msg = new Message(); b = new Bundle(); b.putInt("Callback", 73); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); // draw map no-async msg = new Message(); b = new Bundle(); b.putInt("Callback", 64); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); } catch (Exception e) { e.printStackTrace(); } break; case 22: // clear all traffic blocks try { File traffic_file = new File(MAP_FILENAME_PATH + "/traffic.txt"); traffic_file.delete(); // update route, if a route is set msg = new Message(); b = new Bundle(); b.putInt("Callback", 73); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); // draw map no-async msg = new Message(); b = new Bundle(); b.putInt("Callback", 64); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); } catch (Exception e) { } break; case 23: // clear all GPX maps try { File gpx_file = new File(MAP_FILENAME_PATH + "/gpxtracks.txt"); gpx_file.delete(); // draw map no-async msg = new Message(); b = new Bundle(); b.putInt("Callback", 64); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); } catch (Exception e) { } break; case 24: // show feedback form Intent i4 = new Intent(this, NavitFeedbackFormActivity.class); this.startActivityForResult(i4, Navit.NavitSendFeedback_id); break; case 25: // share the current destination with your friends String current_target_string2 = NavitGraphics.CallbackGeoCalc(4, 1, 1); if (current_target_string2.equals("x:x")) { Log.e("Navit", "no target set!"); } else { try { String tmp[] = current_target_string2.split(":", 2); if (Navit.OSD_route_001.arriving_time_valid) { share_location(tmp[0], tmp[1], Navit.get_text("Meeting Point"), Navit.get_text("Meeting Point"), Navit.OSD_route_001.arriving_time, true); } else { share_location(tmp[0], tmp[1], Navit.get_text("Meeting Point"), Navit.get_text("Meeting Point"), "", true); } } catch (Exception e) { e.printStackTrace(); Log.e("Navit", "problem with target!"); } } break; case 26: // donate Log.e("Navit", "start donate app"); donate(); break; case 27: // donate Log.e("Navit", "donate bitcoins"); donate_bitcoins(); break; case 28: // replay GPS file Intent intent771 = new Intent(getBaseContext(), FileDialog.class); File a1 = new File(Navit.NAVIT_DATA_DEBUG_DIR); try { // convert the "/../" in the path to normal absolut dir intent771.putExtra(FileDialog.START_PATH, a1.getCanonicalPath()); //can user select directories or not intent771.putExtra(FileDialog.CAN_SELECT_DIR, false); // disable the "new" button intent771.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN); //alternatively you can set file filter intent771.putExtra(FileDialog.FORMAT_FILTER, new String[] { "txt", "yaml" }); startActivityForResult(intent771, Navit.NavitReplayFileConvChooser_id); } catch (IOException e1) { e1.printStackTrace(); } break; case 29: // About Screen Intent it002 = new Intent(this, ZANaviAboutPage.class); this.startActivityForResult(it002, Navit.ZANaviAbout_id); break; case 88: // dummy entry, just to make "breaks" in the menu break; case 601: // DEBUG: activate demo vehicle and set position to position to screen center Navit.DemoVehicle = true; msg = new Message(); b = new Bundle(); b.putInt("Callback", 101); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); final Thread demo_v_001 = new Thread() { @Override public void run() { try { Thread.sleep(1000); // wait 1 seconds before we start try { float lat = 0; float lon = 0; String lat_lon = ""; if (Navit.GFX_OVERSPILL) { lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * (NG__map_main.view.getWidth() / 2 + NavitGraphics.mCanvasWidth_overspill), NavitGraphics.Global_dpi_factor * (NG__map_main.view.getHeight() / 2 + NavitGraphics.mCanvasHeight_overspill)); } else { lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * NG__map_main.view.getWidth() / 2, NavitGraphics.Global_dpi_factor * NG__map_main.view.getHeight() / 2); } String tmp[] = lat_lon.split(":", 2); //System.out.println("tmp=" + lat_lon); lat = Float.parseFloat(tmp[0]); lon = Float.parseFloat(tmp[1]); //System.out.println("ret=" + lat_lon + " lat=" + lat + " lon=" + lon); Location l = null; l = new Location("ZANavi Demo 001"); l.setLatitude(lat); l.setLongitude(lon); l.setBearing(0.0f); l.setSpeed(0); l.setAccuracy(4.0f); // accuracy 4 meters // NavitVehicle.update_compass_heading(0.0f); NavitVehicle.set_mock_location__fast(l); } catch (Exception e) { } Message msg = new Message(); Bundle b = new Bundle(); b.putInt("Callback", 52); b.putString("s", "45"); // speed in km/h of Demo-Vehicle // b.putString("s", "20"); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); } catch (Exception e) { } } }; demo_v_001.start(); msg = new Message(); b = new Bundle(); b.putInt("Callback", 51); if (Navit.GFX_OVERSPILL) { b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getWidth() / 2) + NavitGraphics.mCanvasWidth_overspill))); b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getHeight() / 2) + NavitGraphics.mCanvasHeight_overspill))); } else { b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getWidth() / 2)); b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getHeight() / 2)); } msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); break; case 602: // DEBUG: toggle textview with spoken and translated string (to help with translation) try { if (NavitGraphics.NavitMsgTv2_.getVisibility() == View.VISIBLE) { NavitGraphics.NavitMsgTv2_.setVisibility(View.GONE); NavitGraphics.NavitMsgTv2_.setEnabled(false); NavitGraphics.NavitMsgTv2sc_.setVisibility(View.GONE); NavitGraphics.NavitMsgTv2sc_.setEnabled(false); } else { NavitGraphics.NavitMsgTv2sc_.setVisibility(View.VISIBLE); NavitGraphics.NavitMsgTv2sc_.setEnabled(true); NavitGraphics.NavitMsgTv2_.setVisibility(View.VISIBLE); NavitGraphics.NavitMsgTv2_.setEnabled(true); } } catch (Exception e) { e.printStackTrace(); } break; case 603: // DEBUG: show all possible navigation commands (also translated) NavitGraphics.generate_all_speech_commands(); break; case 604: // DEBUG: activate FAST driving demo vehicle and set position to screen center Navit.DemoVehicle = true; msg = new Message(); b = new Bundle(); b.putInt("Callback", 52); b.putString("s", "800"); // speed in ~km/h of Demo-Vehicle msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); msg = new Message(); b = new Bundle(); b.putInt("Callback", 51); if (Navit.GFX_OVERSPILL) { b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getWidth() / 2) + NavitGraphics.mCanvasWidth_overspill))); b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * ((Navit.NG__map_main.view.getHeight() / 2) + NavitGraphics.mCanvasHeight_overspill))); } else { b.putInt("x", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getWidth() / 2)); b.putInt("y", (int) (NavitGraphics.Global_dpi_factor * Navit.NG__map_main.view.getHeight() / 2)); } msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); try { float lat = 0; float lon = 0; lat = 0; lon = 0; String lat_lon = ""; if (Navit.GFX_OVERSPILL) { lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * (NG__map_main.view.getWidth() / 2 + NavitGraphics.mCanvasWidth_overspill), NavitGraphics.Global_dpi_factor * (NG__map_main.view.getHeight() / 2 + NavitGraphics.mCanvasHeight_overspill)); } else { lat_lon = NavitGraphics.CallbackGeoCalc(1, NavitGraphics.Global_dpi_factor * NG__map_main.view.getWidth() / 2, NavitGraphics.Global_dpi_factor * NG__map_main.view.getHeight() / 2); } String tmp[] = lat_lon.split(":", 2); //System.out.println("tmp=" + lat_lon); lat = Float.parseFloat(tmp[0]); lon = Float.parseFloat(tmp[1]); //System.out.println("ret=" + lat_lon + " lat=" + lat + " lon=" + lon); Location l = null; l = new Location("ZANavi Demo 001"); l.setLatitude(lat); l.setLongitude(lon); l.setBearing(0.0f); l.setSpeed(0); l.setAccuracy(4.0f); // accuracy 4 meters // NavitVehicle.update_compass_heading(0.0f); NavitVehicle.set_mock_location__fast(l); } catch (Exception e) { } break; case 605: // DEBUG: toggle Routgraph on/off msg = new Message(); b = new Bundle(); b.putInt("Callback", 71); Navit.Routgraph_enabled = 1 - Navit.Routgraph_enabled; b.putString("s", "" + Navit.Routgraph_enabled); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); break; case 606: // DEBUG: spill contents of index file(s) msg = new Message(); b = new Bundle(); b.putInt("Callback", 83); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); break; case 607: export_map_points_to_sdcard(); break; case 608: import_map_points_from_sdcard(); break; case 609: // run yaml tests new Thread() { public void run() { try { ZANaviDebugReceiver.DR_run_all_yaml_tests(); } catch (Exception e) { } } }.start(); break; case 99: try { if (wl_navigating != null) { //if (wl_navigating.isHeld()) //{ wl_navigating.release(); Log.e("Navit", "WakeLock Nav: release 1"); //} } } catch (Exception e) { e.printStackTrace(); } // exit this.onPause(); this.onStop(); this.exit(); //msg = new Message(); //b = new Bundle(); //b.putInt("Callback", 5); //b.putString("cmd", "quit();"); //msg.setData(b); //N_NavitGraphics.callback_handler.sendMessage(msg); break; } return true; }
From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java
public void show_app_manager_click() { if (getConfig().getBoolean("vibration", false)) { this.vib = ((Vibrator) getContext().getSystemService("vibrator")); this.vib.vibrate(50L); }//from ww w . j av a2 s . c om if (Build.VERSION.SDK_INT >= 9) { } for (;;) { try { Intent localIntent1 = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS", Uri.parse("package:" + pli.pkgName)); localIntent1.setFlags(131072); startActivity(localIntent1); return_from_control_panel = true; return; } catch (ActivityNotFoundException localActivityNotFoundException1) { try { Intent localIntent2 = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS"); localIntent2.setData(Uri.parse("package:" + pli.pkgName)); localIntent2.setFlags(131072); startActivity(localIntent2); } catch (ActivityNotFoundException localActivityNotFoundException2) { startActivity(new Intent("android.settings.MANAGE_APPLICATIONS_SETTINGS")); } continue; } Intent localIntent3 = new Intent("android.intent.action.VIEW"); localIntent3.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails"); localIntent3.putExtra("com.android.settings.ApplicationPkgName", pli.pkgName); localIntent3.putExtra("pkg", pli.pkgName); localIntent3.setFlags(131072); startActivity(localIntent3); } }