Example usage for android.widget ImageView setImageBitmap

List of usage examples for android.widget ImageView setImageBitmap

Introduction

In this page you can find the example usage for android.widget ImageView setImageBitmap.

Prototype

@android.view.RemotableViewMethod
public void setImageBitmap(Bitmap bm) 

Source Link

Document

Sets a Bitmap as the content of this ImageView.

Usage

From source file:com.juick.android.UserCenterActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    JuickAdvancedApplication.setupTheme(this);
    handler = new Handler();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.user_center);
    final ListView list = (ListView) findViewById(R.id.list);
    final View listWait = findViewById(R.id.list_wait);
    final TextView userRealName = (TextView) findViewById(R.id.user_realname);
    final ImageView userPic = (ImageView) findViewById(R.id.userpic);
    final TextView userName = (TextView) findViewById(R.id.username);
    search = findViewById(R.id.search);// ww w  . j a v a2s  .c om
    final View stats = findViewById(R.id.stats);
    userRealName.setText("...");
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        finish();
        return;
    }
    uname = extras.getString("uname");
    final int uid = extras.getInt("uid");

    final MessageID mid = (MessageID) extras.getSerializable("mid");
    final MessagesSource messagesSource = (MessagesSource) extras.getSerializable("messagesSource");
    if (uname == null || mid == null) {
        finish();
        return;
    }
    int height = getWindow().getWindowManager().getDefaultDisplay().getHeight();
    final int userpicSize = height <= 320 ? 32 : 96;
    float scaledDensity = getResources().getDisplayMetrics().scaledDensity;
    userPic.setMinimumHeight((int) (scaledDensity * userpicSize));
    userPic.setMinimumWidth((int) (scaledDensity * userpicSize));
    stats.setEnabled(false);
    userName.setText("@" + uname);
    final boolean russian = Locale.getDefault().getLanguage().equals("ru");
    new Thread() {
        @Override
        public void run() {
            final Utils.RESTResponse json = Utils.getJSON(UserCenterActivity.this,
                    "http://" + Utils.JA_ADDRESS + "/api/userinfo?uname=" + Uri.encode(uname), null);
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    stats.setEnabled(true);
                    if (json.getErrorText() != null) {
                        Toast.makeText(UserCenterActivity.this, "JA server: " + json.getErrorText(),
                                Toast.LENGTH_LONG).show();
                        listWait.setVisibility(View.GONE);
                    } else {
                        final UserInfo userInfo = new Gson().fromJson(json.getResult(), UserInfo.class);
                        if (userInfo == null) {
                            Toast.makeText(UserCenterActivity.this, "Unable to parse JSON", Toast.LENGTH_LONG)
                                    .show();
                            listWait.setVisibility(View.GONE);
                        } else {
                            userRealName.setText(userInfo.fullName);
                            listWait.setVisibility(View.GONE);
                            list.setVisibility(View.VISIBLE);
                            list.setAdapter(new BaseAdapter() {
                                @Override
                                public int getCount() {
                                    return userInfo.getExtraInfo().size();
                                }

                                @Override
                                public Object getItem(int position) {
                                    return userInfo.getExtraInfo().get(position);
                                }

                                @Override
                                public long getItemId(int position) {
                                    return position;
                                }

                                @Override
                                public View getView(int position, View convertView, ViewGroup parent) {
                                    if (convertView == null) {
                                        convertView = getLayoutInflater().inflate(R.layout.listitem_userinfo,
                                                null);
                                    }
                                    TextView text = (TextView) convertView.findViewById(R.id.text);
                                    TextView text2 = (TextView) convertView.findViewById(R.id.text2);
                                    String info = userInfo.getExtraInfo().get(position);
                                    int ix = info.indexOf("|");
                                    if (ix == -1) {
                                        text.setText(info);
                                        if (russian && UserInfo.translations.containsKey(info)) {
                                            info = UserInfo.translations.get(info);
                                        }
                                        text2.setText("");
                                    } else {
                                        String theInfo = info.substring(0, ix);
                                        if (russian && UserInfo.translations.containsKey(theInfo)) {
                                            theInfo = UserInfo.translations.get(theInfo);
                                        }
                                        text.setText(theInfo);
                                        String value = info.substring(ix + 1);
                                        if (value.startsWith("Date:")) {
                                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                            value = value.substring(5);
                                            value = sdf.format(new Date(Long.parseLong(value)));
                                        }
                                        text2.setText(value);
                                    }
                                    return convertView;
                                }
                            });
                        }
                    }
                }
            });
        }

    }.start();

    View subscribe_user = findViewById(R.id.subscribe_user);
    View unsubscribe_user = findViewById(R.id.unsubscribe_user);
    View subscribe_comments = findViewById(R.id.subscribe_comments);
    View unsubscribe_comments = findViewById(R.id.unsubscribe_comments);
    View filter_user = findViewById(R.id.filter_user);
    View blacklist_user = findViewById(R.id.blacklist_user);
    View show_blog = findViewById(R.id.show_blog);
    MicroBlog microBlog = MainActivity.getMicroBlog(mid.getMicroBlogCode());
    final MessageMenu mm = microBlog.getMessageMenu(this, messagesSource, null, null);
    JuickMessage message = microBlog.createMessage();
    mm.listSelectedItem = message;
    message.User = new JuickUser();
    message.User.UName = uname;
    message.User.UID = uid;
    message.setMID(mid);
    final UserpicStorage.AvatarID avatarID = microBlog.getAvatarID(message);

    final UserpicStorage.Listener userpicListener = new UserpicStorage.Listener() {
        @Override
        public void onUserpicReady(UserpicStorage.AvatarID id, int size) {
            final UserpicStorage.Listener thiz = this;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    UserpicStorage.instance.removeListener(avatarID, userpicSize, thiz);
                    final Bitmap userpic = UserpicStorage.instance.getUserpic(UserCenterActivity.this, avatarID,
                            userpicSize, thiz);
                    userPic.setImageBitmap(userpic); // can be null
                }
            });
        }
    };
    Bitmap userpic = UserpicStorage.instance.getUserpic(this, avatarID, userpicSize, userpicListener);
    userPic.setImageBitmap(userpic); // can be null

    subscribe_user.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mm.actionSubscribeUser();
        }
    });
    show_blog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mm.listSelectedItem.User.UID == 0) {
                JuickMicroBlog.obtainProperUserIdByName(UserCenterActivity.this, mm.listSelectedItem.User.UName,
                        "Getting Juick User Id", new Utils.Function<Void, Pair<String, String>>() {
                            @Override
                            public Void apply(Pair<String, String> cred) {
                                mm.listSelectedItem.User.UID = Integer.parseInt(cred.first);
                                mm.actionUserBlog();
                                return null;
                            }
                        });
            } else {
                mm.actionUserBlog();
            }
        }
    });
    search.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            search.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
                @Override
                public void onCreateContextMenu(ContextMenu menu, View v,
                        ContextMenu.ContextMenuInfo menuInfo) {
                    menu.add(0, SEARCH_PAST_CONVERSATIONS, 0, "My dialogs with user");
                    menu.add(0, SEARCH_MORE, 1, "More");
                }
            });
            search.showContextMenu();
        }
    });
    stats.setOnClickListener(new View.OnClickListener() {

        NewJuickPreferenceActivity.MenuItem[] items = new NewJuickPreferenceActivity.MenuItem[] {
                new NewJuickPreferenceActivity.MenuItem(R.string.UserAllTimeActivityReport,
                        R.string.UserAllTimeActivityReport2, new Runnable() {
                            @Override
                            public void run() {
                                NewJuickPreferenceActivity.showChart(UserCenterActivity.this,
                                        "USER_ACTIVITY_VOLUME", "uid=" + uid);
                            }
                        }),
                new NewJuickPreferenceActivity.MenuItem(R.string.UserHoursReport, R.string.UserHoursReport2,
                        new Runnable() {
                            @Override
                            public void run() {
                                NewJuickPreferenceActivity.showChart(UserCenterActivity.this,
                                        "USER_HOURS_ACTIVITY", "uid=" + uid + "&tzoffset="
                                                + TimeZone.getDefault().getRawOffset() / 1000 / 60 / 60);
                            }
                        }) };

        @Override
        public void onClick(View v) {
            list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    items[position].action.run();
                }
            });
            list.setAdapter(new BaseAdapter() {
                @Override
                public int getCount() {
                    return items.length;
                }

                @Override
                public Object getItem(int position) {
                    return items[position];
                }

                @Override
                public long getItemId(int position) {
                    return position;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    LayoutInflater layoutInflater = getLayoutInflater();
                    View listItem = layoutInflater.inflate(android.R.layout.simple_list_item_2, null);
                    TextView text = (TextView) listItem.findViewById(android.R.id.text1);
                    text.setText(items[position].labelId);
                    TextView text2 = (TextView) listItem.findViewById(android.R.id.text2);
                    text2.setText(items[position].label2Id);
                    return listItem;
                }
            });
        }
    });
    blacklist_user.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mm.actionBlacklistUser();
        }
    });
    filter_user.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mm.actionFilterUser(uname);
        }
    });
    unsubscribe_user.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mm.actionUnsubscribeUser();
        }
    });
    subscribe_comments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            enableJAM(new Runnable() {
                @Override
                public void run() {
                    JAMService.instance.client.subscribeToComments(uname);
                }
            });
        }
    });
    unsubscribe_comments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            enableJAM(new Runnable() {
                @Override
                public void run() {
                    JAMService.instance.client.unsubscribeFromComments(uname);
                }
            });
        }
    });
}

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

