Skip to content

Commit

Permalink
增加修改 月份下划线颜色 日期圆形颜色 倍数设置 倍数设置默认为2的倍数 最底为2
Browse files Browse the repository at this point in the history
  • Loading branch information
StarrySky123123123 committed Feb 2, 2020
1 parent f13efbc commit dcf8e6c
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 28
defaultConfig {
// applicationId "com.example.a13479.customdate"
minSdkVersion 15
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<com.example.customdatelibrary.ZhxDate
android:id="@+id/zhx"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
</com.example.customdatelibrary.ZhxDate>

</LinearLayout>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}

Expand Down
4 changes: 1 addition & 3 deletions customdatelibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:28.+'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.github.KuangGang:RoundCorners:1.0.4'
}

// 指定编码
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.customdatelibrary;

public class Constant {
public static String MONTH_XHX = "#00EE76";
public static String DAYITEM = "#00EE76";
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.customdatelibrary;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
Expand Down Expand Up @@ -83,6 +84,11 @@ public void setType(int type) {
resh();
}

public void setBs(int bs) {
this.bs = bs;
resh();
}

private void resh(){
initData();
initView(view);
Expand All @@ -100,6 +106,10 @@ public ZhxDate(Context context, AttributeSet attrs) {
private void init(Context context, AttributeSet attrs) {
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.zhxdate, this, true);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MenuItemLayout);
Constant.MONTH_XHX = a.getString(R.styleable.MenuItemLayout_month_xhxcolor)==null?"#4678ff":a.getString(R.styleable.MenuItemLayout_month_xhxcolor);
Constant.DAYITEM = a.getString(R.styleable.MenuItemLayout_dayitemcolor)==null?"#4678ff":a.getString(R.styleable.MenuItemLayout_dayitemcolor);
bs = a.getInteger(R.styleable.MenuItemLayout_bs,2);
initView(view);
initmonth();
initday();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
Expand All @@ -11,6 +12,7 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.customdatelibrary.Constant;
import com.example.customdatelibrary.MethodUtil;
import com.example.customdatelibrary.R;

Expand Down Expand Up @@ -132,8 +134,7 @@ private void dxpre(final ViewHolder viewHolder, final int i) {
}
if (index == i) {
viewHolder.dayItemL1.setTag(true);
viewHolder.dayItemT1.setBackgroundResource(R.drawable.button_radius_bule);
viewHolder.dayItemT1.setTextColor(Color.parseColor("#ffffff"));
setPreTure(viewHolder.dayItemT1);
}
viewHolder.dayItemL1.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -160,12 +161,10 @@ public void onClick(View v) {
}
if (viewHolder.dayItemL1.getTag() == null || (boolean) viewHolder.dayItemL1.getTag() == false) {
//没有选中
viewHolder.dayItemT1.setBackgroundResource(R.drawable.button_radius_bule);
viewHolder.dayItemT1.setTextColor(Color.parseColor("#ffffff"));
setPreTure(viewHolder.dayItemT1);
viewHolder.dayItemL1.setTag(true);
} else {
viewHolder.dayItemT1.setBackgroundResource(R.drawable.button_radius_white);
viewHolder.dayItemT1.setTextColor(Color.parseColor("#8B8989"));
setPreFalse(viewHolder.dayItemT1);
viewHolder.dayItemL1.setTag(false);
}
}
Expand All @@ -185,8 +184,7 @@ private void dgljpre(final ViewHolder viewHolder, final int i) {
public void onClick(View v) {
if (dgljs.get(i).dayItemL1.getTag() == null || (boolean) dgljs.get(i).dayItemL1.getTag() == false) {
//没有选中
dgljs.get(i).dayItemT1.setBackgroundResource(R.drawable.button_radius_bule);
dgljs.get(i).dayItemT1.setTextColor(Color.parseColor("#ffffff"));
setPreTure(viewHolder.dayItemT1);
dgljs.get(i).dayItemL1.setTag(true);
dgljcolor2(i);
} else {
Expand All @@ -202,16 +200,18 @@ private void dgljcolor() {
dgljs.get(a).dayItemL1.setTag(true);
dgljs.get(a).dayItemT1.setBackgroundResource(R.drawable.button_radius_bule_left);
dgljs.get(a).dayItemT1.setTextColor(Color.parseColor("#ffffff"));
uploadShape(dgljs.get(a).dayItemT1);
} else if (i == b) {
dgljs.get(b).dayItemL1.setTag(true);
dgljs.get(b).dayItemT1.setBackgroundResource(R.drawable.button_radius_bule_right);
dgljs.get(b).dayItemT1.setTextColor(Color.parseColor("#ffffff"));
uploadShape(dgljs.get(b).dayItemT1);
} else if (i > a && i < b) {
dgljs.get(i).dayItemT1.setBackgroundResource(R.drawable.button_bule);
dgljs.get(i).dayItemT1.setTextColor(Color.parseColor("#ffffff"));
uploadShape(dgljs.get(i).dayItemT1);
} else {
dgljs.get(i).dayItemT1.setBackgroundResource(R.drawable.button_white);
dgljs.get(i).dayItemT1.setTextColor(Color.parseColor("#8B8989"));
setPreFalse(dgljs.get(i).dayItemT1);
}
}
}
Expand Down Expand Up @@ -258,8 +258,7 @@ private void clearcolor() {
b = -1;
for (int i = 0; i < dgljs.size(); i++) {
dgljs.get(i).dayItemL1.setTag(false);
dgljs.get(i).dayItemT1.setBackgroundResource(R.drawable.button_radius_white);
dgljs.get(i).dayItemT1.setTextColor(Color.parseColor("#8B8989"));
setPreFalse(dgljs.get(i).dayItemT1);
}
}

Expand All @@ -272,8 +271,7 @@ public void DownFourpre(int x, int y) {
if (!TextUtils.isEmpty(dgljs.get(i).dayItemT1.getText())) {
if (isTouchPointInView2(dgljs.get(i).dayItemT1, x, y)) {
firstIndex = i;
dgljs.get(i).dayItemT1.setBackgroundResource(R.drawable.button_radius_bule);
dgljs.get(i).dayItemT1.setTextColor(Color.parseColor("#ffffff"));
setPreTure(dgljs.get(i).dayItemT1);
dgljs.get(i).dayItemL1.setTag(true);
}
}
Expand All @@ -284,13 +282,11 @@ public void Fourpre(int x, int y) {
for (int i = firstIndex; i < dgljs.size(); i++) {
if (!TextUtils.isEmpty(dgljs.get(i).dayItemT1.getText())) {
if (isTouchPointInView(dgljs.get(i).dayItemT1, x, y)) {
dgljs.get(i).dayItemT1.setBackgroundResource(R.drawable.button_radius_bule);
dgljs.get(i).dayItemT1.setTextColor(Color.parseColor("#ffffff"));
setPreTure(dgljs.get(i).dayItemT1);
dgljs.get(i).dayItemL1.setTag(true);
setCowColor(i);
} else {
dgljs.get(i).dayItemT1.setBackgroundResource(R.drawable.button_radius_white);
dgljs.get(i).dayItemT1.setTextColor(Color.parseColor("#8B8989"));
setPreFalse(dgljs.get(i).dayItemT1);
dgljs.get(i).dayItemL1.setTag(false);
}
}
Expand Down Expand Up @@ -345,8 +341,7 @@ private void setCowColor(int i) {
for (int m = firstIndex; m < max; m++) {
if (!TextUtils.isEmpty(dgljs.get(m).dayItemT1.getText())) {
dgljs.get(m).dayItemL1.setTag(true);
dgljs.get(m).dayItemT1.setBackgroundResource(R.drawable.button_radius_bule);
dgljs.get(m).dayItemT1.setTextColor(Color.parseColor("#ffffff"));
setPreTure(dgljs.get(m).dayItemT1);
}
}
}
Expand All @@ -372,4 +367,21 @@ public List<String> getList() {
}
return res;
}

private void uploadShape(TextView textView){
GradientDrawable mGroupDrawable= (GradientDrawable) textView.getBackground();
/*设置整体背景颜色*/
mGroupDrawable.setColor(Color.parseColor(Constant.DAYITEM));
}

private void setPreTure(TextView textView){
textView.setBackgroundResource(R.drawable.button_radius_bule);
textView.setTextColor(Color.parseColor("#ffffff"));
uploadShape(textView);
}

private void setPreFalse(TextView textView){
textView.setBackgroundResource(R.drawable.button_radius_white);
textView.setTextColor(Color.parseColor("#8B8989"));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.example.customdatelibrary.adapter;

import android.graphics.Color;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.customdatelibrary.Constant;
import com.example.customdatelibrary.R;
import com.kproduce.roundcorners.RoundTextView;

import java.util.List;

Expand Down Expand Up @@ -42,9 +45,11 @@ public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
viewHolder.monthItemT1.setText(list.get(i));
viewHolder.monthItemT1.setTextColor(Color.parseColor("#cccccc"));
viewHolder.monthItemT2.setBackgroundColor(Color.parseColor("#ffffff"));
viewHolder.monthItemT1.setTypeface(Typeface.SANS_SERIF, Typeface.NORMAL);
if (i == index){
viewHolder.monthItemT1.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
viewHolder.monthItemT1.setTextColor(Color.parseColor("#000000"));
viewHolder.monthItemT2.setBackgroundColor(Color.parseColor("#4678ff"));
viewHolder.monthItemT2.setBackgroundColor(Color.parseColor(Constant.MONTH_XHX));
}
viewHolder.monthItemT1.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -72,12 +77,12 @@ public int getItemCount() {

static class ViewHolder extends RecyclerView.ViewHolder {
private TextView monthItemT1;
private TextView monthItemT2;
private RoundTextView monthItemT2;

public ViewHolder(@NonNull View itemView) {
super(itemView);
monthItemT1 = (TextView) itemView.findViewById(R.id.month_item_t1);
monthItemT2 = (TextView) itemView.findViewById(R.id.month_item_t2);
monthItemT2 = (RoundTextView) itemView.findViewById(R.id.month_item_t2);
}
}
}
1 change: 1 addition & 0 deletions customdatelibrary/src/main/res/layout/day_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="14sp"
android:textColor="#8B8989"
android:text="1"/>
Expand Down
9 changes: 5 additions & 4 deletions customdatelibrary/src/main/res/layout/month_item.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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:layout_width="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:minWidth="60dp"
android:layout_height="40dp"
android:paddingLeft="5dp"
Expand All @@ -10,13 +10,14 @@
<TextView
android:id="@+id/month_item_t1"
android:text="一月"
android:textSize="13sp"
android:textSize="15sp"
android:gravity="center"
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="35dp" />
<TextView
<com.kproduce.roundcorners.RoundTextView
android:id="@+id/month_item_t2"
app:rRadius="10dp"
android:background="#4678ff"
android:layout_width="match_parent"
android:layout_height="3dp" />
Expand Down
4 changes: 2 additions & 2 deletions customdatelibrary/src/main/res/layout/monthfragment.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -9,4 +9,4 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
7 changes: 4 additions & 3 deletions customdatelibrary/src/main/res/layout/zhxdate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/i1"
android:padding="5dp"
android:padding="6dp"
android:src="@drawable/jiantouzuo"
android:layout_width="30dp"
android:layout_height="match_parent" />
<TextView
android:id="@+id/t1"
android:text="2020"
android:textSize="15sp"
android:textSize="16sp"
android:textStyle="bold"
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/i2"
android:padding="5dp"
android:padding="6dp"
android:src="@drawable/jiantouyou"
android:layout_width="30dp"
android:layout_height="match_parent" />
Expand All @@ -38,6 +38,7 @@
android:layout_width="match_parent"
android:layout_height="40dp">
</android.support.v7.widget.RecyclerView>

<com.example.customdatelibrary.NoSlidingViewPager
android:id="@+id/v1"
android:layout_width="match_parent"
Expand Down
8 changes: 8 additions & 0 deletions customdatelibrary/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MenuItemLayout">
<attr name="month_xhxcolor" format="string" />
<attr name="dayitemcolor" format="string" />
<attr name="bs" format="integer" />
</declare-styleable>
</resources>

0 comments on commit dcf8e6c

Please sign in to comment.