Android Open Source - APO-DZ-Android Link Adapter






From Project

Back to project page APO-DZ-Android.

License

The source code is released under:

MIT License

If you think the Android project APO-DZ-Android 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 org.upennapo.app.adapter;
/*from  www  .java2  s.  c o  m*/
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import org.upennapo.app.R;
import org.upennapo.app.fragment.LinkListFragment;

/**
 * Custom adapter that sections arrays of links and targets.
 */
public class LinkAdapter extends ArrayAdapter<String> {

    private static final int NUM_VIEW_TYPES = 2;
    private static final int TYPE_HEADER = 0;
    private static final int TYPE_ITEM = 1;
    private String[] mTitles, mDescriptions, mTargets;

    public LinkAdapter(Context context, int layout, Bundle args) {
        super(context, layout);
        mTitles = args.getStringArray(LinkListFragment.TITLES);
        mDescriptions = args.getStringArray(LinkListFragment.DESCRIPTIONS);
        mTargets = args.getStringArray(LinkListFragment.TARGETS);
        super.addAll(mTitles);
    }

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

    @Override
    public int getItemViewType(int position) {
        final String headerFlag = getContext().getString(R.string.link_header_flag);
        return headerFlag.equals(mTargets[position]) ? TYPE_HEADER : TYPE_ITEM;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        final int itemType = getItemViewType(position);
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            viewHolder = new ViewHolder();

            switch (itemType) {
                case TYPE_HEADER:
                    convertView = inflater.inflate(R.layout.list_header, parent, false);
                    viewHolder.textView = (TextView) convertView.findViewById(R.id.link_header);
                    break;

                case TYPE_ITEM:
                    convertView = inflater.inflate(R.layout.item_link_text, parent, false);
                    viewHolder.textView = (TextView) convertView.findViewById(R.id.main_text);
                    viewHolder.textViewSecondary = (TextView) convertView.findViewById(R.id.secondary_text);
                    break;
            }

            assert convertView != null;
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textView.setText(mTitles[position]);

        // If there is a description for this link, draw & display it.
        TextView description = viewHolder.textViewSecondary;
        if (mDescriptions != null && mDescriptions.length == mTitles.length
                && mDescriptions[position].length() > 0 && itemType != TYPE_HEADER) {
            description.setText(mDescriptions[position]);
            description.setVisibility(View.VISIBLE);
        } else if (description != null && description.getVisibility() == View.VISIBLE
                && mDescriptions != null && mDescriptions.length == mTitles.length
                && mDescriptions[position].length() == 0) {
            description.setVisibility(View.GONE);
        }

        return convertView;
    }

    @Override
    public boolean isEnabled(int position) {
        return !mTargets[position].equals(getContext().getString(R.string.link_header_flag));
    }

    private static class ViewHolder {
        TextView textView;
        TextView textViewSecondary;
    }
}




Java Source Code List

org.upennapo.app.activity.AlumModeActivity.java
org.upennapo.app.activity.DirectoryActivity.java
org.upennapo.app.activity.DirectoryDetailsActivity.java
org.upennapo.app.activity.EasterEggActivity.java
org.upennapo.app.activity.LoginActivity.java
org.upennapo.app.activity.MainActivity.java
org.upennapo.app.activity.WebActivity.java
org.upennapo.app.adapter.AlphabeticalAdapter.java
org.upennapo.app.adapter.LinkAdapter.java
org.upennapo.app.fragment.AlumDirectoryFragment.java
org.upennapo.app.fragment.BrotherStatusFragment.java
org.upennapo.app.fragment.DirectoryFragment.java
org.upennapo.app.fragment.LinkListFragment.java
org.upennapo.app.fragment.NavigationDrawerFragment.java
org.upennapo.app.fragment.WebFragment.java
org.upennapo.app.model.Brother.java
org.upennapo.app.model.DataManager.java
org.upennapo.app.model.User.java