private void uploadPhotoToServer(String file, final Message menssage, final JSONObject dataSend,
        final ProgressBar progressBar, final RelativeLayout progressLayout, final TextView progressText,
        final ImageView messageContent) {
    try {/*  w  ww .  j a  v  a 2s . c om*/
        RequestParams p = new RequestParams();
        final File archivo = new File(file);
        p.put("image", archivo);
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                progressBar.setIndeterminate(false);
                progressText.setText("0%");
            }
        });
        SpeakHttp.post("messages/" + SessionCustom.getUserId(activity) + "/upload/photo", p,
                new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, final JSONObject response) {
                        super.onSuccess(statusCode, headers, response);
                        try {
                            JSONObject jsonObject = response.getJSONObject("data_response");
                            JSONArray photoArray = new JSONArray();
                            photoArray.put(0, jsonObject.getString("file_name"));
                            dataSend.put("photos", photoArray);
                            menssage.fileName = photoArray.toString();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        if (SpeakSocket.mSocket != null)
                            if (SpeakSocket.mSocket.connected()) {
                                menssage.status = 1;
                                SpeakSocket.mSocket.emit("message", dataSend);
                            } else {
                                menssage.status = -1;
                            }
                        menssage.fileUploaded = true;
                        menssage.save();
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (menssage.photo != null) {
                                    Bitmap bmp = BitmapFactory.decodeByteArray(menssage.photo, 0,
                                            menssage.photo.length);
                                    messageContent.setImageBitmap(bmp);
                                    progressLayout.setVisibility(View.GONE);
                                    System.gc();
                                }
                            }
                        });
                    }

                    @Override
                    public void onProgress(final long bytesWritten, final long totalSize) {
                        if (bytesWritten != totalSize) {
                            activity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    double prog = (100 / (double) totalSize) * (double) bytesWritten;
                                    progressBar.setProgress((int) Math.round(prog));
                                    progressText.setText((int) Math.round(prog) + "%");
                                    Log.e("PROGRESO", (int) Math.round(prog) + "");
                                }
                            });
                        }
                    }

                    @Override
                    public void onFinish() {
                        System.gc();
                    }
                }, activity);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

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

