Android Open Source - Lessaging Sms Adapter






From Project

Back to project page Lessaging.

License

The source code is released under:

GNU General Public License

If you think the Android project Lessaging 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 fr.lessaging.adapters;
/*w w w  .  j  av a2  s  .  c om*/
import android.content.Context;
import android.support.v4.view.GravityCompat;
import android.telephony.PhoneNumberUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;


import java.util.ArrayList;

import fr.lessaging.R;
import fr.lessaging.message.Message;
import fr.lessaging.utils.AppConfig;

/**
 * Created by lheido on 31/10/14.
 */
public class SmsAdapter extends SmsBaseAdapter {

    public SmsAdapter(Context context, String contactPhone, ArrayList<Message> conversation) {
        super(context, contactPhone, conversation);
    }

    @Override
    public View getView(int r, View convertView, ViewGroup parent) {
        Message message = this.getItem(r);
        SmsBaseViewHolder holder;
        if(convertView == null){
            holder = new SmsBaseViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.message, parent, false);
            holder.mBody = (TextView) convertView.findViewById(R.id.message);
            holder.mdate = (TextView) convertView.findViewById(R.id.date_message);
            holder.mLayout = (RelativeLayout) convertView.findViewById(R.id.message_relativeLayout);
            holder.mIsRead = (View) convertView.findViewById(R.id.is_read);
            convertView.setTag(holder);
        }
        else
            holder = (SmsBaseViewHolder) convertView.getTag();

//        userPref.setUserPref(PreferenceManager.getDefaultSharedPreferences(mContext));

        holder.mBody.setText(message.getBody());
//        holder.mBody.setTextSize(userPref.text_size);
        holder.mdate.setText(message.getDate(mContext));

        //RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.mLayout.getLayoutParams();
        if(AppConfig.DEBUG){
            Log.v("SmsAdapter", "mPhoneContact="+mPhoneContact+", message.getSender()="+message.getSender()+
            ", compare="+PhoneNumberUtils.compare(mPhoneContact, message.getSender())
            );
        }
//        if(!PhoneNumberUtils.compare(mPhoneContact, message.getSender())) {
        if(message.getType() == 2) {
            holder.mLayout.setGravity(GravityCompat.END);
            holder.mLayout.setPadding(42, 0, 0, 0);
            holder.mBody.setBackgroundColor(mContext.getResources().getColor(R.color.grey_mid_high));
            if(message.isRead())
                holder.mIsRead.setBackgroundColor(mContext.getResources().getColor(R.color.read_green));
            else{
                holder.mIsRead.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));
            }
        }
        else {
            holder.mLayout.setGravity(GravityCompat.START);
            holder.mLayout.setPadding(0, 0, 42, 0);
            holder.mBody.setBackgroundColor(mContext.getResources().getColor(R.color.grey_low));
            holder.mIsRead.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));
        }
        return convertView;
    }
}




Java Source Code List

fr.lessaging.ApplicationTest.java
fr.lessaging.MainActivity.java
fr.lessaging.adapters.ConversationsListAdapter.java
fr.lessaging.adapters.MmsAdapter.java
fr.lessaging.adapters.SmsAdapter.java
fr.lessaging.adapters.SmsBaseAdapter.java
fr.lessaging.adapters.ViewPagerAdapter.java
fr.lessaging.conversation.Conversation.java
fr.lessaging.conversation.ConversationsList.java
fr.lessaging.fragments.CurrentConversationFragment.java
fr.lessaging.fragments.MmsFragment.java
fr.lessaging.fragments.NavigationDrawerFragment.java
fr.lessaging.fragments.SmsBaseFragment.java
fr.lessaging.fragments.SmsFragment.java
fr.lessaging.message.MessageManager.java
fr.lessaging.message.MessageTaskCallback.java
fr.lessaging.message.Message.java
fr.lessaging.message.MmsTask.java
fr.lessaging.message.SmsTask.java
fr.lessaging.preferences.LessagingPreference.java
fr.lessaging.preferences.PrefConversationFragment.java
fr.lessaging.preferences.PrefGeneralFragment.java
fr.lessaging.preferences.PrefListConversationsFragment.java
fr.lessaging.preferences.PrefReceiveFragment.java
fr.lessaging.receiver.MessageReceiver.java
fr.lessaging.utils.AppConfig.java
fr.lessaging.utils.BuildFragment.java
fr.lessaging.utils.LessagingNotification.java
fr.lessaging.utils.LessagingVibrator.java
fr.lessaging.utils.UserPref.java