Example usage for android.text Html fromHtml

List of usage examples for android.text Html fromHtml

Introduction

In this page you can find the example usage for android.text Html fromHtml.

Prototype

@Deprecated
public static Spanned fromHtml(String source) 

Source Link

Document

Returns displayable styled text from the provided HTML string with the legacy flags #FROM_HTML_MODE_LEGACY .

Usage

From source file:com.bookkos.bircle.CaptureActivity.java

private void setScanUnregisterBookView() {

    int registSelectShelfRelativeLayout_width = displayWidth;
    int registSelectShelfRelativeLayout_height = displayHeight / 3;
    int registSelectShelfRelativeLayout_x = 0;
    int registSelectShelfRelativeLayout_y = displayHeight;
    registSelectShelfRelativeLayout.setTranslationX(registSelectShelfRelativeLayout_x);
    registSelectShelfRelativeLayout.setTranslationY(registSelectShelfRelativeLayout_y);
    registSelectShelfRelativeLayout.setLayoutParams(new FrameLayout.LayoutParams(
            registSelectShelfRelativeLayout_width, registSelectShelfRelativeLayout_height));
    //registSelectShelfRelativeLayout.setVisibility(View.GONE);

    int textViewLinearLayout_width = displayWidth;
    int textViewLinearLayout_height = registSelectShelfRelativeLayout_height / 4;
    textViewLinearLayout.setLayoutParams(
            new RelativeLayout.LayoutParams(textViewLinearLayout_width, textViewLinearLayout_height));
    RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) textViewLinearLayout.getLayoutParams();
    //      params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    textViewLinearLayout.setLayoutParams(params1);

    String tempText = "<font color=#3498db>?????!</font><br />?????????QR???, ?????\"\"????";
    tempTextView.setText(Html.fromHtml(tempText));
    tempTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize - displayInch * 1.5f);

    int buttonLinearLayout_width = displayWidth;
    int buttonLinearLayout_height = registSelectShelfRelativeLayout_height / 4;
    int buttonLinearLayout_x = 0;
    int buttonLinearLayout_y = displayHeight;
    //      buttonLinearLayout.setTranslationX(buttonLinearLayout_x);
    //      buttonLinearLayout.setTranslationY(buttonLinearLayout_y);
    buttonLinearLayout.setLayoutParams(/*w w  w  . j  av a 2 s . co  m*/
            new RelativeLayout.LayoutParams(buttonLinearLayout_width, buttonLinearLayout_height));
    RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) buttonLinearLayout.getLayoutParams();
    params2.addRule(RelativeLayout.BELOW, R.id.text_view_linear_layout);
    buttonLinearLayout.setLayoutParams(params2);

    int listViewLinearLayout_width = displayWidth;
    int listViewLinearLayout_height = registSelectShelfRelativeLayout_height / 2;
    int listViewLinearLayout_x = 0;
    int listViewLinearLayout_y = displayHeight;
    //      listViewLinearLayout.setTranslationX(listViewLinearLayout_x);
    //      listViewLinearLayout.setTranslationY(listViewLinearLayout_y);
    listViewLinearLayout.setLayoutParams(
            new RelativeLayout.LayoutParams(listViewLinearLayout_width, listViewLinearLayout_height));
    RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams) listViewLinearLayout.getLayoutParams();
    params3.addRule(RelativeLayout.BELOW, R.id.button_linear_layout);
    listViewLinearLayout.setLayoutParams(params3);
    //      listViewLinearLayout.setVisibility(View.GONE);

    int decisionButton_width = displayWidth / 5 * 2;
    //      int decisionButton_height = displayHeight / 10;
    int decisionButton_height = registSelectShelfRelativeLayout_height / 4;
    int decisionButton_x = ((displayWidth / 2) - decisionButton_width) / 2;
    int decisionButton_y = displayHeight - (titleBarHeight * 4);
    decisionButton.setTranslationX(decisionButton_x);
    //      decisionButton.setTranslationY(decisionButton_y);
    decisionButton.setLayoutParams(new LinearLayout.LayoutParams(decisionButton_width, decisionButton_height));
    decisionButton.setBackgroundColor(Color.argb(255, 230, 126, 34));
    decisionButton.setTextColor(Color.WHITE);
    decisionButton.setText("");
    decisionButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            doDecideClick(registSelectShelfIsbn, registSelectShelfId, registSelectShelfName);
            registButton.setEnabled(true);
            borrowReturnButton.setEnabled(true);
        }
    });

    int cancelButton_width = displayWidth / 5 * 2;
    //      int cancelButton_height = displayHeight / 10;
    int cancelButton_height = registSelectShelfRelativeLayout_height / 4;
    int cancelButton_x = ((displayWidth / 2) + decisionButton_x) - decisionButton_width;
    int cancelButton_y = displayHeight - (titleBarHeight * 4);
    cancelButton.setTranslationX(cancelButton_x);
    //      cancelButton.setTranslationY(cancelButton_y);
    cancelButton.setLayoutParams(new LinearLayout.LayoutParams(cancelButton_width, cancelButton_height));
    cancelButton.setBackgroundColor(Color.argb(255, 127, 140, 141));
    cancelButton.setText("");
    cancelButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            resetRegistSelectShelfData();
            animateTranslationY(registSelectShelfRelativeLayout,
                    displayHeight - displayHeight / 3 - titleBarHeight, displayHeight);
            registFlag = 0;
            registButton.setEnabled(true);
            borrowReturnButton.setEnabled(true);
        }
    });

}

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