private void uploadVideoToServer(String file, final Message menssage, final JSONObject dataSend,
        final ProgressBar progressBar, final RelativeLayout progressLayout, final TextView progressText,
        final ImageView messageContent) {

    try {/*from www  .  ja  v a  2  s  . c  o  m*/
        RequestParams p = new RequestParams();
        final File archivo = new File(file);
        p.put("video", archivo);
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                progressBar.setIndeterminate(false);
                progressText.setText("0%");
            }
        });

        SpeakHttp.client.setTimeout(70000);
        SpeakHttp.client.setResponseTimeout(70000);
        SpeakHttp.post("messages/" + SessionCustom.getUserId(activity) + "/upload/video", p,
                new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, final JSONObject response) {
                        super.onSuccess(statusCode, headers, response);
                        try {
                            JSONObject jsonObject = response.getJSONObject("data_response");
                            JSONArray photoArray = new JSONArray();
                            photoArray.put(0, jsonObject.getString("file_name"));
                            dataSend.put("videos", photoArray);
                            menssage.fileName = photoArray.toString();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        if (SpeakSocket.mSocket != null)
                            if (SpeakSocket.mSocket.connected()) {
                                menssage.status = 1;
                                SpeakSocket.mSocket.emit("message", dataSend);
                            } else {
                                menssage.status = -1;
                            }
                        menssage.fileUploaded = true;
                        menssage.save();
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (menssage.photo != null) {
                                    Bitmap bmp = BitmapFactory.decodeByteArray(menssage.photo, 0,
                                            menssage.photo.length);
                                    messageContent.setImageBitmap(bmp);
                                    progressLayout.setVisibility(View.GONE);
                                    System.gc();
                                }
                            }
                        });

                    }

                    @Override
                    public void onProgress(final long bytesWritten, final long totalSize) {
                        if (bytesWritten != totalSize) {
                            activity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    double prog = (100 / (double) totalSize) * (double) bytesWritten;
                                    progressBar.setProgress((int) Math.round(prog));
                                    progressText.setText((int) Math.round(prog) + "%");
                                    Log.e("PROGRESO", (int) Math.round(prog) + "");
                                }
                            });
                        }
                    }

                    @Override
                    public void onFinish() {
                        System.gc();
                    }
                }, activity);

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

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

