cn.aigestudio.datepicker.utils.MeasureUtil Java Examples

The following examples show how to use cn.aigestudio.datepicker.utils.MeasureUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatePicker.java    From Memory-capsule with Apache License 2.0 4 votes vote down vote up
public DatePicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTManager = DPTManager.getInstance();
    mLManager = DPLManager.getInstance();

    // 设置排列方向为竖向
    setOrientation(VERTICAL);

    LayoutParams llParams =
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // 标题栏根布局
    RelativeLayout rlTitle = new RelativeLayout(context);
    rlTitle.setBackgroundColor(mTManager.colorTitleBG());
    int rlTitlePadding = MeasureUtil.dp2px(context, 10);
    rlTitle.setPadding(rlTitlePadding, rlTitlePadding, rlTitlePadding, rlTitlePadding);

    // 周视图根布局
    LinearLayout llWeek = new LinearLayout(context);
    llWeek.setBackgroundColor(mTManager.colorTitleBG());
    llWeek.setOrientation(HORIZONTAL);
    int llWeekPadding = MeasureUtil.dp2px(context, 5);
    llWeek.setPadding(0, llWeekPadding, 0, llWeekPadding);
    LayoutParams lpWeek = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpWeek.weight = 1;

    // 标题栏子元素布局参数
    RelativeLayout.LayoutParams lpYear =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpYear.addRule(RelativeLayout.CENTER_VERTICAL);
    RelativeLayout.LayoutParams lpMonth =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpMonth.addRule(RelativeLayout.CENTER_IN_PARENT);
    RelativeLayout.LayoutParams lpEnsure =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpEnsure.addRule(RelativeLayout.CENTER_VERTICAL);
    lpEnsure.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    // --------------------------------------------------------------------------------标题栏
    // 年份显示
    tvYear = new TextView(context);
    tvYear.setText("2015");
    tvYear.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvYear.setTextColor(mTManager.colorTitle());

    // 月份显示
    tvMonth = new TextView(context);
    tvMonth.setText("六月");
    tvMonth.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    tvMonth.setTextColor(mTManager.colorTitle());

    // 确定显示
    tvEnsure = new TextView(context);
    tvEnsure.setText(mLManager.titleEnsure());
    tvEnsure.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvEnsure.setTextColor(mTManager.colorTitle());
    tvEnsure.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != onDateSelectedListener) {
                onDateSelectedListener.onDateSelected(monthView.getDateSelected());
            }
        }
    });

    rlTitle.addView(tvYear, lpYear);
    rlTitle.addView(tvMonth, lpMonth);
    rlTitle.addView(tvEnsure, lpEnsure);

    addView(rlTitle, llParams);

    // --------------------------------------------------------------------------------周视图
    for (int i = 0; i < mLManager.titleWeek().length; i++) {
        TextView tvWeek = new TextView(context);
        tvWeek.setText(mLManager.titleWeek()[i]);
        tvWeek.setGravity(Gravity.CENTER);
        tvWeek.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        tvWeek.setTextColor(mTManager.colorTitle());
        llWeek.addView(tvWeek, lpWeek);
    }
    addView(llWeek, llParams);

    // ------------------------------------------------------------------------------------月视图
    monthView = new MonthView(context);
    monthView.setOnDateChangeListener(new MonthView.OnDateChangeListener() {
        @Override
        public void onMonthChange(int month) {
            tvMonth.setText(mLManager.titleMonth()[month - 1]);
        }

        @Override
        public void onYearChange(int year) {
            String tmp = String.valueOf(year);
            if (tmp.startsWith("-")) {
                tmp = tmp.replace("-", mLManager.titleBC());
            }
            tvYear.setText(tmp);
        }
    });
    addView(monthView, llParams);
}
 