public void showMensajeContact(int position, final Context context, final MsgGroups message, View rowView,
        TextView icnMessageArrow) {//  w w  w .ja  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 icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy);
    final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back);
    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 contactPhoto = (TextView) rowView.findViewById(R.id.contact_photo);
    final TextView contactName = (TextView) rowView.findViewById(R.id.contact_name);
    final TextView contactPhone = (TextView) rowView.findViewById(R.id.contact_phone);
    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, icnMesajeCopy, TFCache.TF_SPEAKALL);
    TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL);
    TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL);
    TFCache.apply(context, contactPhoto, TFCache.TF_SPEAKALL);
    TFCache.apply(context, prevMessages, TFCache.TF_WHITNEY_MEDIUM);
    TFCache.apply(context, messageDate, TFCache.TF_WHITNEY_MEDIUM);
    TFCache.apply(context, contactName, TFCache.TF_WHITNEY_MEDIUM);
    TFCache.apply(context, contactPhone, TFCache.TF_WHITNEY_MEDIUM);
    TFCache.apply(context, userName, TFCache.TF_WHITNEY_MEDIUM);

    try {
        JSONObject contactData = new JSONObject(message.mensaje);
        contactName.setText(contactData.getString("nombre"));
        contactPhone.setText(Html.fromHtml("<u>" + contactData.getString("telefono") + "</u>"));
        if (contactPhone.length() > 0) {
            contactPhone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ((MainActivity) activity).dontClose = true;
                    hideKeyBoard();
                    Intent intent = new Intent(Intent.ACTION_CALL,
                            Uri.parse("tel:" + contactPhone.getText().toString()));
                    context.startActivity(intent);
                }
            });
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    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);
                    }
                }
            });
        }
    }

    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);
                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(message.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_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_email", message.emisorEmail);
                data.put("message", message.mensaje);
                data.put("source_lang", message.emisorLang);
                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) {
                e.printStackTrace();
            }
        }
        if (status == -1) {
            messageStatus.setTextSize(11);
            mensajeLayout.setBackgroundResource(R.drawable.message_errorout_background);
            icnMessageArrow.setTextColor(getResources().getColor(R.color.speak_all_disable_red));
            messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString());
        }
        if (status == 2) {
            messageStatus.setTextSize(16);
            mensajeLayout.setBackgroundResource(R.drawable.message_out_background);
            icnMessageArrow.setTextColor(getResources().getColor(R.color.speak_all_red));
            messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString());
        }
        if (status == 3) {
            messageStatus.setTextSize(11);
            mensajeLayout.setBackgroundResource(R.drawable.message_out_background);
            icnMessageArrow.setTextColor(getResources().getColor(R.color.speak_all_red));
            messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString());
        }
        if (status == 4) {
            messageStatus.setTextSize(11);
            mensajeLayout.setBackgroundResource(R.drawable.message_out_background);
            icnMessageArrow.setTextColor(getResources().getColor(R.color.speak_all_red));
            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) {
                    longclick = true;
                    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.container3, ForwarForFragment.newInstance(message.mensaje))
                        .addToBackStack(null).commit();
                ((MainActivity) activity).setOnBackPressedListener(null);
            } else {
                getFragmentManager().beginTransaction()
                        .replace(R.id.container3, ForwarForFragment.newInstance(message.mensajeTrad))
                        .addToBackStack(null).commit();
                ((MainActivity) activity).setOnBackPressedListener(null);
            }
        }
    });

    rowView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (messageSelected != null) {
                View vista = messagesList.findViewWithTag(messageSelected);
                if (!messageSelected.equals(message.mensajeId)) {
                    longclick = true;
                    vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE);
                    ((MainActivity) activity).setOnBackPressedListener(null);
                    messageSelected = null;
                }
            }

            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 == -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_email", mensaje.emisorEmail);
                    data.put("source_lang", mensaje.emisorLang);
                    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) {
                    e.printStackTrace();
                }
                if (!mensaje.emisor.equals(u.id)) {
                    if (!longclick) {
                        showDialogAddContact(mensaje.mensaje);
                    }
                    longclick = false;
                }
            }
        }
    });

}

From source file:com.irccloud.android.fragment.MessageViewFragment.java

private void update_global_msg() {
    if (globalMsgView != null) {
        if (conn != null && conn.globalMsg != null) {
            globalMsg.setText(Html.fromHtml(conn.globalMsg));
            globalMsgView.setVisibility(View.VISIBLE);
        } else {/*w  w  w  .j a  va 2 s . c om*/
            globalMsgView.setVisibility(View.GONE);
        }
    }
}

From source file:com.bookkos.bircle.CaptureActivity.java