private void uploadPhotoToServer(String file, final MsgGroups menssage, final JSONObject dataSend,
        final ProgressBar progressBar, final RelativeLayout progressLayout, final TextView progressText,
        final ImageView messageContent) {
    try {/*from  ww w  .  jav  a 2 s.com*/
        RequestParams p = new RequestParams();
        final File archivo = new File(file);
        p.put("image", archivo);
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                progressBar.setIndeterminate(false);
                progressText.setText("0%");
            }
        });
        SpeakHttp.post("messages/" + SessionCustom.getUserId(activity) + "/upload/photo", p,
                new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, final JSONObject response) {
                        super.onSuccess(statusCode, headers, response);
                        try {
                            JSONObject jsonObject = response.getJSONObject("data_response");
                            JSONArray photoArray = new JSONArray();
                            photoArray.put(0, jsonObject.getString("file_name"));
                            dataSend.put("photos", photoArray);
                            menssage.fileName = photoArray.toString();
                            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 (menssage.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);
                                            }
                                        }
                                    }
                                    dataSend.put("targets", targets);
                                    menssage.receptores = targets.toString();
                                    SpeakSocket.mSocket.emit("message", dataSend);
                                } 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 (menssage.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);
                                            }
                                        }
                                    }
                                    menssage.receptores = targets.toString();
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        menssage.fileUploaded = true;
                        menssage.save();
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (menssage.photo != null) {
                                    Bitmap bmp = BitmapFactory.decodeByteArray(menssage.photo, 0,
                                            menssage.photo.length);
                                    messageContent.setImageBitmap(bmp);
                                    progressLayout.setVisibility(View.GONE);
                                    System.gc();
                                }
                            }
                        });
                    }

                    @Override
                    public void onProgress(final long bytesWritten, final long totalSize) {
                        if (bytesWritten != totalSize) {
                            activity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    double prog = (100 / (double) totalSize) * (double) bytesWritten;
                                    progressBar.setProgress((int) Math.round(prog));
                                    progressText.setText((int) Math.round(prog) + "%");
                                }
                            });
                        }
                    }

                    @Override
                    public void onFinish() {
                        System.gc();
                    }
                }, activity);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

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

