Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
JunGenius committed Jan 18, 2019
1 parent c144717 commit 650b40c
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 136 deletions.
111 changes: 0 additions & 111 deletions app/src/main/java/com/qj/picker/CustomCalendarViewDialog.java

This file was deleted.

129 changes: 129 additions & 0 deletions app/src/main/java/com/qj/picker/MDCalendarDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.qj.picker;

import android.app.AlertDialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.qj.picker.calendarview.CalendarDay;
import com.qj.picker.calendarview.MaterialCalendarView;
import com.qj.picker.tool.DateUtil;

import java.util.Date;

/**
* @author qujun
* @des 自定日期选择器
* @time 2019/1/18 0:17
* Because had because, so had so, since has become since, why say why。
**/

public class MDCalendarDialog {

private MaterialCalendarView mcv = null;

private Button btnSure = null;

private TextView txtTitle = null;

private MDCalendarDialog.Builder mBuilder = null;

private AlertDialog dialog = null;

MDCalendarDialog(MDCalendarDialog.Builder builder) {
this.mBuilder = mBuilder;
}

public void show() {

dialog = new AlertDialog.Builder(mBuilder.mContext).create();
dialog.setCancelable(mBuilder.isCancel);
dialog.show();

Window window = dialog.getWindow();

if (window == null) {
return;
}

window.setContentView(R.layout.custom_datetime_view);
mcv = window.findViewById(R.id.mcv);
btnSure = window.findViewById(R.id.btn_sure);
txtTitle = window.findViewById(R.id.txt_title);
txtTitle.setText(mBuilder.title);

if (mBuilder.currentDate == null) {
mBuilder.currentDate = new Date();
}
mcv.setSelectedDate(mBuilder.currentDate);
mcv.setCurrentDate(mBuilder.currentDate);

btnSure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mBuilder.onDetermineSelectorListener == null) {
return;
}
CalendarDay date = mcv.getSelectedDate();
if (date == null) {
mBuilder.onDetermineSelectorListener.noSelector();
return;
}
mBuilder.onDetermineSelectorListener.determineSelector(DateUtil.getNextDateStr(date.getDate(), 0), date.getDate());
dialog.dismiss();
}
});
}


public static class Builder {

private boolean isCancel = false;

private Date currentDate = null;

private String title = "";

private Context mContext = null;

private OnDetermineSelectorListener onDetermineSelectorListener = null;

public Builder(Context context) {
mContext = context;
}

public Builder setIsCancel(boolean isCancel) {
this.isCancel = isCancel;
return this;
}

public Builder setTitle(String title) {
this.title = title;
return this;
}

public Builder setCurrentDate(Date date) {
currentDate = date;
return this;
}

public Builder onDetermineSeleterListener(OnDetermineSelectorListener onDetermineSelectorListener) {
this.onDetermineSelectorListener = onDetermineSelectorListener;
return this;
}

public MDCalendarDialog build() {
return new MDCalendarDialog(this);
}
}


public interface OnDetermineSelectorListener {

void determineSelector(String dateStr, Date date);

void noSelector();
}
}
41 changes: 16 additions & 25 deletions app/src/main/res/layout/custom_datetime_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,27 @@
xmlns:app="http://schemas.android.com/apk/res-auto">


<LinearLayout
android:padding="10dp"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<ImageView
android:id="@+id/img_icon"
android:src="@mipmap/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/txt_title"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"
android:textColor="@color/material_black"
android:text="请选择出乘日期"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
<TextView
android:id="@+id/txt_title"
android:layout_marginStart="10dp"
android:layout_gravity="center_vertical"
android:textColor="@color/material_black"
android:drawableStart="@mipmap/information"
android:drawablePadding="10dp"
android:gravity="center_vertical"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<ImageView
android:scaleType="fitXY"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="@mipmap/line_record"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:contentDescription="@string/icon_description" />


<com.qj.picker.calendarview.MaterialCalendarView
Expand All @@ -55,8 +45,9 @@


<Button
android:id="@+id/button"
android:text="确 定"
android:id="@+id/btn_sure"
android:text="@string/btn_sure"
android:textColor="@color/material_white"
android:background="@drawable/login_btn_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
<string name="previous">Go to previous</string>
<string name="next">Go to next</string>
<string name="calendar">Calendar</string>


<string name="icon_description">日期选择器图标</string>

<string name="btn_sure">确 定</string>
</resources>

0 comments on commit 650b40c

Please sign in to comment.