Android Open Source - Android-Activity-Tracker-for-Dynamics-CRM Activities Item Adapter






From Project

Back to project page Android-Activity-Tracker-for-Dynamics-CRM.

License

The source code is released under:

MIT License

If you think the Android project Android-Activity-Tracker-for-Dynamics-CRM 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

// Android Activity Tracker Sample app for Microsoft Dynamics CRM
////from www  .  j  av  a 2s  .  c  o m
// Copyright (c) Microsoft Corporation
// All rights reserved.
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the ""Software""), to deal in the Software without
// restriction, including without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
//    The above copyright notice and this permission notice shall be included in all copies
//    or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package com.microsoft.activitytracker.Adapters;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.microsoft.activitytracker.Classes.Entity;
import com.microsoft.activitytracker.Classes.Utils;
import com.microsoft.activitytracker.R;
import com.google.gson.internal.LinkedTreeMap;

import java.util.ArrayList;

import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;

public class ActivitiesItemAdapter extends BaseAdapter implements StickyListHeadersAdapter
{
    enum ActivityTypeCode
    {
        TASK,
        EMAIL,
        APPOINTMENT,
        LETTER,
        PHONECALL,
        FAX
    }

    private String mHeader;
    private Object mItems;
    private Context mContext;

    public ActivitiesItemAdapter(Context context, Object objects)
    {
        this.mContext = context;
        this.mItems = objects;
        this.mHeader = mContext.getResources().getString(R.string.recent_label);
    }

    private static class ViewHolder
    {
        TextView title;
        TextView date;
        ImageView type;
    }

    /**
     * This view holder is used to store the text for the text item that is used when a string
     * is passed into the adapter.
     */
    private static class TextViewHolder {
        TextView message;
    }

    @Override
    public long getHeaderId(int i) {
        return mHeader.hashCode();
    }

    @Override
    public View getHeaderView(int i, View convertView, ViewGroup parent) {
        final ViewHolder thisHolder;

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            thisHolder = new ViewHolder();

            convertView = inflater.inflate(R.layout.header_item_layout, parent, false);

            thisHolder.title = (TextView)convertView.findViewById(R.id.header_text);

            convertView.setTag(thisHolder);
        }
        else
            thisHolder = (ViewHolder)convertView.getTag();

        thisHolder.title.setText(mHeader);

        return convertView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        final Object thisItem = this.getItem(position);

        if (getItemViewType(position) == 0) {
            final LinkedTreeMap thisActivity = (LinkedTreeMap)thisItem;
            final ViewHolder thisHolder;

            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                thisHolder = new ViewHolder();

                convertView = inflater.inflate(R.layout.activity_item_layout, parent, false);

                thisHolder.date = (TextView) convertView.findViewById(R.id.activity_date);
                thisHolder.title = (TextView) convertView.findViewById(R.id.activity_title);
                thisHolder.type = (ImageView) convertView.findViewById(R.id.activityImage);

                convertView.setTag(thisHolder);
            } else {
                thisHolder = (ViewHolder) convertView.getTag();
            }

            thisHolder.title.setText(thisActivity.get("Subject").toString());
            thisHolder.date.setText(Utils.getDatefromJsonDate(thisActivity.get("ActualEnd").toString()));