Example #2
Source File: DatePicker.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
public DatePicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTManager = DPTManager.getInstance();
    mLManager = DPLManager.getInstance();

    // 设置排列方向为竖向
    setOrientation(VERTICAL);

    LayoutParams llParams =
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // 标题栏根布局
     rlTitle = new RelativeLayout(context);
    rlTitle.setBackgroundColor(mTManager.colorTitleBG());
    int rlTitlePadding = MeasureUtil.dp2px(context, 8);
    rlTitle.setPadding(rlTitlePadding, rlTitlePadding, rlTitlePadding, rlTitlePadding);

    // 周视图根布局
     llWeek = new LinearLayout(context);
    llWeek.setBackgroundColor(mTManager.colorTitleBG());
    llWeek.setOrientation(HORIZONTAL);
    int llWeekPadding = MeasureUtil.dp2px(context, 4);
    llWeek.setPadding(0, llWeekPadding, 0, llWeekPadding);
    LayoutParams lpWeek = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpWeek.weight = 1;

    // 标题栏子元素布局参数
    RelativeLayout.LayoutParams lpYear =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpYear.addRule(RelativeLayout.CENTER_VERTICAL);
    RelativeLayout.LayoutParams lpMonth =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpMonth.addRule(RelativeLayout.CENTER_IN_PARENT);
    RelativeLayout.LayoutParams lpEnsure =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpEnsure.addRule(RelativeLayout.CENTER_VERTICAL);
    lpEnsure.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    // --------------------------------------------------------------------------------标题栏
    // 年份显示
    tvYear = new TextView(context);
    tvYear.setText("2015");
    tvYear.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvYear.setTextColor(mTManager.colorTitle());

    // 月份显示
    tvMonth = new TextView(context);
    tvMonth.setText("六月");
    tvMonth.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    tvMonth.setTextColor(mTManager.colorTitle());

    // 确定显示
    tvEnsure = new TextView(context);
    tvEnsure.setText(mLManager.titleEnsure());
    tvEnsure.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvEnsure.setTextColor(mTManager.colorTitle());
    tvEnsure.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != onDateSelectedListener) {
                onDateSelectedListener.onDateSelected(monthView.getDateSelected());
            }
        }
    });

    rlTitle.addView(tvYear, lpYear);
    rlTitle.addView(tvMonth, lpMonth);
    rlTitle.addView(tvEnsure, lpEnsure);

    addView(rlTitle, llParams);

    // --------------------------------------------------------------------------------周视图
    for (int i = 0; i < mLManager.titleWeek().length; i++) {
        TextView tvWeek = new TextView(context);
        tvWeek.setText(mLManager.titleWeek()[i]);
        tvWeek.setGravity(Gravity.CENTER);
        tvWeek.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        tvWeek.setTextColor(mTManager.colorTitle());
        llWeek.addView(tvWeek, lpWeek);
    }
    addView(llWeek, llParams);

    // ------------------------------------------------------------------------------------月视图
    monthView = new MonthView(context);
    monthView.setOnDateChangeListener(new MonthView.OnDateChangeListener() {
        @Override
        public void onMonthChange(int month) {
            tvMonth.setText(mLManager.titleMonth()[month - 1]);
        }

        @Override
        public void onYearChange(int year) {
            String tmp = String.valueOf(year);
            if (tmp.startsWith("-")) {
                tmp = tmp.replace("-", mLManager.titleBC());
            }
            tvYear.setText(tmp);
        }
    });
    addView(monthView, llParams);
}
 
Example #3
Source File: DatePicker.java    From DatePicker with Apache License 2.0 4 votes vote down vote up
public DatePicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTManager = DPTManager.getInstance();
    mLManager = DPLManager.getInstance();

    // 设置排列方向为竖向
    setOrientation(VERTICAL);

    LayoutParams llParams =
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    // 标题栏根布局
    RelativeLayout rlTitle = new RelativeLayout(context);
    rlTitle.setBackgroundColor(mTManager.colorTitleBG());
    int rlTitlePadding = MeasureUtil.dp2px(context, 10);
    rlTitle.setPadding(rlTitlePadding, rlTitlePadding, rlTitlePadding, rlTitlePadding);

    // 周视图根布局
    LinearLayout llWeek = new LinearLayout(context);
    llWeek.setBackgroundColor(mTManager.colorTitleBG());
    llWeek.setOrientation(HORIZONTAL);
    int llWeekPadding = MeasureUtil.dp2px(context, 5);
    llWeek.setPadding(0, llWeekPadding, 0, llWeekPadding);
    LayoutParams lpWeek = new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpWeek.weight = 1;

    // 标题栏子元素布局参数
    RelativeLayout.LayoutParams lpYear =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpYear.addRule(RelativeLayout.CENTER_VERTICAL);
    RelativeLayout.LayoutParams lpMonth =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpMonth.addRule(RelativeLayout.CENTER_IN_PARENT);
    RelativeLayout.LayoutParams lpEnsure =
            new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    lpEnsure.addRule(RelativeLayout.CENTER_VERTICAL);
    lpEnsure.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    // --------------------------------------------------------------------------------标题栏
    // 年份显示
    tvYear = new TextView(context);
    tvYear.setText("2015");
    tvYear.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvYear.setTextColor(mTManager.colorTitle());

    // 月份显示
    tvMonth = new TextView(context);
    tvMonth.setText("六月");
    tvMonth.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    tvMonth.setTextColor(mTManager.colorTitle());

    // 确定显示
    tvEnsure = new TextView(context);
    tvEnsure.setText(mLManager.titleEnsure());
    tvEnsure.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    tvEnsure.setTextColor(mTManager.colorTitle());
    tvEnsure.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != onDateSelectedListener) {
                onDateSelectedListener.onDateSelected(monthView.getDateSelected());
            }
        }
    });

    rlTitle.addView(tvYear, lpYear);
    rlTitle.addView(tvMonth, lpMonth);
    rlTitle.addView(tvEnsure, lpEnsure);

    addView(rlTitle, llParams);

    // --------------------------------------------------------------------------------周视图
    for (int i = 0; i < mLManager.titleWeek().length; i++) {
        TextView tvWeek = new TextView(context);
        tvWeek.setText(mLManager.titleWeek()[i]);
        tvWeek.setGravity(Gravity.CENTER);
        tvWeek.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        tvWeek.setTextColor(mTManager.colorTitle());
        llWeek.addView(tvWeek, lpWeek);
    }
    addView(llWeek, llParams);

    // ------------------------------------------------------------------------------------月视图
    monthView = new MonthView(context);
    monthView.setOnDateChangeListener(new MonthView.OnDateChangeListener() {
        @Override
        public void onMonthChange(int month) {
            tvMonth.setText(mLManager.titleMonth()[month - 1]);
        }

        @Override
        public void onYearChange(int year) {
            String tmp = String.valueOf(year);
            if (tmp.startsWith("-")) {
                tmp = tmp.replace("-", mLManager.titleBC());
            }
            tvYear.setText(tmp);
        }
    });
    addView(monthView, llParams);
}