Skip to content

Commit

Permalink
重构
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Mar 20, 2020
1 parent 88388bf commit 51a85c3
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 68 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
5 changes: 1 addition & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ android {
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'

testImplementation 'junit:junit:4.12'
Expand Down
9 changes: 3 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,10 @@
android:name=".activity.TestStretchActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />

<activity
android:name=".TestActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />
<!-- <activity-->
<!-- android:name=".TestActivity"-->
<!-- android:configChanges="orientation|screenSize|keyboardHidden" />-->

<activity
android:name=".TestAdapterCalendarActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />

<activity
android:name=".activity.GeneralAdapterActivity"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/necer/ncalendar/TestActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.necer.ncalendar;

import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.google.android.material.tabs.TabLayout;

import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;
Expand All @@ -13,6 +16,7 @@
import com.necer.ncalendar.fragment.Fragment3;
import com.necer.ncalendar.fragment.Fragment4;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -31,6 +35,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
tabLayout = findViewById(R.id.tl_tabs);




List<Fragment> fragments = new ArrayList<>();
List<String> titles = new ArrayList<>();
fragments.add(new Fragment1());
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_miui10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
app:selectCircleColor="#398FE9"
app:solarHolidayTextColor="#519EDC"
app:solarTermTextColor="#519EDC"
app:solarTextColor="@color/colorAccent"
app:todaySolarTextColor="#398FE9">


Expand Down
7 changes: 3 additions & 4 deletions ncalendar/src/main/java/com/necer/calendar/BaseCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

import android.text.TextUtils;
import android.util.AttributeSet;
Expand All @@ -25,6 +24,7 @@
import com.necer.painter.CalendarPainter;
import com.necer.utils.Attrs;
import com.necer.utils.AttrsUtil;
import com.necer.view.CalendarViewPager;
import com.necer.view.ICalendarView;

import org.joda.time.LocalDate;
Expand All @@ -36,13 +36,13 @@
* Created by necer on 2018/9/11.
* qq群:127278900
*/
public abstract class BaseCalendar extends ViewPager implements ICalendar {
public abstract class BaseCalendar extends CalendarViewPager implements ICalendar {



//5.0
//修改部分参数命名
//增加多选预置 取消不取消
//增加多选预置 可取消可不取消
//重写InnerPainter
//增加日期变化行为参数 1、点击选中 2、点击跳转(上下月的情况) 3、滑动翻页 4、api跳转 等
//跳转日期不用post
Expand All @@ -51,7 +51,6 @@ public abstract class BaseCalendar extends ViewPager implements ICalendar {




private Context mContext;
private Attrs mAttrs;

Expand Down
2 changes: 1 addition & 1 deletion ncalendar/src/main/java/com/necer/utils/AttrsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static Attrs getAttrs(Context context, AttributeSet attributeSet) {
attrs.solarTermTextColor = ta.getColor(R.styleable.NCalendar_solarTermTextColor, context.getResources().getColor(R.color.solarTermTextColor));

attrs.selectCircleColor = ta.getColor(R.styleable.NCalendar_selectCircleColor, context.getResources().getColor(R.color.selectCircleColor));
attrs.solarTextSize = ta.getDimension(R.styleable.NCalendar_solarTextSize, CalendarUtil.sp2px(context, 18));
attrs.solarTextSize = ta.getDimension(R.styleable.NCalendar_solarTextSize, context.getResources().getDimension(R.dimen.solarTextSize));
attrs.lunarTextSize = ta.getDimension(R.styleable.NCalendar_lunarTextSize, CalendarUtil.sp2px(context, 10));
attrs.lunarDistance = ta.getDimension(R.styleable.NCalendar_lunarDistance, CalendarUtil.dp2px(context, 15));
attrs.holidayDistance = ta.getDimension(R.styleable.NCalendar_holidayDistance, CalendarUtil.dp2px(context, 15));
Expand Down
45 changes: 0 additions & 45 deletions ncalendar/src/main/java/com/necer/utils/CalendarUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.util.TypedValue;
import android.view.WindowManager;

import com.necer.entity.CalendarDate;
import com.necer.entity.Lunar;
Expand All @@ -21,47 +20,10 @@
public class CalendarUtil {


/**
* 屏幕宽度
*
* @param context
* @return
*/
public static int getScreenWith(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
return windowManager.getDefaultDisplay().getWidth();
}


/**
*
* @param color 原来的颜色
* @param alpha 透明度,小数
* @return
*/
/*
public static int getAlphaColor(int color, double alpha) {
int a = (int) Math.round(alpha * 255);
String hex = Integer.toHexString(a).toUpperCase();
if (hex.length() == 1) hex = "0" + hex;
String hexCode = "#" + hex + String.format("%06X", Integer.valueOf(16777215 & color));
int newColor;
try {
newColor = Color.parseColor(hexCode);
} catch (Throwable throwable) {
newColor = color;
}
return newColor;
}
*/


/**
* dp转px
*
* @param context
* @param
* @return
*/
public static float dp2px(Context context, int dpVal) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
Expand All @@ -70,10 +32,6 @@ public static float dp2px(Context context, int dpVal) {

/**
* sp转px
*
* @param context
* @param spVal
* @return
*/
public static float sp2px(Context context, float spVal) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
Expand All @@ -82,9 +40,6 @@ public static float sp2px(Context context, float spVal) {

/**
* 两个日期是否同月
* @param date1
* @param date2
* @return
*/
public static boolean isEqualsMonth(LocalDate date1, LocalDate date2) {
return date1.getYear() == date2.getYear() && date1.getMonthOfYear() == date2.getMonthOfYear();
Expand Down
21 changes: 13 additions & 8 deletions ncalendar/src/main/java/com/necer/utils/HolidayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,21 @@ public static String getLunarHoliday(int lunarYear, int lunarMonth, int lunarDay
}

//法定节假日 休息的日期
public static List<String> holidayList = Arrays.asList("2017-12-30", "2017-12-31", "2018-01-01", "2018-02-15", "2018-02-16", "2018-02-17", "2018-02-18",
"2018-02-19", "2018-02-20", "2018-02-21", "2018-04-05", "2018-04-06", "2018-04-07", "2018-04-29", "2018-04-30", "2018-05-01", "2018-06-16", "2018-06-17",
"2018-06-18", "2018-09-22", "2018-09-23", "2018-09-24", "2018-10-01", "2018-10-02", "2018-10-03", "2018-10-04", "2018-10-05", "2018-10-06", "2018-10-07",
"2018-12-30", "2018-12-31", "2019-01-01", "2019-02-04", "2019-02-05", "2019-02-06", "2019-02-07", "2019-02-08", "2019-02-09", "2019-02-10", "2019-04-05", "2019-04-06",
"2019-04-07", "2019-05-01", "2019-05-02", "2019-05-03", "2019-05-04", "2019-06-07", "2019-06-08", "2019-06-09", "2019-09-13", "2019-09-14", "2019-09-15", "2019-10-01", "2019-10-02",
"2019-10-03", "2019-10-04", "2019-10-05", "2019-10-06", "2019-10-07");
public static List<String> holidayList = Arrays.asList(
"2017-12-30", "2017-12-31", "2018-01-01", "2018-02-15", "2018-02-16", "2018-02-17", "2018-02-18", "2018-02-19", "2018-02-20", "2018-02-21", "2018-04-05",
"2018-04-06", "2018-04-07", "2018-04-29", "2018-04-30", "2018-05-01", "2018-06-16", "2018-06-17", "2018-06-18", "2018-09-22", "2018-09-23", "2018-09-24",
"2018-10-01", "2018-10-02", "2018-10-03", "2018-10-04", "2018-10-05", "2018-10-06", "2018-10-07", "2018-12-30", "2018-12-31", "2019-01-01", "2019-02-04",
"2019-02-05", "2019-02-06", "2019-02-07", "2019-02-08", "2019-02-09", "2019-02-10", "2019-04-05", "2019-04-06", "2019-04-07", "2019-05-01", "2019-05-02",
"2019-05-03", "2019-05-04", "2019-06-07", "2019-06-08", "2019-06-09", "2019-09-13", "2019-09-14", "2019-09-15", "2019-10-01", "2019-10-02", "2019-10-03",
"2019-10-04", "2019-10-05", "2019-10-06", "2019-10-07", "2020-01-01", "2020-01-24", "2020-01-25", "2020-01-26", "2020-01-27", "2020-01-28", "2020-01-29",
"2020-01-30", "2020-01-31", "2020-02-01", "2020-02-02", "2020-04-04", "2020-04-05", "2020-04-06", "2020-05-01", "2020-05-02", "2020-05-03", "2020-05-04",
"2020-05-05", "2020-06-25", "2020-06-26", "2020-06-27", "2020-10-01", "2020-10-02", "2020-10-03", "2020-10-04", "2020-10-05", "2020-10-06", "2020-10-07",
"2020-10-08");

//补班的日期
public static List<String> workdayList = Arrays.asList("2018-02-11", "2018-02-24", "2018-04-08", "2018-04-28", "2018-09-29", "2018-04-30", "2018-12-29",
"2019-02-02", "2019-02-03", "2019-04-28", "2019-05-05", "2019-09-29", "2019-10-12");
public static List<String> workdayList = Arrays.asList(
"2018-02-11", "2018-02-24", "2018-04-08", "2018-04-28", "2018-09-29", "2018-04-30", "2018-12-29", "2019-02-02", "2019-02-03", "2019-04-28", "2019-05-05",
"2019-09-29", "2019-10-12", "2020-01-19", "2020-04-26", "2020-05-09", "2020-06-28", "2020-09-27", "2020-10-10");


}
45 changes: 45 additions & 0 deletions ncalendar/src/main/java/com/necer/view/CalendarViewPager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.necer.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

/**
* Created by necer on 2020/3/20.
*/
public class CalendarViewPager extends ViewPager {


private boolean mScrollEnable = true;


public CalendarViewPager(@NonNull Context context) {
super(context);
}

public CalendarViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mScrollEnable) {
return super.onInterceptTouchEvent(ev);
} else {
return false;
}
}

public boolean scrollEnable() {
return mScrollEnable;
}

public void setScrollEnable(boolean scrollEnable) {
this.mScrollEnable = scrollEnable;
}

}
10 changes: 10 additions & 0 deletions ncalendar/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>



<dimen name="solarTextSize">18sp</dimen>



</resources>

0 comments on commit 51a85c3

Please sign in to comment.