Example usage for android.widget ExpandableListAdapter getChild

List of usage examples for android.widget ExpandableListAdapter getChild

Introduction

In this page you can find the example usage for android.widget ExpandableListAdapter getChild.

Prototype

Object getChild(int groupPosition, int childPosition);

Source Link

Document

Gets the data associated with the given child within the given group.

Usage

From source file:com.granita.tasks.TaskListFragment.java

private void selectChildView(ExpandableListView expandLV, int groupPosition, int childPosition, boolean force) {
    if (groupPosition < mAdapter.getGroupCount() && childPosition < mAdapter.getChildrenCount(groupPosition)) {
        // a task instance element has been clicked, get it's instance id and notify the activity
        ExpandableListAdapter listAdapter = expandLV.getExpandableListAdapter();
        Cursor cursor = (Cursor) listAdapter.getChild(groupPosition, childPosition);

        if (cursor == null) {
            return;
        }/*from   ww  w  . j a v a2s  . c o m*/
        // TODO: for now we get the id of the task, not the instance, once we support recurrence we'll have to change that
        Long selectTaskId = cursor.getLong(cursor.getColumnIndex(Instances.TASK_ID));

        if (selectTaskId != null) {
            // Notify the active callbacks interface (the activity, if the fragment is attached to one) that an item has been selected.

            // TODO: use the instance URI one we support recurrence
            Uri taskUri = ContentUris.withAppendedId(Tasks.getContentUri(mAuthority), selectTaskId);

            mCallbacks.onItemSelected(taskUri, force, mInstancePosition);
        }
    }
}

From source file:com.granita.tasks.TaskListFragment.java

@Override
public boolean onFlingEnd(ListView v, View listElement, int pos, int direction) {
    long packedPos = mExpandableListView.getExpandableListPosition(pos);
    if (ExpandableListView.getPackedPositionType(packedPos) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        ExpandableListAdapter listAdapter = mExpandableListView.getExpandableListAdapter();
        Cursor cursor = (Cursor) listAdapter.getChild(ExpandableListView.getPackedPositionGroup(packedPos),
                ExpandableListView.getPackedPositionChild(packedPos));

        if (cursor != null) {
            // TODO: for now we get the id of the task, not the instance, once we support recurrence we'll have to change that
            Long taskId = cursor.getLong(cursor.getColumnIndex(Instances.TASK_ID));

            if (taskId != null) {
                boolean closed = cursor.getLong(cursor.getColumnIndex(Instances.IS_CLOSED)) > 0;
                String title = cursor.getString(cursor.getColumnIndex(Instances.TITLE));
                // TODO: use the instance URI once we support recurrence
                Uri taskUri = ContentUris.withAppendedId(Tasks.getContentUri(mAuthority), taskId);

                if (direction == FlingDetector.RIGHT_FLING) {
                    if (closed) {
                        removeTask(taskUri, title);
                        // we do not know for sure if the task has been removed since the user is asked for confirmation first, so return false

                        return false;

                    } else {
                        return setCompleteTask(taskUri, title, true);
                    }//from  ww w .  j  a  v  a 2 s  .  com
                } else if (direction == FlingDetector.LEFT_FLING) {
                    if (closed) {
                        return setCompleteTask(taskUri, title, false);
                    } else {
                        openTaskEditor(taskUri,
                                cursor.getString(cursor.getColumnIndex(Instances.ACCOUNT_TYPE)));
                        return false;
                    }
                }
            }
        }
    }

    return false;
}

From source file:com.granita.tasks.TaskListFragment.java

@Override
public void onFlingStart(ListView listView, View listElement, int position, int direction) {

    // control the visibility of the views that reveal behind a flinging element regarding the fling direction
    int rightFlingViewId = mGroupDescriptor.getElementViewDescriptor().getFlingRevealRightViewId();
    int leftFlingViewId = mGroupDescriptor.getElementViewDescriptor().getFlingRevealLeftViewId();
    TextView rightFlingView = null;// w w w  . j av a  2 s  .c  o  m
    TextView leftFlingView = null;

    if (rightFlingViewId != -1) {
        rightFlingView = (TextView) listElement.findViewById(rightFlingViewId);
    }
    if (leftFlingViewId != -1) {
        leftFlingView = (TextView) listElement.findViewById(leftFlingViewId);
    }

    Resources resources = getActivity().getResources();

    // change title and icon regarding the task status
    long packedPos = mExpandableListView.getExpandableListPosition(position);
    if (ExpandableListView.getPackedPositionType(packedPos) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        ExpandableListAdapter listAdapter = mExpandableListView.getExpandableListAdapter();
        Cursor cursor = (Cursor) listAdapter.getChild(ExpandableListView.getPackedPositionGroup(packedPos),
                ExpandableListView.getPackedPositionChild(packedPos));

        if (cursor != null) {
            int taskStatus = cursor.getInt(cursor.getColumnIndex(Instances.STATUS));
            if (leftFlingView != null && rightFlingView != null) {
                if (taskStatus == Instances.STATUS_COMPLETED) {
                    leftFlingView.setText(R.string.fling_task_delete);
                    leftFlingView.setCompoundDrawablesWithIntrinsicBounds(
                            resources.getDrawable(R.drawable.content_discard), null, null, null);
                    rightFlingView.setText(R.string.fling_task_uncomplete);
                    rightFlingView.setCompoundDrawablesWithIntrinsicBounds(null, null,
                            resources.getDrawable(R.drawable.content_remove_light), null);
                } else {
                    leftFlingView.setText(R.string.fling_task_complete);
                    leftFlingView.setCompoundDrawablesWithIntrinsicBounds(
                            resources.getDrawable(R.drawable.ic_action_complete), null, null, null);
                    rightFlingView.setText(R.string.fling_task_edit);
                    rightFlingView.setCompoundDrawablesWithIntrinsicBounds(null, null,
                            resources.getDrawable(R.drawable.content_edit), null);
                }
            }
        }
    }

    if (rightFlingView != null) {
        rightFlingView.setVisibility(direction != FlingDetector.LEFT_FLING ? View.GONE : View.VISIBLE);
    }
    if (leftFlingView != null) {
        leftFlingView.setVisibility(direction != FlingDetector.RIGHT_FLING ? View.GONE : View.VISIBLE);
    }

}