List of usage examples for android.widget TextView getViewTreeObserver
public ViewTreeObserver getViewTreeObserver()
From source file:co.paulburke.android.textviewpager.TextViewPagerAdapter.java
@Override public TextView instantiateItem(final ViewGroup container, final int position) { TextView view = null; if (mLayoutRes > 0) view = (TextView) mInflater.inflate(mLayoutRes, container, false); else/*from ww w . j a v a2 s . co m*/ view = new TextView(mContext, null, R.attr.textViewPagerStyle); if (mText != null) { int offset = 0; int end = mText.length(); int size = mOffsets.length; if (size == 0) { // Add the OnGlobalLayoutListener, which measures the text and // reports paged character offsets if the text layout is taller // than the container. PagingLayoutListener listener = new PagingLayoutListener(view, mMeasureListener); view.getViewTreeObserver().addOnGlobalLayoutListener(listener); } else { offset = mOffsets[position]; int lastPage = size - 1; // Don't consider the last page measured, in case there is more // text to be displayed. if (position < lastPage) end = mOffsets[position + 1]; } final CharSequence sub = mText.subSequence(offset, end); view.setText(sub != null ? sub : mContext.getText(R.string.unable_to_load_text)); container.addView(view, 0); if (DEBUG) Log.d(TAG, "instantiateItem position = " + position + ", offset = " + offset + ", end = " + end + ", text = " + sub); } return view; }
From source file:com.desno365.mods.Tabs.FragmentTab2.java
@Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragmenttab2, container, false); // xml tab TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_portal_is); // id TextView version textVersion.setText(MainActivity.modsContainer.portal.getVersion()); // MainActivity variable that holds the latest version TextView textCompatibility = (TextView) rootView.findViewById(R.id.portal_compatibility); // id TextView compatibility textCompatibility.setText(MainActivity.modsContainer.portal.getCompatibility()); // MainActivity variable that holds the versions compatibility final TextView textChangelog = (TextView) rootView.findViewById(R.id.portal_changelog); // id TextView changelog textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.portal.getChangelog())); // MainActivity variable that holds the latest changelog textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance()); textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES); final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab2); // id TextView show/hide changelog textShowHide.setText(getResources().getString(R.string.show_changelog)); textShowHide.setOnClickListener(new View.OnClickListener() { @Override//from w w w .jav a2 s .com public void onClick(View v) { if (!displayingAllChangelog) { // get the TextView height that will be used when hiding the changelog changelogHiddenHeight = textChangelog.getHeight(); DesnoUtils.expandTextView(container, textChangelog); displayingAllChangelog = true; textShowHide.setText(getResources().getString(R.string.hide_changelog)); } else { DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight); displayingAllChangelog = false; textShowHide.setText(getResources().getString(R.string.show_changelog)); } } }); // make the show/hide button invisible if it is not necessary ViewTreeObserver vto = textShowHide.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) { textShowHide.setVisibility(View.GONE); } else { textShowHide.setVisibility(View.VISIBLE); } } }); return rootView; }
From source file:com.desno365.mods.Tabs.FragmentTab3.java
@Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragmenttab3, container, false); // xml tab TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_laser_is); // id TextView version textVersion.setText(MainActivity.modsContainer.laser.getVersion()); // MainActivity variable that holds the latest version TextView textCompatibility = (TextView) rootView.findViewById(R.id.laser_compatibility); // id TextView compatibility textCompatibility.setText(MainActivity.modsContainer.laser.getCompatibility()); // MainActivity variable that holds the versions compatibility final TextView textChangelog = (TextView) rootView.findViewById(R.id.laser_changelog); // id TextView changelog textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.laser.getChangelog())); // MainActivity variable that holds the latest changelog textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance()); textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES); final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab3); // id TextView show/hide changelog textShowHide.setText(getResources().getString(R.string.show_changelog)); textShowHide.setOnClickListener(new View.OnClickListener() { @Override/*w w w . j a v a 2 s . c o m*/ public void onClick(View v) { if (!displayingAllChangelog) { // get the TextView height that will be used when hiding the changelog changelogHiddenHeight = textChangelog.getHeight(); DesnoUtils.expandTextView(container, textChangelog); displayingAllChangelog = true; textShowHide.setText(getResources().getString(R.string.hide_changelog)); } else { DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight); displayingAllChangelog = false; textShowHide.setText(getResources().getString(R.string.show_changelog)); } } }); // make the show/hide button invisible if it is not necessary ViewTreeObserver vto = textShowHide.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) { textShowHide.setVisibility(View.GONE); } else { textShowHide.setVisibility(View.VISIBLE); } } }); return rootView; }
From source file:com.desno365.mods.Tabs.FragmentTab4.java
@Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragmenttab4, container, false); // xml tab TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_turrets_is); // id TextView version textVersion.setText(MainActivity.modsContainer.turrets.getVersion()); // MainActivity variable that holds the latest version TextView textCompatibility = (TextView) rootView.findViewById(R.id.turrets_compatibility); // id TextView compatibility textCompatibility.setText(MainActivity.modsContainer.turrets.getCompatibility()); // MainActivity variable that holds the versions compatibility final TextView textChangelog = (TextView) rootView.findViewById(R.id.turrets_changelog); // id TextView changelog textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.turrets.getChangelog())); // MainActivity variable that holds the latest changelog textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance()); textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES); final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab4); // id TextView show/hide changelog textShowHide.setText(getResources().getString(R.string.show_changelog)); textShowHide.setOnClickListener(new View.OnClickListener() { @Override/*from ww w .j a v a2s . co m*/ public void onClick(View v) { if (!displayingAllChangelog) { // get the TextView height that will be used when hiding the changelog changelogHiddenHeight = textChangelog.getHeight(); DesnoUtils.expandTextView(container, textChangelog); displayingAllChangelog = true; textShowHide.setText(getResources().getString(R.string.hide_changelog)); } else { DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight); displayingAllChangelog = false; textShowHide.setText(getResources().getString(R.string.show_changelog)); } } }); // make the show/hide button invisible if it is not necessary ViewTreeObserver vto = textShowHide.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) { textShowHide.setVisibility(View.GONE); } else { textShowHide.setVisibility(View.VISIBLE); } } }); return rootView; }
From source file:com.desno365.mods.Tabs.FragmentTab5.java
@Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragmenttab5, container, false); // xml tab TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_jukebox_is); // id TextView version textVersion.setText(MainActivity.modsContainer.jukebox.getVersion()); // MainActivity variable that holds the latest version TextView textCompatibility = (TextView) rootView.findViewById(R.id.jukebox_compatibility); // id TextView compatibility textCompatibility.setText(MainActivity.modsContainer.jukebox.getCompatibility()); // MainActivity variable that holds the versions compatibility final TextView textChangelog = (TextView) rootView.findViewById(R.id.jukebox_changelog); // id TextView changelog textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.jukebox.getChangelog())); // MainActivity variable that holds the latest changelog textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance()); textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES); final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab5); // id TextView show/hide changelog textShowHide.setText(getResources().getString(R.string.show_changelog)); textShowHide.setOnClickListener(new View.OnClickListener() { @Override/*ww w. ja v a 2 s. c o m*/ public void onClick(View v) { if (!displayingAllChangelog) { // get the TextView height that will be used when hiding the changelog changelogHiddenHeight = textChangelog.getHeight(); DesnoUtils.expandTextView(container, textChangelog); displayingAllChangelog = true; textShowHide.setText(getResources().getString(R.string.hide_changelog)); } else { DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight); displayingAllChangelog = false; textShowHide.setText(getResources().getString(R.string.show_changelog)); } } }); // make the show/hide button invisible if it is not necessary ViewTreeObserver vto = textShowHide.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) { textShowHide.setVisibility(View.GONE); } else { textShowHide.setVisibility(View.VISIBLE); } } }); return rootView; }
From source file:com.desno365.mods.Tabs.FragmentTab6.java
@Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragmenttab6, container, false); // xml tab TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_guns_is); // id TextView version textVersion.setText(MainActivity.modsContainer.desnoGuns.getVersion()); // MainActivity variable that holds the latest version TextView textCompatibility = (TextView) rootView.findViewById(R.id.guns_compatibility); // id TextView compatibility textCompatibility.setText(MainActivity.modsContainer.desnoGuns.getCompatibility()); // MainActivity variable that holds the versions compatibility final TextView textChangelog = (TextView) rootView.findViewById(R.id.guns_changelog); // id TextView changelog textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.desnoGuns.getChangelog())); // MainActivity variable that holds the latest changelog textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance()); textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES); final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab6); // id TextView show/hide changelog textShowHide.setText(getResources().getString(R.string.show_changelog)); textShowHide.setOnClickListener(new View.OnClickListener() { @Override/* ww w. j a v a 2 s . c om*/ public void onClick(View v) { if (!displayingAllChangelog) { // get the TextView height that will be used when hiding the changelog changelogHiddenHeight = textChangelog.getHeight(); DesnoUtils.expandTextView(container, textChangelog); displayingAllChangelog = true; textShowHide.setText(getResources().getString(R.string.hide_changelog)); } else { DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight); displayingAllChangelog = false; textShowHide.setText(getResources().getString(R.string.show_changelog)); } } }); // make the show/hide button invisible if it is not necessary ViewTreeObserver vto = textShowHide.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) { textShowHide.setVisibility(View.GONE); } else { textShowHide.setVisibility(View.VISIBLE); } } }); return rootView; }
From source file:com.desno365.mods.Tabs.FragmentTab7.java
@Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragmenttab7, container, false); // xml tab TextView textVersion = (TextView) rootView.findViewById(R.id.latest_version_unreal_is); // id TextView version textVersion.setText(MainActivity.modsContainer.unreal.getVersion()); // MainActivity variable that holds the latest version TextView textCompatibility = (TextView) rootView.findViewById(R.id.unreal_compatibility); // id TextView compatibility textCompatibility.setText(MainActivity.modsContainer.unreal.getCompatibility()); // MainActivity variable that holds the versions compatibility final TextView textChangelog = (TextView) rootView.findViewById(R.id.unreal_changelog); // id TextView changelog textChangelog.setText(android.text.Html.fromHtml(MainActivity.modsContainer.unreal.getChangelog())); // MainActivity variable that holds the latest changelog textChangelog.setMovementMethod(android.text.method.LinkMovementMethod.getInstance()); textChangelog.setMaxLines(SharedConstants.CHANGELOG_TEXT_MAX_LINES); final TextView textShowHide = (TextView) rootView.findViewById(R.id.changelog_show_hide_tab7); // id TextView show/hide changelog textShowHide.setText(getResources().getString(R.string.show_changelog)); textShowHide.setOnClickListener(new View.OnClickListener() { @Override/*ww w . j av a2 s .c o m*/ public void onClick(View v) { if (!displayingAllChangelog) { // get the TextView height that will be used when hiding the changelog changelogHiddenHeight = textChangelog.getHeight(); DesnoUtils.expandTextView(container, textChangelog); displayingAllChangelog = true; textShowHide.setText(getResources().getString(R.string.hide_changelog)); } else { DesnoUtils.collapseTextView(container, textChangelog, changelogHiddenHeight); displayingAllChangelog = false; textShowHide.setText(getResources().getString(R.string.show_changelog)); } } }); // make the show/hide button invisible if it is not necessary ViewTreeObserver vto = textShowHide.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new android.view.ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (textChangelog.getLineCount() <= SharedConstants.CHANGELOG_TEXT_MAX_LINES) { textShowHide.setVisibility(View.GONE); } else { textShowHide.setVisibility(View.VISIBLE); } } }); return rootView; }
From source file:Main.java
/** * Make a textview to a collapsible textview with the indicator on the right of the textview * /*from w w w. j a v a 2 s . c o m*/ * @param tv , {@link TextView} to be converted * @param upDrawableResId , drawable resource id to be used as up indicator * @param downDrawableResId , drawable resource id to be used as down indicator * @param lineTreshold , no of line to be displayed for the collapsed state */ public static void makeCollapsible(final TextView tv, int upDrawableResId, int downDrawableResId, final int lineTreshold) { final Drawable[] drawables = tv.getCompoundDrawables(); final Drawable up = tv.getContext().getResources().getDrawable(upDrawableResId); final Drawable down = tv.getContext().getResources().getDrawable(downDrawableResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); tv.setEllipsize(TruncateAt.END); tv.setMaxLines(lineTreshold); tv.setTag(true); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v instanceof TextView) { TextView tv = (TextView) v; boolean snippet = (Boolean) tv.getTag(); if (snippet) { // show everything snippet = false; tv.setMaxLines(Integer.MAX_VALUE); tv.setEllipsize(null); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up, drawables[3]); } else { // show snippet snippet = true; tv.setMaxLines(lineTreshold); tv.setEllipsize(TruncateAt.END); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); } tv.setTag(snippet); } } }); } else { tv.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { ViewTreeObserver vto = tv.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override public void onGlobalLayout() { tv.setEllipsize(TruncateAt.END); int line = tv.getLineCount(); tv.setMaxLines(lineTreshold); if (line <= lineTreshold) { tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // empty listener // Log.d("line count", "count: "+ // tv.getLineCount()); } }); if (tv.getLayout() != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { tv.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { tv.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } return; } tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); tv.setTag(true); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v instanceof TextView) { TextView tv = (TextView) v; boolean snippet = (Boolean) tv.getTag(); if (snippet) { snippet = false; // show everything tv.setMaxLines(Integer.MAX_VALUE); tv.setEllipsize(null); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up, drawables[3]); } else { snippet = true; // show snippet tv.setMaxLines(lineTreshold); tv.setEllipsize(TruncateAt.END); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); } tv.setTag(snippet); } } }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { tv.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { tv.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } }); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); } }
From source file:com.mobiletin.inputmethod.indic.LatinIME.java
@Override public void setExtractView(final View view) { final TextView prevExtractEditText = mExtractEditText; super.setExtractView(view); TextView nextExtractEditText = null; if (view != null) { final View extractEditText = view.findViewById(android.R.id.inputExtractEditText); if (extractEditText instanceof TextView) { nextExtractEditText = (TextView) extractEditText; }/*from w ww . ja v a 2 s .com*/ } if (prevExtractEditText == nextExtractEditText) { return; } if (ProductionFlags.ENABLE_CURSOR_ANCHOR_INFO_CALLBACK && prevExtractEditText != null) { prevExtractEditText.getViewTreeObserver().removeOnPreDrawListener(mExtractTextViewPreDrawListener); } mExtractEditText = nextExtractEditText; if (ProductionFlags.ENABLE_CURSOR_ANCHOR_INFO_CALLBACK && mExtractEditText != null) { mExtractEditText.getViewTreeObserver().addOnPreDrawListener(mExtractTextViewPreDrawListener); } }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
public void showMensajeText(int position, Context context, final MsgGroups message, View rowView, TextView icnMessageArrow) {/*from w w w. j av a 2s. co 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); final TextView messageContent = (TextView) 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); 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, messageContent, 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, prevMessages, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageDate, 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); } } }); } } 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)) { messageContent.setText(message.mensaje); 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() { 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_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) { 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(); } messageContent.setText(message.mensajeTrad); 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; } }); } if (message.orientation == 0) { messageContent.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (messageContent.getLineCount() > 1) { mensajeLayout.setOrientation(LinearLayout.VERTICAL); messageContent.setPadding(0, messageContent.getPaddingTop(), 0, 0); new Update(Message.class).set("orientation = ?", 2) .where("mensajeId = ?", message.mensajeId).execute(); messageContent.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { new Update(Message.class).set("orientation = ?", 1) .where("mensajeId = ?", message.mensajeId).execute(); messageContent.getViewTreeObserver().removeGlobalOnLayoutListener(this); } } }); } else { if (message.orientation == 2) { mensajeLayout.setOrientation(LinearLayout.VERTICAL); messageContent.setPadding(0, messageContent.getPaddingTop(), 0, 0); } } 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.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)) { 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_lang", mensaje.emisorLang); data.put("message", mensaje.mensaje); data.put("translation_required", mensaje.translation); data.put("message_id", mensaje.mensajeId); data.put("source_email", message.emisorEmail); data.put("targets", new JSONArray(mensaje.receptores)); 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(); } } } }); }