Android Open Source - SymptomManagement Step Pager Strip






From Project

Back to project page SymptomManagement.

License

The source code is released under:

Apache License

If you think the Android project SymptomManagement 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 com.android.capstone.patient.checkin_now.ui;
/* ww w.  j a v  a 2  s  .  c o m*/

import com.android.capstone.R;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;

public class StepPagerStrip extends View {
   
  private static final int[] ATTRS = new int[]{android.R.attr.gravity};
  
    private int mPageCount;
    private int mCurrentPage;

    private int mGravity = Gravity.LEFT | Gravity.TOP;
    private float mTabWidth;
    private float mTabHeight;
    private float mTabSpacing;

    private Paint mPrevTabPaint;
    private Paint mSelectedTabPaint;
    private Paint mSelectedLastTabPaint;
    private Paint mNextTabPaint;

    private RectF mTempRectF = new RectF();

 
    private OnPageSelectedListener mOnPageSelectedListener;

    public StepPagerStrip(Context context) {
        this(context, null, 0);
    }

    public StepPagerStrip(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public StepPagerStrip(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
        mGravity = a.getInteger(0, mGravity);
        a.recycle();

        final Resources res = getResources();
        mTabWidth = res.getDimensionPixelSize(R.dimen.step_pager_tab_width);
        mTabHeight = res.getDimensionPixelSize(R.dimen.step_pager_tab_height);
        mTabSpacing = res.getDimensionPixelSize(R.dimen.step_pager_tab_spacing);

        mPrevTabPaint = new Paint();
        mPrevTabPaint.setColor(res.getColor(R.color.step_pager_previous_tab_color));

        mSelectedTabPaint = new Paint();
        mSelectedTabPaint.setColor(res.getColor(R.color.step_pager_selected_tab_color));

        mSelectedLastTabPaint = new Paint();
        mSelectedLastTabPaint.setColor(res.getColor(R.color.step_pager_selected_last_tab_color));

        mNextTabPaint = new Paint();
        mNextTabPaint.setColor(res.getColor(R.color.step_pager_next_tab_color));
    }

    public void setOnPageSelectedListener(OnPageSelectedListener onPageSelectedListener) {
        mOnPageSelectedListener = onPageSelectedListener;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (mPageCount == 0) {
            return;
        }

        float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
        float totalLeft;
        boolean fillHorizontal = false;

        switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
            case Gravity.CENTER_HORIZONTAL:
                totalLeft = (getWidth() - totalWidth) / 2;
                break;
            case Gravity.RIGHT:
                totalLeft = getWidth() - getPaddingRight() - totalWidth;
                break;
            case Gravity.FILL_HORIZONTAL:
                totalLeft = getPaddingLeft();
                fillHorizontal = true;
                break;
            default:
                totalLeft = getPaddingLeft();
        }

        switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
            case Gravity.CENTER_VERTICAL:
                mTempRectF.top = (int) (getHeight() - mTabHeight) / 2;
                break;
            case Gravity.BOTTOM:
                mTempRectF.top = getHeight() - getPaddingBottom() - mTabHeight;
                break;
            default:
                mTempRectF.top = getPaddingTop();
        }

        mTempRectF.bottom = mTempRectF.top + mTabHeight;

