List of usage examples for android.widget TextView getText
@ViewDebug.CapturedViewProperty
public CharSequence getText()
From source file:com.android.mms.ui.ComposeMessageActivity.java
private Uri getSelectedUriFromMessageList(ListView listView, int position) { // If the context menu was opened over a uri, get that uri. MessageListItem msglistItem = (MessageListItem) listView.getChildAt(position); if (msglistItem == null) { // FIXME: Should get the correct view. No such interface in ListView currently // to get the view by position. The ListView.getChildAt(position) cannot // get correct view since the list doesn't create one child for each item. // And if setSelection(position) then getSelectedView(), // cannot get corrent view when in touch mode. return null; }/*from w w w . j av a 2s .co m*/ TextView textView; CharSequence text = null; int selStart = -1; int selEnd = -1; //check if message sender is selected textView = (TextView) msglistItem.findViewById(R.id.text_view); if (textView != null) { text = textView.getText(); selStart = textView.getSelectionStart(); selEnd = textView.getSelectionEnd(); } // Check that some text is actually selected, rather than the cursor // just being placed within the TextView. if (selStart != selEnd) { int min = Math.min(selStart, selEnd); int max = Math.max(selStart, selEnd); URLSpan[] urls = ((Spanned) text).getSpans(min, max, URLSpan.class); if (urls.length == 1) { return Uri.parse(urls[0].getURL()); } } //no uri was selected return null; }
From source file:edu.mit.viral.shen.DroidFish.java
private final Dialog moveListMenuDialog() { final int EDIT_HEADERS = 0; final int EDIT_COMMENTS = 1; final int REMOVE_SUBTREE = 2; final int MOVE_VAR_UP = 3; final int MOVE_VAR_DOWN = 4; final int ADD_NULL_MOVE = 5; List<CharSequence> lst = new ArrayList<CharSequence>(); List<Integer> actions = new ArrayList<Integer>(); // lst.add(getString(R.string.edit_headers)); actions.add(EDIT_HEADERS); // if (ctrl.humansTurn()) { lst.add(getString(R.string.edit_comments)); actions.add(EDIT_COMMENTS);//from w w w.j a va 2s .co m // } // lst.add(getString(R.string.truncate_gametree)); actions.add(REMOVE_SUBTREE); // if (ctrl.numVariations() > 1) { // lst.add(getString(R.string.move_var_up)); actions.add(MOVE_VAR_UP); // lst.add(getString(R.string.move_var_down)); actions.add(MOVE_VAR_DOWN); // } boolean allowNullMove = gameMode.analysisMode() || (gameMode.playerWhite() && gameMode.playerBlack() && !gameMode.clocksActive()); if (allowNullMove) { lst.add(getString(R.string.add_null_move)); actions.add(ADD_NULL_MOVE); } final List<Integer> finalActions = actions; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.edit_game); builder.setItems(lst.toArray(new CharSequence[lst.size()]), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (finalActions.get(item)) { case EDIT_HEADERS: { final TreeMap<String, String> headers = new TreeMap<String, String>(); ctrl.getHeaders(headers); AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this); builder.setTitle(R.string.edit_headers); View content = View.inflate(DroidFish.this, R.layout.edit_headers, null); builder.setView(content); final TextView event, site, date, round, white, black; event = (TextView) content.findViewById(R.id.ed_header_event); site = (TextView) content.findViewById(R.id.ed_header_site); date = (TextView) content.findViewById(R.id.ed_header_date); round = (TextView) content.findViewById(R.id.ed_header_round); white = (TextView) content.findViewById(R.id.ed_header_white); black = (TextView) content.findViewById(R.id.ed_header_black); event.setText(headers.get("Event")); site.setText(headers.get("Site")); date.setText(headers.get("Date")); round.setText(headers.get("Round")); white.setText(headers.get("White")); black.setText(headers.get("Black")); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { headers.put("Event", event.getText().toString().trim()); headers.put("Site", site.getText().toString().trim()); headers.put("Date", date.getText().toString().trim()); headers.put("Round", round.getText().toString().trim()); headers.put("White", white.getText().toString().trim()); headers.put("Black", black.getText().toString().trim()); ctrl.setHeaders(headers); setBoardFlip(true); } }); builder.show(); break; } case EDIT_COMMENTS: { AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this); builder.setTitle(R.string.edit_comments); View content = View.inflate(DroidFish.this, R.layout.edit_comments, null); builder.setView(content); DroidChessController.CommentInfo commInfo = ctrl.getComments(); final TextView preComment, moveView, nag, postComment; preComment = (TextView) content.findViewById(R.id.ed_comments_pre); moveView = (TextView) content.findViewById(R.id.ed_comments_move); nag = (TextView) content.findViewById(R.id.ed_comments_nag); postComment = (TextView) content.findViewById(R.id.ed_comments_post); preComment.setText(commInfo.preComment); postComment.setText(commInfo.postComment); moveView.setText(commInfo.move); String nagStr = Node.nagStr(commInfo.nag).trim(); if ((nagStr.length() == 0) && (commInfo.nag > 0)) nagStr = String.format(Locale.US, "%d", commInfo.nag); nag.setText(nagStr); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String pre = preComment.getText().toString().trim(); String post = postComment.getText().toString().trim(); int nagVal = Node.strToNag(nag.getText().toString()); DroidChessController.CommentInfo commInfo = new DroidChessController.CommentInfo(); commInfo.preComment = pre; commInfo.postComment = post; commInfo.nag = nagVal; ctrl.setComments(commInfo); } }); builder.show(); break; } case REMOVE_SUBTREE: ctrl.removeSubTree(); break; case MOVE_VAR_UP: ctrl.moveVariation(-1); break; case MOVE_VAR_DOWN: ctrl.moveVariation(1); break; case ADD_NULL_MOVE: ctrl.makeHumanNullMove(); break; } moveListMenuDlg = null; } }); AlertDialog alert = builder.create(); moveListMenuDlg = alert; return alert; }
From source file:edu.mit.viral.shen.DroidFish.java
private final void initUI() { leftHanded = leftHandedView();/* w w w. ja va2 s. com*/ setContentView(leftHanded ? R.layout.main_left_handed : R.layout.main); Util.overrideFonts(findViewById(android.R.id.content)); // title lines need to be regenerated every time due to layout changes (rotations) secondTitleLine = findViewById(R.id.second_title_line); // whiteTitleText = (TextView)findViewById(R.id.white_clock); // whiteTitleText.setSelected(true); // blackTitleText = (TextView)findViewById(R.id.black_clock); // blackTitleText.setSelected(true); engineTitleText = (TextView) findViewById(R.id.title_text); whiteFigText = (TextView) findViewById(R.id.white_pieces); whiteFigText.setTypeface(figNotation); whiteFigText.setSelected(true); // whiteFigText.setTextColor(whiteTitleText.getTextColors()); blackFigText = (TextView) findViewById(R.id.black_pieces); blackFigText.setTypeface(figNotation); blackFigText.setSelected(true); // blackFigText.setTextColor(blackTitleText.getTextColors()); summaryTitleText = (TextView) findViewById(R.id.title_text_summary); status = (TextView) findViewById(R.id.status); // server = (TextView)findViewById(R.id.server); moveListScroll = (ScrollView) findViewById(R.id.scrollView); moveList = (TextView) findViewById(R.id.moveList); defaultMoveListTypeFace = moveList.getTypeface(); thinking = (TextView) findViewById(R.id.thinking); defaultThinkingListTypeFace = thinking.getTypeface(); status.setFocusable(false); moveListScroll.setFocusable(false); moveList.setFocusable(false); moveList.setMovementMethod(LinkMovementMethod.getInstance()); thinking.setFocusable(false); cb = (ChessBoardPlay) findViewById(R.id.chessboard); cb.setFocusable(true); cb.requestFocus(); cb.setClickable(true); cb.setPgnOptions(pgnOptions); final GestureDetector gd = new GestureDetector(new GestureDetector.SimpleOnGestureListener() { private float scrollX = 0; private float scrollY = 0; @Override public boolean onDown(MotionEvent e) { if (!boardGestures) { handleClick(e); return true; } scrollX = 0; scrollY = 0; return false; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (!boardGestures) return false; cb.cancelLongPress(); if (invertScrollDirection) { distanceX = -distanceX; distanceY = -distanceY; } if ((scrollSensitivity > 0) && (cb.sqSize > 0)) { scrollX += distanceX; scrollY += distanceY; float scrollUnit = cb.sqSize * scrollSensitivity; if (Math.abs(scrollX) >= Math.abs(scrollY)) { // Undo/redo int nRedo = 0, nUndo = 0; while (scrollX > scrollUnit) { nRedo++; scrollX -= scrollUnit; } while (scrollX < -scrollUnit) { nUndo++; scrollX += scrollUnit; } if (nUndo + nRedo > 0) scrollY = 0; if (nRedo + nUndo > 1) { boolean analysis = gameMode.analysisMode(); boolean human = gameMode.playerWhite() || gameMode.playerBlack(); if (analysis || !human) ctrl.setGameMode(new GameMode(GameMode.TWO_PLAYERS)); } for (int i = 0; i < nRedo; i++) ctrl.redoMove(); for (int i = 0; i < nUndo; i++) ctrl.undoMove(); ctrl.setGameMode(gameMode); } else { // Next/previous variation int varDelta = 0; while (scrollY > scrollUnit) { varDelta++; scrollY -= scrollUnit; } while (scrollY < -scrollUnit) { varDelta--; scrollY += scrollUnit; } if (varDelta != 0) scrollX = 0; ctrl.changeVariation(varDelta); } } return true; } @Override public boolean onSingleTapUp(MotionEvent e) { if (!boardGestures) return false; cb.cancelLongPress(); handleClick(e); return true; } @Override public boolean onDoubleTapEvent(MotionEvent e) { if (!boardGestures) return false; if (e.getAction() == MotionEvent.ACTION_UP) handleClick(e); return true; } private final void handleClick(MotionEvent e) { if (ctrl.humansTurn()) { int sq = cb.eventToSquare(e); Move m = cb.mousePressed(sq); if (m != null) { ctrl.makeHumanMove(m); String longfen = TextIO.toFEN(cb.pos); String sentout = utils.getSendMessageJSON(longfen); sendJSON(sentout); // String fen1=longfen.replaceAll("D","1");] // commented out 04/12/15 // sendDataone(longfen, 1); } setEgtbHints(cb.getSelectedSquare()); } } @Override public void onLongPress(MotionEvent e) { if (!boardGestures) return; ((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).vibrate(20); removeDialog(BOARD_MENU_DIALOG); showDialog(BOARD_MENU_DIALOG); } }); cb.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { return gd.onTouchEvent(event); } }); cb.setOnTrackballListener(new ChessBoard.OnTrackballListener() { public void onTrackballEvent(MotionEvent event) { if (ctrl.humansTurn()) { Move m = cb.handleTrackballEvent(event); if (m != null) ctrl.makeHumanMove(m); setEgtbHints(cb.getSelectedSquare()); } } }); moveList.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { removeDialog(MOVELIST_MENU_DIALOG); showDialog(MOVELIST_MENU_DIALOG); return true; } }); thinking.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { if (mShowThinking || gameMode.analysisMode()) { if (!pvMoves.isEmpty()) { removeDialog(THINKING_MENU_DIALOG); showDialog(THINKING_MENU_DIALOG); } } return true; } }); custom1Button = (ImageButton) findViewById(R.id.custom1Button); custom1ButtonActions.setImageButton(custom1Button, this); custom2Button = (ImageButton) findViewById(R.id.custom2Button); custom2ButtonActions.setImageButton(custom2Button, this); custom3Button = (ImageButton) findViewById(R.id.custom3Button); custom3ButtonActions.setImageButton(custom3Button, this); /* modeButton = (ImageButton)findViewById(R.id.modeButton); modeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showDialog(GAME_MODE_DIALOG); } }); */ undoButton = (ImageButton) findViewById(R.id.undoButton); undoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ctrl.undoMove(); sendDataone(TextIO.toFEN(cb.pos), 1); } }); undoButton.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { removeDialog(GO_BACK_MENU_DIALOG); showDialog(GO_BACK_MENU_DIALOG); return true; } }); commentButton = (ImageButton) findViewById(R.id.commentbutton); commentButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this); builder.setTitle(R.string.edit_comments); View content = View.inflate(DroidFish.this, R.layout.edit_comments, null); builder.setView(content); DroidChessController.CommentInfo commInfo = ctrl.getComments(); final TextView preComment, moveView, nag, postComment; preComment = (TextView) content.findViewById(R.id.ed_comments_pre); moveView = (TextView) content.findViewById(R.id.ed_comments_move); nag = (TextView) content.findViewById(R.id.ed_comments_nag); postComment = (TextView) content.findViewById(R.id.ed_comments_post); preComment.setText(commInfo.preComment); postComment.setText(commInfo.postComment); moveView.setText(commInfo.move); String nagStr = Node.nagStr(commInfo.nag).trim(); if ((nagStr.length() == 0) && (commInfo.nag > 0)) nagStr = String.format(Locale.US, "%d", commInfo.nag); nag.setText(nagStr); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String pre = preComment.getText().toString().trim(); String post = postComment.getText().toString().trim(); sendComment(post); int nagVal = Node.strToNag(nag.getText().toString()); DroidChessController.CommentInfo commInfo = new DroidChessController.CommentInfo(); commInfo.preComment = pre; commInfo.postComment = post; commInfo.nag = nagVal; ctrl.setComments(commInfo); } }); builder.show(); } }); commentButton.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { removeDialog(GO_FORWARD_MENU_DIALOG); showDialog(GO_FORWARD_MENU_DIALOG); return true; } }); redoButton = (ImageButton) findViewById(R.id.redoButton); redoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ctrl.redoMove(); //startNewGame(2); } }); redoButton.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { removeDialog(GO_FORWARD_MENU_DIALOG); showDialog(GO_FORWARD_MENU_DIALOG); return true; } }); }
From source file:com.if3games.chessonline.DroidFish.java
private final Dialog moveListMenuDialog() { final int EDIT_HEADERS = 0; final int EDIT_COMMENTS = 1; final int REMOVE_SUBTREE = 2; final int MOVE_VAR_UP = 3; final int MOVE_VAR_DOWN = 4; final int ADD_NULL_MOVE = 5; List<CharSequence> lst = new ArrayList<CharSequence>(); List<Integer> actions = new ArrayList<Integer>(); lst.add(getString(R.string.edit_headers)); actions.add(EDIT_HEADERS);/* w w w . ja va 2 s .c o m*/ if (ctrl.humansTurn()) { lst.add(getString(R.string.edit_comments)); actions.add(EDIT_COMMENTS); } lst.add(getString(R.string.truncate_gametree)); actions.add(REMOVE_SUBTREE); if (ctrl.numVariations() > 1) { lst.add(getString(R.string.move_var_up)); actions.add(MOVE_VAR_UP); lst.add(getString(R.string.move_var_down)); actions.add(MOVE_VAR_DOWN); } boolean allowNullMove = gameMode.analysisMode() || (gameMode.playerWhite() && gameMode.playerBlack() && !gameMode.clocksActive()); if (allowNullMove) { lst.add(getString(R.string.add_null_move)); actions.add(ADD_NULL_MOVE); } final List<Integer> finalActions = actions; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.edit_game); builder.setItems(lst.toArray(new CharSequence[lst.size()]), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { switch (finalActions.get(item)) { case EDIT_HEADERS: { final TreeMap<String, String> headers = new TreeMap<String, String>(); ctrl.getHeaders(headers); AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this); builder.setTitle(R.string.edit_headers); View content = View.inflate(DroidFish.this, R.layout.edit_headers, null); builder.setView(content); final TextView event, site, date, round, white, black; event = (TextView) content.findViewById(R.id.ed_header_event); site = (TextView) content.findViewById(R.id.ed_header_site); date = (TextView) content.findViewById(R.id.ed_header_date); round = (TextView) content.findViewById(R.id.ed_header_round); white = (TextView) content.findViewById(R.id.ed_header_white); black = (TextView) content.findViewById(R.id.ed_header_black); event.setText(headers.get("Event")); site.setText(headers.get("Site")); date.setText(headers.get("Date")); round.setText(headers.get("Round")); white.setText(headers.get("White")); black.setText(headers.get("Black")); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { headers.put("Event", event.getText().toString().trim()); headers.put("Site", site.getText().toString().trim()); headers.put("Date", date.getText().toString().trim()); headers.put("Round", round.getText().toString().trim()); headers.put("White", white.getText().toString().trim()); headers.put("Black", black.getText().toString().trim()); ctrl.setHeaders(headers); setBoardFlip(true); } }); builder.show(); break; } case EDIT_COMMENTS: { AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this); builder.setTitle(R.string.edit_comments); View content = View.inflate(DroidFish.this, R.layout.edit_comments, null); builder.setView(content); DroidChessController.CommentInfo commInfo = ctrl.getComments(); final TextView preComment, moveView, nag, postComment; preComment = (TextView) content.findViewById(R.id.ed_comments_pre); moveView = (TextView) content.findViewById(R.id.ed_comments_move); nag = (TextView) content.findViewById(R.id.ed_comments_nag); postComment = (TextView) content.findViewById(R.id.ed_comments_post); preComment.setText(commInfo.preComment); postComment.setText(commInfo.postComment); moveView.setText(commInfo.move); String nagStr = Node.nagStr(commInfo.nag).trim(); if ((nagStr.length() == 0) && (commInfo.nag > 0)) nagStr = String.format(Locale.US, "%d", commInfo.nag); nag.setText(nagStr); builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String pre = preComment.getText().toString().trim(); String post = postComment.getText().toString().trim(); int nagVal = Node.strToNag(nag.getText().toString()); DroidChessController.CommentInfo commInfo = new DroidChessController.CommentInfo(); commInfo.preComment = pre; commInfo.postComment = post; commInfo.nag = nagVal; ctrl.setComments(commInfo); } }); builder.show(); break; } case REMOVE_SUBTREE: ctrl.removeSubTree(); break; case MOVE_VAR_UP: ctrl.moveVariation(-1); break; case MOVE_VAR_DOWN: ctrl.moveVariation(1); break; case ADD_NULL_MOVE: ctrl.makeHumanNullMove(); break; } moveListMenuDlg = null; } }); AlertDialog alert = builder.create(); moveListMenuDlg = alert; return alert; }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
public void showMensajeMember(int position, Context context, final MsgGroups message, View rowView) { final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageDate = (TextView) rowView.findViewById(R.id.message_date); TextView messageMember = (TextView) rowView.findViewById(R.id.message_member); TFCache.apply(context, prevMessages, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageDate, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageMember, TFCache.TF_WHITNEY_MEDIUM); if (position == 0) { if (mensajesTotal > mensajesOffset) { prevMessages.setVisibility(View.VISIBLE); prevMessages.setOnClickListener(new View.OnClickListener() { @Override//from ww w .j a va 2 s . c om 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); } } } messageMember.setText(message.mensaje); }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
public void showMensajeLocation(int position, Context context, final MsgGroups message, View rowView, TextView icnMessageArrow) {/*from ww w.ja va2s. c o m*/ final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageTime = (TextView) rowView.findViewById(R.id.message_time); final TextView icnMesajeTempo = (TextView) rowView.findViewById(R.id.icn_message_tempo); final View icnMensajeTempoDivider = (View) rowView.findViewById(R.id.icn_message_tempo_divider); final TextView icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy); final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back); final ImageView messageContent = (ImageView) rowView.findViewById(R.id.message_content); TextView messageStatus = (TextView) rowView.findViewById(R.id.message_status); final LinearLayout messageMenu = (LinearLayout) rowView.findViewById(R.id.messages_menu_layout); final LinearLayout mensajeLayout = (LinearLayout) rowView.findViewById(R.id.mensaje_layout); TextView messageDate = (TextView) rowView.findViewById(R.id.message_date); TextView messageLocationText = (TextView) rowView.findViewById(R.id.message_location_text); TextView messageLocationIcon = (TextView) rowView.findViewById(R.id.message_location_icon); final CircleImageView imageUser = (CircleImageView) rowView.findViewById(R.id.chat_row_user_pic); final TextView userName = (TextView) rowView.findViewById(R.id.username_text); TFCache.apply(context, messageTime, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, icnMesajeTempo, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeCopy, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageLocationIcon, TFCache.TF_SPEAKALL); TFCache.apply(context, messageDate, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageLocationText, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, userName, TFCache.TF_WHITNEY_MEDIUM); if (position == 0) { if (mensajesTotal > mensajesOffset) { prevMessages.setVisibility(View.VISIBLE); prevMessages.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { prevMessages.setVisibility(View.GONE); if (mensajesTotal - mensajesOffset >= 10) { mensajesLimit = 10; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } else { mensajesLimit = mensajesTotal - mensajesOffset; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } } }); } } double latitud = 0; double longitud = 0; try { JSONObject locationData = new JSONObject(message.mensaje); messageLocationText.setText(locationData.getString("direccion")); latitud = Double.parseDouble(locationData.getString("latitud")); longitud = Double.parseDouble(locationData.getString("longitud")); } catch (JSONException e) { e.printStackTrace(); } DateFormat dateDay = new SimpleDateFormat("d"); DateFormat dateDayText = new SimpleDateFormat("EEEE"); DateFormat dateMonth = new SimpleDateFormat("MMMM"); DateFormat dateYear = new SimpleDateFormat("yyyy"); DateFormat timeFormat = new SimpleDateFormat("h:mm a"); Calendar fechamsj = Calendar.getInstance(); fechamsj.setTimeInMillis(message.emitedAt); String time = timeFormat.format(fechamsj.getTime()); String dayMessage = dateDay.format(fechamsj.getTime()); String monthMessage = dateMonth.format(fechamsj.getTime()); String yearMessage = dateYear.format(fechamsj.getTime()); String dayMessageText = dateDayText.format(fechamsj.getTime()); char[] caracteres = dayMessageText.toCharArray(); caracteres[0] = Character.toUpperCase(caracteres[0]); dayMessageText = new String(caracteres); Calendar fechaActual = Calendar.getInstance(); String dayActual = dateDay.format(fechaActual.getTime()); String monthActual = dateMonth.format(fechaActual.getTime()); String yearActual = dateYear.format(fechaActual.getTime()); String fechaMostrar = ""; if (dayMessage.equals(dayActual) && monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { fechaMostrar = getString(R.string.messages_today); } else if (monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { int days = Integer.parseInt(dayActual) - Integer.parseInt(dayMessage); if (days < 7) { switch (days) { case 1: fechaMostrar = getString(R.string.messages_yesterday); break; default: fechaMostrar = dayMessageText; break; } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } messageDate.setText(fechaMostrar); if (position != -1) { if (itemAnterior != null) { if (!fechaMostrar.equals(fechaAnterior)) { itemAnterior.findViewById(R.id.message_date).setVisibility(View.VISIBLE); } else { itemAnterior.findViewById(R.id.message_date).setVisibility(View.GONE); } } itemAnterior = rowView; fechaAnterior = fechaMostrar; } else { View v = messagesList.getChildAt(messagesList.getChildCount() - 1); if (v != null) { TextView tv = (TextView) v.findViewById(R.id.message_date); if (tv.getText().toString().equals(fechaMostrar)) { messageDate.setVisibility(View.GONE); } else { messageDate.setVisibility(View.VISIBLE); } } } messageTime.setText(time); if (message.emisor.equals(u.id)) { int status = 0; try { JSONArray contactos = new JSONArray(message.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); Log.w("STATUS", contacto.getInt("status") + contacto.getString("name")); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } if (status != -1) { rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(30); MsgGroups mensaje = new Select().from(MsgGroups.class) .where("mensajeId = ?", message.mensajeId).executeSingle(); int status = 0; try { JSONArray contactos = new JSONArray(mensaje.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } if (status != 4) { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } else { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } return false; } }); } if (status == 1) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(getResources().getColor(R.color.speak_all_disable_red)); messageStatus.setTextColor(getResources().getColor(R.color.speak_all_ligh_gray)); messageStatus.setText(Finder.STRING.ICN_MSJ_SENDING.toString()); ValueAnimator colorAnim = ObjectAnimator.ofFloat(messageStatus, "alpha", 1, 0); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.setDuration(1000).start(); animaciones.put(message.mensajeId, colorAnim); JSONObject data = new JSONObject(); try { data.put("type", message.tipo); data.put("group_id", message.grupoId); data.put("group_name", grupo.nombreGrupo); data.put("source", message.emisor); data.put("source_lang", message.emisorLang); data.put("source_email", message.emisorEmail); data.put("message", message.mensaje); data.put("translation_required", message.translation); data.put("message_id", message.mensajeId); data.put("delay", message.delay); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (message.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); targets.put(targets.length(), newContact); } } } data.put("targets", targets); message.receptores = targets.toString(); message.save(); SpeakSocket.mSocket.emit("message", data); } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (message.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); targets.put(targets.length(), newContact); } } } message.receptores = targets.toString(); message.save(); } changeStatus(message.mensajeId); } } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } } if (status == -1) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString()); } if (status == 3) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString()); } if (status == 2) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString()); } if (status == 4) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_OPENED.toString()); } } else { final Contact contacto = new Select().from(Contact.class).where(" id_contact= ?", message.emisor) .executeSingle(); if (contacto != null) { new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { if (contacto.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(contacto.photo, 0, contacto.photo.length); imageUser.setImageBitmap(bmp); userName.setText(contacto.fullName); } } }); } }).start(); } rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(20); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", -100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", -150, 0)); set.setDuration(200).start(); return false; } }); } icnMesajeBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (message.emisor.equals(u.id)) { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensaje)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } else { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensajeTrad)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } } }); final double finalLatitud = latitud; final double finalLongitud = longitud; rowView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MsgGroups mensaje = new Select().from(MsgGroups.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); int status = 0; try { JSONArray contactos = new JSONArray(mensaje.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); if (!messageSelected.equals(message.mensajeId)) { vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } else { if (status != -1) { dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + finalLatitud + "," + finalLongitud)); i.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(i); } } if (status == -1) { JSONObject data = new JSONObject(); try { data.put("type", mensaje.tipo); data.put("group_id", mensaje.grupoId); data.put("group_name", grupo.nombreGrupo); data.put("source", mensaje.emisor); data.put("source_lang", mensaje.emisorLang); data.put("source_email", mensaje.emisorEmail); data.put("message", mensaje.mensaje); data.put("translation_required", mensaje.translation); data.put("message_id", mensaje.mensajeId); data.put("delay", mensaje.delay); JSONArray targets = new JSONArray(); JSONArray contactos = new JSONArray(grupo.targets); if (SpeakSocket.mSocket != null) { if (SpeakSocket.mSocket.connected()) { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (mensaje.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", 1); targets.put(targets.length(), newContact); } } } data.put("targets", targets); mensaje.receptores = targets.toString(); mensaje.save(); SpeakSocket.mSocket.emit("message", data); } else { for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); JSONObject newContact = new JSONObject(); Contact contact = new Select().from(Contact.class) .where("id_contact = ?", contacto.getString("name")).executeSingle(); if (contact != null) { if (!contact.idContacto.equals(u.id)) { if (mensaje.translation) newContact.put("lang", contact.lang); else newContact.put("lang", u.lang); newContact.put("name", contact.idContacto); newContact.put("screen_name", contact.screenName); newContact.put("status", -1); targets.put(targets.length(), newContact); } } } mensaje.receptores = targets.toString(); mensaje.save(); } changeStatus(mensaje.mensajeId); } } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } } } }); }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
public void showMensajeText(int position, Context context, final MsgGroups message, View rowView, TextView icnMessageArrow) {//from w w w. j a va2 s.c o m final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageTime = (TextView) rowView.findViewById(R.id.message_time); final TextView 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(); } } } }); }
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
public void showMensajeLocation(int position, Context context, final Message message, View rowView, TextView icnMessageArrow) {// w w w .j ava 2 s. c o m final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageTime = (TextView) rowView.findViewById(R.id.message_time); final TextView icnMesajeTempo = (TextView) rowView.findViewById(R.id.icn_message_tempo); final View icnMensajeTempoDivider = (View) rowView.findViewById(R.id.icn_message_tempo_divider); final TextView icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy); final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back); final ImageView messageContent = (ImageView) rowView.findViewById(R.id.message_content); TextView messageStatus = (TextView) rowView.findViewById(R.id.message_status); final LinearLayout messageMenu = (LinearLayout) rowView.findViewById(R.id.messages_menu_layout); final LinearLayout mensajeLayout = (LinearLayout) rowView.findViewById(R.id.mensaje_layout); TextView messageDate = (TextView) rowView.findViewById(R.id.message_date); TextView messageLocationText = (TextView) rowView.findViewById(R.id.message_location_text); TextView messageLocationIcon = (TextView) rowView.findViewById(R.id.message_location_icon); TFCache.apply(context, messageTime, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, icnMesajeTempo, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeCopy, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageLocationIcon, TFCache.TF_SPEAKALL); TFCache.apply(context, messageDate, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageLocationText, TFCache.TF_WHITNEY_MEDIUM); if (position == 0) { if (mensajesTotal > mensajesOffset) { prevMessages.setVisibility(View.VISIBLE); prevMessages.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { prevMessages.setVisibility(View.GONE); if (mensajesTotal - mensajesOffset >= 10) { mensajesLimit = 10; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } else { mensajesLimit = mensajesTotal - mensajesOffset; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } } }); } } double latitud = 0; double longitud = 0; try { JSONObject locationData = new JSONObject(message.mensaje); messageLocationText.setText(locationData.getString("direccion")); latitud = Double.parseDouble(locationData.getString("latitud")); longitud = Double.parseDouble(locationData.getString("longitud")); } catch (JSONException e) { e.printStackTrace(); } DateFormat dateDay = new SimpleDateFormat("d"); DateFormat dateDayText = new SimpleDateFormat("EEEE"); DateFormat dateMonth = new SimpleDateFormat("MMMM"); DateFormat dateYear = new SimpleDateFormat("yyyy"); DateFormat timeFormat = new SimpleDateFormat("h:mm a"); Calendar fechamsj = Calendar.getInstance(); fechamsj.setTimeInMillis(message.emitedAt); String time = timeFormat.format(fechamsj.getTime()); String dayMessage = dateDay.format(fechamsj.getTime()); String monthMessage = dateMonth.format(fechamsj.getTime()); String yearMessage = dateYear.format(fechamsj.getTime()); String dayMessageText = dateDayText.format(fechamsj.getTime()); char[] caracteres = dayMessageText.toCharArray(); caracteres[0] = Character.toUpperCase(caracteres[0]); dayMessageText = new String(caracteres); Calendar fechaActual = Calendar.getInstance(); String dayActual = dateDay.format(fechaActual.getTime()); String monthActual = dateMonth.format(fechaActual.getTime()); String yearActual = dateYear.format(fechaActual.getTime()); String fechaMostrar = ""; if (dayMessage.equals(dayActual) && monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { fechaMostrar = getString(R.string.messages_today); } else if (monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { int days = Integer.parseInt(dayActual) - Integer.parseInt(dayMessage); if (days < 7) { switch (days) { case 1: fechaMostrar = getString(R.string.messages_yesterday); break; default: fechaMostrar = dayMessageText; break; } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } messageDate.setText(fechaMostrar); if (position != -1) { if (itemAnterior != null) { if (!fechaMostrar.equals(fechaAnterior)) { itemAnterior.findViewById(R.id.message_date).setVisibility(View.VISIBLE); } else { itemAnterior.findViewById(R.id.message_date).setVisibility(View.GONE); } } itemAnterior = rowView; fechaAnterior = fechaMostrar; } else { View v = messagesList.getChildAt(messagesList.getChildCount() - 1); if (v != null) { TextView tv = (TextView) v.findViewById(R.id.message_date); if (tv.getText().toString().equals(fechaMostrar)) { messageDate.setVisibility(View.GONE); } else { messageDate.setVisibility(View.VISIBLE); } } } messageTime.setText(time); if (message.emisor.equals(u.id)) { if (message.status != -1) { rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(30); Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { icnMesajeTempo.setVisibility(View.VISIBLE); icnMensajeTempoDivider.setVisibility(View.VISIBLE); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeTempo, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeTempo, "translationX", 150, 0), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } else { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } return false; } }); } if (message.status == 1) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setTextColor(getResources().getColor(R.color.speak_all_ligh_gray)); messageStatus.setText(Finder.STRING.ICN_MSJ_SENDING.toString()); ValueAnimator colorAnim = ObjectAnimator.ofFloat(messageStatus, "alpha", 1, 0); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.setDuration(1000).start(); animaciones.put(message.mensajeId, colorAnim); JSONObject data = new JSONObject(); try { data.put("message_id", message.mensajeId); data.put("source", message.emisor); data.put("source_email", message.emisorEmail); data.put("target_email", message.receptorEmail); data.put("target", message.receptor); data.put("message", message.mensaje); data.put("source_lang", message.emisorLang); data.put("delay", message.delay); data.put("type", message.tipo); } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { message.status = 1; SpeakSocket.mSocket.emit("message", data); } else { message.status = -1; } } if (message.status == -1) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString()); } if (message.status == 3) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString()); } if (message.status == 2) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString()); } if (message.status == 4) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_OPENED.toString()); icnMensajeTempoDivider.setVisibility(View.GONE); icnMesajeTempo.setVisibility(View.GONE); } else { icnMensajeTempoDivider.setVisibility(View.INVISIBLE); icnMesajeTempo.setVisibility(View.INVISIBLE); } } else { mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getFriendBalloon(activity)); if (message.tipo == Integer.parseInt(getString(R.string.MSG_TYPE_BROADCAST_PHOTO))) { messageStatus.setTextSize(15); messageStatus.setText(Finder.STRING.ICN_BROADCAST_FILL.toString()); } //messageContent.setText(message.mensajeTrad); icnMesajeTempo.setVisibility(View.GONE); rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(20); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", -100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", -150, 0)); set.setDuration(200).start(); return false; } }); } icnMesajeTempo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { JSONObject notifyMessage = new JSONObject(); try { Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { notifyMessage.put("type", mensaje.tipo); notifyMessage.put("message_id", mensaje.mensajeId); notifyMessage.put("source", mensaje.receptor); notifyMessage.put("status", 5); SpeakSocket.mSocket.emit("message-status", notifyMessage); } new Delete().from(Message.class).where("mensajeId = ?", mensaje.mensajeId).execute(); Message message = null; if (mensaje.emisor.equals(u.id)) { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.receptor, mensaje.receptor) .orderBy("emitedAt DESC").executeSingle(); } else { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.emisor, mensaje.emisor) .orderBy("emitedAt DESC").executeSingle(); } if (message != null) { Chats chat = null; if (mensaje.emisor.equals(u.id)) { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.receptor) .executeSingle(); } else { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.emisor) .executeSingle(); } if (chat != null) { chat.mensajeId = message.mensajeId; chat.lastStatus = message.status; chat.emitedAt = message.emitedAt; chat.lang = message.emisorLang; chat.notRead = 0; if (chat.idContacto.equals(message.emisor)) chat.lastMessage = message.mensajeTrad; else chat.lastMessage = message.mensaje; chat.save(); } } else { if (mensaje.emisor.equals(u.id)) { new Delete().from(Chats.class).where("idContacto = ?", mensaje.receptor).execute(); } else { new Delete().from(Chats.class).where("idContacto = ?", mensaje.emisor).execute(); } } View delete = messagesList.findViewWithTag(mensaje.mensajeId); if (delete != null) messagesList.removeView(delete); messageSelected = null; ((MainActivity) activity).setOnBackPressedListener(null); } catch (JSONException e) { e.printStackTrace(); } } } ); icnMesajeCopy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*ClipData clip = ClipData.newPlainText("text", messageContent.getText().toString()); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(clip); Toast.makeText(activity, "Copiado", Toast.LENGTH_SHORT).show();*/ } } ); icnMesajeBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (message.emisor.equals(u.id)) { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensaje)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } else { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensajeTrad)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } } } ); final double finalLatitud = latitud; final double finalLongitud = longitud; rowView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); if (!messageSelected.equals(message.mensajeId)) { vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } else { if (mensaje.status != -1) { dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + finalLatitud + "," + finalLongitud)); i.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(i); } } if (mensaje.status == -1) { JSONObject data = new JSONObject(); try { data.put("message_id", mensaje.mensajeId); data.put("source", mensaje.emisor); data.put("source_email", mensaje.emisorEmail); data.put("target_email", mensaje.receptorEmail); data.put("target", mensaje.receptor); data.put("message", message.mensaje); data.put("source_lang", mensaje.emisorLang); data.put("delay", mensaje.delay); data.put("type", mensaje.tipo); } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { mensaje.status = 1; SpeakSocket.mSocket.emit("message", data); } else { mensaje.status = -1; } changeStatus(mensaje.mensajeId, mensaje.status); } } } ); }
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
public void showMensajePhoto(int position, Context context, final Message message, View rowView, TextView icnMessageArrow) {// www . ja va2s . c o m final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageTime = (TextView) rowView.findViewById(R.id.message_time); final TextView icnMesajeTempo = (TextView) rowView.findViewById(R.id.icn_message_tempo); final View icnMensajeTempoDivider = (View) rowView.findViewById(R.id.icn_message_tempo_divider); final TextView icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy); final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back); final ImageView messageContent = (ImageView) rowView.findViewById(R.id.message_content); TextView messageStatus = (TextView) rowView.findViewById(R.id.message_status); final LinearLayout messageMenu = (LinearLayout) rowView.findViewById(R.id.messages_menu_layout); final LinearLayout mensajeLayout = (LinearLayout) rowView.findViewById(R.id.mensaje_layout); TextView messageDate = (TextView) rowView.findViewById(R.id.message_date); final ProgressBar progressBar = (ProgressBar) rowView.findViewById(R.id.progress_bar); final RelativeLayout progressLayout = (RelativeLayout) rowView.findViewById(R.id.progress_layout); final TextView progressText = (TextView) rowView.findViewById(R.id.progress_message); TFCache.apply(context, messageTime, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, icnMesajeTempo, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeCopy, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, prevMessages, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageDate, 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)) { new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { if (message.fileUploaded) { if (message.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(message.photo, 0, message.photo.length); messageContent.setImageBitmap(bmp); bmp = null; } } else { if (message.photoBlur != null) { Bitmap bmp = BitmapFactory.decodeByteArray(message.photoBlur, 0, message.photoBlur.length); messageContent.setImageBitmap(bmp); bmp = null; } } } }); } }).start(); if (message.status != -1) { rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(30); Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { icnMesajeTempo.setVisibility(View.VISIBLE); icnMensajeTempoDivider.setVisibility(View.VISIBLE); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeTempo, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeTempo, "translationX", 150, 0), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } else { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } return false; } }); } if (message.status == 1) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setTextColor(getResources().getColor(R.color.speak_all_ligh_gray)); messageStatus.setText(Finder.STRING.ICN_MSJ_SENDING.toString()); ValueAnimator colorAnim = ObjectAnimator.ofFloat(messageStatus, "alpha", 1, 0); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.setDuration(1000).start(); animaciones.put(message.mensajeId, colorAnim); try { final JSONObject mensaje = new JSONObject(); mensaje.put("message_id", message.mensajeId); mensaje.put("source", message.emisor); mensaje.put("source_email", message.emisorEmail); mensaje.put("target_email", message.receptorEmail); mensaje.put("target", message.receptor); mensaje.put("type", message.tipo); mensaje.put("delay", message.delay); if (!message.fileUploaded) { progressLayout.setVisibility(View.VISIBLE); new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { uploadPhotoToServer(message.photoName, message, mensaje, progressBar, progressLayout, progressText, messageContent); } }); } }).start(); } } catch (JSONException e) { e.printStackTrace(); } } if (message.status == -1) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString()); } if (message.status == 3) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString()); } if (message.status == 2) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString()); } if (message.status == 4) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_OPENED.toString()); icnMensajeTempoDivider.setVisibility(View.GONE); icnMesajeTempo.setVisibility(View.GONE); } else { icnMensajeTempoDivider.setVisibility(View.INVISIBLE); icnMesajeTempo.setVisibility(View.INVISIBLE); } } else { mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getFriendBalloon(activity)); if (message.tipo == Integer.parseInt(getString(R.string.MSG_TYPE_BROADCAST_PHOTO))) { messageStatus.setTextSize(15); messageStatus.setText(Finder.STRING.ICN_BROADCAST_FILL.toString()); } new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { File archivo = new File(message.photoName); if (archivo.exists()) { if (message.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(message.photo, 0, message.photo.length); messageContent.setImageBitmap(bmp); bmp = null; } } else { if (message.photoBlur != null) { Bitmap bmp = BitmapFactory.decodeByteArray(message.photoBlur, 0, message.photoBlur.length); messageContent.setImageBitmap(bmp); bmp = null; } } } }); } }).start(); //messageContent.setText(message.mensajeTrad); icnMesajeTempo.setVisibility(View.GONE); rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(20); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", -100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", -150, 0)); set.setDuration(200).start(); return false; } }); } icnMesajeTempo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { JSONObject notifyMessage = new JSONObject(); try { Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { notifyMessage.put("type", mensaje.tipo); notifyMessage.put("message_id", mensaje.mensajeId); notifyMessage.put("source", mensaje.receptor); notifyMessage.put("status", 5); SpeakSocket.mSocket.emit("message-status", notifyMessage); } new Delete().from(Message.class).where("mensajeId = ?", mensaje.mensajeId).execute(); Message message = null; if (mensaje.emisor.equals(u.id)) { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.receptor, mensaje.receptor) .orderBy("emitedAt DESC").executeSingle(); } else { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.emisor, mensaje.emisor) .orderBy("emitedAt DESC").executeSingle(); } if (message != null) { Chats chat = null; if (mensaje.emisor.equals(u.id)) { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.receptor) .executeSingle(); } else { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.emisor) .executeSingle(); } if (chat != null) { chat.mensajeId = message.mensajeId; chat.lastStatus = message.status; chat.emitedAt = message.emitedAt; chat.lang = message.emisorLang; chat.notRead = 0; if (chat.idContacto.equals(message.emisor)) chat.lastMessage = message.mensajeTrad; else chat.lastMessage = message.mensaje; chat.save(); } } else { if (mensaje.emisor.equals(u.id)) { new Delete().from(Chats.class).where("idContacto = ?", mensaje.receptor).execute(); } else { new Delete().from(Chats.class).where("idContacto = ?", mensaje.emisor).execute(); } } View delete = messagesList.findViewWithTag(mensaje.mensajeId); if (delete != null) messagesList.removeView(delete); messageSelected = null; ((MainActivity) activity).setOnBackPressedListener(null); } catch (JSONException e) { e.printStackTrace(); } } } ); icnMesajeCopy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*ClipData clip = ClipData.newPlainText("text", messageContent.getText().toString()); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(clip); Toast.makeText(activity, "Copiado", Toast.LENGTH_SHORT).show();*/ } } ); icnMesajeBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (message.emisor.equals(u.id)) { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensaje)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } else { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensajeTrad)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } } } ); rowView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); if (!messageSelected.equals(message.mensajeId)) { vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } else { if (mensaje.fileDownloaded || mensaje.fileUploaded) { if (mensaje.status != -1) { dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent i = new Intent(); i.setAction(android.content.Intent.ACTION_VIEW); File videoFile2Play2 = new File(message.photoName); i.setDataAndType(Uri.fromFile(videoFile2Play2), "image/*"); startActivity(i); } } } if (mensaje.status == -1) { String message = mensaje.mensaje; JSONObject data = new JSONObject(); try { data.put("message_id", mensaje.mensajeId); data.put("source", mensaje.emisor); data.put("source_email", mensaje.emisorEmail); data.put("target_email", mensaje.receptorEmail); data.put("target", mensaje.receptor); data.put("message", message); data.put("source_lang", mensaje.emisorLang); data.put("delay", mensaje.delay); data.put("type", mensaje.tipo); } catch (JSONException e) { e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { mensaje.status = 1; SpeakSocket.mSocket.emit("message", data); } else { mensaje.status = -1; } changeStatus(mensaje.mensajeId, mensaje.status); } } } ); }
From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java
public void showMensajePhoto(int position, Context context, final MsgGroups message, View rowView, TextView icnMessageArrow) {//w ww . j a v a 2 s . com final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageTime = (TextView) rowView.findViewById(R.id.message_time); final TextView icnMesajeTempo = (TextView) rowView.findViewById(R.id.icn_message_tempo); final View icnMensajeTempoDivider = (View) rowView.findViewById(R.id.icn_message_tempo_divider); final TextView icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy); final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back); final ImageView messageContent = (ImageView) rowView.findViewById(R.id.message_content); TextView messageStatus = (TextView) rowView.findViewById(R.id.message_status); final LinearLayout messageMenu = (LinearLayout) rowView.findViewById(R.id.messages_menu_layout); final LinearLayout mensajeLayout = (LinearLayout) rowView.findViewById(R.id.mensaje_layout); TextView messageDate = (TextView) rowView.findViewById(R.id.message_date); final ProgressBar progressBar = (ProgressBar) rowView.findViewById(R.id.progress_bar); final RelativeLayout progressLayout = (RelativeLayout) rowView.findViewById(R.id.progress_layout); final TextView progressText = (TextView) rowView.findViewById(R.id.progress_message); final CircleImageView imageUser = (CircleImageView) rowView.findViewById(R.id.chat_row_user_pic); final TextView userName = (TextView) rowView.findViewById(R.id.username_text); TFCache.apply(context, messageTime, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, icnMesajeTempo, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeCopy, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, 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)) { new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { if (message.fileUploaded) { if (message.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(message.photo, 0, message.photo.length); messageContent.setImageBitmap(bmp); bmp = null; } } else { if (message.photoBlur != null) { Bitmap bmp = BitmapFactory.decodeByteArray(message.photoBlur, 0, message.photoBlur.length); messageContent.setImageBitmap(bmp); bmp = null; } } } }); } }).start(); int status = 0; try { JSONArray contactos = new JSONArray(message.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); Log.w("STATUS", contacto.getInt("status") + contacto.getString("name")); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } if (status != -1) { rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(30); MsgGroups mensaje = new Select().from(MsgGroups.class) .where("mensajeId = ?", message.mensajeId).executeSingle(); int status = 0; try { JSONArray contactos = new JSONArray(mensaje.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } if (status != 4) { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } else { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } return false; } }); } if (status == 1) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); 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); final 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("targets", new JSONArray(message.receptores)); data.put("delay", message.delay); if (!message.fileUploaded) { progressLayout.setVisibility(View.VISIBLE); new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { uploadPhotoToServer(message.photoName, message, data, progressBar, progressLayout, progressText, messageContent); } }); } }).start(); } else { data.put("photos", message.fileName); 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 .setBackgroundDrawable(getResources().getDrawable(R.drawable.message_errorout_background)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString()); } if (status == 3) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.message_out_background)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString()); } if (status == 2) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.message_out_background)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString()); } if (status == 4) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.message_out_background)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_OPENED.toString()); } } else { new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { File archivo = new File(message.photoName); if (archivo.exists()) { if (message.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(message.photo, 0, message.photo.length); messageContent.setImageBitmap(bmp); bmp = null; } } else { if (message.photoBlur != null) { Bitmap bmp = BitmapFactory.decodeByteArray(message.photoBlur, 0, message.photoBlur.length); messageContent.setImageBitmap(bmp); bmp = null; } } } }); } }).start(); final Contact contacto = new Select().from(Contact.class).where(" id_contact= ?", message.emisor) .executeSingle(); if (contacto != null) { new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { if (contacto.photo != null) { Bitmap bmp = BitmapFactory.decodeByteArray(contacto.photo, 0, contacto.photo.length); imageUser.setImageBitmap(bmp); userName.setText(contacto.fullName); } } }); } }).start(); } rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(20); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", -100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", -150, 0)); set.setDuration(200).start(); return false; } }); } icnMesajeBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (message.emisor.equals(u.id)) { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensaje)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } else { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensajeTrad)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } } }); rowView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final MsgGroups mensaje = new Select().from(MsgGroups.class) .where("mensajeId = ?", message.mensajeId).executeSingle(); int status = 0; try { JSONArray contactos = new JSONArray(mensaje.receptores); for (int i = 0; i < contactos.length(); i++) { JSONObject contacto = contactos.getJSONObject(i); if (status == 0 || contacto.getInt("status") <= status) { status = contacto.getInt("status"); } } } catch (JSONException e) { e.printStackTrace(); } if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); if (!messageSelected.equals(message.mensajeId)) { vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } else { if (mensaje.fileDownloaded || mensaje.fileUploaded) { if (status != -1) { dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent i = new Intent(); i.setAction(android.content.Intent.ACTION_VIEW); File videoFile2Play2 = new File(message.photoName); i.setDataAndType(Uri.fromFile(videoFile2Play2), "image/*"); startActivity(i); } } } if (status == -1) { final JSONObject data = new JSONObject(); try { data.put("type", mensaje.tipo); data.put("group_id", mensaje.grupoId); data.put("group_name", grupo.nombreGrupo); data.put("source", mensaje.emisor); data.put("source_lang", mensaje.emisorLang); data.put("source_email", mensaje.emisorEmail); data.put("message", mensaje.mensaje); data.put("translation_required", mensaje.translation); data.put("message_id", mensaje.mensajeId); data.put("targets", new JSONArray(mensaje.receptores)); data.put("delay", mensaje.delay); if (!mensaje.fileUploaded) { progressLayout.setVisibility(View.VISIBLE); new Thread(new Runnable() { @Override public void run() { activity.runOnUiThread(new Runnable() { @Override public void run() { uploadPhotoToServer(mensaje.photoName, mensaje, data, progressBar, progressLayout, progressText, messageContent); } }); } }).start(); } else { data.put("photos", mensaje.fileName); 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); 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(); } } } }); }