Android Open Source - FisgoDroid Chat Base View






From Project

Back to project page FisgoDroid.

License

The source code is released under:

The smiley icons bundled with this application belong to Meneame.NET and are licensed under the Creative Commons by-sa 3.0 license. For more information, please visit http://creativecommons.org/licens...

If you think the Android project FisgoDroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.meneame.fisgodroid;
/*from  ww  w .  j a  va2 s  .  co m*/
import java.text.SimpleDateFormat;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.Html;
import android.text.Selection;
import android.text.Spannable;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

public class ChatBaseView extends LinearLayout
{
    private ChatMessage mChatMsg = null;
    private TextView mUsername;
    private TextView mMessage;
    private ImageView mAvatar;
    private TextView mTimestamp;

    // From
    // http://stackoverflow.com/questions/15836306/can-a-textview-be-selectable-and-contain-links
    // Thanks oakleaf!
    private static class CustomMovementMethod extends LinkMovementMethod
    {
        @Override
        public boolean canSelectArbitrarily()
        {
            return true;
        }

        @Override
        public void initialize(TextView widget, Spannable text)
        {
            Selection.setSelection(text, text.length());
        }

        @Override
        public void onTakeFocus(TextView view, Spannable text, int dir)
        {
            if ( (dir & (View.FOCUS_FORWARD | View.FOCUS_DOWN)) != 0 )
            {
                if ( view.getLayout() == null )
                {
                    // This shouldn't be null, but do something sensible if it
                    // is.
                    Selection.setSelection(text, text.length());
                }
            }
            else
            {
                Selection.setSelection(text, text.length());
            }
        }
    }
    
    public ChatBaseView(Context context, int resourceId)
    {
        super(context);

        // Create the view
        LayoutInflater.from(getContext()).inflate(resourceId, this, true);
        mMessage = (TextView) findViewById(R.id.chat_message);
        mUsername = (TextView) findViewById(R.id.chat_username);
        mAvatar = (ImageView) findViewById(R.id.chat_avatar);
        mTimestamp = (TextView) findViewById(R.id.chat_timestamp);

        setSelectableText();
        mMessage.setMovementMethod(new CustomMovementMethod());
        
        // Used for showing the user's profile
        mAvatar.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Intent intent = new Intent(getContext(), ProfileActivity.class);
                intent.putExtra("userid", mChatMsg.getUserid());
                getContext().startActivity(intent);
            }
        });
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setSelectableText()
    {
        // Set the text selectable on API level >= 11
        if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB )
        {
            mMessage.setTextIsSelectable(true);
        }
    }
    
    public void setChatMessage(ChatMessage chatMsg, boolean highlight )
    {
        mChatMsg = chatMsg;

        Picasso.with(getContext()).cancelRequest(mAvatar);
        
        if ( mChatMsg != null )
        {
            String parsedMessage = Smileys.parseMessage(mChatMsg.getMessage());

            // Highlight when they mention our name
            if ( highlight )
            {
                parsedMessage = "<b>" + parsedMessage + "</b>";
            }
            
            // Timestamp formatting
            SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
            
            Spanned message = Html.fromHtml(parsedMessage, null, Smileys.getTagHandler(getContext(), mMessage));
            mMessage.setText(message);
            mUsername.setText(mChatMsg.getUser());
            Picasso.with(getContext()).load(mChatMsg.getIcon()).placeholder(R.drawable.default_avatar).into(mAvatar);
            
            mTimestamp.setText(dateFormat.format(mChatMsg.getWhen()));
        }
    }
}




Java Source Code List

jp.tomorrowkey.android.GifDecoder.java
net.meneame.fisgodroid.AnimatedGifDrawable.java
net.meneame.fisgodroid.ChatActivity.java
net.meneame.fisgodroid.ChatBaseView.java
net.meneame.fisgodroid.ChatBubbleView.java
net.meneame.fisgodroid.ChatLineView.java
net.meneame.fisgodroid.ChatMessage.java
net.meneame.fisgodroid.ChatType.java
net.meneame.fisgodroid.DynamicTextView.java
net.meneame.fisgodroid.FisgoScheduler.java
net.meneame.fisgodroid.FisgoService.java
net.meneame.fisgodroid.FisgodroidApplication.java
net.meneame.fisgodroid.FriendshipStatus.java
net.meneame.fisgodroid.HttpService.java
net.meneame.fisgodroid.IHttpService.java
net.meneame.fisgodroid.ImageUpload.java
net.meneame.fisgodroid.LogSaver.java
net.meneame.fisgodroid.LoginActivity.java
net.meneame.fisgodroid.LoginStatus.java
net.meneame.fisgodroid.Notifications.java
net.meneame.fisgodroid.ProfileActivity.java
net.meneame.fisgodroid.SettingsActivity.java
net.meneame.fisgodroid.SmileyPickerView.java
net.meneame.fisgodroid.SmileySpan.java
net.meneame.fisgodroid.Smiley.java
net.meneame.fisgodroid.Smileys.java
net.meneame.fisgodroid.ThreeStateChecboxHackView.java
net.meneame.fisgodroid.UserProfileFetcher.java
net.meneame.fisgodroid.UserProfile.java
net.meneame.fisgodroid.adapters.BubblesChatAdapter.java
net.meneame.fisgodroid.adapters.ChatMessageAdapter.java
net.meneame.fisgodroid.adapters.LegacyChatAdapter.java
net.meneame.fisgodroid.notifications.ElementAdapter.java
net.meneame.fisgodroid.notifications.NotificationElement.java
net.meneame.fisgodroid.notifications.NotificationView.java
net.meneame.fisgodroid.notifications.NotificationsIndicatorDrawable.java
net.meneame.fisgodroid.notifications.NotificationsLayout.java
net.meneame.fisgodroid.notifications.NotificationsPoller.java