Search in sources :

Example 1 with ExpandCollapseAnimation

use of com.instructure.speedgrader.util.ExpandCollapseAnimation in project instructure-android by instructure.

the class StudentListView method initListView.

private void initListView(View popupView) {
    // get the listview inside our popupwindow and set our adapter to it
    mListView = (ListView) popupView.findViewById(R.id.studentList);
    mSubmissionsAdapter = new UserSubmissionsListAdapter(mActivity.getApplicationContext(), mSubmissionsList, mAssignment, mListView, ((App) mActivity.getApplication()).showStudentNames(), mListener);
    if (isSortByName) {
        mSubmissionsAdapter.sortSubmissionsByName(((App) mActivity.getApplication()).showUngradedStudentsFirst());
    } else {
        mSubmissionsAdapter.sortSubmissionsByGrade();
    }
    final ViewGroup header = (ViewGroup) LayoutInflater.from(mActivity).inflate(R.layout.student_list_headerview, mListView, false);
    final RelativeLayout row = (RelativeLayout) header.findViewById(R.id.row);
    final LinearLayout dropDown = (LinearLayout) header.findViewById(R.id.rowDropdown);
    final RadioGroup radioGroup = (RadioGroup) header.findViewById(R.id.radioGroup);
    final ImageView expandArrow = (ImageView) header.findViewById(R.id.expandArrow);
    final TextView sectionTitle = (TextView) header.findViewById(R.id.sectionTitle);
    row.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ExpandCollapseAnimation.setHeightForWrapContent(mActivity, dropDown);
            ExpandCollapseAnimation expandCollapseAnimation = new ExpandCollapseAnimation(dropDown, 200);
            expandCollapseAnimation.setAnimationListener(new Animation.AnimationListener() {

                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    RotateAnimation rotationAnim;
                    if (dropDown.getHeight() < 50) {
                        // For some reason, onAnimatinoEnd is getting called slightly before the animation actually ends, causing the height to be a value something greater than 0.
                        // currently closed
                        rotationAnim = new RotateAnimation(180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    } else {
                        // currently open
                        rotationAnim = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    }
                    rotationAnim.setDuration(100);
                    rotationAnim.setFillAfter(true);
                    expandArrow.startAnimation(rotationAnim);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            });
            dropDown.startAnimation(expandCollapseAnimation);
        }
    });
    // Set our arrow to gray
    final Drawable d = CanvasContextColor.getColoredDrawable(mApplicationContext, R.drawable.ic_cv_arrow_down_fill, ContextCompat.getColor(mActivity.getApplicationContext(), R.color.lightGray));
    expandArrow.setImageDrawable(d);
    mListView.addHeaderView(header);
    mListView.setTextFilterEnabled(true);
    mListView.setAdapter(mSubmissionsAdapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // show the submission clicked
            dismiss();
            int positionInList = mSubmissionsAdapter.getPositionForSubmission((Submission) mListView.getItemAtPosition(position));
            mListener.onCurrentSubmission(positionInList);
        }
    });
    initSectionsRadioGroup(radioGroup, sectionTitle, header);
}
Also used : App(com.instructure.speedgrader.util.App) RadioGroup(android.widget.RadioGroup) Submission(com.instructure.canvasapi.model.Submission) UserSubmissionsListAdapter(com.instructure.speedgrader.adapters.UserSubmissionsListAdapter) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) SearchView(android.support.v7.widget.SearchView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) RotateAnimation(android.view.animation.RotateAnimation) RelativeLayout(android.widget.RelativeLayout) ExpandCollapseAnimation(com.instructure.speedgrader.util.ExpandCollapseAnimation) ExpandCollapseAnimation(com.instructure.speedgrader.util.ExpandCollapseAnimation) Animation(android.view.animation.Animation) RotateAnimation(android.view.animation.RotateAnimation) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Aggregations

ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 SearchView (android.support.v7.widget.SearchView)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Animation (android.view.animation.Animation)1 RotateAnimation (android.view.animation.RotateAnimation)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 RadioGroup (android.widget.RadioGroup)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 Submission (com.instructure.canvasapi.model.Submission)1 UserSubmissionsListAdapter (com.instructure.speedgrader.adapters.UserSubmissionsListAdapter)1 App (com.instructure.speedgrader.util.App)1 ExpandCollapseAnimation (com.instructure.speedgrader.util.ExpandCollapseAnimation)1