        float tabWidth = mTabWidth;
        if (fillHorizontal) {
            tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft()
                    - (mPageCount - 1) * mTabSpacing) / mPageCount;
        }

        for (int i = 0; i < mPageCount; i++) {
            mTempRectF.left = totalLeft + (i * (tabWidth + mTabSpacing));
            mTempRectF.right = mTempRectF.left + tabWidth;
            canvas.drawRect(mTempRectF, i < mCurrentPage
                    ? mPrevTabPaint
                    : (i > mCurrentPage
                            ? mNextTabPaint
                            : (i == mPageCount - 1
                                    ? mSelectedLastTabPaint
                                    : mSelectedTabPaint)));
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(
                View.resolveSize(
                        (int) (mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing)
                                + getPaddingLeft() + getPaddingRight(),
                        widthMeasureSpec),
                View.resolveSize(
                        (int) mTabHeight
                                + getPaddingTop() + getPaddingBottom(),
                        heightMeasureSpec));
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        scrollCurrentPageIntoView();
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (mOnPageSelectedListener != null) {
            switch (event.getActionMasked()) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_MOVE:
                    int position = hitTest(event.getX());
                    if (position >= 0) {
                        mOnPageSelectedListener.onPageStripSelected(position);
                    }
                    return true;
            }
        }
        return super.onTouchEvent(event);
    }

    private int hitTest(float x) {
        if (mPageCount == 0) {
            return -1;
        }

        float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
        float totalLeft;
        boolean fillHorizontal = false;

        switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
            case Gravity.CENTER_HORIZONTAL:
                totalLeft = (getWidth() - totalWidth) / 2;
                break;
            case Gravity.RIGHT:
                totalLeft = getWidth() - getPaddingRight() - totalWidth;
                break;
            case Gravity.FILL_HORIZONTAL:
                totalLeft = getPaddingLeft();
                fillHorizontal = true;
                break;
            default:
                totalLeft = getPaddingLeft();
        }

        float tabWidth = mTabWidth;
        if (fillHorizontal) {
            tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft()
                    - (mPageCount - 1) * mTabSpacing) / mPageCount;
        }

        float totalRight = totalLeft + (mPageCount * (tabWidth + mTabSpacing));
        if (x >= totalLeft && x <= totalRight && totalRight > totalLeft) {
            return (int) (((x - totalLeft) / (totalRight - totalLeft)) * mPageCount);
        } else {
            return -1;
        }
    }

    public void setCurrentPage(int currentPage) {
        mCurrentPage = currentPage;
        invalidate();
        scrollCurrentPageIntoView();
    }

    private void scrollCurrentPageIntoView() {
        // TODO: only works with left gravity for now
//
//        float widthToActive = getPaddingLeft() + (mCurrentPage + 1) * (mTabWidth + mTabSpacing)
//                - mTabSpacing;
//        int viewWidth = getWidth();
//
//        int startScrollX = getScrollX();
//        int destScrollX = (widthToActive > viewWidth) ? (int) (widthToActive - viewWidth) : 0;
//
//        if (mScroller == null) {
//            mScroller = new Scroller(getContext());
//        }
//
//        mScroller.abortAnimation();
//        mScroller.startScroll(startScrollX, 0, destScrollX - startScrollX, 0);
//        postInvalidate();
    }

    public void setPageCount(int count) {
        mPageCount = count;
        invalidate();
    }

    public static interface OnPageSelectedListener {
        void onPageStripSelected(int position);
    }

//
//    @Override
//    public void computeScroll() {
//        super.computeScroll();
//        if (mScroller.computeScrollOffset()) {
//            setScrollX(mScroller.getCurrX());
//        }
//    }
}




Java Source Code List