private void uploadVideoToServer(String file, final MsgGroups menssage, final JSONObject dataSend,
        final ProgressBar progressBar, final RelativeLayout progressLayout, final TextView progressText,
        final ImageView messageContent) {

    try {//from www .j av a2  s .c  o  m
        RequestParams p = new RequestParams();
        final File archivo = new File(file);
        p.put("video", archivo);
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                progressBar.setIndeterminate(false);
                progressText.setText("0%");
            }
        });

        SpeakHttp.client.setTimeout(70000);
        SpeakHttp.client.setResponseTimeout(70000);
        SpeakHttp.post("messages/" + SessionCustom.getUserId(activity) + "/upload/video", p,
                new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, final JSONObject response) {
                        super.onSuccess(statusCode, headers, response);
                        try {
                            JSONObject jsonObject = response.getJSONObject("data_response");
                            JSONArray photoArray = new JSONArray();
                            photoArray.put(0, jsonObject.getString("file_name"));
                            dataSend.put("videos", photoArray);
                            menssage.fileName = photoArray.toString();
                            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 (menssage.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);
                                            }
                                        }
                                    }
                                    dataSend.put("targets", targets);
                                    menssage.receptores = targets.toString();
                                    SpeakSocket.mSocket.emit("message", dataSend);
                                } 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 (menssage.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);
                                            }
                                        }
                                    }
                                    menssage.receptores = targets.toString();
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        menssage.fileUploaded = true;
                        menssage.save();
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (menssage.photo != null) {
                                    Bitmap bmp = BitmapFactory.decodeByteArray(menssage.photo, 0,
                                            menssage.photo.length);
                                    messageContent.setImageBitmap(bmp);
                                    progressLayout.setVisibility(View.GONE);
                                    System.gc();
                                }
                            }
                        });

                    }

                    @Override
                    public void onProgress(final long bytesWritten, final long totalSize) {
                        if (bytesWritten != totalSize) {
                            activity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    double prog = (100 / (double) totalSize) * (double) bytesWritten;
                                    progressBar.setProgress((int) Math.round(prog));
                                    progressText.setText((int) Math.round(prog) + "%");
                                }
                            });
                        }
                    }

                    @Override
                    public void onFinish() {
                        System.gc();
                    }
                }, activity);

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

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

public void showMensajePhoto(int position, Context context, final Message message, View rowView,
        TextView icnMessageArrow) {//ww  w  .j  a va 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);
    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.ConversationChatFragment.java

public void showMensajeVideo(int position, Context context, final Message message, View rowView,
        TextView icnMessageArrow) {//from  ww w.  ja  v  a  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);
    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 (new File(message.videoName).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;
                                }
                            }
                        } 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);
                    System.gc();
                    File fileVideo = new File(message.videoName);
                    if (fileVideo.length() > 10000000) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                runTranscodingUsingLoader(message.videoName, message, mensaje, progressBar,
                                        progressLayout, progressText, messageContent);
                            }
                        }).start();
                    } else {
                        uploadVideoToServer(message.videoName, message, mensaje, progressBar, progressLayout,
                                progressText, messageContent);
                    }

                } else {
                    mensaje.put("videos", message.fileName);
                    if (SpeakSocket.mSocket != null)
                        if (SpeakSocket.mSocket.connected()) {
                            message.status = 1;
                            SpeakSocket.mSocket.emit("message", mensaje);
                        } else {
                            message.status = -1;
                        }
                    message.save();
                    changeStatus(message.mensajeId, message.status);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        Log.e("SIGUIENTE TAREA", "SIGUIENTE TAREA");
        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.videoName);
                        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) {
            final Message mensaje1 = 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 (mensaje1.status != -1) {
                    if (mensaje1.fileDownloaded || mensaje1.fileUploaded) {
                        dontClose = true;
                        ((MainActivity) activity).dontClose = true;
                        hideKeyBoard();
                        Intent i = new Intent();
                        i.setAction(android.content.Intent.ACTION_VIEW);
                        File videoFile2Play2 = new File(message.videoName);
                        i.setDataAndType(Uri.fromFile(videoFile2Play2), "video/*");
                        startActivity(i);
                    }
                }
            }
            if (mensaje1.status == -1) {
                final JSONObject data = new JSONObject();
                try {
                    data.put("message_id", mensaje1.mensajeId);
                    data.put("source", mensaje1.emisor);
                    data.put("source_email", mensaje1.emisorEmail);
                    data.put("target_email", mensaje1.receptorEmail);
                    data.put("target", mensaje1.receptor);
                    data.put("type", mensaje1.tipo);
                    data.put("delay", mensaje1.delay);
                    if (!mensaje1.fileUploaded) {
                        Log.w("REENVIANDO VIDEO", "REENVIO VIDEO");
                        progressLayout.setVisibility(View.VISIBLE);
                        File fileVideo = new File(mensaje1.videoName);
                        if (fileVideo.length() > 10000000) {
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    Log.w("COMPRESS VIDEO", "COMPRESS VIDEO");
                                    if (SpeakSocket.mSocket != null)
                                        if (SpeakSocket.mSocket.connected()) {
                                            mensaje1.status = 1;
                                        } else {
                                            mensaje1.status = -1;
                                            runTranscodingUsingLoader(mensaje1.videoName, mensaje1, data,
                                                    progressBar, progressLayout, progressText, messageContent);
                                        }
                                    mensaje1.save();
                                    changeStatus(mensaje1.mensajeId, mensaje1.status);
                                }
                            }).start();

                        } else {
                            uploadVideoToServer(mensaje1.videoName, mensaje1, data, progressBar, progressLayout,
                                    progressText, messageContent);
                        }
                    } else {
                        data.put("videos", message.fileName);
                        if (SpeakSocket.mSocket != null)
                            if (SpeakSocket.mSocket.connected()) {
                                mensaje1.status = 1;
                                SpeakSocket.mSocket.emit("message", data);
                            } else {
                                mensaje1.status = -1;
                            }
                        mensaje1.save();
                        changeStatus(mensaje1.mensajeId, mensaje1.status);
                    }
                } catch (JSONException e) {
                    Log.w("--->", e.toString());
                    e.printStackTrace();
                }
            }
        }
    }

    );

}

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

