Android Open Source - scrumchatter Team Array Adapter






From Project

Back to project page scrumchatter.

License

The source code is released under:

GNU General Public License

If you think the Android project scrumchatter 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

/**
 * Copyright 2013 Carmen Alvarez//from   www.  j  av  a 2s  .co m
 *
 * This file is part of Scrum Chatter.
 *
 * Scrum Chatter is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Scrum Chatter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Scrum Chatter. If not, see <http://www.gnu.org/licenses/>.
 */
package ca.rmen.android.scrumchatter.team;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import ca.rmen.android.scrumchatter.Constants;
import ca.rmen.android.scrumchatter.R;
import ca.rmen.android.scrumchatter.provider.TeamColumns;

/**
 * Adapter for the list of teams. The adapter contains all the team names, sorted alphabetically. In addition, one additional item is added to the end, which is
 * a special string "New team...", which the user may tap on to create a new team. Each item, except for the last one, has a radio button.
 */
public class TeamArrayAdapter extends ArrayAdapter<CharSequence> {
    private static final String TAG = Constants.TAG + "/" + TeamArrayAdapter.class.getSimpleName();
    private final Context mContext;

    public TeamArrayAdapter(final Context context) {
        super(context, android.R.layout.simple_list_item_single_choice);
        Log.v(TAG, "Constructor");
        mContext = context;
        reload();
    }

    /**
     * Query the DB for the list of team names, then add the team names to the adapter.
     */
    public void reload() {
        new AsyncTask<Void, Void, List<CharSequence>>() {

            /**
             * Query the teams table, and return a list of the team names, plus the special "New team..." item.
             */
            @Override
            protected List<CharSequence> doInBackground(Void... params) {
                Log.v(TAG, "doInBackground");
                List<CharSequence> teamNames = new ArrayList<CharSequence>();
                Cursor c = mContext.getContentResolver().query(TeamColumns.CONTENT_URI, new String[] { TeamColumns.TEAM_NAME }, null, null,
                        TeamColumns.TEAM_NAME + " COLLATE NOCASE");

                if (c != null) {
                    try {
                        // Add the names of all the teams
                        while (c.moveToNext()) {
                            teamNames.add(c.getString(0));
                        }
                        // Add the special element for a "new team"
                        teamNames.add(mContext.getString(R.string.new_team));
                    } finally {
                        c.close();
                    }
                }
                return teamNames;
            }

            /**
             * Reset the adapter data in one go (only one notification at the end).
             */
            @Override
            protected void onPostExecute(List<CharSequence> teamNames) {
                setNotifyOnChange(false);
                clear();
                for (CharSequence teamName : teamNames)
                    add(teamName);
                notifyDataSetChanged();
            }
        }.execute();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View result = super.getView(position, convertView, parent);
        if (result instanceof CheckedTextView) {
            CheckedTextView ctv = (CheckedTextView) result;
            // The last item is the special "New team..." item. Don't show a radio button for this item
            if (position == getCount() - 1) ctv.setCheckMarkDrawable(0);
            // Hack for Android 2.x: replace the radio button. See {@link DialogStyleHacks}
            else
                ctv.setCheckMarkDrawable(R.drawable.btn_radio_holo_light);
        }
        return result;
    }
}




Java Source Code List

ca.rmen.android.scrumchatter.Constants.java
ca.rmen.android.scrumchatter.about.AboutActivity.java
ca.rmen.android.scrumchatter.dialog.ChoiceDialogFragment.java
ca.rmen.android.scrumchatter.dialog.ConfirmDialogFragment.java
ca.rmen.android.scrumchatter.dialog.DialogFragmentFactory.java
ca.rmen.android.scrumchatter.dialog.DialogStyleHacks.java
ca.rmen.android.scrumchatter.dialog.InfoDialogFragment.java
ca.rmen.android.scrumchatter.dialog.InputDialogFragment.java
ca.rmen.android.scrumchatter.dialog.ProgressDialogFragment.java
ca.rmen.android.scrumchatter.export.DBExport.java
ca.rmen.android.scrumchatter.export.FileExport.java
ca.rmen.android.scrumchatter.export.MeetingExport.java
ca.rmen.android.scrumchatter.export.MeetingsExport.java
ca.rmen.android.scrumchatter.main.MainActivity.java
ca.rmen.android.scrumchatter.meeting.Meetings.java
ca.rmen.android.scrumchatter.meeting.detail.MeetingActivity.java
ca.rmen.android.scrumchatter.meeting.detail.MeetingCursorAdapter.java
ca.rmen.android.scrumchatter.meeting.detail.MeetingFragment.java
ca.rmen.android.scrumchatter.meeting.detail.MeetingPagerAdapter.java
ca.rmen.android.scrumchatter.meeting.detail.Meeting.java
ca.rmen.android.scrumchatter.meeting.list.MeetingsCursorAdapter.java
ca.rmen.android.scrumchatter.meeting.list.MeetingsListFragment.java
ca.rmen.android.scrumchatter.member.list.MembersCursorAdapter.java
ca.rmen.android.scrumchatter.member.list.MembersListFragment.java
ca.rmen.android.scrumchatter.member.list.Members.java
ca.rmen.android.scrumchatter.provider.DBImport.java
ca.rmen.android.scrumchatter.provider.MeetingColumns.java
ca.rmen.android.scrumchatter.provider.MeetingCursorWrapper.java
ca.rmen.android.scrumchatter.provider.MeetingMemberColumns.java
ca.rmen.android.scrumchatter.provider.MeetingMemberCursorWrapper.java
ca.rmen.android.scrumchatter.provider.MemberColumns.java
ca.rmen.android.scrumchatter.provider.MemberCursorWrapper.java
ca.rmen.android.scrumchatter.provider.MemberStatsColumns.java
ca.rmen.android.scrumchatter.provider.ScrumChatterDatabase.java
ca.rmen.android.scrumchatter.provider.ScrumChatterProvider.java
ca.rmen.android.scrumchatter.provider.TeamColumns.java
ca.rmen.android.scrumchatter.team.TeamArrayAdapter.java
ca.rmen.android.scrumchatter.team.Teams.java
ca.rmen.android.scrumchatter.util.IOUtils.java
ca.rmen.android.scrumchatter.util.TextUtils.java
ca.rmen.android.scrumchatter.util.ViewHolder.java