Android之日历触屏测试
结构:
DiaryTest.apk下载
BaseCalendar:
package com.cdp.Activity; import java.util.Calendar;
import java.util.Date; import com.dcs.test.R;
import com.test.Tools.NumberHelper; import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;
import android.widget.LinearLayout.LayoutParams; public class BaseCalendar extends Activity implements OnTouchListener { //判断手势用
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200; //动画
private Animation slideLeftIn;
private Animation slideLeftOut;
private Animation slideRightIn;
private Animation slideRightOut;
private ViewFlipper viewFlipper;
GestureDetector mGesture = null; @Override
public boolean onTouch(View v, MotionEvent event) {
return mGesture.onTouchEvent(event);
} AnimationListener animationListener=new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
} @Override
public void onAnimationRepeat(Animation animation) {
} @Override
public void onAnimationEnd(Animation animation) {
//当动画完成后调用
CreateGirdView();
}
}; class GestureListener extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideLeftIn);
viewFlipper.setOutAnimation(slideLeftOut);
viewFlipper.showNext();
setNextViewItem();
//CreateGirdView();
return true; } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideRightIn);
viewFlipper.setOutAnimation(slideRightOut);
viewFlipper.showPrevious();
setPrevViewItem();
//CreateGirdView();
return true; }
} catch (Exception e) {
// nothing
}
return false;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// ListView lv = getListView();
//得到当前选中的是第几个单元格
int pos = gView2.pointToPosition((int) e.getX(), (int) e.getY());
LinearLayout txtDay = (LinearLayout) gView2.findViewById(pos + 5000);
if (txtDay != null) {
if (txtDay.getTag() != null) {
Date date = (Date) txtDay.getTag();
calSelected.setTime(date); gAdapter.setSelectedDate(calSelected);
gAdapter.notifyDataSetChanged(); gAdapter1.setSelectedDate(calSelected);
gAdapter1.notifyDataSetChanged(); gAdapter3.setSelectedDate(calSelected);
gAdapter3.notifyDataSetChanged();
}
} Log.i("TEST", "onSingleTapUp - pos=" + pos); return false;
}
} // / }}} // 基本变量
private Context mContext = BaseCalendar.this;
private GridView title_gView;
private GridView gView1;// 上一个月
private GridView gView2;// 当前月
private GridView gView3;// 下一个月
// private GridView gView1;
boolean bIsSelection = false;// 是否是选择事件发生
private Calendar calStartDate = Calendar.getInstance();// 当前显示的日历
private Calendar calSelected = Calendar.getInstance(); // 选择的日历
private Calendar calToday = Calendar.getInstance(); // 今日
private CalendarGridViewAdapter gAdapter;
private CalendarGridViewAdapter gAdapter1;
private CalendarGridViewAdapter gAdapter3;
// 顶部按钮
private Button btnToday = null;
private RelativeLayout mainLayout;
private int iMonthViewCurrentMonth = 0; // 当前视图月
private int iMonthViewCurrentYear = 0; // 当前视图年
private int iFirstDayOfWeek = Calendar.MONDAY; private static final int mainLayoutID = 88; // 设置主布局ID
private static final int titleLayoutID = 77; // title布局ID
private static final int caltitleLayoutID = 66; // title布局ID
private static final int calLayoutID = 55; // 日历布局ID
/** 底部菜单文字 **/
String[] menu_toolbar_name_array; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(generateContentView());
UpdateStartDateForMonth(); slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
slideRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
slideRightOut = AnimationUtils.loadAnimation(this,R.anim.slide_right_out); slideLeftIn.setAnimationListener(animationListener);
slideLeftOut.setAnimationListener(animationListener);
slideRightIn.setAnimationListener(animationListener);
slideRightOut.setAnimationListener(animationListener); mGesture = new GestureDetector(this, new GestureListener());
} AlertDialog.OnKeyListener onKeyListener = new AlertDialog.OnKeyListener() { @Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
BaseCalendar.this.finish();
}
return false; } }; // 生成内容视图
private View generateContentView() {
// 创建一个垂直的线性布局(整体内容)
viewFlipper = new ViewFlipper(this);
viewFlipper.setId(calLayoutID); mainLayout = new RelativeLayout(this); // 创建一个垂直的线性布局(整体内容)
RelativeLayout.LayoutParams params_main = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
mainLayout.setLayoutParams(params_main);
mainLayout.setId(mainLayoutID);
mainLayout.setGravity(Gravity.CENTER_HORIZONTAL); LinearLayout layTopControls = createLayout(LinearLayout.HORIZONTAL); // 生成顶部按钮布局 generateTopButtons(layTopControls); // 生成顶部按钮 (上一月,下一月,当前月)
RelativeLayout.LayoutParams params_title = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params_title.topMargin = 5;
// params_title.addRule(RelativeLayout.ALIGN_PARENT_TOP, 20);
layTopControls.setId(titleLayoutID);
mainLayout.addView(layTopControls, params_title); calStartDate = getCalendarStartDate(); setTitleGirdView();
RelativeLayout.LayoutParams params_cal_title = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params_cal_title.addRule(RelativeLayout.BELOW, titleLayoutID);
// params_cal_title.topMargin = 5;
mainLayout.addView(title_gView, params_cal_title); CreateGirdView(); RelativeLayout.LayoutParams params_cal = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params_cal.addRule(RelativeLayout.BELOW, caltitleLayoutID); mainLayout.addView(viewFlipper, params_cal); LinearLayout br = new LinearLayout(this);
RelativeLayout.LayoutParams params_br = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, 1);
params_br.addRule(RelativeLayout.BELOW, calLayoutID);
br.setBackgroundColor(getResources().getColor(R.color.calendar_background));
mainLayout.addView(br, params_br); return mainLayout; } // 创建一个线性布局
// 参数:方向
private LinearLayout createLayout(int iOrientation) {
LinearLayout lay = new LinearLayout(this);
LayoutParams params = new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,// *fill_parent,填满父控件的空白
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = 10;
// 设置布局参数
lay.setLayoutParams(params);// *wrap_content,表示大小刚好足够显示当前控件里的内容
lay.setOrientation(iOrientation);// 设置方向
lay.setGravity(Gravity.LEFT);
return lay;
} // 生成顶部按钮
// 参数:布局
private void generateTopButtons(LinearLayout layTopControls) {
// 创建一个当前月按钮(中间的按钮)
btnToday = new Button(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
lp.leftMargin = 20;
btnToday.setLayoutParams(lp);
btnToday.setTextSize(25);
btnToday.setBackgroundResource(Color.TRANSPARENT);//
// btn_cal.setBackgroundResource(R.drawable.editbox_background_normal);//
// 设置当前月按钮的背景颜色为按钮默认颜色 // 当前月的点击事件的监听
btnToday.setOnClickListener(new Button.OnClickListener() {
public void onClick(View arg0) {
setToDayViewItem();
}
}); layTopControls.setGravity(Gravity.CENTER_HORIZONTAL);
layTopControls.addView(btnToday); } private void setTitleGirdView() { title_gView = setGirdView();
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
// params.topMargin = 5;
title_gView.setLayoutParams(params);
title_gView.setVerticalSpacing(0);// 垂直间隔
title_gView.setHorizontalSpacing(0);// 水平间隔
TitleGridAdapter titleAdapter = new TitleGridAdapter(this);
title_gView.setAdapter(titleAdapter);// 设置菜单Adapter
title_gView.setId(caltitleLayoutID);
} private void CreateGirdView() { Calendar tempSelected1 = Calendar.getInstance(); // 临时
Calendar tempSelected2 = Calendar.getInstance(); // 临时
Calendar tempSelected3 = Calendar.getInstance(); // 临时
tempSelected1.setTime(calStartDate.getTime());
tempSelected2.setTime(calStartDate.getTime());
tempSelected3.setTime(calStartDate.getTime()); gView1 = new CalendarGridView(mContext);
tempSelected1.add(Calendar.MONTH, -1);
gAdapter1 = new CalendarGridViewAdapter(this, tempSelected1);
gView1.setAdapter(gAdapter1);// 设置菜单Adapter
gView1.setId(calLayoutID); gView2 = new CalendarGridView(mContext);
gAdapter = new CalendarGridViewAdapter(this, tempSelected2);
gView2.setAdapter(gAdapter);// 设置菜单Adapter
gView2.setId(calLayoutID); gView3 = new CalendarGridView(mContext);
tempSelected3.add(Calendar.MONTH, 1);
gAdapter3 = new CalendarGridViewAdapter(this, tempSelected3);
gView3.setAdapter(gAdapter3);// 设置菜单Adapter
gView3.setId(calLayoutID); gView2.setOnTouchListener(this);
gView1.setOnTouchListener(this);
gView3.setOnTouchListener(this); if (viewFlipper.getChildCount() != 0) {
viewFlipper.removeAllViews();
} viewFlipper.addView(gView2);
viewFlipper.addView(gView3);
viewFlipper.addView(gView1); String s = calStartDate.get(Calendar.YEAR)
+ "-"
+ NumberHelper.LeftPad_Tow_Zero(calStartDate
.get(Calendar.MONTH) + 1); btnToday.setText(s);
} private GridView setGirdView() {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
GridView gridView = new GridView(this);
gridView.setLayoutParams(params);
gridView.setNumColumns(7);// 设置每行列数
gridView.setGravity(Gravity.CENTER_VERTICAL);// 位置居中
gridView.setVerticalSpacing(1);// 垂直间隔
gridView.setHorizontalSpacing(1);// 水平间隔
gridView.setBackgroundColor(getResources().getColor(
R.color.calendar_background)); WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
int i = display.getWidth() / 7;
int j = display.getWidth() - (i * 7);
int x = j / 2;
gridView.setPadding(x, 0, 0, 0);// 居中 return gridView;
} // 上一个月
private void setPrevViewItem() {
iMonthViewCurrentMonth--;// 当前选择月--
// 如果当前月为负数的话显示上一年
if (iMonthViewCurrentMonth == -1) {
iMonthViewCurrentMonth = 11;
iMonthViewCurrentYear--;
}
calStartDate.set(Calendar.DAY_OF_MONTH, 1); // 设置日为当月1日
calStartDate.set(Calendar.MONTH, iMonthViewCurrentMonth); // 设置月
calStartDate.set(Calendar.YEAR, iMonthViewCurrentYear); // 设置年 } // 当月
private void setToDayViewItem() { calSelected.setTimeInMillis(calToday.getTimeInMillis());
calSelected.setFirstDayOfWeek(iFirstDayOfWeek);
calStartDate.setTimeInMillis(calToday.getTimeInMillis());
calStartDate.setFirstDayOfWeek(iFirstDayOfWeek); } // 下一个月
private void setNextViewItem() {
iMonthViewCurrentMonth++;
if (iMonthViewCurrentMonth == 12) {
iMonthViewCurrentMonth = 0;
iMonthViewCurrentYear++;
}
calStartDate.set(Calendar.DAY_OF_MONTH, 1);
calStartDate.set(Calendar.MONTH, iMonthViewCurrentMonth);
calStartDate.set(Calendar.YEAR, iMonthViewCurrentYear); } // 根据改变的日期更新日历
// 填充日历控件用
private void UpdateStartDateForMonth() {
calStartDate.set(Calendar.DATE, 1); // 设置成当月第一天
iMonthViewCurrentMonth = calStartDate.get(Calendar.MONTH);// 得到当前日历显示的月
iMonthViewCurrentYear = calStartDate.get(Calendar.YEAR);// 得到当前日历显示的年 String s = calStartDate.get(Calendar.YEAR)
+ "-"
+ NumberHelper.LeftPad_Tow_Zero(calStartDate
.get(Calendar.MONTH) + 1);
btnToday.setText(s); // 星期一是2 星期天是1 填充剩余天数
int iDay = 0;
int iFirstDayOfWeek = Calendar.MONDAY;
int iStartDay = iFirstDayOfWeek;
if (iStartDay == Calendar.MONDAY) {
iDay = calStartDate.get(Calendar.DAY_OF_WEEK) - Calendar.MONDAY;
if (iDay < 0)
iDay = 6;
}
if (iStartDay == Calendar.SUNDAY) {
iDay = calStartDate.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY;
if (iDay < 0)
iDay = 6;
}
calStartDate.add(Calendar.DAY_OF_WEEK, -iDay); } private Calendar getCalendarStartDate() {
calToday.setTimeInMillis(System.currentTimeMillis());
calToday.setFirstDayOfWeek(iFirstDayOfWeek); if (calSelected.getTimeInMillis() == 0) {
calStartDate.setTimeInMillis(System.currentTimeMillis());
calStartDate.setFirstDayOfWeek(iFirstDayOfWeek);
} else {
calStartDate.setTimeInMillis(calSelected.getTimeInMillis());
calStartDate.setFirstDayOfWeek(iFirstDayOfWeek);
} return calStartDate;
} public class TitleGridAdapter extends BaseAdapter { int[] titles = new int[] { R.string.Sun, R.string.Mon, R.string.Tue,
R.string.Wed, R.string.Thu, R.string.Fri, R.string.Sat }; private Activity activity; // construct
public TitleGridAdapter(Activity a) {
activity = a;
} @Override
public int getCount() {
return titles.length;
} @Override
public Object getItem(int position) {
return titles[position];
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout iv = new LinearLayout(activity);
TextView txtDay = new TextView(activity);
txtDay.setFocusable(false);
txtDay.setBackgroundColor(Color.TRANSPARENT);
iv.setOrientation(1); txtDay.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); int i = (Integer) getItem(position); txtDay.setTextColor(Color.WHITE);
Resources res = getResources(); if (i == R.string.Sat) {
// 周六
txtDay.setBackgroundColor(res.getColor(R.color.title_text_6));
} else if (i == R.string.Sun) {
// 周日
txtDay.setBackgroundColor(res.getColor(R.color.title_text_7));
} else { } txtDay.setText((Integer) getItem(position)); iv.addView(txtDay, lp); return iv;
}
} }
CalendarGridView:
package com.cdp.Activity; import com.dcs.test.R; import android.app.Activity;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.GridView;
import android.widget.LinearLayout; public class CalendarGridView extends GridView{ private Context mContext; public CalendarGridView(Context context) {
super(context);
mContext = context; setGirdView();
} private void setGirdView() {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); setLayoutParams(params);
setNumColumns(7);// 设置每行列数
setGravity(Gravity.CENTER_VERTICAL);// 位置居中
setVerticalSpacing(1);// 垂直间隔
setHorizontalSpacing(1);// 水平间隔
setBackgroundColor(getResources().getColor(R.color.calendar_background)); WindowManager windowManager = ((Activity)mContext).getWindowManager();
Display display = windowManager.getDefaultDisplay();
int i = display.getWidth() / 7;
int j = display.getWidth() - (i * 7);
int x = j / 2;
setPadding(x, 0, 0, 0);// 居中
}
}
CalendarGridViewAdapter: package com.cdp.Activity; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import com.dcs.test.R;
import android.app.Activity;
import android.content.res.Resources;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams; public class CalendarGridViewAdapter extends BaseAdapter { private Calendar calStartDate = Calendar.getInstance();// 当前显示的日历
private Calendar calSelected = Calendar.getInstance(); // 选择的日历 public void setSelectedDate(Calendar cal)
{
calSelected=cal;
} private Calendar calToday = Calendar.getInstance(); // 今日
private int iMonthViewCurrentMonth = 0; // 当前视图月
// 根据改变的日期更新日历
// 填充日历控件用
private void UpdateStartDateForMonth() {
calStartDate.set(Calendar.DATE, 1); // 设置成当月第一天
iMonthViewCurrentMonth = calStartDate.get(Calendar.MONTH);// 得到当前日历显示的月 // 星期一是2 星期天是1 填充剩余天数
int iDay = 0;
int iFirstDayOfWeek = Calendar.MONDAY;
int iStartDay = iFirstDayOfWeek;
if (iStartDay == Calendar.MONDAY) {
iDay = calStartDate.get(Calendar.DAY_OF_WEEK) - Calendar.MONDAY;
if (iDay < 0)
iDay = 6;
}
if (iStartDay == Calendar.SUNDAY) {
iDay = calStartDate.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY;
if (iDay < 0)
iDay = 6;
}
calStartDate.add(Calendar.DAY_OF_WEEK, -iDay); calStartDate.add(Calendar.DAY_OF_MONTH, -1);// 周日第一位 }
ArrayList<java.util.Date> titles;
private ArrayList<java.util.Date> getDates() { UpdateStartDateForMonth(); ArrayList<java.util.Date> alArrayList = new ArrayList<java.util.Date>(); for (int i = 1; i <= 42; i++) {
alArrayList.add(calStartDate.getTime());
calStartDate.add(Calendar.DAY_OF_MONTH, 1);
} return alArrayList;
} private Activity activity;
Resources resources;
// construct
public CalendarGridViewAdapter(Activity a,Calendar cal) {
calStartDate=cal;
activity = a;
resources=activity.getResources();
titles = getDates();
} public CalendarGridViewAdapter(Activity a) {
activity = a;
resources=activity.getResources();
} @Override
public int getCount() {
return titles.size();
} @Override
public Object getItem(int position) {
return titles.get(position);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout iv = new LinearLayout(activity);
iv.setId(position + 5000);
LinearLayout imageLayout = new LinearLayout(activity);
imageLayout.setOrientation(0);
iv.setGravity(Gravity.CENTER);
iv.setOrientation(1);
iv.setBackgroundColor(resources.getColor(R.color.white)); Date myDate = (Date) getItem(position);
Calendar calCalendar = Calendar.getInstance();
calCalendar.setTime(myDate); final int iMonth = calCalendar.get(Calendar.MONTH);
final int iDay = calCalendar.get(Calendar.DAY_OF_WEEK); // 判断周六周日
iv.setBackgroundColor(resources.getColor(R.color.white));
if (iDay == 7) {
// 周六
iv.setBackgroundColor(resources.getColor(R.color.text_6));
} else if (iDay == 1) {
// 周日
iv.setBackgroundColor(resources.getColor(R.color.text_7));
} else { }
// 判断周六周日结束 TextView txtToDay = new TextView(activity);// 日本老黄历
txtToDay.setGravity(Gravity.CENTER_HORIZONTAL);
txtToDay.setTextSize(9);
if (equalsDate(calToday.getTime(), myDate)) {
// 当前日期
iv.setBackgroundColor(resources.getColor(R.color.event_center));
txtToDay.setText("TODAY!");
} // 设置背景颜色
if (equalsDate(calSelected.getTime(), myDate)) {
// 选择的
iv.setBackgroundColor(resources.getColor(R.color.selection));
} else {
if (equalsDate(calToday.getTime(), myDate)) {
// 当前日期
iv.setBackgroundColor(resources.getColor(R.color.calendar_zhe_day));
}
}
// 设置背景颜色结束 // 日期开始
TextView txtDay = new TextView(activity);// 日期
txtDay.setGravity(Gravity.CENTER_HORIZONTAL); // 判断是否是当前月
if (iMonth == iMonthViewCurrentMonth) {
txtToDay.setTextColor(resources.getColor(R.color.ToDayText));
txtDay.setTextColor(resources.getColor(R.color.Text));
} else {
txtDay.setTextColor(resources.getColor(R.color.noMonth));
txtToDay.setTextColor(resources.getColor(R.color.noMonth));
} int day = myDate.getDate(); // 日期
txtDay.setText(String.valueOf(day));
txtDay.setId(position + 500);
iv.setTag(myDate); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
iv.addView(txtDay, lp); LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
iv.addView(txtToDay, lp1);
// 日期结束
// iv.setOnClickListener(view_listener); return iv;
} @Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
} private Boolean equalsDate(Date date1, Date date2) { if (date1.getYear() == date2.getYear()
&& date1.getMonth() == date2.getMonth()
&& date1.getDate() == date2.getDate()) {
return true;
} else {
return false;
} } }
NumberHelper:
package com.test.Tools; public class NumberHelper { public static String LeftPad_Tow_Zero(int str) {
java.text.DecimalFormat format = new java.text.DecimalFormat("00");
return format.format(str); } }
最后记得添加权限:
<!--往sdcard中写入数据的权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<!--在sdcard中创建/删除文件的权限 -->
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>
<!-- 访问互联网 -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- 包管理 -->
<uses-permission android:name="android.permission.RESTART_PACKAGES"></uses-permission>
run:
Android之日历触屏测试的更多相关文章
- 〖Android〗屏幕触屏事件录制与回放
需求: 不管是做自动化测试的,还是传媒技术的,自动化操作Android App是一种操作需求: 自动化的操作可以节省很多的人力资源投入: 实现: Android UI界面的自动化,通常有两个方法: 1 ...
- 转:Android随笔之——使用Root权限实现后台模拟全局按键、触屏事件方法(类似按键精灵)
本文转载自CSDN的jzj1993,原文连接:http://blog.csdn.net/jzj1993/article/details/39158865 有时我们需要使用安卓实现在后台模拟系统按键,比 ...
- android滑动基础篇 - 触屏显示信息
效果图: 代码部分: activity类代码: package com.TouchView; /* * android滑动基础篇 * */ import android.app.Activity; i ...
- 【转载】jQuery手机移动端触屏日历日期选择
文章转载自 科e互联 http://www.internetke.com/ 原文链接:http://www.internetke.com/effects/css3/2015/0120/1222.htm ...
- Android: 触屏fling/scroll/drag的区别及其详细过程
Google了一下,终于搞清了touch screen下的几种操作模式(对应的是事件). 对于一个view, 常用的操作有点击(click)和长按(long press)二种.实际上,这些操作类型是A ...
- Android之触屏事件
方法一: 新建"MyView"类 package onTouchEvent; import android.content.Context; import android.grap ...
- Android:触屏事件
Android触屏事件包含两种: 1)屏幕触屏事件:重写onTouchEvent(MotionEvent event): 2)控件触屏事件:给控件注册触屏事件,setOnTouchEventListe ...
- 触屏手机3G网站设计
随着智能手机iphone和Android的热潮,衍生出基于Safari和Chrome浏览器的触屏手机网站Touch Screen Mobile Website. 触屏手机网站在中国还属于起步阶段,从行 ...
- 在触屏设备中拖动 overflow 元素
在 Android 和 iOS 等触屏设备中,如果网页中某元素设置 overflow: auto 或者 overflow:scroll,那么问题就来了.在 Android 3.0 之前以及 iPhon ...
随机推荐
- 如何将std::string转int,double? (C/C++) (C) (template)
http://www.cnblogs.com/oomusou/archive/2008/08/01/525647.html http://blog.sina.com.cn/s/blog_a843a88 ...
- Spring和Hibernate集成的HibernateTemplate的一些常用方法总结
1:get/load存取单条数据 public Teacher getTeacherById(Long id) { return (Teacher)this.hibernateTemplate.get ...
- C#中反射的使用(How to use reflect in CSharp)(3)Emit的使用
Emit意在动态构建一个可以执行(当然也就可以反射)或者只可以反射的动态库. 个人认为在不得不使用反射的情况下,使用Emit会使得效率提升空间很大.亦或者动态插件模式的软件设计中会用到. 依然2%的废 ...
- 更新插件时提示“正在更新缓存”“正在等待jockey-backend退出”
Ubuntu 11 更新语言插件, 更新时 提示正在更新缓存”“正在等待jockey-backend退出”,然后就不动了. 解决方案: 在终端中键入ps -e | grep jockey 系统会显示一 ...
- MRuby 编译笔记
专注于嵌入式脚本的MRuby在Windows下的编译笔记: 环境: OS: Windows 8.1, 使用 VS Express 2013 for Desktop. 材料: MRuby : 下载源码就 ...
- poj 3613 Cow Relays
Cow Relays Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5411 Accepted: 2153 Descri ...
- [AngularJS] Html ngSanitize, $sce
Safely render arbitrary HTML snippets by using ngSanitize and $sce. By default angularJS consider us ...
- iOS小结
一.内存管理情况 1- autorelease,当用户的代码在持续运行时,自动释放池是不会被销毁的,这段时间内用户可以安全地使用自动释放的对象.当用户的代码运行告一段 落,开始等待用户的操作,自动释放 ...
- Key Task
Problem Description The Czech Technical University is rather old - you already know that it celebrat ...
- 网络IPC:套接字
网络进程间通信(network IPC):不同计算机(通过网络相连)上运行的进程相互通信的机制. 套接字网络IPC接口:进程能够使用该接口和其他进程通信.通过该接口,其他进程运行位置是透明的,它们可以 ...