android.UnusedStub.java
com.android.capstone.BaseActivity.java
com.android.capstone.DatePickerFragment.java
com.android.capstone.MainActivity.java
com.android.capstone.RegisterFragment.java
com.android.capstone.data.CheckinSvcApi.java
com.android.capstone.data.Checkin.java
com.android.capstone.data.Doctor.java
com.android.capstone.data.GPlusProfile.java
com.android.capstone.data.MedicationCheckinQA.java
com.android.capstone.data.Medications.java
com.android.capstone.data.Patient.java
com.android.capstone.data.VDoctor.java
com.android.capstone.data.VPatient.java
com.android.capstone.db.SymptomManagementContract.java
com.android.capstone.db.SymptomManagementDbHelper.java
com.android.capstone.db.SymptomManagementProvider.java
com.android.capstone.doctor.CheckinLogsListAdapter.java
com.android.capstone.doctor.CheckinLogs_Doctor_Fragment.java
com.android.capstone.doctor.DisplayCheckinActivity.java
com.android.capstone.doctor.DoctorMain_Fragment.java
com.android.capstone.doctor.Doctor_Main_CursorAdapter.java
com.android.capstone.doctor.Doctor_VPatient_Activity.java
com.android.capstone.doctor.Doctor_VPatient_Fragment.java
com.android.capstone.doctor.MedicationsListAdapter.java
com.android.capstone.doctor.MedicationsListFragment.java
com.android.capstone.doctor.alarm.CheckPainIntentService.java
com.android.capstone.doctor.alarm.CheckPain.java
com.android.capstone.doctor.alarm.CheckinAlarmService.java
com.android.capstone.doctor.alarm.OnBootReceiver.java
com.android.capstone.gcm.GcmBroadcastReceiver.java
com.android.capstone.gcm.GcmIntentService.java
com.android.capstone.patient.CheckinNowActivity.java
com.android.capstone.patient.PatientMain_Fragment.java
com.android.capstone.patient.Patient_Main_CursorAdapter.java
com.android.capstone.patient.ReminderCursorAdapter.java
com.android.capstone.patient.RemindersActivity.java
com.android.capstone.patient.TimePickerFragment.java
com.android.capstone.patient.checkin_now.model.AbstractWizardModel.java
com.android.capstone.patient.checkin_now.model.BranchPage.java
com.android.capstone.patient.checkin_now.model.CheckinNow_Model.java
com.android.capstone.patient.checkin_now.model.ModelCallbacks.java
com.android.capstone.patient.checkin_now.model.MultipleFixedChoicePage.java
com.android.capstone.patient.checkin_now.model.PageList.java
com.android.capstone.patient.checkin_now.model.PageTreeNode.java
com.android.capstone.patient.checkin_now.model.Page.java
com.android.capstone.patient.checkin_now.model.ReviewItem.java
com.android.capstone.patient.checkin_now.model.SingleFixedChoicePage.java
com.android.capstone.patient.checkin_now.ui.MultipleChoiceFragment.java
com.android.capstone.patient.checkin_now.ui.PageFragmentCallbacks.java
com.android.capstone.patient.checkin_now.ui.ReviewFragment.java
com.android.capstone.patient.checkin_now.ui.SingleChoiceFragment.java
com.android.capstone.patient.checkin_now.ui.StepPagerStrip.java
com.android.capstone.task.AddCheckinTask.java
com.android.capstone.task.AddMedicationsTask.java
com.android.capstone.task.AddPatientTask.java
com.android.capstone.task.GetClientCategoryTask.java
com.android.capstone.task.GetClientInfoTask.java
com.android.capstone.task.GetUserImageTask.java
com.android.capstone.task.RegisterDoctorTask.java
com.android.capstone.task.RegisterPatientTask.java
com.android.capstone.utils.CommonUtils.java
com.android.capstone.utils.RetrofitUtils.java
com.android.capstone.utils.SharedPrefUtils.java
com.android.capstone.views.CheckinLogsView.java
com.android.capstone.views.FloatingActionButton.java
com.coursera.capstone.checkin.Application.java
com.coursera.capstone.checkin.client.CheckinSvcApi.java
com.coursera.capstone.checkin.client.TokenSvcApi.java
com.coursera.capstone.checkin.controller.CheckinSvc.java
com.coursera.capstone.data.CheckinUtils.java
com.coursera.capstone.data.Checkin.java
com.coursera.capstone.data.ClientUtils.java
com.coursera.capstone.data.Constants.java
com.coursera.capstone.data.DoctorUtils.java
com.coursera.capstone.data.Doctor.java
com.coursera.capstone.data.InvalidRequestException.java
com.coursera.capstone.data.Medications.java
com.coursera.capstone.data.Message.java
com.coursera.capstone.data.MulticastResult.java
com.coursera.capstone.data.PMF.java
com.coursera.capstone.data.PatientUtils.java
com.coursera.capstone.data.Patient.java
com.coursera.capstone.data.Result.java
com.coursera.capstone.data.Sender.java
com.coursera.capstone.data.Token.java
com.coursera.capstone.data.VDoctor.java
com.coursera.capstone.data.VPatient.java
com.coursera.capstone.interceptor.AuthorizationInterceptor.java
com.coursera.capstone.interceptor.Checker.java