public void showMensajePhoto(int position, Context context, final MsgGroups message, View rowView,
        TextView icnMessageArrow) {/*from   w w  w . j  a va2 s.c om*/
    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();
                }
            }
        }
    });

}

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

public void showMensajeVideo(int position, Context context, final MsgGroups message, View rowView,
        TextView icnMessageArrow) {/*ww  w  . ja v  a 2s  .  c om*/
    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 (new File(message.videoName).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;
                                }
                            }
                        } 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);
                    System.gc();
                    File fileVideo = new File(message.videoName);
                    if (fileVideo.length() > 10000000) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                runTranscodingUsingLoader(message.videoName, message, data, progressBar,
                                        progressLayout, progressText, messageContent);
                            }
                        }).start();
                    } else {
                        uploadVideoToServer(message.videoName, message, data, progressBar, progressLayout,
                                progressText, messageContent);
                    }

                } else {
                    data.put("videos", 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.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 {
        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.videoName);
                        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 mensaje1 = new Select().from(MsgGroups.class)
                    .where("mensajeId = ?", message.mensajeId).executeSingle();

            int status = 0;
            try {
                JSONArray contactos = new JSONArray(mensaje1.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) {
                    if (mensaje1.fileDownloaded || mensaje1.fileUploaded) {
                        dontClose = true;
                        ((MainActivity) activity).dontClose = true;
                        hideKeyBoard();
                        Intent i = new Intent();
                        i.setAction(android.content.Intent.ACTION_VIEW);
                        File videoFile2Play2 = new File(message.videoName);
                        i.setDataAndType(Uri.fromFile(videoFile2Play2), "video/*");
                        startActivity(i);
                    }
                }
            }
            if (status == -1) {
                final JSONObject data = new JSONObject();
                try {
                    data.put("type", mensaje1.tipo);
                    data.put("group_id", mensaje1.grupoId);
                    data.put("group_name", grupo.nombreGrupo);
                    data.put("source", mensaje1.emisor);
                    data.put("source_lang", message.emisorLang);
                    data.put("source_email", mensaje1.emisorEmail);
                    data.put("message", mensaje1.mensaje);
                    data.put("translation_required", mensaje1.translation);
                    data.put("message_id", mensaje1.mensajeId);
                    data.put("targets", new JSONArray(mensaje1.receptores));
                    data.put("delay", mensaje1.delay);
                    if (!mensaje1.fileUploaded) {
                        progressLayout.setVisibility(View.VISIBLE);
                        System.gc();
                        File fileVideo = new File(mensaje1.videoName);
                        if (fileVideo.length() > 10000000) {
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    runTranscodingUsingLoader(mensaje1.videoName, mensaje1, data, progressBar,
                                            progressLayout, progressText, messageContent);
                                }
                            }).start();
                        } else {
                            uploadVideoToServer(mensaje1.videoName, mensaje1, data, progressBar, progressLayout,
                                    progressText, messageContent);
                        }

                    } else {
                        data.put("videos", mensaje1.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 (mensaje1.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);
                                mensaje1.receptores = targets.toString();
                                mensaje1.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 (mensaje1.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);
                                        }
                                    }
                                }
                                mensaje1.receptores = targets.toString();
                                mensaje1.save();
                            }
                        }
                        changeStatus(mensaje1.mensajeId);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}