adapter包
BaseAdapter
package com.example.qiangqiang.adapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
public abstract class BaseAdapter<T> extends android.widget.BaseAdapter {
protected Context mContext;
public ArrayList<T> mBeanList;
public BaseAdapter(Context c) {
mContext = c;
}
public BaseAdapter(Context c, ArrayList<T> beanList) {
mContext = c;
mBeanList = beanList;
}
public void setData(ArrayList<T> beanList) {
if (mBeanList == null)
mBeanList = new ArrayList<T>();
else
mBeanList.clear();
if (beanList == null) {
mBeanList.clear();
notifyDataSetChanged();
return;
}
mBeanList.addAll(beanList);
notifyDataSetChanged();
}
public void removeData(int position) {
mBeanList.remove(position);
notifyDataSetChanged();
}
public void removeData(T data) {
mBeanList.remove(data);
notifyDataSetChanged();
}
public void addListData(ArrayList<T> beanList) {
if (mBeanList == null) {
mBeanList = new ArrayList<T>();
}
if (beanList == null) {
return;
}
mBeanList.addAll(beanList);
notifyDataSetChanged();
}
public void addData(T bean) {
if (mBeanList == null)
mBeanList = new ArrayList<T>();
if (bean == null)
return;
mBeanList.add(bean);
notifyDataSetChanged();
}
public void addData(int index,T bean) {
if (mBeanList == null)
mBeanList = new ArrayList<T>();
if (bean == null)
return;
mBeanList.add(index,bean);
notifyDataSetChanged();
}
public ArrayList<T> getData() {
if (mBeanList == null)
mBeanList = new ArrayList<T>();
return mBeanList;
}
@Override
public int getCount() {
return mBeanList.size();
}
public ArrayList<T> getBeanList() {
if (mBeanList == null)
mBeanList = new ArrayList<>();
return mBeanList;
}
@Override
public T getItem(int position) {
return mBeanList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public abstract View getView(int position, View convertView, ViewGroup parent);
}
————————————————————————————————————————————————————————
DateAdapter
package com.example.qiangqiang.adapter;
import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.qiangqiang.R;
import com.example.qiangqiang.bean.DateEntity;
import java.util.ArrayList;
/**
* author:Administrator on 2017/4/10 16:11
* description:文件说明
* version:版本
*/
public class DateAdapter extends BaseAdapter {
private Context mContext ;
private ArrayList<DateEntity> datas ;
private String[] weekTitle = {"日","一", "二", "三", "四", "五", "六"};
public DateAdapter(Context mContext, ArrayList<DateEntity> datas) {
this.mContext = mContext;
this.datas = datas;
}
@Override
public int getCount() {
return datas.size();
}
@Override
public DateEntity getItem(int position) {
return datas.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private int selectedPosition = -1;// 选中的位置
public void setSelectedPosition(int position) {
selectedPosition = position;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
DateEntity info = datas.get(position);
if (convertView == null) {
holder = new ViewHolder();
convertView = View.inflate(mContext, R.layout.item_data, null);
holder.image = (ImageView) convertView.findViewById(R.id.image);
holder.week_num = (TextView) convertView.findViewById(R.id.week_num);
holder.item_data = (TextView) convertView.findViewById(R.id.item_data);
holder.layout_week = convertView.findViewById(R.id.layout_week);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.week_num.setText(weekTitle[position]);
holder.item_data.setText(info.day);
if (selectedPosition == position) {
holder.week_num.setTextColor(ContextCompat.getColor(mContext,R.color.color_b0b8b2));
holder.item_data.setTextColor(ContextCompat.getColor(mContext,R.color.color_b0b8b2));
if (info.isToday){
holder.layout_week.setBackgroundResource(R.drawable.select_green_bg);
}else {
holder.layout_week.setBackgroundResource(R.drawable.select_bg);
}
} else {
if (info.isToday){
holder.week_num.setTextColor(ContextCompat.getColor(mContext,R.color.color_b0b8b2));
holder.layout_week.setBackgroundResource(R.drawable.select_green_bg);
holder.item_data.setTextColor(ContextCompat.getColor(mContext,R.color.color_b0b8b2));
}else {
holder.week_num.setTextColor(ContextCompat.getColor(mContext,R.color.color_999999));
holder.item_data.setTextColor(ContextCompat.getColor(mContext,R.color.color_333333));
holder.layout_week.setBackgroundColor(ContextCompat.getColor(mContext,R.color.color_ffffff));
}
}
return convertView;
}
public class ViewHolder {
TextView week_num;
TextView item_data;
ImageView image;
View layout_week;
}
}
————————————————————————————————————————————————————————
DateMonthAdapter
package com.sf.qldb.kuguan.adapter; import android.content.Context; import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.sf.qldb.R; import com.sf.qldb.kuguan.bean.DateEntity; import java.util.ArrayList; public class DateMonthAdapter extends BaseAdapter<DateEntity> { private String dateString; public DateMonthAdapter(Context c) { super(c); } public void setDateString(String dateString) { this.dateString = dateString; } @Override public void setData(ArrayList<DateEntity> beanList) { super.setData(beanList); } private int selectedPosition = -1;// 选中的位置 public void setSelectedPosition(int position) { selectedPosition = position; notifyDataSetChanged(); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; DateEntity info = getData().get(position); if (convertView == null) { holder = new ViewHolder(); convertView = View.inflate(mContext, R.layout.item_month_data, null); holder.data = (TextView) convertView.findViewById(R.id.data); holder.luna = (TextView) convertView.findViewById(R.id.luna); holder.bg = convertView.findViewById(R.id.bg); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } if (TextUtils.isEmpty(info.date)) { holder.data.setText(""); holder.luna.setText(""); holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); } else { holder.luna.setText(info.luna); holder.data.setText(info.day); if (dateString.equals(info.date)) { if (info.isToday) { holder.bg.setBackgroundResource(R.drawable.select_bg); //holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_56aaae)); holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_28d19d)); holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_28d19d)); } else { holder.bg.setBackgroundResource(R.drawable.select_bg); holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); } } else { if (info.isToday) { holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_28d19d)); holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_28d19d)); } else { holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_666666)); holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_999999)); } } } if (selectedPosition == position) { if (!TextUtils.isEmpty(info.date)) { if (info.isToday) { holder.bg.setBackgroundResource(R.drawable.select_bg); //holder.bg.setBackgroundResource(R.drawable.select_green_bg); holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_333333)); holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); } else { holder.bg.setBackgroundResource(R.drawable.select_bg); holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_333333)); holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); } } } else { if (info.isToday) { holder.bg.setBackgroundResource(R.drawable.select_green_bg); holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_333333)); holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_b0b8b2)); } else { holder.bg.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ffffff)); holder.data.setTextColor(ContextCompat.getColor(mContext, R.color.color_666666)); holder.luna.setTextColor(ContextCompat.getColor(mContext, R.color.color_999999)); } } return convertView; } public class ViewHolder { TextView data; TextView luna ; View bg ; } }
————————————————————————————————————————————————————————
————————————————————————————————————————————————————————
bean包
DateEntity
package com.example.qiangqiang.bean;
public class DateEntity {
public long million ; //时间戳
public String weekName ; //周几
public int weekNum ; //一周中第几天,非中式
public String date ; //日期
public boolean isToday ; //是否今天
public String day ; //天
public String luna ; //阴历
@Override
public String toString() {
return "DateEntity{" +
"million=" + million +
", weekName='" + weekName + '\'' +
", weekNum=" + weekNum +
", date='" + date + '\'' +
", isToday=" + isToday +
", day='" + day + '\'' +
", luna='" + luna + '\'' +
'}';
}
}
________________________________________________________________________________________________________________________________________________________________________________________________________
utils包
DataUtils
package com.example.qiangqiang.utils;
import com.example.qiangqiang.bean.DateEntity;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
public class DataUtils {
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
public static int selectPosition =-1;
public static int getSelectPosition() {
return selectPosition;
}
/**
*
* 获取当前日期一周的日期
* @param date
* @return
*/
public static ArrayList<DateEntity> getWeek(String date){
ArrayList<DateEntity> result = new ArrayList<>();
Calendar cal =Calendar.getInstance();
try {
cal.setTime(dateFormat.parse(date));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); //获取本周一的日期
for (int i = 0; i < 7; i++) {
DateEntity entity = new DateEntity();
entity.date = getValue(cal.get(cal.YEAR))+"-"+getValue(cal.get(cal.MONTH)+1)+"-"+getValue(cal.get(cal.DATE));
entity.million = cal.getTimeInMillis() ;
entity.day = getValue(cal.get(cal.DATE));
entity.weekNum = cal.get(Calendar.DAY_OF_WEEK);
entity.weekName = getWeekName(entity.weekNum);
entity.isToday = isToday(entity.date);
cal.add(Calendar.DATE, 1);
result.add(entity);
}
return result ;
}
/**
* 获取当前日期一月的日期
* @param date
* @return
*/
public static ArrayList<DateEntity> getMonth(String date){
ArrayList<DateEntity> result = new ArrayList<>();
Calendar cal =Calendar.getInstance();
try {
cal.setTime( new SimpleDateFormat("yyyy-MM").parse(date));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int max = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 1; i <=max; i++) {
DateEntity entity = new DateEntity();
entity.date = getValue(cal.get(cal.YEAR))+"-"+getValue(cal.get(cal.MONTH)+1)+"-"+getValue(cal.get(cal.DATE));
entity.million = cal.getTimeInMillis() ;
entity.weekNum = cal.get(Calendar.DAY_OF_WEEK);
entity.day = getValue(cal.get(cal.DATE));
entity.weekName = getWeekName(entity.weekNum);
entity.isToday = isToday(entity.date);
entity.luna = getLuna(entity.date);
cal.add(Calendar.DATE, 1);
result.add(entity);
}
//为了用空的值填补第一个之前的日期
//先获取在本周内是周几
int weekNum = result.get(0).weekNum -1 ;
for (int j = 0 ;j<weekNum;j++){
DateEntity entity = new DateEntity();
result.add(0,entity);
}
for (int i = 0; i <result.size(); i++) {
if (date.equals(result.get(i).date)){
selectPosition = i ;
}
}
return result ;
}
/**
* 根据美式周末到周一 返回
* @param weekNum
* @return
*/
private static String getWeekName(int weekNum) {
String name = "" ;
switch (weekNum) {
case 1:
name = "星期日";
break;
case 2:
name = "星期一";
break;
case 3:
name = "星期二";
break;
case 4:
name = "星期三";
break;
case 5:
name = "星期四";
break;
case 6:
name = "星期五";
break;
case 7:
name = "星期六";
break;
default:
break;
}
return name;
}
/**
* 是否是今天
* @param sdate
* @return
*/
public static boolean isToday(String sdate){
boolean b = false;
Date time = null ;
try {
time = dateFormat.parse(sdate);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Date today = new Date();
if(time != null){
String nowDate = dateFormater.get().format(today);
String timeDate = dateFormater.get().format(time);
if(nowDate.equals(timeDate)){
b = true;
}
}
return b;
}
/**
* 个位数补0操作
* @param num
* @return
*/
public static String getValue(int num){
return String.valueOf(num>9?num:("0"+num));
}
private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd");
}
};
/**
* 获取系统当前日期
*/
public static String getCurrDate(String format) {
SimpleDateFormat formatter = new SimpleDateFormat(format);
Date curDate = new Date(System.currentTimeMillis());//获取当前时间
String str = formatter.format(curDate);
return str;
}
/**
* 格式化日期
*/
public static String formatDate(String date ,String format) {
SimpleDateFormat formatter = new SimpleDateFormat(format);
Date curDate = null;//获取当前时间
try {
curDate = formatter.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
String str = formatter.format(curDate);
return str;
}
/**
* 切换周的时候用
* 获取前/后 几天的一个日期
* @param currentData
* @param dayNum
* @return
*/
public static String getSomeDays(String currentData,int dayNum){
Calendar c = Calendar.getInstance();
//过去七天
try {
c.setTime(DataUtils.dateFormat.parse(currentData));
} catch (ParseException e) {
e.printStackTrace();
}
c.add(Calendar.DATE, dayNum);
Date d = c.getTime();
String day = DataUtils.dateFormat.format(d);
return day ;
}
/**
* 获取前/后 几个月的一个日期 切换月的时候用
* @param currentData
* @param monthNum
* @return
*/
public static String getSomeMonthDay(String currentData,int monthNum){
Calendar c = Calendar.getInstance();
try {
c.setTime(new SimpleDateFormat("yyyy-MM").parse(currentData));
} catch (ParseException e) {
e.printStackTrace();
}
c.set(Calendar.MONTH, c.get(Calendar.MONTH) +monthNum);
Date day = c.getTime();
return new SimpleDateFormat("yyyy-MM-dd").format(day);
}
/**
* 获取阴历
* @param date
* @return
*/
public static String getLuna(String date){
Calendar today = Calendar.getInstance();
try {
today.setTime(Lunar.chineseDateFormat.parse(date));
} catch (ParseException e) {
e.printStackTrace();
}
return new Lunar(today).toString() ;
}
}
____________________________________________________________________________________________________
Lunar
package com.example.qiangqiang.utils;
import android.text.TextUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
@SuppressWarnings({"unused", "SynchronizeOnNonFinalField"})
public class Lunar {
private int year;
private int month;
private int day;
private boolean leap;
final static String chineseNumber[] = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
public static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy-MM-dd");
final static long[] lunarInfo = new long[]
{0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2,
0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977,
0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970,
0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950,
0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557,
0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0,
0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0,
0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6,
0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570,
0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0,
0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5,
0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930,
0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530,
0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45,
0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0};
//====== 传回农历 y年的总天数
final private static int yearDays(int y) {
int i, sum = 348;
for (i = 0x8000; i > 0x8; i >>= 1) {
if ((lunarInfo[y - 1900] & i) != 0) sum += 1;
}
return (sum + leapDays(y));
}
//====== 传回农历 y年闰月的天数
final private static int leapDays(int y) {
if (leapMonth(y) != 0) {
if ((lunarInfo[y - 1900] & 0x10000) != 0)
return 30;
else
return 29;
} else
return 0;
}
//====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0
final private static int leapMonth(int y) {
return (int) (lunarInfo[y - 1900] & 0xf);
}
//====== 传回农历 y年m月的总天数
final private static int monthDays(int y, int m) {
if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
return 29;
else
return 30;
}
//====== 传回农历 y年的生肖
final public String animalsYear() {
final String[] Animals = new String[]{"鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"};
return Animals[(year - 4) % 12];
}
//====== 传入 月日的offset 传回干支, 0=甲子
final private static String cyclicalm(int num) {
final String[] Gan = new String[]{"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"};
final String[] Zhi = new String[]{"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"};
return (Gan[num % 10] + Zhi[num % 12]);
}
//====== 传入 offset 传回干支, 0=甲子
final public String cyclical() {
int num = year - 1900 + 36;
return (cyclicalm(num));
}
/** *//**
* 传出y年m月d日对应的农历.
* yearCyl3:农历年与1864的相差数 ?
* monCyl4:从1900年1月31日以来,闰月数
* dayCyl5:与1900年1月31日相差的天数,再加40 ?
* @param cal
* @return
*/
public Lunar(Calendar cal) {
@SuppressWarnings("unused") int yearCyl, monCyl, dayCyl;
int leapMonth = 0;
Date baseDate = null;
try {
baseDate = chineseDateFormat.parse("1900-01-31");
} catch (ParseException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
//求出和1900年1月31日相差的天数
int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L);
dayCyl = offset + 40;
monCyl = 14;
//用offset减去每农历年的天数
// 计算当天是农历第几天
//i最终结果是农历的年份
//offset是当年的第几天
int iYear, daysOfYear = 0;
for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) {
daysOfYear = yearDays(iYear);
offset -= daysOfYear;
monCyl += 12;
}
if (offset < 0) {
offset += daysOfYear;
iYear--;
monCyl -= 12;
}
//农历年份
year = iYear;
yearCyl = iYear - 1864;
leapMonth = leapMonth(iYear); //闰哪个月,1-12
leap = false;
//用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
int iMonth, daysOfMonth = 0;
for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
//闰月
if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {
--iMonth;
leap = true;
daysOfMonth = leapDays(year);
} else
daysOfMonth = monthDays(year, iMonth);
offset -= daysOfMonth;
//解除闰月
if (leap && iMonth == (leapMonth + 1)) leap = false;
if (!leap) monCyl++;
}
//offset为0时,并且刚才计算的月份是闰月,要校正
if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
if (leap) {
leap = false;
} else {
leap = true;
--iMonth;
--monCyl;
}
}
//offset小于0时,也要校正
if (offset < 0) {
offset += daysOfMonth;
--iMonth;
--monCyl;
}
month = iMonth;
day = offset + 1;
}
public static String getChinaDayString(int day) {
String chineseTen[] = {"初", "十", "廿", "卅"};
int n = day % 10 == 0 ? 9 : day % 10 - 1;
if (day > 30)
return "";
if (day == 10)
return "初十";
else
return chineseTen[day / 10] + chineseNumber[n];
}
public String toString() {
return getChinaDayString(day);
}
}
________________________________________________________________________________________________________________________________________________________________________________________________________
view包
DataView
package com.example.qiangqiang.view;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.example.qiangqiang.R;
import com.example.qiangqiang.adapter.DateAdapter;
import com.example.qiangqiang.bean.DateEntity;
import com.example.qiangqiang.utils.DataUtils;
import java.util.ArrayList;
/**
* author:Administrator on 2017/4/10 16:04
* description:文件说明
* version:版本
*/
public class DataView extends LinearLayout implements View.OnClickListener, AdapterView.OnItemClickListener {
private ArrayList<DateEntity> millisList ;
private TextView frontWeekTv ;
private TextView nextWeekTv ;
// private TextView currentDateTv ;
private DateAdapter mAdapter ;
private ArrayList<DateEntity> datas ;
private String dataFormate = "yyyy-MM-dd" ;
private String currentData ;
private DatePopupWindow popupWindow ;
public DataView(Context context) {
this(context,null);
}
public DataView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs,0);
}
public DataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
datas = new ArrayList<>();
millisList = new ArrayList<>();
View view = LayoutInflater.from(getContext()).inflate(R.layout.view_data,null,false);
frontWeekTv = (TextView)view.findViewById(R.id.front_week);
frontWeekTv.setOnClickListener(this);
nextWeekTv = (TextView)view.findViewById(R.id.next_week);
nextWeekTv.setOnClickListener(this);
// currentDateTv = (TextView)view.findViewById(R.id.now_day);
// currentDateTv.setOnClickListener(this);
mAdapter = new DateAdapter(getContext(),datas);
addView(view);
}
public void getData(String dateNumber){
datas.clear();
millisList.clear();
// currentDateTv.setText(dateNumber);
frontWeekTv.setText(dateNumber);
if (TextUtils.isEmpty(dateNumber)){
dateNumber = DataUtils.getCurrDate(dataFormate);
}
millisList = DataUtils.getWeek(dateNumber);
if (millisList==null || millisList.size()<=0){
return;
}
datas.addAll(millisList);
for (int i=0;i<millisList.size();i++){
if (dateNumber.equals(millisList.get(i).date)){
mAdapter.setSelectedPosition(i);
currentData = millisList.get(i).date;
// currentDateTv.setText(currentData);
frontWeekTv.setText(currentData);
if (onSelectListener!=null){
onSelectListener.onSelected(millisList.get(i));
}
}
}
if (TextUtils.isEmpty(currentData)){
mAdapter.setSelectedPosition(0);
currentData = millisList.get(0).date ;
// currentDateTv.setText();
frontWeekTv.setText(millisList.get(0).date);
if (onSelectListener!=null){
onSelectListener.onSelected(millisList.get(0));
}
}
mAdapter.notifyDataSetChanged();
}
public void getData1(String dateNumber){
datas.clear();
millisList.clear();
// currentDateTv.setText(dateNumber);
nextWeekTv.setText(dateNumber);
if (TextUtils.isEmpty(dateNumber)){
dateNumber = DataUtils.getCurrDate(dataFormate);
}
millisList = DataUtils.getWeek(dateNumber);
if (millisList==null || millisList.size()<=0){
return;
}
datas.addAll(millisList);
for (int i=0;i<millisList.size();i++){
if (dateNumber.equals(millisList.get(i).date)){
mAdapter.setSelectedPosition(i);
currentData = millisList.get(i).date;
// currentDateTv.setText(currentData);
nextWeekTv.setText(currentData);
if (onSelectListener!=null){
onSelectListener.onSelected(millisList.get(i));
}
}
}
if (TextUtils.isEmpty(currentData)){
mAdapter.setSelectedPosition(0);
currentData = millisList.get(0).date ;
// currentDateTv.setText();
frontWeekTv.setText(millisList.get(0).date);
if (onSelectListener!=null){
onSelectListener.onSelected(millisList.get(0));
}
}
mAdapter.notifyDataSetChanged();
}
@Override
public void onClick(View view) {
int id = view.getId();
if (id==frontWeekTv.getId()){
showPopupWindow(this);
}else if (id==nextWeekTv.getId()){
showPopupWindow1(this);
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DateEntity entity = datas.get(position);
currentData = entity.date ;
// currentDateTv.setText(currentData);
/* frontWeekTv.setText(currentData);
nextWeekTv.setText(currentData);*/
mAdapter.setSelectedPosition(position);
if (onSelectListener!=null){
onSelectListener.onSelected(millisList.get(position));
}
}
private void showPopupWindow(View v) {
popupWindow = new DatePopupWindow(getContext(),currentData);
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
// popupWindow.showAsDropDown(v);
popupWindow.showAtLocation(v,Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
popupWindow.setOnItemClick(new DatePopupWindow.OnItemClick() {
@Override
public void onItemClick(String date) {
getData(date);
}
});
}
private void showPopupWindow1(View v) {
popupWindow = new DatePopupWindow(getContext(),currentData);
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
// popupWindow.showAsDropDown(v);
popupWindow.showAtLocation(v,Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
popupWindow.setOnItemClick(new DatePopupWindow.OnItemClick() {
@Override
public void onItemClick(String date) {
getData1(date);
}
});
}
/**
* 选中日期之后的回调
*/
private OnSelectListener onSelectListener ;
public void setOnSelectListener(OnSelectListener onSelectListener) {
this.onSelectListener = onSelectListener;
}
public interface OnSelectListener{
void onSelected(DateEntity date);
}
}
____________________________________________________________________________________________________
DatePopupWindow
package com.example.qiangqiang.view;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.util.Log;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.example.qiangqiang.R;
import com.example.qiangqiang.adapter.DateMonthAdapter;
import com.example.qiangqiang.utils.DataUtils;
/**
* author:Administrator on 2017/4/11 15:43
* description:文件说明
* version:版本
*/
public class DatePopupWindow extends PopupWindow implements View.OnClickListener{
private View conentView;
private GridView gridView ;
private TextView frontMonthTv ;
private TextView nextMonthTv ;
private TextView currentDateTv ;
private DateMonthAdapter adapter ;
private TextView ok,quxiao ;
public String date ;
private int currentPosition =-1 ;
final int RIGHT = 0;
final int LEFT = 1;
private GestureDetector gestureDetector;
public DatePopupWindow(final Context context,String dateString) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
conentView = inflater.inflate(R.layout.view_poup, null);
int h = context.getResources().getDisplayMetrics().heightPixels;
int w = context.getResources().getDisplayMetrics().widthPixels;
// 设置SelectPicPopupWindow的View
this.setContentView(conentView);
// 设置SelectPicPopupWindow弹出窗体的宽
this.setWidth(w);
// 设置SelectPicPopupWindow弹出窗体的高
this.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
// 设置SelectPicPopupWindow弹出窗体可点击
this.setFocusable(true);
this.setOutsideTouchable(true);
// 刷新状态
this.update();
// 实例化一个ColorDrawable颜色为半透明
ColorDrawable dw = new ColorDrawable(0000000000);
// 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作
this.setBackgroundDrawable(dw);
// this.setAnimationStyle(android.R.style.Animation_Dialog);
// 设置SelectPicPopupWindow弹出窗体动画效果
// this.setAnimationStyle(R.style.Animation_Pop_style);
gridView = (GridView) conentView.findViewById(R.id.list);
frontMonthTv = (TextView)conentView.findViewById(R.id.front_month);
frontMonthTv.setOnClickListener(this);
nextMonthTv = (TextView)conentView.findViewById(R.id.next_month);
nextMonthTv.setOnClickListener(this);
ok = (TextView)conentView.findViewById(R.id.ok);
quxiao = (TextView)conentView.findViewById(R.id.quxiao);
ok.setOnClickListener(this);
quxiao.setOnClickListener(this);
gestureDetector = new GestureDetector(context,onGestureListener);
currentDateTv = (TextView)conentView.findViewById(R.id.now_month);
this.date = dateString ;
if (TextUtils.isEmpty(date)){
this.date = DataUtils.getCurrDate("yyyy-MM-dd");
}
currentDateTv.setText(DataUtils.formatDate(date,"yyyy-MM"));
adapter = new DateMonthAdapter(context);
adapter.setData(DataUtils.getMonth(date));
gridView.setAdapter(adapter);
adapter.setDateString(date);
adapter.setSelectedPosition(DataUtils.getSelectPosition());
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (onItemClick!=null && !TextUtils.isEmpty(adapter.getItem(position).date)){
adapter.setSelectedPosition(position);
currentDateTv.setText(DataUtils.formatDate(adapter.getItem(position).date,"yyyy-MM"));
date = adapter.getItem(position).date ;
}
}
});
gridView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
}
/**
* 手势监听是否是左右滑动
*/
private GestureDetector.OnGestureListener onGestureListener =
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float x = e2.getX() - e1.getX();
float y = e2.getY() - e1.getY();
if (x > 100) {
doResult(RIGHT);
} else if (x < -100) {
doResult(LEFT);
}
return true;
}
};
public void doResult(int action) {
switch (action) {
case RIGHT:
date = DataUtils.getSomeMonthDay(date,-1);
adapter.setData(DataUtils.getMonth(date));
adapter.setDateString(date);
adapter.setSelectedPosition(DataUtils.getSelectPosition());
currentDateTv.setText(DataUtils.formatDate(date,"yyyy-MM"));
Log.e("wenzihao","go right");
break;
case LEFT:
date = DataUtils.getSomeMonthDay(date,+1);
adapter.setData(DataUtils.getMonth(date));
adapter.setDateString(date);
adapter.setSelectedPosition(DataUtils.getSelectPosition());
currentDateTv.setText(DataUtils.formatDate(date,"yyyy-MM"));
Log.e("wenzihao","go left");
break;
}
}
public OnItemClick onItemClick ;
public void setOnItemClick(OnItemClick onItemClick) {
this.onItemClick = onItemClick;
}
@Override
public void onClick(View view) {
int id = view.getId();
if (id==frontMonthTv.getId()){
date = DataUtils.getSomeMonthDay(date,-1);
adapter.setData(DataUtils.getMonth(date));
adapter.setDateString(date);
adapter.setSelectedPosition(DataUtils.getSelectPosition());
currentDateTv.setText(DataUtils.formatDate(date,"yyyy-MM"));
}else if (id==nextMonthTv.getId()){
date = DataUtils.getSomeMonthDay(date,+1);
adapter.setData(DataUtils.getMonth(date));
adapter.setDateString(date);
adapter.setSelectedPosition(DataUtils.getSelectPosition());
currentDateTv.setText(DataUtils.formatDate(date,"yyyy-MM"));
}else if (id==ok.getId()){
if (onItemClick!=null){
onItemClick.onItemClick(date);
}
dismiss();
}else if (id==quxiao.getId()){
dismiss();
}
}
/**
* 点击回调接口
*/
public interface OnItemClick{
void onItemClick(String date);
}
@Override
public void dismiss() {
super.dismiss();
}
}
____________________________________________________________________________________________________
SquareLayout
package com.example.qiangqiang.view;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class SquareLayout extends LinearLayout {
public SquareLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SquareLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SquareLayout(Context context) {
super(context);
}
@SuppressWarnings("unused")
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// For simple implementation, or internal size is always 0.
// We depend on the container to specify the layout size of
// our view. We can't really know what it is since we will be
// adding and removing different arbitrary views and do not
// want the layout to change as this happens.
setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));
// Children are just made to fill our space.
int childWidthSize = getMeasuredWidth();
int childHeightSize = getMeasuredHeight();
//高度和宽度一样
heightMeasureSpec = widthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
____________________________________________________________________________________________________
mainactivity
package com.example.qiangqiang;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import com.example.qiangqiang.bean.DateEntity;
import com.example.qiangqiang.view.DataView;
public class MainActivity extends AppCompatActivity {
private DataView dataView ;
private TextView info ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
info = (TextView) findViewById(R.id.info);
dataView = (DataView) findViewById(R.id.week);
}
}
____________________________________________________________________________________________________
drawble
bg_btn_login_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape>
<solid android:color="@color/color_c61a04" />
<corners android:radius="6dp" />
</shape></item>
<item android:state_enabled="false"><shape>
<solid android:color="@color/color_cccccc" />
<corners android:radius="6dp" />
</shape></item>
<item><shape>
<solid android:color="@color/color_d81e06" />
<corners android:radius="6dp" />
</shape></item>
</selector>
____________________________________________________________________________________________________
ic_launcher_background.xml
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillColor="#26A69A"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
</vector>
____________________________________________________________________________________________________icon_left.png
icon_right.png
ok_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="40dp"
android:height="40dp"
/>
<solid
android:color="@color/color_28d19d"
/>
<corners
android:radius="5dp"
/>
</shape>
____________________________________________________________________________________________________
select_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="40dp"
android:height="40dp"
/>
<solid
android:color="@color/colorAccent"
/>
</shape>
____________________________________________________________________________________________________
select_green_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="40dp"
android:height="40dp"
/>
</shape>
____________________________________________________________________________________________________
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:background="@color/colorPrimaryDark"
android:text="日历控件"
android:gravity="center"
android:textSize="16sp"
android:textColor="@color/color_ffffff"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="48dp" />
<TextView
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="选择日期"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.example.qiangqiang.view.DataView
android:id="@+id/week"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.example.qiangqiang.view.DataView>
<TextView
android:id="@+id/info"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_weight="1"
android:lineSpacingExtra="3dp"
android:lineSpacingMultiplier="1.2"
android:gravity="center|left"
android:textSize="14sp"
android:textColor="@color/color_666666"
android:layout_height="wrap_content" />
</LinearLayout>
____________________________________________________________________________________________________
item_data.xml
<?xml version="1.0" encoding="utf-8"?>
<com.example.qiangqiang.view.SquareLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_week"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/week_num"
android:layout_width="wrap_content"
android:text="一"
android:gravity="center"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:textColor="#999999"
android:textSize="12sp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/item_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingBottom="2dp"
android:gravity="center"
android:textStyle="bold"
android:textSize="16sp"
android:text="10"
android:textColor="#333333" />
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:paddingBottom="2dp"
android:visibility="invisible"
android:layout_height="wrap_content" />
</com.example.qiangqiang.view.SquareLayout>
____________________________________________________________________________________________________
item_month_data.xml
<?xml version="1.0" encoding="utf-8"?>
<com.example.qiangqiang.view.SquareLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_ffffff"
android:gravity="center"
android:padding="2dp"
android:orientation="vertical">
<TextView
android:id="@+id/data"
android:layout_width="wrap_content"
android:textSize="16sp"
android:textColor="@color/color_999999"
android:gravity="center"
android:text=""
android:background="@null"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/luna"
android:layout_width="match_parent"
android:textSize="10sp"
android:textColor="@color/color_999999"
android:gravity="center"
android:text=""
android:background="@null"
android:layout_height="wrap_content" />
</com.example.qiangqiang.view.SquareLayout>
____________________________________________________________________________________________________
view_data.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_marginTop="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/front_week"
android:layout_marginLeft="20dp"
android:layout_width="0px"
android:layout_weight="5"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:drawableLeft="@drawable/icon_left"
android:drawablePadding="5dp"
android:gravity="center"
android:paddingRight="50dp"
android:text="2017-7-9"
android:textColor="#55A8AC"
android:textSize="16dp"
android:background="#ffff"
android:paddingLeft="20dp"/>
<TextView
android:id="@+id/now_day"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="-"
android:drawablePadding="5dp"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:id="@+id/next_week"
android:layout_marginRight="20dp"
android:layout_width="0px"
android:layout_weight="5"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:drawableLeft="@drawable/icon_left"
android:gravity="center"
android:paddingRight="50dp"
android:paddingLeft="20dp"
android:text="2019-8-6"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textColor="#55A8AC"
android:textSize="16dp"
android:background="#ffff"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@null" />
</LinearLayout>
____________________________________________________________________________________________________
view_poup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_ffffff"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:id="@+id/front_month"
android:layout_width="0px"
android:layout_weight="5"
android:layout_height="match_parent"
android:drawableLeft="@drawable/icon_left"
android:paddingLeft="100dp"
android:drawablePadding="5dp"
android:layout_gravity="center"
android:textColor="#999999"
android:textSize="16dp" />
<TextView
android:id="@+id/now_month"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="2016-01-10"
android:textColor="#333333"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:id="@+id/next_month"
android:layout_width="0px"
android:layout_weight="5"
android:layout_height="match_parent"
android:drawablePadding="5dp"
android:drawableRight="@drawable/icon_right"
android:gravity="center"
android:paddingRight="50dp"
android:textColor="#999999"
android:textSize="16dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/color_eeeeee" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="@color/color_eeeeee"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/color_eeeeee"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="center"
android:text="日"
android:textColor="@color/colorAccent"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_eeeeee" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/color_eeeeee"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="center"
android:text="一"
android:textColor="@color/color_333333"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_eeeeee" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/color_eeeeee"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="center"
android:text="二"
android:textColor="@color/color_333333"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_eeeeee" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/color_eeeeee"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="center"
android:text="三"
android:textColor="@color/color_333333"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_eeeeee" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/color_eeeeee"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="center"
android:text="四"
android:textColor="@color/color_333333"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_eeeeee" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/color_eeeeee"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="center"
android:text="五"
android:textColor="@color/color_333333"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_eeeeee" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="match_parent"
android:background="@color/color_eeeeee"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:gravity="center"
android:text="六"
android:textColor="@color/colorAccent"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/color_eeeeee" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/color_eeeeee" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/color_ffffff">
<GridView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_ffffff"
android:cacheColorHint="@android:color/transparent"
android:gravity="center"
android:fadingEdge="none"
android:overScrollMode="never"
android:horizontalSpacing="1dp"
android:listSelector="@android:color/transparent"
android:numColumns="7"
android:scrollbars="none"
android:stretchMode="columnWidth"
android:verticalSpacing="1dp"></GridView>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="16dp"
android:layout_marginBottom="30dp"
android:orientation="horizontal">
<TextView
android:id="@+id/quxiao"
android:layout_width="0px"
android:layout_weight="5"
android:layout_height="wrap_content"
android:text="取消"
android:textSize="16dp"
android:layout_marginLeft="20dp"
android:textColor="#55A8AC"/>
<TextView
android:id="@+id/ok"
android:layout_width="0px"
android:layout_weight="5"
android:layout_height="wrap_content"
android:text="确定"
android:gravity="right"
android:textSize="16dp"
android:textColor="#55A8AC"
android:layout_marginRight="20dp"/>
</LinearLayout>
</LinearLayout>
____________________________________________________________________________________________________
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Animation_Pop_style">
<item name="android:windowEnterAnimation">@anim/popshow</item>
<!-- 指定显示的动画xml -->
<item name="android:windowExitAnimation">@anim/pophide</item>
<!-- 指定消失的动画xml -->
</style>
</resources>