            try {
                switch (ActivityTypeCode.valueOf(thisActivity.get("ActivityTypeCode").toString().toUpperCase())) {
                    case TASK:
                        thisHolder.type.setImageResource(R.drawable.ic_activity_check);
                        break;
                    case APPOINTMENT:
                        thisHolder.type.setImageResource(R.drawable.ic_activity_appt);
                        break;
                    case LETTER:
                        thisHolder.type.setImageResource(R.drawable.ic_activity_note);
                        break;
                    case PHONECALL:
                        thisHolder.type.setImageResource(R.drawable.ic_activity_phone);
                        break;
                    default:
                        thisHolder.type.setImageResource(R.drawable.ic_activity_generic);
                        break;
                }
            }
            catch(IllegalArgumentException ex) {
                Log.d("ItemActivityAdapter", thisActivity.get("ActivityTypeCode").toString() +
                        " not in Activity Enum, setting to generic activity");
                thisHolder.type.setImageResource(R.drawable.ic_activity_generic);
            }
        }
        else {
            final String thisText = thisItem.toString();
            final TextViewHolder thisHolder;

            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(R.layout.item_text_layout, parent, false);

                thisHolder = new TextViewHolder();

                thisHolder.message = (TextView)convertView.findViewById(R.id.message_text);
                convertView.setTag(thisHolder);
            }
            else {
                thisHolder = (TextViewHolder)convertView.getTag();
            }

            thisHolder.message.setText(thisText);
        }


        return convertView;
    }

    @Override
    public int getCount() {
        return ((ArrayList)mItems).size();
    }

    @Override
    public Object getItem(int position)
    {
        return ((ArrayList)mItems).get(position);
    }

    @Override
    public int getItemViewType(int position) {
        if (getItem(position).getClass() == LinkedTreeMap.class) {
            return 0;
        }
        else {
            return 1;
        }
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

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




Java Source Code List

com.microsoft.aad.adal.ADALError.java
com.microsoft.aad.adal.AuthenticationActivity.java
com.microsoft.aad.adal.AuthenticationCallback.java
com.microsoft.aad.adal.AuthenticationCancelError.java
com.microsoft.aad.adal.AuthenticationConstants.java
com.microsoft.aad.adal.AuthenticationContext.java
com.microsoft.aad.adal.AuthenticationException.java
com.microsoft.aad.adal.AuthenticationParameters.java
com.microsoft.aad.adal.AuthenticationRequestState.java
com.microsoft.aad.adal.AuthenticationRequest.java
com.microsoft.aad.adal.AuthenticationResult.java
com.microsoft.aad.adal.AuthenticationSettings.java
com.microsoft.aad.adal.BrokerProxy.java
com.microsoft.aad.adal.CacheKey.java
com.microsoft.aad.adal.ChallangeResponseBuilder.java
com.microsoft.aad.adal.DefaultTokenCacheStore.java
com.microsoft.aad.adal.Discovery.java
com.microsoft.aad.adal.ExceptionExtensions.java
com.microsoft.aad.adal.FileTokenCacheStore.java
com.microsoft.aad.adal.HashMapExtensions.java
com.microsoft.aad.adal.HttpWebRequest.java
com.microsoft.aad.adal.HttpWebResponse.java
com.microsoft.aad.adal.IBrokerProxy.java
com.microsoft.aad.adal.IConnectionService.java
com.microsoft.aad.adal.IDeviceCertificate.java
com.microsoft.aad.adal.IDiscovery.java
com.microsoft.aad.adal.IJWSBuilder.java
com.microsoft.aad.adal.ITokenCacheStore.java
com.microsoft.aad.adal.ITokenStoreQuery.java
com.microsoft.aad.adal.IWebRequestHandler.java
com.microsoft.aad.adal.IdToken.java
com.microsoft.aad.adal.JWSBuilder.java
com.microsoft.aad.adal.Logger.java
com.microsoft.aad.adal.MemoryTokenCacheStore.java
com.microsoft.aad.adal.Oauth2.java
com.microsoft.aad.adal.PRNGFixes.java
com.microsoft.aad.adal.PackageHelper.java
com.microsoft.aad.adal.PromptBehavior.java
com.microsoft.aad.adal.StorageHelper.java
com.microsoft.aad.adal.StringExtensions.java
com.microsoft.aad.adal.TokenCacheItem.java
com.microsoft.aad.adal.UserInfo.java
com.microsoft.aad.adal.WebRequestHandler.java
com.microsoft.aad.adal.package-info.java
com.microsoft.activitytracker.Activities.CheckInActivity.java
com.microsoft.activitytracker.Activities.ItemActivity.java
com.microsoft.activitytracker.Activities.MainActivity.java
com.microsoft.activitytracker.Activities.SetupActivity.java
com.microsoft.activitytracker.Adapters.ActivitiesItemAdapter.java
com.microsoft.activitytracker.Adapters.MainItemAdapter.java
com.microsoft.activitytracker.Classes.ActivityTracker.java
com.microsoft.activitytracker.Classes.Constants.java
com.microsoft.activitytracker.Classes.Entity.java
com.microsoft.activitytracker.Classes.RecentHistorydbHandler.java
com.microsoft.activitytracker.Classes.Utils.java
com.microsoft.activitytracker.Core.NetworkCalls.java
com.microsoft.activitytracker.Core.SoapExecuteParser.java
com.microsoft.activitytracker.Core.SoapRetrieveMultipleParser.java