private void resizeTitleSizeTooSmall() {
    int group_text_bytes_length = 0;

    try {/*from  ww  w .  ja v  a2  s .  c o m*/
        group_text_bytes_length = groupName.getBytes("SHIFT-JIS").length;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    // ????(??)????????
    if (group_text_bytes_length > 10 && group_text_bytes_length <= 14) {
        groupName = "<small>" + groupName + "</small>";
    } else if (group_text_bytes_length > 14 && group_text_bytes_length <= 18) {
        groupName = "<small><small>" + groupName + "</small></small>";
    } else if (group_text_bytes_length > 18 && group_text_bytes_length <= 24) {
        groupName = "<small><small><small>" + groupName + "</small></small></small>";
    } else if (group_text_bytes_length > 24) {

        int split_point = 12;
        String split_text1 = "";
        int split_text1_length = 0;

        while (split_point < 24) {
            split_text1 = groupName.substring(0, split_point);
            try {
                split_text1_length = split_text1.getBytes("SHIFT-JIS").length;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            if (split_text1_length <= 24) {
                split_point++;
            } else {
                break;
            }

            if (split_point >= groupName.length()) {
                split_point--;
                break;
            }
        }

        split_text1 = groupName.substring(0, split_point);
        String split_text2 = groupName.substring(split_point, groupName.length());
        groupName = "<small><small><small>" + split_text1 + "</small></small></small>";
        subGroupText = "<small><small>" + split_text2 + "</small></small>";
        actionBar.setSubtitle(Html.fromHtml("<font color=#FF0000>" + subGroupText + "</font>"));
    }
}

From source file:com.bookkos.bircle.CaptureActivity.java

private void resizeTitleSizeSmall() {
    int group_text_bytes_length = 0;

    try {//from   w  ww  . j  a v  a 2  s .c o m
        group_text_bytes_length = groupName.getBytes("SHIFT-JIS").length;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    // ????(??)????????
    if (group_text_bytes_length > 14 && group_text_bytes_length <= 18) {
        groupName = "<small>" + groupName + "</small>";
    } else if (group_text_bytes_length > 18 && group_text_bytes_length <= 22) {
        groupName = "<small><small>" + groupName + "</small></small>";
    } else if (group_text_bytes_length > 22 && group_text_bytes_length <= 30) {
        groupName = "<small><small><small>" + groupName + "</small></small></small>";
    } else if (group_text_bytes_length > 30) {
        /* 
         * ??1?????? 30byte
         * ??? 30byte ????, ?? 30byte ????????
         * (split_point?1?2??)
         * ?????????, ?? 30byte ??1???????
         */
        int split_point = 15;
        String split_text1 = "";
        int split_text1_length = 0;

        while (split_point < 30) {
            split_text1 = groupName.substring(0, split_point);
            try {
                split_text1_length = split_text1.getBytes("SHIFT-JIS").length;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            if (split_text1_length <= 30) {
                split_point++;
            } else {
                break;
            }

            if (split_point >= groupName.length()) {
                split_point--;
                break;
            }
        }

        split_text1 = groupName.substring(0, split_point);
        String split_text2 = groupName.substring(split_point, groupName.length());
        groupName = "<small><small><small>" + split_text1 + "</small></small></small>";
        subGroupText = "<small><small>" + split_text2 + "</small></small>";
        actionBar.setSubtitle(Html.fromHtml("<font color=#FF0000>" + subGroupText + "</font>"));
    }
}

From source file:cgeo.geocaching.cgBase.java

public cgTrackable parseTrackable(String page) {
    if (StringUtils.isBlank(page)) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackable: No page given");
        return null;
    }//from  w w  w  .  j  a v a  2 s. c  o m

    final cgTrackable trackable = new cgTrackable();

    // trackable geocode
    try {
        final Matcher matcherGeocode = PATTERN_TRACKABLE_Geocode.matcher(page);
        if (matcherGeocode.find() && matcherGeocode.groupCount() > 0) {
            trackable.geocode = matcherGeocode.group(1).toUpperCase();
        }
    } catch (Exception e) {
        // failed to parse trackable geocode
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable geocode");
    }

    // trackable id
    try {
        final Matcher matcherTrackableId = PATTERN_TRACKABLE_TrackableId.matcher(page);
        if (matcherTrackableId.find() && matcherTrackableId.groupCount() > 0) {
            trackable.guid = matcherTrackableId.group(1);
        }
    } catch (Exception e) {
        // failed to parse trackable id
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable id");
    }

    // trackable icon
    try {
        final Matcher matcherTrackableIcon = PATTERN_TRACKABLE_Icon.matcher(page);
        if (matcherTrackableIcon.find() && matcherTrackableIcon.groupCount() > 0) {
            trackable.iconUrl = matcherTrackableIcon.group(1);
        }
    } catch (Exception e) {
        // failed to parse trackable icon
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable icon");
    }

    // trackable name
    try {
        final Matcher matcherName = PATTERN_TRACKABLE_Name.matcher(page);
        if (matcherName.find() && matcherName.groupCount() > 1) {
            trackable.name = matcherName.group(2);
        }
    } catch (Exception e) {
        // failed to parse trackable name
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable name");
    }

    // trackable type
    if (StringUtils.isNotBlank(trackable.name)) {
        try {
            final Matcher matcherType = PATTERN_TRACKABLE_Type.matcher(page);
            if (matcherType.find() && matcherType.groupCount() > 0) {
                trackable.type = matcherType.group(1);
            }
        } catch (Exception e) {
            // failed to parse trackable type
            Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable type");
        }
    }

    // trackable owner name
    try {
        final Matcher matcherOwner = PATTERN_TRACKABLE_Owner.matcher(page);
        if (matcherOwner.find() && matcherOwner.groupCount() > 0) {
            trackable.ownerGuid = matcherOwner.group(1);
            trackable.owner = matcherOwner.group(2);
        }
    } catch (Exception e) {
        // failed to parse trackable owner name
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable owner name");
    }

    // trackable origin
    try {
        final Matcher matcherOrigin = PATTERN_TRACKABLE_Origin.matcher(page);
        if (matcherOrigin.find() && matcherOrigin.groupCount() > 0) {
            trackable.origin = matcherOrigin.group(1);
        }
    } catch (Exception e) {
        // failed to parse trackable origin
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable origin");
    }

    // trackable spotted
    try {
        final Matcher matcherSpottedCache = PATTERN_TRACKABLE_SpottedCache.matcher(page);
        if (matcherSpottedCache.find() && matcherSpottedCache.groupCount() > 0) {
            trackable.spottedGuid = matcherSpottedCache.group(1);
            trackable.spottedName = matcherSpottedCache.group(2);
            trackable.spottedType = cgTrackable.SPOTTED_CACHE;
        }

        final Matcher matcherSpottedUser = PATTERN_TRACKABLE_SpottedUser.matcher(page);
        if (matcherSpottedUser.find() && matcherSpottedUser.groupCount() > 0) {
            trackable.spottedGuid = matcherSpottedUser.group(1);
            trackable.spottedName = matcherSpottedUser.group(2);
            trackable.spottedType = cgTrackable.SPOTTED_USER;
        }

        final Matcher matcherSpottedUnknown = PATTERN_TRACKABLE_SpottedUnknown.matcher(page);
        if (matcherSpottedUnknown.find()) {
            trackable.spottedType = cgTrackable.SPOTTED_UNKNOWN;
        }

        final Matcher matcherSpottedOwner = PATTERN_TRACKABLE_SpottedOwner.matcher(page);
        if (matcherSpottedOwner.find()) {
            trackable.spottedType = cgTrackable.SPOTTED_OWNER;
        }
    } catch (Exception e) {
        // failed to parse trackable last known place
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable last known place");
    }

    // released
    try {
        final Matcher matcherReleased = PATTERN_TRACKABLE_Released.matcher(page);
        if (matcherReleased.find() && matcherReleased.groupCount() > 0 && matcherReleased.group(1) != null) {
            try {
                if (trackable.released == null) {
                    trackable.released = dateTbIn1.parse(matcherReleased.group(1));
                }
            } catch (Exception e) {
                //
            }

            try {
                if (trackable.released == null) {
                    trackable.released = dateTbIn2.parse(matcherReleased.group(1));
                }
            } catch (Exception e) {
                //
            }
        }
    } catch (Exception e) {
        // failed to parse trackable released date
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable released date");
    }

    // trackable distance
    try {
        final Matcher matcherDistance = PATTERN_TRACKABLE_Distance.matcher(page);
        if (matcherDistance.find() && matcherDistance.groupCount() > 0) {
            try {
                trackable.distance = DistanceParser.parseDistance(matcherDistance.group(1), settings.units);
            } catch (NumberFormatException e) {
                trackable.distance = null;
                throw e;
            }
        }
    } catch (Exception e) {
        // failed to parse trackable distance
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable distance");
    }

    // trackable goal
    try {
        final Matcher matcherGoal = PATTERN_TRACKABLE_Goal.matcher(page);
        if (matcherGoal.find() && matcherGoal.groupCount() > 0) {
            trackable.goal = matcherGoal.group(1);
        }
    } catch (Exception e) {
        // failed to parse trackable goal
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable goal");
    }

    // trackable details & image
    try {
        final Matcher matcherDetailsImage = PATTERN_TRACKABLE_DetailsImage.matcher(page);
        if (matcherDetailsImage.find() && matcherDetailsImage.groupCount() > 0) {
            final String image = matcherDetailsImage.group(3);
            final String details = matcherDetailsImage.group(4);

            if (image != null) {
                trackable.image = image;
            }
            if (details != null) {
                trackable.details = details;
            }
        }
    } catch (Exception e) {
        // failed to parse trackable details & image
        Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable details & image");
    }

    // trackable logs
    try {
        final Matcher matcherLogs = PATTERN_TRACKABLE_Log.matcher(page);
        /*
         * 1. Type (img)
         * 2. Date
         * 3. Author
         * 4. Cache-GUID
         * 5. Cache-name
         * 6. Logtext
         */
        while (matcherLogs.find()) {
            final cgLog logDone = new cgLog();

            if (logTypes.containsKey(matcherLogs.group(1).toLowerCase())) {
                logDone.type = logTypes.get(matcherLogs.group(1).toLowerCase());
            } else {
                logDone.type = logTypes.get("icon_note");
            }

            logDone.author = Html.fromHtml(matcherLogs.group(3)).toString();

            try {
                logDone.date = parseGcCustomDate(matcherLogs.group(2)).getTime();
            } catch (ParseException e) {
            }

            logDone.log = matcherLogs.group(6).trim();

            if (matcherLogs.group(4) != null && matcherLogs.group(5) != null) {
                logDone.cacheGuid = matcherLogs.group(4);
                logDone.cacheName = matcherLogs.group(5);
            }

            trackable.logs.add(logDone);
        }
    } catch (Exception e) {
        // failed to parse logs
        Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache logs");
    }

    app.saveTrackable(trackable);

    return trackable;
}

From source file:com.bookkos.bircle.CaptureActivity.java

private void resizeTitleSizeMiddle() {
    int group_text_bytes_length = 0;

    try {// ww  w.  j a v a 2  s. co  m
        group_text_bytes_length = groupName.getBytes("SHIFT-JIS").length;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    // ????(??)????????
    if (group_text_bytes_length > 22 && group_text_bytes_length <= 28) {
        groupName = "<small>" + groupName + "</small>";
    } else if (group_text_bytes_length > 28 && group_text_bytes_length <= 36) {
        groupName = "<small><small>" + groupName + "</small></small>";
    } else if (group_text_bytes_length > 36 && group_text_bytes_length <= 50) {
        groupName = "<small><small><small>" + groupName + "</small></small></small>";
    } else if (group_text_bytes_length > 50) {
        int split_point = 18;
        String split_text1 = "";
        int split_text1_length = 0;

        while (split_point < 36) {
            split_text1 = groupName.substring(0, split_point);
            try {
                split_text1_length = split_text1.getBytes("SHIFT-JIS").length;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            if (split_text1_length < 36) {
                split_point++;
            } else {
                break;
            }

            if (split_point >= groupName.length()) {
                split_point--;
                break;
            }
        }

        split_text1 = groupName.substring(0, split_point);
        String split_text2 = groupName.substring(split_point, groupName.length());
        groupName = "<small><small>" + split_text1 + "</small></small>";
        subGroupText = "<small>" + split_text2 + "</small>";
        actionBar.setSubtitle(Html.fromHtml("<font color=#FF0000>" + subGroupText + "</font>"));
    }
}

From source file:com.bookkos.bircle.CaptureActivity.java

private void resizeTitleSizeLarge() {
    int group_text_bytes_length = 0;

    try {/*  w  w  w .  ja v a 2 s  .  co m*/
        group_text_bytes_length = groupName.getBytes("SHIFT-JIS").length;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    // ????(??)????????
    if (group_text_bytes_length > 34 && group_text_bytes_length <= 42) {
        groupName = "<small>" + groupName + "</small>";
    } else if (group_text_bytes_length > 42 && group_text_bytes_length <= 52) {
        groupName = "<small><small>" + groupName + "</small></small>";
    } else if (group_text_bytes_length > 52 && group_text_bytes_length <= 68) {
        groupName = "<small><small><small>" + groupName + "</small></small></small>";
    } else if (group_text_bytes_length > 68) {
        int split_point = 25;
        String split_text1 = "";
        int split_text1_length = 0;

        while (split_point < 52) {
            split_text1 = groupName.substring(0, split_point);
            try {
                split_text1_length = split_text1.getBytes("SHIFT-JIS").length;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            if (split_text1_length < 52) {
                split_point++;
            } else {
                break;
            }

            if (split_point >= groupName.length()) {
                split_point--;
                break;
            }
        }

        split_text1 = groupName.substring(0, split_point);
        String split_text2 = groupName.substring(split_point, groupName.length());
        groupName = "<small><small>" + split_text1 + "</small></small>";
        subGroupText = "<small>" + split_text2 + "</small>";
        actionBar.setSubtitle(Html.fromHtml("<font color=#FF0000>" + subGroupText + "</font>"));
    }
}

From source file:cgeo.geocaching.cgBase.java

public static List<cgTrackableLog> parseTrackableLog(String page) {
    if (StringUtils.isEmpty(page)) {
        return null;
    }// www .  jav  a  2  s. c o  m

    final List<cgTrackableLog> trackables = new ArrayList<cgTrackableLog>();

    int startPos = -1;
    int endPos = -1;

    startPos = page.indexOf("<table id=\"tblTravelBugs\"");
    if (startPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: ID \"tblTravelBugs\" not found on page");
        return null;
    }

    page = page.substring(startPos); // cut on <table

    endPos = page.indexOf("</table>");
    if (endPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: end of ID \"tblTravelBugs\" not found on page");
        return null;
    }

    page = page.substring(0, endPos); // cut on </table>

    startPos = page.indexOf("<tbody>");
    if (startPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: tbody not found on page");
        return null;
    }

    page = page.substring(startPos); // cut on <tbody>

    endPos = page.indexOf("</tbody>");
    if (endPos == -1) {
        Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: end of tbody not found on page");
        return null;
    }

    page = page.substring(0, endPos); // cut on </tbody>

    final Pattern trackablePattern = Pattern
            .compile("<tr id=\"ctl00_ContentBody_LogBookPanel1_uxTrackables_repTravelBugs_ctl[0-9]+_row\"[^>]*>"
                    + "[^<]*<td>[^<]*<a href=\"[^\"]+\">([A-Z0-9]+)</a>[^<]*</td>[^<]*<td>([^<]+)</td>[^<]*<td>"
                    + "[^<]*<select name=\"ctl00\\$ContentBody\\$LogBookPanel1\\$uxTrackables\\$repTravelBugs\\$ctl([0-9]+)\\$ddlAction\"[^>]*>"
                    + "([^<]*<option value=\"([0-9]+)(_[a-z]+)?\">[^<]+</option>)+"
                    + "[^<]*</select>[^<]*</td>[^<]*</tr>", Pattern.CASE_INSENSITIVE);
    final Matcher trackableMatcher = trackablePattern.matcher(page);
    while (trackableMatcher.find()) {
        if (trackableMatcher.groupCount() > 0) {
            final cgTrackableLog trackable = new cgTrackableLog();

            if (trackableMatcher.group(1) != null) {
                trackable.trackCode = trackableMatcher.group(1);
            } else {
                continue;
            }
            if (trackableMatcher.group(2) != null) {
                trackable.name = Html.fromHtml(trackableMatcher.group(2)).toString();
            } else {
                continue;
            }
            if (trackableMatcher.group(3) != null) {
                trackable.ctl = Integer.valueOf(trackableMatcher.group(3));
            } else {
                continue;
            }
            if (trackableMatcher.group(5) != null) {
                trackable.id = Integer.valueOf(trackableMatcher.group(5));
            } else {
                continue;
            }

            Log.i(cgSettings.tag, "Trackable in inventory (#" + trackable.ctl + "/" + trackable.id + "): "
                    + trackable.trackCode + " - " + trackable.name);

            trackables.add(trackable);
        }
    }

    return trackables;
}

From source file:carnero.cgeo.original.libs.Base.java

public Trackable parseTrackable(String page) {
    if (page == null || page.length() == 0) {
        Log.e(Settings.tag, "cgeoBase.parseTrackable: No page given");
        return null;
    }//from w  ww.ja  va 2s .com

    final Pattern patternTrackableId = Pattern.compile(
            "<a id=\"ctl00_ContentBody_LogLink\" title=\"[^\"]*\" href=\".*log\\.aspx\\?wid=([a-z0-9\\-]+)\"[^>]*>[^<]*</a>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternGeocode = Pattern.compile(
            "<span id=\"ctl00_ContentBody_BugDetails_BugTBNum\" String=\"[^\"]*\">Use[^<]*<strong>(TB[0-9a-z]+)[^<]*</strong> to reference this item.[^<]*</span>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternName = Pattern.compile(
            "<h2>([^<]*<img[^>]*>)?[^<]*<span id=\"ctl00_ContentBody_lbHeading\">([^<]+)</span>[^<]*</h2>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternOwner = Pattern.compile(
            "<dt>[^\\w]*Owner:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugOwner\" title=\"[^\"]*\" href=\"[^\"]*/profile/\\?guid=([a-z0-9\\-]+)\">([^<]+)<\\/a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternReleased = Pattern.compile(
            "<dt>[^\\w]*Released:[^<]*</dt>[^<]*<dd>[^<]*<span id=\"ctl00_ContentBody_BugDetails_BugReleaseDate\">([^<]+)<\\/span>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternOrigin = Pattern.compile(
            "<dt>[^\\w]*Origin:[^<]*</dt>[^<]*<dd>[^<]*<span id=\"ctl00_ContentBody_BugDetails_BugOrigin\">([^<]+)<\\/span>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternSpottedCache = Pattern.compile(
            "<dt>[^\\w]*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\" title=\"[^\"]*\" href=\"[^\"]*/seek/cache_details.aspx\\?guid=([a-z0-9\\-]+)\">In ([^<]+)</a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternSpottedUser = Pattern.compile(
            "<dt>[^\\w]*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\" href=\"[^\"]*/profile/\\?guid=([a-z0-9\\-]+)\">In the hands of ([^<]+).</a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternSpottedUnknown = Pattern.compile(
            "<dt>[^\\w]*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\">Unknown Location[^<]*</a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternSpottedOwner = Pattern.compile(
            "<dt>[^\\w]*Recently Spotted:[^<]*</dt>[^<]*<dd>[^<]*<a id=\"ctl00_ContentBody_BugDetails_BugLocation\">In the hands of the owner[^<]*</a>[^<]*</dd>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternGoal = Pattern.compile(
            "<h3>[^\\w]*Current GOAL[^<]*</h3>[^<]*<p[^>]*>(.*)</p>[^<]*<h3>[^\\w]*About This Item[^<]*</h3>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternDetailsImage = Pattern.compile(
            "<h3>[^\\w]*About This Item[^<]*</h3>([^<]*<p>([^<]*<img id=\"ctl00_ContentBody_BugDetails_BugImage\" class=\"[^\"]+\" src=\"([^\"]+)\"[^>]*>)?[^<]*</p>)?[^<]*<p[^>]*>(.*)</p>[^<]*<div id=\"ctl00_ContentBody_BugDetails_uxAbuseReport\">",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternLogs = Pattern.compile(
            "<table class=\"TrackableItemLogTable Table\">(.*)<\\/table>[^<]*<ul", Pattern.CASE_INSENSITIVE);
    final Pattern patternIcon = Pattern.compile(
            "<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"([^\"]+)\"[^>]*>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternType = Pattern.compile(
            "<img id=\"ctl00_ContentBody_BugTypeImage\" class=\"TravelBugHeaderIcon\" src=\"[^\"]+\" alt=\"([^\"]+)\"[^>]*>",
            Pattern.CASE_INSENSITIVE);
    final Pattern patternDistance = Pattern.compile(
            "<h4[^>]*[^\\w]*Tracking History \\(([0-9\\.,]+(km|mi))[^\\)]*\\)", Pattern.CASE_INSENSITIVE);

    final Trackable trackable = new Trackable();

    // trackable geocode
    try {
        final Matcher matcherGeocode = patternGeocode.matcher(page);
        while (matcherGeocode.find()) {
            if (matcherGeocode.groupCount() > 0) {
                trackable.geocode = matcherGeocode.group(1).toUpperCase();
            }
        }
    } catch (Exception e) {
        // failed to parse trackable geocode
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable geocode");
    }

    // trackable id
    try {
        final Matcher matcherTrackableId = patternTrackableId.matcher(page);
        while (matcherTrackableId.find()) {
            if (matcherTrackableId.groupCount() > 0) {
                trackable.guid = matcherTrackableId.group(1);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable id
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable id");
    }

    // trackable icon
    try {
        final Matcher matcherTrackableIcon = patternIcon.matcher(page);
        while (matcherTrackableIcon.find()) {
            if (matcherTrackableIcon.groupCount() > 0) {
                trackable.iconUrl = matcherTrackableIcon.group(1);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable icon
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable icon");
    }

    // trackable name
    try {
        final Matcher matcherName = patternName.matcher(page);
        while (matcherName.find()) {
            if (matcherName.groupCount() > 1) {
                trackable.name = matcherName.group(2);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable name
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable name");
    }

    // trackable type
    if (trackable.name != null && trackable.name.length() > 0) {
        try {
            final Matcher matcherType = patternType.matcher(page);
            while (matcherType.find()) {
                if (matcherType.groupCount() > 0) {
                    trackable.type = matcherType.group(1);
                }
            }
        } catch (Exception e) {
            // failed to parse trackable type
            Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable type");
        }
    }

    // trackable owner name
    try {
        final Matcher matcherOwner = patternOwner.matcher(page);
        while (matcherOwner.find()) {
            if (matcherOwner.groupCount() > 0) {
                trackable.ownerGuid = matcherOwner.group(1);
                trackable.owner = matcherOwner.group(2);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable owner name
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable owner name");
    }

    // trackable origin
    try {
        final Matcher matcherOrigin = patternOrigin.matcher(page);
        while (matcherOrigin.find()) {
            if (matcherOrigin.groupCount() > 0) {
                trackable.origin = matcherOrigin.group(1);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable origin
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable origin");
    }

    // trackable spotted
    try {
        final Matcher matcherSpottedCache = patternSpottedCache.matcher(page);
        while (matcherSpottedCache.find()) {
            if (matcherSpottedCache.groupCount() > 0) {
                trackable.spottedGuid = matcherSpottedCache.group(1);
                trackable.spottedName = matcherSpottedCache.group(2);
                trackable.spottedType = Trackable.SPOTTED_CACHE;
            }
        }

        final Matcher matcherSpottedUser = patternSpottedUser.matcher(page);
        while (matcherSpottedUser.find()) {
            if (matcherSpottedUser.groupCount() > 0) {
                trackable.spottedGuid = matcherSpottedUser.group(1);
                trackable.spottedName = matcherSpottedUser.group(2);
                trackable.spottedType = Trackable.SPOTTED_USER;
            }
        }

        final Matcher matcherSpottedUnknown = patternSpottedUnknown.matcher(page);
        if (matcherSpottedUnknown.find()) {
            trackable.spottedType = Trackable.SPOTTED_UNKNOWN;
        }

        final Matcher matcherSpottedOwner = patternSpottedOwner.matcher(page);
        if (matcherSpottedOwner.find()) {
            trackable.spottedType = Trackable.SPOTTED_OWNER;
        }
    } catch (Exception e) {
        // failed to parse trackable last known place
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable last known place");
    }

    // released
    try {
        final Matcher matcherReleased = patternReleased.matcher(page);
        while (matcherReleased.find()) {
            if (matcherReleased.groupCount() > 0 && matcherReleased.group(1) != null) {
                try {
                    if (trackable.released == null) {
                        trackable.released = dateTbIn1.parse(matcherReleased.group(1));
                    }
                } catch (Exception e) {
                    //
                }

                try {
                    if (trackable.released == null) {
                        trackable.released = dateTbIn2.parse(matcherReleased.group(1));
                    }
                } catch (Exception e) {
                    //
                }
            }
        }
    } catch (Exception e) {
        // failed to parse trackable released date
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable released date");
    }

    // trackable distance
    try {
        final Matcher matcherDistance = patternDistance.matcher(page);
        while (matcherDistance.find()) {
            if (matcherDistance.groupCount() > 0) {
                trackable.distance = parseDistance(matcherDistance.group(1));
            }
        }
    } catch (Exception e) {
        // failed to parse trackable distance
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable distance");
    }

    // trackable goal
    try {
        final Matcher matcherGoal = patternGoal.matcher(page);
        while (matcherGoal.find()) {
            if (matcherGoal.groupCount() > 0) {
                trackable.goal = matcherGoal.group(1);
            }
        }
    } catch (Exception e) {
        // failed to parse trackable goal
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable goal");
    }

    // trackable details & image
    try {
        final Matcher matcherDetailsImage = patternDetailsImage.matcher(page);
        while (matcherDetailsImage.find()) {
            if (matcherDetailsImage.groupCount() > 0) {
                final String image = matcherDetailsImage.group(3);
                final String details = matcherDetailsImage.group(4);

                if (image != null) {
                    trackable.image = image;
                }
                if (details != null) {
                    trackable.details = details;
                }
            }
        }
    } catch (Exception e) {
        // failed to parse trackable details & image
        Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable details & image");
    }

    // trackable logs
    try {
        final Matcher matcherLogs = patternLogs.matcher(page);
        while (matcherLogs.find()) {
            if (matcherLogs.groupCount() > 0) {
                final Pattern patternLog = Pattern.compile("[^>]*>"
                        + "[^<]*<td[^<]*<img src=[\"|'].*\\/icons\\/([^\\.]+)\\.[a-z]{2,5}[\"|'][^>]*>&nbsp;(\\d+).(\\d+).(\\d+)[^<]*</td>"
                        + "[^<]*<td>[^<]*<a href=[^>]+>([^<]+)<.a>([^<]*|[^<]*<a href=[\"|'].*guid=([^\"]*)\">([^<]*)</a>[^<]*)</td>"
                        + "[^<]*<td>[^<]*</td>" + "[^<]*<td[^<]*<a href=[^>]+>[^<]+</a>[^<]*</td>[^<]*</tr>"
                        + "[^<]*<tr[^>]*>[^<]*<td[^>]*>(.*?)</td>[^<]*</tr>.*" + "");
                // 1 filename == type
                // 2 month
                // 3 date
                // 4 year
                // 5 user
                // 6 action dependent
                // 7 cache guid
                // 8 cache name
                // 9 text
                final String[] logs = matcherLogs.group(1).split("<tr class=\"Data BorderTop");
                final int logsCnt = logs.length;

                for (int k = 1; k < logsCnt; k++) {
                    final Matcher matcherLog = patternLog.matcher(logs[k]);
                    if (matcherLog.find()) {
                        final CacheLog logDone = new CacheLog();

                        String logTmp = matcherLog.group(9);
                        logTmp = Pattern.compile("<p>").matcher(logTmp).replaceAll("\n");
                        logTmp = Pattern.compile("<br[^>]*>").matcher(logTmp).replaceAll("\n");
                        logTmp = Pattern.compile("<\\/p>").matcher(logTmp).replaceAll("");
                        logTmp = Pattern.compile("\r+").matcher(logTmp).replaceAll("\n");

                        int day = -1;
                        try {
                            day = Integer.parseInt(matcherLog.group(3));
                        } catch (Exception e) {
                            Log.w(Settings.tag, "Failed to parse logs date (day): " + e.toString());
                        }

                        int month = -1;
                        try {
                            month = Integer.parseInt(matcherLog.group(2));
                            month -= 1;
                        } catch (Exception e) {
                            Log.w(Settings.tag, "Failed to parse logs date (month): " + e.toString());
                        }

                        int year = -1;
                        try {
                            year = Integer.parseInt(matcherLog.group(4));
                        } catch (Exception e) {
                            Log.w(Settings.tag, "Failed to parse logs date (year): " + e.toString());
                        }

                        long logDate;
                        if (year > 0 && month >= 0 && day > 0) {
                            Calendar date = Calendar.getInstance();
                            date.set(year, month, day, 12, 0, 0);
                            logDate = date.getTimeInMillis();
                            logDate = (long) (Math.ceil(logDate / 1000)) * 1000;
                        } else {
                            logDate = 0;
                        }

                        if (logTypes.containsKey(matcherLog.group(1).toLowerCase()) == true) {
                            logDone.type = logTypes.get(matcherLog.group(1).toLowerCase());
                        } else {
                            logDone.type = logTypes.get("icon_note");
                        }

                        logDone.author = Html.fromHtml(matcherLog.group(5)).toString();
                        logDone.date = logDate;
                        logDone.log = logTmp;
                        if (matcherLog.group(7) != null && matcherLog.group(8) != null) {
                            logDone.cacheGuid = matcherLog.group(7);
                            logDone.cacheName = matcherLog.group(8);
                        }

                        trackable.logs.add(logDone);
                    }
                }
            }
        }
    } catch (Exception e) {
        // failed to parse logs
        Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache logs");
    }

    app.saveTrackable(trackable);

    return trackable;
}