mirror of https://github.com/tasks/tasks
CRLF patch from Arne
parent
26c0d077c7
commit
8b6241b042
@ -1,29 +1,29 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent">
|
android:layout_height="fill_parent">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
<com.todoroo.astrid.ui.CalendarView
|
<com.todoroo.astrid.ui.CalendarView
|
||||||
android:id="@+id/CalendarView"
|
android:id="@+id/CalendarView"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_weight="7">
|
android:layout_weight="7">
|
||||||
<Button android:layout_width="wrap_content"
|
<Button android:layout_width="wrap_content"
|
||||||
android:layout_height="fill_parent" android:text="Cancel" android:id="@+id/CancelButton"
|
android:layout_height="fill_parent" android:text="Cancel" android:id="@+id/CancelButton"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@ -1,65 +1,65 @@
|
|||||||
package com.todoroo.astrid.ui;
|
package com.todoroo.astrid.ui;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
import com.timsu.astrid.R;
|
import com.timsu.astrid.R;
|
||||||
import com.todoroo.astrid.ui.CalendarView.OnSelectedDateListener;
|
import com.todoroo.astrid.ui.CalendarView.OnSelectedDateListener;
|
||||||
|
|
||||||
public class CalendarDialog extends Dialog implements OnClickListener, OnSelectedDateListener {
|
public class CalendarDialog extends Dialog implements OnClickListener, OnSelectedDateListener {
|
||||||
|
|
||||||
private final Button cancelButton;
|
private final Button cancelButton;
|
||||||
private Date calendarDate;
|
private Date calendarDate;
|
||||||
|
|
||||||
private final CalendarView calendarView;
|
private final CalendarView calendarView;
|
||||||
|
|
||||||
public CalendarDialog(Context context, Date calendarDate) {
|
public CalendarDialog(Context context, Date calendarDate) {
|
||||||
super(context);
|
super(context);
|
||||||
this.calendarDate = calendarDate;
|
this.calendarDate = calendarDate;
|
||||||
/** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
|
/** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
/** Design the dialog in main.xml file */
|
/** Design the dialog in main.xml file */
|
||||||
setContentView(R.layout.calendar);
|
setContentView(R.layout.calendar);
|
||||||
|
|
||||||
LayoutParams params = getWindow().getAttributes();
|
LayoutParams params = getWindow().getAttributes();
|
||||||
params.height = LayoutParams.FILL_PARENT;
|
params.height = LayoutParams.FILL_PARENT;
|
||||||
params.width = LayoutParams.FILL_PARENT;
|
params.width = LayoutParams.FILL_PARENT;
|
||||||
getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
|
getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
|
||||||
|
|
||||||
cancelButton = (Button) findViewById(R.id.CancelButton);
|
cancelButton = (Button) findViewById(R.id.CancelButton);
|
||||||
|
|
||||||
calendarView = (CalendarView) findViewById(R.id.CalendarView);
|
calendarView = (CalendarView) findViewById(R.id.CalendarView);
|
||||||
calendarView.setCalendarDate(calendarDate);
|
calendarView.setCalendarDate(calendarDate);
|
||||||
calendarView.setOnSelectedDateListener(this);
|
calendarView.setOnSelectedDateListener(this);
|
||||||
|
|
||||||
cancelButton.setOnClickListener(this);
|
cancelButton.setOnClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (v == cancelButton) {
|
if (v == cancelButton) {
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSelectedDate(Date date) {
|
public void onSelectedDate(Date date) {
|
||||||
calendarDate = date;
|
calendarDate = date;
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCalendarDate() {
|
public Date getCalendarDate() {
|
||||||
return calendarDate;
|
return calendarDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCalendarDate(Date calendarDate) {
|
public void setCalendarDate(Date calendarDate) {
|
||||||
this.calendarDate = calendarDate;
|
this.calendarDate = calendarDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,403 +1,403 @@
|
|||||||
package com.todoroo.astrid.ui;
|
package com.todoroo.astrid.ui;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import com.timsu.astrid.R;
|
import com.timsu.astrid.R;
|
||||||
|
|
||||||
public class CalendarView extends View {
|
public class CalendarView extends View {
|
||||||
|
|
||||||
private static final int PADDING = 3;
|
private static final int PADDING = 3;
|
||||||
private final static int CURVE_RADIUS = 5;
|
private final static int CURVE_RADIUS = 5;
|
||||||
private final static int TEXT_SIZE = 16;
|
private final static int TEXT_SIZE = 16;
|
||||||
private static final float MONTH_TEXT_SIZE = 22;
|
private static final float MONTH_TEXT_SIZE = 22;
|
||||||
|
|
||||||
private Paint borderPaint;
|
private Paint borderPaint;
|
||||||
private Paint borderRightAlignPaint;
|
private Paint borderRightAlignPaint;
|
||||||
private Paint backColorPaint;
|
private Paint backColorPaint;
|
||||||
private Paint whiteCenterAlignLargePaint;
|
private Paint whiteCenterAlignLargePaint;
|
||||||
private Paint darkRightAlignPaint;
|
private Paint darkRightAlignPaint;
|
||||||
private Paint todayCalendarPaint;
|
private Paint todayCalendarPaint;
|
||||||
private Paint dayPaint;
|
private Paint dayPaint;
|
||||||
private Paint calendarPaint;
|
private Paint calendarPaint;
|
||||||
private float density;
|
private float density;
|
||||||
|
|
||||||
private int leftArrowHeight;
|
private int leftArrowHeight;
|
||||||
private int leftArrowWidth;
|
private int leftArrowWidth;
|
||||||
private int rightArrowHeight;
|
private int rightArrowHeight;
|
||||||
private int rightArrowWidth;
|
private int rightArrowWidth;
|
||||||
private int leftArrowX = 0;
|
private int leftArrowX = 0;
|
||||||
private int leftArrowY = 0;
|
private int leftArrowY = 0;
|
||||||
private int rightArrowX = 0;
|
private int rightArrowX = 0;
|
||||||
private int rightArrowY = 0;
|
private int rightArrowY = 0;
|
||||||
|
|
||||||
private int[] dayLeftArr;
|
private int[] dayLeftArr;
|
||||||
private int[] dayTopArr;
|
private int[] dayTopArr;
|
||||||
|
|
||||||
private int boxWidth;
|
private int boxWidth;
|
||||||
private int boxHeight;
|
private int boxHeight;
|
||||||
|
|
||||||
private Date calendarDate = new Date();
|
private Date calendarDate = new Date();
|
||||||
private int currentHighlightDay = -1;
|
private int currentHighlightDay = -1;
|
||||||
|
|
||||||
public interface OnSelectedDateListener {
|
public interface OnSelectedDateListener {
|
||||||
public void onSelectedDate(Date date);
|
public void onSelectedDate(Date date);
|
||||||
}
|
}
|
||||||
private OnSelectedDateListener onSelectedDateListener;
|
private OnSelectedDateListener onSelectedDateListener;
|
||||||
|
|
||||||
public void setOnSelectedDateListener(
|
public void setOnSelectedDateListener(
|
||||||
OnSelectedDateListener onSelectedDateListener) {
|
OnSelectedDateListener onSelectedDateListener) {
|
||||||
this.onSelectedDateListener = onSelectedDateListener;
|
this.onSelectedDateListener = onSelectedDateListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. This version is only needed if you will be instantiating
|
* Constructor. This version is only needed if you will be instantiating
|
||||||
* the object manually (not from a layout XML file).
|
* the object manually (not from a layout XML file).
|
||||||
* @param context
|
* @param context
|
||||||
*/
|
*/
|
||||||
public CalendarView(Context context) {
|
public CalendarView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
initCalendarView(context);
|
initCalendarView(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CalendarView(Context context, AttributeSet attrs) {
|
public CalendarView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
initCalendarView(context);
|
initCalendarView(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void initCalendarView(Context context) {
|
private final void initCalendarView(Context context) {
|
||||||
Display display = ((WindowManager) context.getSystemService(
|
Display display = ((WindowManager) context.getSystemService(
|
||||||
Context.WINDOW_SERVICE)).getDefaultDisplay();
|
Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||||
|
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
display.getMetrics(metrics);
|
display.getMetrics(metrics);
|
||||||
density = metrics.density;
|
density = metrics.density;
|
||||||
|
|
||||||
borderPaint = new Paint();
|
borderPaint = new Paint();
|
||||||
borderPaint.setAntiAlias(true);
|
borderPaint.setAntiAlias(true);
|
||||||
borderPaint.setColor(Color.BLACK);
|
borderPaint.setColor(Color.BLACK);
|
||||||
|
|
||||||
borderRightAlignPaint = new Paint();
|
borderRightAlignPaint = new Paint();
|
||||||
borderRightAlignPaint.setAntiAlias(true);
|
borderRightAlignPaint.setAntiAlias(true);
|
||||||
borderRightAlignPaint.setColor(Color.WHITE);
|
borderRightAlignPaint.setColor(Color.WHITE);
|
||||||
borderRightAlignPaint.setTextSize(TEXT_SIZE * density);
|
borderRightAlignPaint.setTextSize(TEXT_SIZE * density);
|
||||||
borderRightAlignPaint.setTextAlign(Paint.Align.RIGHT);
|
borderRightAlignPaint.setTextAlign(Paint.Align.RIGHT);
|
||||||
|
|
||||||
dayPaint = new Paint();
|
dayPaint = new Paint();
|
||||||
dayPaint.setAntiAlias(true);
|
dayPaint.setAntiAlias(true);
|
||||||
dayPaint.setColor(Color.rgb(137, 135, 132));
|
dayPaint.setColor(Color.rgb(137, 135, 132));
|
||||||
|
|
||||||
calendarPaint = new Paint();
|
calendarPaint = new Paint();
|
||||||
calendarPaint.setAntiAlias(true);
|
calendarPaint.setAntiAlias(true);
|
||||||
calendarPaint.setColor(Color.rgb(202, 201, 194));
|
calendarPaint.setColor(Color.rgb(202, 201, 194));
|
||||||
|
|
||||||
whiteCenterAlignLargePaint = new Paint();
|
whiteCenterAlignLargePaint = new Paint();
|
||||||
whiteCenterAlignLargePaint.setAntiAlias(true);
|
whiteCenterAlignLargePaint.setAntiAlias(true);
|
||||||
whiteCenterAlignLargePaint.setColor(Color.WHITE);
|
whiteCenterAlignLargePaint.setColor(Color.WHITE);
|
||||||
whiteCenterAlignLargePaint.setTextAlign(Paint.Align.CENTER);
|
whiteCenterAlignLargePaint.setTextAlign(Paint.Align.CENTER);
|
||||||
whiteCenterAlignLargePaint.setTextSize(MONTH_TEXT_SIZE * density);
|
whiteCenterAlignLargePaint.setTextSize(MONTH_TEXT_SIZE * density);
|
||||||
|
|
||||||
darkRightAlignPaint = new Paint();
|
darkRightAlignPaint = new Paint();
|
||||||
darkRightAlignPaint.setAntiAlias(true);
|
darkRightAlignPaint.setAntiAlias(true);
|
||||||
darkRightAlignPaint.setColor(Color.rgb(40, 40, 40));
|
darkRightAlignPaint.setColor(Color.rgb(40, 40, 40));
|
||||||
darkRightAlignPaint.setTextAlign(Paint.Align.RIGHT);
|
darkRightAlignPaint.setTextAlign(Paint.Align.RIGHT);
|
||||||
darkRightAlignPaint.setTextSize(TEXT_SIZE * density);
|
darkRightAlignPaint.setTextSize(TEXT_SIZE * density);
|
||||||
|
|
||||||
todayCalendarPaint = new Paint();
|
todayCalendarPaint = new Paint();
|
||||||
todayCalendarPaint.setAntiAlias(true);
|
todayCalendarPaint.setAntiAlias(true);
|
||||||
todayCalendarPaint.setColor(Color.rgb(222, 221, 154));
|
todayCalendarPaint.setColor(Color.rgb(222, 221, 154));
|
||||||
|
|
||||||
backColorPaint = new Paint();
|
backColorPaint = new Paint();
|
||||||
backColorPaint.setAntiAlias(true);
|
backColorPaint.setAntiAlias(true);
|
||||||
backColorPaint.setColor(Color.rgb(68, 68, 68));
|
backColorPaint.setColor(Color.rgb(68, 68, 68));
|
||||||
|
|
||||||
setPadding(PADDING, PADDING, PADDING, PADDING);
|
setPadding(PADDING, PADDING, PADDING, PADDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see android.view.View#measure(int, int)
|
* @see android.view.View#measure(int, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
setMeasuredDimension(measureWidth(widthMeasureSpec),
|
setMeasuredDimension(measureWidth(widthMeasureSpec),
|
||||||
measureHeight(heightMeasureSpec));
|
measureHeight(heightMeasureSpec));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the width of this view
|
* Determines the width of this view
|
||||||
* @param measureSpec A measureSpec packed into an int
|
* @param measureSpec A measureSpec packed into an int
|
||||||
* @return The width of the view, honoring constraints from measureSpec
|
* @return The width of the view, honoring constraints from measureSpec
|
||||||
*/
|
*/
|
||||||
private int measureWidth(int measureSpec) {
|
private int measureWidth(int measureSpec) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int specMode = MeasureSpec.getMode(measureSpec);
|
int specMode = MeasureSpec.getMode(measureSpec);
|
||||||
int specSize = MeasureSpec.getSize(measureSpec);
|
int specSize = MeasureSpec.getSize(measureSpec);
|
||||||
|
|
||||||
if (specMode == MeasureSpec.EXACTLY) {
|
if (specMode == MeasureSpec.EXACTLY) {
|
||||||
// We were told how big to be
|
// We were told how big to be
|
||||||
result = specSize;
|
result = specSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines the height of this view
|
* Determines the height of this view
|
||||||
* @param measureSpec A measureSpec packed into an int
|
* @param measureSpec A measureSpec packed into an int
|
||||||
* @return The height of the view, honoring constraints from measureSpec
|
* @return The height of the view, honoring constraints from measureSpec
|
||||||
*/
|
*/
|
||||||
private int measureHeight(int measureSpec) {
|
private int measureHeight(int measureSpec) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int specMode = MeasureSpec.getMode(measureSpec);
|
int specMode = MeasureSpec.getMode(measureSpec);
|
||||||
int specSize = MeasureSpec.getSize(measureSpec);
|
int specSize = MeasureSpec.getSize(measureSpec);
|
||||||
|
|
||||||
if (specMode == MeasureSpec.EXACTLY) {
|
if (specMode == MeasureSpec.EXACTLY) {
|
||||||
// We were told how big to be
|
// We were told how big to be
|
||||||
result = specSize;
|
result = specSize;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see android.view.View#onDraw(android.graphics.Canvas)
|
* @see android.view.View#onDraw(android.graphics.Canvas)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), backColorPaint);
|
canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), backColorPaint);
|
||||||
|
|
||||||
// Outermost border -- Start
|
// Outermost border -- Start
|
||||||
RectF outerMostBorder = new RectF();
|
RectF outerMostBorder = new RectF();
|
||||||
|
|
||||||
outerMostBorder.set(5, 5, getMeasuredWidth() - 5, getMeasuredHeight() - 5);
|
outerMostBorder.set(5, 5, getMeasuredWidth() - 5, getMeasuredHeight() - 5);
|
||||||
canvas.drawRoundRect(outerMostBorder, CURVE_RADIUS, CURVE_RADIUS, borderPaint);
|
canvas.drawRoundRect(outerMostBorder, CURVE_RADIUS, CURVE_RADIUS, borderPaint);
|
||||||
|
|
||||||
outerMostBorder.set(6, 6, getMeasuredWidth() - 6, getMeasuredHeight() - 6);
|
outerMostBorder.set(6, 6, getMeasuredWidth() - 6, getMeasuredHeight() - 6);
|
||||||
canvas.drawRoundRect(outerMostBorder, CURVE_RADIUS, CURVE_RADIUS, backColorPaint);
|
canvas.drawRoundRect(outerMostBorder, CURVE_RADIUS, CURVE_RADIUS, backColorPaint);
|
||||||
// Outermost border -- end
|
// Outermost border -- end
|
||||||
|
|
||||||
// Month border -- Start
|
// Month border -- Start
|
||||||
RectF rectF = new RectF();
|
RectF rectF = new RectF();
|
||||||
|
|
||||||
float monthTitleHeight = (MONTH_TEXT_SIZE + 30) * density;
|
float monthTitleHeight = (MONTH_TEXT_SIZE + 30) * density;
|
||||||
rectF.set(15, 15, getMeasuredWidth() - 15, monthTitleHeight);
|
rectF.set(15, 15, getMeasuredWidth() - 15, monthTitleHeight);
|
||||||
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, borderPaint);
|
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, borderPaint);
|
||||||
|
|
||||||
rectF.set(16, 16, getMeasuredWidth() - 16, monthTitleHeight - 1);
|
rectF.set(16, 16, getMeasuredWidth() - 16, monthTitleHeight - 1);
|
||||||
// canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, backColorPaint);
|
// canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, backColorPaint);
|
||||||
// Month border -- end
|
// Month border -- end
|
||||||
|
|
||||||
// Month left arrow -- Start
|
// Month left arrow -- Start
|
||||||
Bitmap leftArrow = ((BitmapDrawable)getResources().getDrawable(R.drawable.cal_left)).getBitmap();
|
Bitmap leftArrow = ((BitmapDrawable)getResources().getDrawable(R.drawable.cal_left)).getBitmap();
|
||||||
leftArrowHeight = (int)(leftArrow.getHeight()*density);
|
leftArrowHeight = (int)(leftArrow.getHeight()*density);
|
||||||
leftArrowWidth = (int)(leftArrow.getWidth()*density);
|
leftArrowWidth = (int)(leftArrow.getWidth()*density);
|
||||||
leftArrowX = 24;
|
leftArrowX = 24;
|
||||||
leftArrowY = 8 + (int)((monthTitleHeight / 2 - leftArrowHeight/2));
|
leftArrowY = 8 + (int)((monthTitleHeight / 2 - leftArrowHeight/2));
|
||||||
canvas.drawBitmap(leftArrow, new Rect(0,0,leftArrow.getWidth(),leftArrow.getHeight()),
|
canvas.drawBitmap(leftArrow, new Rect(0,0,leftArrow.getWidth(),leftArrow.getHeight()),
|
||||||
new Rect(leftArrowX, leftArrowY, leftArrowX + leftArrowWidth,
|
new Rect(leftArrowX, leftArrowY, leftArrowX + leftArrowWidth,
|
||||||
leftArrowY + leftArrowHeight), null);
|
leftArrowY + leftArrowHeight), null);
|
||||||
// Month left arrow -- End
|
// Month left arrow -- End
|
||||||
|
|
||||||
// Month right arrow -- Start
|
// Month right arrow -- Start
|
||||||
Bitmap rightArrow = ((BitmapDrawable)getResources().getDrawable(R.drawable.cal_right)).getBitmap();
|
Bitmap rightArrow = ((BitmapDrawable)getResources().getDrawable(R.drawable.cal_right)).getBitmap();
|
||||||
rightArrowHeight = (int)(rightArrow.getHeight()*density);
|
rightArrowHeight = (int)(rightArrow.getHeight()*density);
|
||||||
rightArrowWidth = (int)(rightArrow.getWidth()*density);
|
rightArrowWidth = (int)(rightArrow.getWidth()*density);
|
||||||
rightArrowX = (int) (getMeasuredWidth() - (16 * density) - (PADDING*3) - rightArrow.getWidth());
|
rightArrowX = (int) (getMeasuredWidth() - (16 * density) - (PADDING*3) - rightArrow.getWidth());
|
||||||
rightArrowY = 8 + (int)((monthTitleHeight / 2 - rightArrowHeight/2));
|
rightArrowY = 8 + (int)((monthTitleHeight / 2 - rightArrowHeight/2));
|
||||||
canvas.drawBitmap(rightArrow, new Rect(0,0,rightArrow.getWidth(),rightArrow.getHeight()),
|
canvas.drawBitmap(rightArrow, new Rect(0,0,rightArrow.getWidth(),rightArrow.getHeight()),
|
||||||
new Rect(rightArrowX, rightArrowY, rightArrowX + rightArrowWidth,
|
new Rect(rightArrowX, rightArrowY, rightArrowX + rightArrowWidth,
|
||||||
rightArrowY + rightArrowHeight), null);
|
rightArrowY + rightArrowHeight), null);
|
||||||
// Month right arrow -- End
|
// Month right arrow -- End
|
||||||
|
|
||||||
// Month text -- Start
|
// Month text -- Start
|
||||||
int monthX = getMeasuredWidth() / 2;
|
int monthX = getMeasuredWidth() / 2;
|
||||||
int monthY = (int) (monthTitleHeight / 2 + 15);
|
int monthY = (int) (monthTitleHeight / 2 + 15);
|
||||||
String monthYear = (String) DateFormat.format("MMMM yyyy", calendarDate); //$NON-NLS-1$
|
String monthYear = (String) DateFormat.format("MMMM yyyy", calendarDate); //$NON-NLS-1$
|
||||||
canvas.drawText(monthYear, monthX, monthY, whiteCenterAlignLargePaint);
|
canvas.drawText(monthYear, monthX, monthY, whiteCenterAlignLargePaint);
|
||||||
// Month text -- End
|
// Month text -- End
|
||||||
|
|
||||||
// Day heading -- Start
|
// Day heading -- Start
|
||||||
int dayLeft = 15;
|
int dayLeft = 15;
|
||||||
int dayTop = (int)(monthTitleHeight + PADDING * 2);
|
int dayTop = (int)(monthTitleHeight + PADDING * 2);
|
||||||
|
|
||||||
boxWidth = (getMeasuredWidth() - 38 - (PADDING*2)) / 7;
|
boxWidth = (getMeasuredWidth() - 38 - (PADDING*2)) / 7;
|
||||||
boxHeight = (int) (((getMeasuredHeight() - (monthTitleHeight) - 16) - (PADDING * 8)) / 7);
|
boxHeight = (int) (((getMeasuredHeight() - (monthTitleHeight) - 16) - (PADDING * 8)) / 7);
|
||||||
|
|
||||||
int textX = 0;
|
int textX = 0;
|
||||||
int textY = 0;
|
int textY = 0;
|
||||||
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
int firstDayOfWeek = calendar.getFirstDayOfWeek();
|
int firstDayOfWeek = calendar.getFirstDayOfWeek();
|
||||||
calendar.set(Calendar.DAY_OF_WEEK, firstDayOfWeek);
|
calendar.set(Calendar.DAY_OF_WEEK, firstDayOfWeek);
|
||||||
for(int i = 0; i < 7; i++) {
|
for(int i = 0; i < 7; i++) {
|
||||||
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
||||||
String day = DateUtils.getDayOfWeekString(dayOfWeek, DateUtils.LENGTH_SHORT);
|
String day = DateUtils.getDayOfWeekString(dayOfWeek, DateUtils.LENGTH_SHORT);
|
||||||
calendar.add(Calendar.DATE, 1);
|
calendar.add(Calendar.DATE, 1);
|
||||||
|
|
||||||
rectF.set(dayLeft, dayTop, dayLeft + boxWidth, dayTop + boxHeight);
|
rectF.set(dayLeft, dayTop, dayLeft + boxWidth, dayTop + boxHeight);
|
||||||
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, borderPaint);
|
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, borderPaint);
|
||||||
|
|
||||||
rectF.set(dayLeft+1, dayTop+1, dayLeft + boxWidth - 1, dayTop + boxHeight - 1);
|
rectF.set(dayLeft+1, dayTop+1, dayLeft + boxWidth - 1, dayTop + boxHeight - 1);
|
||||||
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, dayPaint);
|
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, dayPaint);
|
||||||
|
|
||||||
textX = dayLeft + boxWidth - PADDING * 2;
|
textX = dayLeft + boxWidth - PADDING * 2;
|
||||||
textY = dayTop + (boxHeight - boxHeight/8) - PADDING * 2;
|
textY = dayTop + (boxHeight - boxHeight/8) - PADDING * 2;
|
||||||
canvas.drawText(day, textX, textY, darkRightAlignPaint);
|
canvas.drawText(day, textX, textY, darkRightAlignPaint);
|
||||||
|
|
||||||
dayLeft += boxWidth + PADDING;
|
dayLeft += boxWidth + PADDING;
|
||||||
}
|
}
|
||||||
// Day heading -- End
|
// Day heading -- End
|
||||||
|
|
||||||
// Calendar -- Start
|
// Calendar -- Start
|
||||||
calendar.setTime(calendarDate);
|
calendar.setTime(calendarDate);
|
||||||
|
|
||||||
if (currentHighlightDay == -1) {
|
if (currentHighlightDay == -1) {
|
||||||
currentHighlightDay = calendar.get(Calendar.DATE);
|
currentHighlightDay = calendar.get(Calendar.DATE);
|
||||||
}
|
}
|
||||||
int today = -1;
|
int today = -1;
|
||||||
Calendar todayCalendar = Calendar.getInstance();
|
Calendar todayCalendar = Calendar.getInstance();
|
||||||
if(calendar.get(Calendar.MONTH) == todayCalendar.get(Calendar.MONTH) &&
|
if(calendar.get(Calendar.MONTH) == todayCalendar.get(Calendar.MONTH) &&
|
||||||
calendar.get(Calendar.YEAR) == todayCalendar.get(Calendar.YEAR))
|
calendar.get(Calendar.YEAR) == todayCalendar.get(Calendar.YEAR))
|
||||||
today = todayCalendar.get(Calendar.DATE);
|
today = todayCalendar.get(Calendar.DATE);
|
||||||
int lastDateOfThisMonth = calendar.getActualMaximum(Calendar.DATE);
|
int lastDateOfThisMonth = calendar.getActualMaximum(Calendar.DATE);
|
||||||
|
|
||||||
calendar.set(Calendar.DATE, 1);
|
calendar.set(Calendar.DATE, 1);
|
||||||
// offset for day of week
|
// offset for day of week
|
||||||
int firstDayOfMonth = calendar.get(Calendar.DAY_OF_WEEK) - firstDayOfWeek + Calendar.SUNDAY;
|
int firstDayOfMonth = calendar.get(Calendar.DAY_OF_WEEK) - firstDayOfWeek + Calendar.SUNDAY;
|
||||||
if(firstDayOfMonth == 0)
|
if(firstDayOfMonth == 0)
|
||||||
firstDayOfMonth = 7;
|
firstDayOfMonth = 7;
|
||||||
boolean firstTime = true;
|
boolean firstTime = true;
|
||||||
int dayOfMonth = 1;
|
int dayOfMonth = 1;
|
||||||
Paint colorPaint, textPaint;
|
Paint colorPaint, textPaint;
|
||||||
|
|
||||||
dayLeftArr = new int[lastDateOfThisMonth];
|
dayLeftArr = new int[lastDateOfThisMonth];
|
||||||
dayTopArr = new int[lastDateOfThisMonth];
|
dayTopArr = new int[lastDateOfThisMonth];
|
||||||
for (int i = 1; i <= 6; i++) {
|
for (int i = 1; i <= 6; i++) {
|
||||||
dayLeft = 15;
|
dayLeft = 15;
|
||||||
dayTop += boxHeight + PADDING;
|
dayTop += boxHeight + PADDING;
|
||||||
for (int j = 1; j <= 7; j++) {
|
for (int j = 1; j <= 7; j++) {
|
||||||
if (firstTime && j != firstDayOfMonth) {
|
if (firstTime && j != firstDayOfMonth) {
|
||||||
dayLeft += boxWidth + PADDING;
|
dayLeft += boxWidth + PADDING;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
|
|
||||||
if (dayOfMonth <= lastDateOfThisMonth) {
|
if (dayOfMonth <= lastDateOfThisMonth) {
|
||||||
if (currentHighlightDay == dayOfMonth) {
|
if (currentHighlightDay == dayOfMonth) {
|
||||||
colorPaint = darkRightAlignPaint;
|
colorPaint = darkRightAlignPaint;
|
||||||
textPaint = borderRightAlignPaint;
|
textPaint = borderRightAlignPaint;
|
||||||
} else if(today == dayOfMonth) {
|
} else if(today == dayOfMonth) {
|
||||||
colorPaint = todayCalendarPaint;
|
colorPaint = todayCalendarPaint;
|
||||||
textPaint = darkRightAlignPaint;
|
textPaint = darkRightAlignPaint;
|
||||||
} else {
|
} else {
|
||||||
colorPaint = calendarPaint;
|
colorPaint = calendarPaint;
|
||||||
textPaint = darkRightAlignPaint;
|
textPaint = darkRightAlignPaint;
|
||||||
}
|
}
|
||||||
dayLeftArr[dayOfMonth-1] = dayLeft;
|
dayLeftArr[dayOfMonth-1] = dayLeft;
|
||||||
dayTopArr[dayOfMonth-1] = dayTop;
|
dayTopArr[dayOfMonth-1] = dayTop;
|
||||||
rectF.set(dayLeft, dayTop, dayLeft + boxWidth, dayTop + boxHeight);
|
rectF.set(dayLeft, dayTop, dayLeft + boxWidth, dayTop + boxHeight);
|
||||||
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, borderPaint);
|
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, borderPaint);
|
||||||
|
|
||||||
rectF.set(dayLeft+1, dayTop+1, dayLeft + boxWidth - 1, dayTop + boxHeight - 1);
|
rectF.set(dayLeft+1, dayTop+1, dayLeft + boxWidth - 1, dayTop + boxHeight - 1);
|
||||||
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, colorPaint);
|
canvas.drawRoundRect(rectF, CURVE_RADIUS, CURVE_RADIUS, colorPaint);
|
||||||
|
|
||||||
textX = dayLeft + boxWidth - PADDING * 2;
|
textX = dayLeft + boxWidth - PADDING * 2;
|
||||||
textY = dayTop + (boxHeight - boxHeight/8) - PADDING * 2;
|
textY = dayTop + (boxHeight - boxHeight/8) - PADDING * 2;
|
||||||
canvas.drawText(String.valueOf(dayOfMonth), textX, textY, textPaint);
|
canvas.drawText(String.valueOf(dayOfMonth), textX, textY, textPaint);
|
||||||
|
|
||||||
dayLeft += boxWidth + PADDING;
|
dayLeft += boxWidth + PADDING;
|
||||||
|
|
||||||
dayOfMonth++;
|
dayOfMonth++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Calendar -- End
|
// Calendar -- End
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
int x = (int) event.getX();
|
int x = (int) event.getX();
|
||||||
int y = (int) event.getY();
|
int y = (int) event.getY();
|
||||||
performClick(x, y);
|
performClick(x, y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performClick(int x, int y) {
|
private void performClick(int x, int y) {
|
||||||
// System.out.println("---------------------Current x, y : " + x + ", " + y);
|
// System.out.println("---------------------Current x, y : " + x + ", " + y);
|
||||||
// Handle left-right arrow click -- start
|
// Handle left-right arrow click -- start
|
||||||
if ((x > leftArrowX && x < (leftArrowX + leftArrowWidth * 2))
|
if ((x > leftArrowX && x < (leftArrowX + leftArrowWidth * 2))
|
||||||
&& (y > 5 && y < (leftArrowY * 2))) {
|
&& (y > 5 && y < (leftArrowY * 2))) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(calendarDate);
|
calendar.setTime(calendarDate);
|
||||||
int currentDay = calendar.get(Calendar.DATE);
|
int currentDay = calendar.get(Calendar.DATE);
|
||||||
calendar.set(Calendar.DATE, 1);
|
calendar.set(Calendar.DATE, 1);
|
||||||
calendar.add(Calendar.MONTH, -1);
|
calendar.add(Calendar.MONTH, -1);
|
||||||
int lastDay = calendar.getActualMaximum(Calendar.DATE);
|
int lastDay = calendar.getActualMaximum(Calendar.DATE);
|
||||||
calendar.set(Calendar.DATE, Math.min(currentDay, lastDay));
|
calendar.set(Calendar.DATE, Math.min(currentDay, lastDay));
|
||||||
calendarDate = calendar.getTime();
|
calendarDate = calendar.getTime();
|
||||||
currentHighlightDay = calendar.get(Calendar.DATE);
|
currentHighlightDay = calendar.get(Calendar.DATE);
|
||||||
this.invalidate();
|
this.invalidate();
|
||||||
} else if ((x > rightArrowX - rightArrowWidth && x < (rightArrowX + rightArrowWidth))
|
} else if ((x > rightArrowX - rightArrowWidth && x < (rightArrowX + rightArrowWidth))
|
||||||
&& (y > 5 && y < (rightArrowY * 2))) {
|
&& (y > 5 && y < (rightArrowY * 2))) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(calendarDate);
|
calendar.setTime(calendarDate);
|
||||||
int currentDay = calendar.get(Calendar.DATE);
|
int currentDay = calendar.get(Calendar.DATE);
|
||||||
calendar.set(Calendar.DATE, 1);
|
calendar.set(Calendar.DATE, 1);
|
||||||
calendar.add(Calendar.MONTH, 1);
|
calendar.add(Calendar.MONTH, 1);
|
||||||
int lastDay = calendar.getActualMaximum(Calendar.DATE);
|
int lastDay = calendar.getActualMaximum(Calendar.DATE);
|
||||||
calendar.set(Calendar.DATE, Math.min(currentDay, lastDay));
|
calendar.set(Calendar.DATE, Math.min(currentDay, lastDay));
|
||||||
calendarDate = calendar.getTime();
|
calendarDate = calendar.getTime();
|
||||||
currentHighlightDay = calendar.get(Calendar.DATE);
|
currentHighlightDay = calendar.get(Calendar.DATE);
|
||||||
this.invalidate();
|
this.invalidate();
|
||||||
// Handle left-right arrow click -- end
|
// Handle left-right arrow click -- end
|
||||||
} else {
|
} else {
|
||||||
// Check if clicked on date
|
// Check if clicked on date
|
||||||
for (int i=0; i<dayLeftArr.length; i++) {
|
for (int i=0; i<dayLeftArr.length; i++) {
|
||||||
if ((x > dayLeftArr[i] && x < dayLeftArr[i]+boxWidth) && (y > dayTopArr[i] && y < dayTopArr[i] + boxHeight)) {
|
if ((x > dayLeftArr[i] && x < dayLeftArr[i]+boxWidth) && (y > dayTopArr[i] && y < dayTopArr[i] + boxHeight)) {
|
||||||
currentHighlightDay = i+1;
|
currentHighlightDay = i+1;
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(calendarDate);
|
calendar.setTime(calendarDate);
|
||||||
calendar.set(Calendar.DATE, currentHighlightDay);
|
calendar.set(Calendar.DATE, currentHighlightDay);
|
||||||
|
|
||||||
calendarDate = calendar.getTime();
|
calendarDate = calendar.getTime();
|
||||||
this.invalidate();
|
this.invalidate();
|
||||||
|
|
||||||
if(onSelectedDateListener != null)
|
if(onSelectedDateListener != null)
|
||||||
onSelectedDateListener.onSelectedDate(calendarDate);
|
onSelectedDateListener.onSelectedDate(calendarDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getCalendarDate() {
|
public Date getCalendarDate() {
|
||||||
return calendarDate;
|
return calendarDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCalendarDate(Date calendarDate) {
|
public void setCalendarDate(Date calendarDate) {
|
||||||
this.calendarDate = calendarDate;
|
this.calendarDate = calendarDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue