From a77005a5958154ae4baaf52fc523fa13685791d9 Mon Sep 17 00:00:00 2001 From: dongjunkun <1440418246@qq.com> Date: Tue, 20 Sep 2016 15:45:57 +0800 Subject: [PATCH] field and method name refactor --- .idea/misc.xml | 2 +- README.md | 56 ++--- .../couponview/ExampleInstrumentedTest.java | 2 +- .../fragments/CouponCustomFragment.java | 33 ++- .../fragments/CouponDashLineFragment.java | 3 +- .../couponview/widget/CouponImageView.java | 96 ++++---- app/src/main/res/layout/activity_main.xml | 6 +- .../res/layout/fragment_coupon_custom.xml | 10 +- .../res/layout/fragment_coupon_image_view.xml | 20 +- .../res/layout/item_coupon_combination.xml | 16 +- .../main/res/layout/item_coupon_dash_line.xml | 16 +- .../res/layout/item_coupon_semi_circle.xml | 16 +- .../com/couponview/ExampleUnitTest.java | 2 +- .../java/yyydjk/com/library/CouponView.java | 96 ++++---- .../yyydjk/com/library/CouponViewHelper.java | 216 +++++++++--------- library/src/main/res/values/attrs.xml | 24 +- 16 files changed, 307 insertions(+), 307 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 4ca3650..6b8fbd7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -44,7 +44,7 @@ - + diff --git a/README.md b/README.md index 6d20149..316f016 100644 --- a/README.md +++ b/README.md @@ -35,18 +35,18 @@ dependencies { |cv_semicircle_color|color|半圆的颜色,一般需要和背景色一致| |cv_semicircle_gap|dimension|半圆之前的间隔| |cv_semicircle_radius|dimension|半圆的半径| -|cv_is_top_semicircle|boolean|是否绘制顶部半圆锯齿| -|cv_is_bottom_semicircle|boolean|是否绘制底部半圆锯齿| -|cv_is_left_semicircle|boolean|是否绘制左侧半圆锯齿| -|cv_is_right_semicircle|boolean|是否绘制右侧半圆锯齿| -|cv_is_top_dash_line|boolean|是否绘制顶部虚线| -|cv_is_bottom_dash_line|boolean|是否绘制底部虚线| -|cv_is_left_dash_line|boolean|是否绘制左侧虚线| -|cv_is_right_dash_line|boolean|是否绘制右侧虚线| -|cv_top_dash_line_margin|dimension|顶部虚线距离View顶部的距离| -|cv_bottom_dash_line_margin|dimension|底部虚线距离View底部的距离| -|cv_left_dash_line_margin|dimension|左侧虚线距离View左侧的距离| -|cv_right_dash_line_margin|dimension|右侧虚线距离View右侧的距离| +|cv_is_semicircle_top|boolean|是否绘制顶部半圆锯齿| +|cv_is_semicircle_bottom|boolean|是否绘制底部半圆锯齿| +|cv_is_semicircle_left|boolean|是否绘制左侧半圆锯齿| +|cv_is_semicircle_right|boolean|是否绘制右侧半圆锯齿| +|cv_is_dash_line_top|boolean|是否绘制顶部虚线| +|cv_is_dash_line_bottom|boolean|是否绘制底部虚线| +|cv_is_dash_line_left|boolean|是否绘制左侧虚线| +|cv_is_dash_line_right|boolean|是否绘制右侧虚线| +|cv_dash_line_margin_top|dimension|顶部虚线距离View顶部的距离| +|cv_dash_line_margin_bottom|dimension|底部虚线距离View底部的距离| +|cv_dash_line_margin_left|dimension|左侧虚线距离View左侧的距离| +|cv_dash_line_margin_right|dimension|右侧虚线距离View右侧的距离| 使用 ~~~ @@ -62,14 +62,14 @@ dependencies { app:cv_dash_line_gap="5dp" app:cv_dash_line_height="2dp" app:cv_dash_line_length="10dp" - app:cv_is_bottom_dash_line="true" - app:cv_is_bottom_semicircle="false" - app:cv_is_left_dash_line="true" - app:cv_is_left_semicircle="false" - app:cv_is_right_dash_line="true" - app:cv_is_right_semicircle="false" - app:cv_is_top_dash_line="true" - app:cv_is_top_semicircle="false" + app:cv_is_dash_line_bottom="true" + app:cv_is_semicircle_bottom="false" + app:cv_is_dash_line_left="true" + app:cv_is_semicircle_left="false" + app:cv_is_dash_line_right="true" + app:cv_is_semicircle_right="false" + app:cv_is_dash_line_top="true" + app:cv_is_semicircle_top="false" app:cv_semicircle_color="@android:color/white" app:cv_semicircle_gap="8dp" app:cv_semicircle_radius="4dp"> @@ -143,14 +143,14 @@ public class CustomView extends YourView{ app:cv_dash_line_gap="5dp" app:cv_dash_line_height="2dp" app:cv_dash_line_length="10dp" - app:cv_is_bottom_dash_line="false" - app:cv_is_bottom_semicircle="true" - app:cv_is_left_dash_line="true" - app:cv_is_left_semicircle="false" - app:cv_is_right_dash_line="true" - app:cv_is_right_semicircle="false" - app:cv_is_top_dash_line="false" - app:cv_is_top_semicircle="true" + app:cv_is_dash_line_bottom="false" + app:cv_is_semicircle_bottom="true" + app:cv_is_dash_line_left="true" + app:cv_is_semicircle_left="false" + app:cv_is_dash_line_right="true" + app:cv_is_semicircle_right="false" + app:cv_is_dash_line_top="false" + app:cv_is_semicircle_top="true" app:cv_semicircle_color="@android:color/white" app:cv_semicircle_gap="8dp" app:cv_semicircle_radius="6dp"/> diff --git a/app/src/androidTest/java/yyydjk/com/couponview/ExampleInstrumentedTest.java b/app/src/androidTest/java/yyydjk/com/couponview/ExampleInstrumentedTest.java index ea7d0bd..6116fc5 100644 --- a/app/src/androidTest/java/yyydjk/com/couponview/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/yyydjk/com/couponview/ExampleInstrumentedTest.java @@ -7,7 +7,7 @@ import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Instrumentation test, which will execute on an Android device. diff --git a/app/src/main/java/yyydjk/com/couponview/fragments/CouponCustomFragment.java b/app/src/main/java/yyydjk/com/couponview/fragments/CouponCustomFragment.java index a9f096f..7e0a9f1 100644 --- a/app/src/main/java/yyydjk/com/couponview/fragments/CouponCustomFragment.java +++ b/app/src/main/java/yyydjk/com/couponview/fragments/CouponCustomFragment.java @@ -56,50 +56,50 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { mSemicircleTop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mCouponView.setTopSemicircle(isChecked); + mCouponView.setSemicircleTop(isChecked); } }); mSemicircleBottom.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mCouponView.setBottomSemicircle(isChecked); + mCouponView.setSemicircleBottom(isChecked); } }); mSemicircleLeft.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mCouponView.setLeftSemicircle(isChecked); + mCouponView.setSemicircleLeft(isChecked); } }); mSemicircleRight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mCouponView.setRightSemicircle(isChecked); + mCouponView.setSemicircleRight(isChecked); } }); mDashLineTop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mCouponView.setTopDashLine(isChecked); + mCouponView.setDashLineTop(isChecked); } }); mDashLineBottom.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mCouponView.setBottomDashLine(isChecked); + mCouponView.setDashLineBottom(isChecked); } }); mDashLineLeft.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mCouponView.setLeftDashLine(isChecked); + mCouponView.setDashLineLeft(isChecked); } }); mDashLineRight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mCouponView.setRightDashLine(isChecked); + mCouponView.setDashLineRight(isChecked); } }); mSbSemicircleRadius.setProgress((int) mCouponView.getSemicircleRadius()); @@ -191,11 +191,11 @@ public void onStopTrackingTouch(SeekBar seekBar) { } }); - mSbTopDashLineMargin.setProgress((int) mCouponView.getTopDashLineMargin()); + mSbTopDashLineMargin.setProgress((int) mCouponView.getDashLineMarginTop()); mSbTopDashLineMargin.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - mCouponView.setTopDashLineMargin(dp2Px(progress)); + mCouponView.setDashLineMarginTop(dp2Px(progress)); } @Override @@ -210,12 +210,11 @@ public void onStopTrackingTouch(SeekBar seekBar) { }); - - mSbBottomDashLineMargin.setProgress((int) mCouponView.getBottomDashLineMargin()); + mSbBottomDashLineMargin.setProgress((int) mCouponView.getDashLineMarginBottom()); mSbBottomDashLineMargin.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - mCouponView.setBottomDashLineMargin(dp2Px(progress)); + mCouponView.setDashLineMarginBottom(dp2Px(progress)); } @Override @@ -229,11 +228,11 @@ public void onStopTrackingTouch(SeekBar seekBar) { } }); - mSbLeftDashLineMargin.setProgress((int) mCouponView.getLeftDashLineMargin()); + mSbLeftDashLineMargin.setProgress((int) mCouponView.getDashLineMarginLeft()); mSbLeftDashLineMargin.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - mCouponView.setLeftDashLineMargin(dp2Px(progress)); + mCouponView.setDashLineMarginLeft(dp2Px(progress)); } @Override @@ -247,11 +246,11 @@ public void onStopTrackingTouch(SeekBar seekBar) { } }); - mSbRightDashLineMargin.setProgress((int) mCouponView.getRightDashLineMargin()); + mSbRightDashLineMargin.setProgress((int) mCouponView.getDashLineMarginRight()); mSbRightDashLineMargin.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - mCouponView.setRightDashLineMargin(dp2Px(progress)); + mCouponView.setDashLineMarginRight(dp2Px(progress)); } @Override diff --git a/app/src/main/java/yyydjk/com/couponview/fragments/CouponDashLineFragment.java b/app/src/main/java/yyydjk/com/couponview/fragments/CouponDashLineFragment.java index 192b7ac..77b0028 100644 --- a/app/src/main/java/yyydjk/com/couponview/fragments/CouponDashLineFragment.java +++ b/app/src/main/java/yyydjk/com/couponview/fragments/CouponDashLineFragment.java @@ -32,6 +32,7 @@ public class CouponDashLineFragment extends Fragment { private CommonAdapter commonAdapter; private List list = new ArrayList<>(); + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -63,7 +64,7 @@ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, Recycle outRect.set(dp2Px(6), dp2Px(6), dp2Px(6), 0); } }); - mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(),2)); + mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2)); mRecyclerView.setAdapter(commonAdapter); } diff --git a/app/src/main/java/yyydjk/com/couponview/widget/CouponImageView.java b/app/src/main/java/yyydjk/com/couponview/widget/CouponImageView.java index 1066b59..d2fceb5 100644 --- a/app/src/main/java/yyydjk/com/couponview/widget/CouponImageView.java +++ b/app/src/main/java/yyydjk/com/couponview/widget/CouponImageView.java @@ -95,99 +95,99 @@ public void setDashLineColor(int dashLineColor) { helper.setDashLineColor(dashLineColor); } - public boolean isTopSemicircle() { - return helper.isTopSemicircle(); + public boolean isSemicircleTop() { + return helper.isSemicircleTop(); } - public void setTopSemicircle(boolean topSemicircle) { - helper.setTopSemicircle(topSemicircle); + public void setSemicircleTop(boolean semicircleTop) { + helper.setSemicircleTop(semicircleTop); } - public boolean isBottomSemicircle() { - return helper.isBottomSemicircle(); + public boolean isSemicircleBottom() { + return helper.isSemicircleBottom(); } - public void setBottomSemicircle(boolean bottomSemicircle) { - helper.setBottomSemicircle(bottomSemicircle); + public void setSemicircleBottom(boolean semicircleBottom) { + helper.setSemicircleBottom(semicircleBottom); } - public boolean isLeftSemicircle() { - return helper.isLeftSemicircle(); + public boolean isSemicircleLeft() { + return helper.isSemicircleLeft(); } - public void setLeftSemicircle(boolean leftSemicircle) { - helper.setLeftSemicircle(leftSemicircle); + public void setSemicircleLeft(boolean semicircleLeft) { + helper.setSemicircleLeft(semicircleLeft); } - public boolean isRightSemicircle() { - return helper.isRightSemicircle(); + public boolean isSemicircleRight() { + return helper.isSemicircleRight(); } - public void setRightSemicircle(boolean rightSemicircle) { - helper.setRightSemicircle(rightSemicircle); + public void setSemicircleRight(boolean semicircleRight) { + helper.setSemicircleRight(semicircleRight); } - public boolean isTopDashLine() { - return helper.isTopDashLine(); + public boolean isDashLineTop() { + return helper.isDashLineTop(); } - public void setTopDashLine(boolean topDashLine) { - helper.setTopDashLine(topDashLine); + public void setDashLineTop(boolean dashLineTop) { + helper.setDashLineTop(dashLineTop); } - public boolean isBottomDashLine() { - return helper.isBottomDashLine(); + public boolean DashLineBottom() { + return helper.isDashLineBottom(); } - public void setBottomDashLine(boolean bottomDashLine) { - helper.setBottomDashLine(bottomDashLine); + public void setDashLineBottom(boolean dashLineBottom) { + helper.setDashLineBottom(dashLineBottom); } - public boolean isLeftDashLine() { - return helper.isLeftDashLine(); + public boolean isDashLineLeft() { + return helper.isDashLineLeft(); } - public void setLeftDashLine(boolean leftDashLine) { - helper.setLeftDashLine(leftDashLine); + public void setDashLineLeft(boolean dashLineLeft) { + helper.setDashLineLeft(dashLineLeft); } - public boolean isRightDashLine() { - return helper.isRightDashLine(); + public boolean isDashLineRight() { + return helper.isDashLineRight(); } - public void setRightDashLine(boolean rightDashLine) { - helper.setRightDashLine(rightDashLine); + public void setDashLineRight(boolean dashLineRight) { + helper.setDashLineRight(dashLineRight); } - public float getTopDashLineMargin() { - return helper.getTopDashLineMargin(); + public float getDashLineMarginTop() { + return helper.getDashLineMarginTop(); } - public void setTopDashLineMargin(float topDashLineMargin) { - helper.setTopDashLineMargin(topDashLineMargin); + public void setDashLineMarginTop(float dashLineMarginTop) { + helper.setDashLineMarginTop(dashLineMarginTop); } - public float getBottomDashLineMargin() { - return helper.getBottomDashLineMargin(); + public float getDashLineMarginBottom() { + return helper.getDashLineMarginBottom(); } - public void setBottomDashLineMargin(float bottomDashLineMargin) { - helper.setBottomDashLineMargin(bottomDashLineMargin); + public void setDashLineMarginBottom(float dashLineMarginBottom) { + helper.setDashLineMarginBottom(dashLineMarginBottom); } - public float getLeftDashLineMargin() { - return helper.getLeftDashLineMargin(); + public float getDashLineMarginLeft() { + return helper.getDashLineMarginLeft(); } - public void setLeftDashLineMargin(float leftDashLineMargin) { - helper.setLeftDashLineMargin(leftDashLineMargin); + public void setDashLineMarginLeft(float dashLineMarginLeft) { + helper.setDashLineMarginLeft(dashLineMarginLeft); } - public float getRightDashLineMargin() { - return helper.getRightDashLineMargin(); + public float getDashLineMarginRight() { + return helper.getDashLineMarginRight(); } - public void setRightDashLineMargin(float rightDashLineMargin) { - helper.setRightDashLineMargin(rightDashLineMargin); + public void setDashLineMarginRight(float dashLineMarginRight) { + helper.setDashLineMarginRight(dashLineMarginRight); } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7a6d7f0..b63e766 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -16,8 +16,8 @@ android:layout_height="wrap_content"/> + android:id="@+id/pager" + android:layout_width="match_parent" + android:layout_height="match_parent"/> diff --git a/app/src/main/res/layout/fragment_coupon_custom.xml b/app/src/main/res/layout/fragment_coupon_custom.xml index fe367e0..28b5868 100644 --- a/app/src/main/res/layout/fragment_coupon_custom.xml +++ b/app/src/main/res/layout/fragment_coupon_custom.xml @@ -15,17 +15,17 @@ android:background="@color/colorGreenPrimary" android:orientation="vertical" android:padding="10dp" - app:cv_bottom_dash_line_margin="5dp" app:cv_dash_line_color="@android:color/white" app:cv_dash_line_gap="10dp" app:cv_dash_line_height="2dp" app:cv_dash_line_length="10dp" - app:cv_left_dash_line_margin="50dp" - app:cv_right_dash_line_margin="50dp" + app:cv_dash_line_margin_bottom="5dp" + app:cv_dash_line_margin_left="50dp" + app:cv_dash_line_margin_right="50dp" + app:cv_dash_line_margin_top="5dp" app:cv_semicircle_color="@android:color/white" app:cv_semicircle_gap="8dp" - app:cv_semicircle_radius="4dp" - app:cv_top_dash_line_margin="5dp"/> + app:cv_semicircle_radius="4dp"/> diff --git a/app/src/main/res/layout/item_coupon_combination.xml b/app/src/main/res/layout/item_coupon_combination.xml index 894b98f..8c8f03b 100644 --- a/app/src/main/res/layout/item_coupon_combination.xml +++ b/app/src/main/res/layout/item_coupon_combination.xml @@ -11,14 +11,14 @@ app:cv_dash_line_gap="5dp" app:cv_dash_line_height="2dp" app:cv_dash_line_length="10dp" - app:cv_is_bottom_dash_line="true" - app:cv_is_bottom_semicircle="false" - app:cv_is_left_dash_line="true" - app:cv_is_left_semicircle="false" - app:cv_is_right_dash_line="true" - app:cv_is_right_semicircle="false" - app:cv_is_top_dash_line="false" - app:cv_is_top_semicircle="true" + app:cv_is_dash_line_bottom="true" + app:cv_is_dash_line_left="true" + app:cv_is_dash_line_right="true" + app:cv_is_dash_line_top="false" + app:cv_is_semicircle_bottom="false" + app:cv_is_semicircle_left="false" + app:cv_is_semicircle_right="false" + app:cv_is_semicircle_top="true" app:cv_semicircle_color="@android:color/white" app:cv_semicircle_gap="8dp" app:cv_semicircle_radius="4dp"/> diff --git a/app/src/main/res/layout/item_coupon_dash_line.xml b/app/src/main/res/layout/item_coupon_dash_line.xml index c42745b..ae4bc63 100644 --- a/app/src/main/res/layout/item_coupon_dash_line.xml +++ b/app/src/main/res/layout/item_coupon_dash_line.xml @@ -12,14 +12,14 @@ app:cv_dash_line_gap="5dp" app:cv_dash_line_height="2dp" app:cv_dash_line_length="10dp" - app:cv_is_bottom_dash_line="true" - app:cv_is_bottom_semicircle="false" - app:cv_is_left_dash_line="true" - app:cv_is_left_semicircle="false" - app:cv_is_right_dash_line="true" - app:cv_is_right_semicircle="false" - app:cv_is_top_dash_line="true" - app:cv_is_top_semicircle="false" + app:cv_is_dash_line_bottom="true" + app:cv_is_dash_line_left="true" + app:cv_is_dash_line_right="true" + app:cv_is_dash_line_top="true" + app:cv_is_semicircle_bottom="false" + app:cv_is_semicircle_left="false" + app:cv_is_semicircle_right="false" + app:cv_is_semicircle_top="false" app:cv_semicircle_color="@android:color/white" app:cv_semicircle_gap="8dp" app:cv_semicircle_radius="4dp"/> diff --git a/app/src/main/res/layout/item_coupon_semi_circle.xml b/app/src/main/res/layout/item_coupon_semi_circle.xml index 49b6ef1..26c5ad6 100644 --- a/app/src/main/res/layout/item_coupon_semi_circle.xml +++ b/app/src/main/res/layout/item_coupon_semi_circle.xml @@ -11,14 +11,14 @@ app:cv_dash_line_gap="5dp" app:cv_dash_line_height="2dp" app:cv_dash_line_length="10dp" - app:cv_is_bottom_dash_line="false" - app:cv_is_bottom_semicircle="true" - app:cv_is_left_dash_line="false" - app:cv_is_left_semicircle="true" - app:cv_is_right_dash_line="false" - app:cv_is_right_semicircle="true" - app:cv_is_top_dash_line="false" - app:cv_is_top_semicircle="true" + app:cv_is_dash_line_bottom="false" + app:cv_is_dash_line_left="false" + app:cv_is_dash_line_right="false" + app:cv_is_dash_line_top="false" + app:cv_is_semicircle_bottom="true" + app:cv_is_semicircle_left="true" + app:cv_is_semicircle_right="true" + app:cv_is_semicircle_top="true" app:cv_semicircle_color="@android:color/white" app:cv_semicircle_gap="8dp" app:cv_semicircle_radius="4dp"/> diff --git a/app/src/test/java/yyydjk/com/couponview/ExampleUnitTest.java b/app/src/test/java/yyydjk/com/couponview/ExampleUnitTest.java index a5c70de..30e01ed 100644 --- a/app/src/test/java/yyydjk/com/couponview/ExampleUnitTest.java +++ b/app/src/test/java/yyydjk/com/couponview/ExampleUnitTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * Example local unit test, which will execute on the development machine (host). diff --git a/library/src/main/java/yyydjk/com/library/CouponView.java b/library/src/main/java/yyydjk/com/library/CouponView.java index b3af525..b504099 100644 --- a/library/src/main/java/yyydjk/com/library/CouponView.java +++ b/library/src/main/java/yyydjk/com/library/CouponView.java @@ -90,99 +90,99 @@ public void setDashLineColor(int dashLineColor) { helper.setDashLineColor(dashLineColor); } - public boolean isTopSemicircle() { - return helper.isTopSemicircle(); + public boolean isSemicircleTop() { + return helper.isSemicircleTop(); } - public void setTopSemicircle(boolean topSemicircle) { - helper.setTopSemicircle(topSemicircle); + public void setSemicircleTop(boolean semicircleTop) { + helper.setSemicircleTop(semicircleTop); } - public boolean isBottomSemicircle() { - return helper.isBottomSemicircle(); + public boolean isSemicircleBottom() { + return helper.isSemicircleBottom(); } - public void setBottomSemicircle(boolean bottomSemicircle) { - helper.setBottomSemicircle(bottomSemicircle); + public void setSemicircleBottom(boolean semicircleBottom) { + helper.setSemicircleBottom(semicircleBottom); } - public boolean isLeftSemicircle() { - return helper.isLeftSemicircle(); + public boolean isSemicircleLeft() { + return helper.isSemicircleLeft(); } - public void setLeftSemicircle(boolean leftSemicircle) { - helper.setLeftSemicircle(leftSemicircle); + public void setSemicircleLeft(boolean semicircleLeft) { + helper.setSemicircleLeft(semicircleLeft); } - public boolean isRightSemicircle() { - return helper.isRightSemicircle(); + public boolean isSemicircleRight() { + return helper.isSemicircleRight(); } - public void setRightSemicircle(boolean rightSemicircle) { - helper.setRightSemicircle(rightSemicircle); + public void setSemicircleRight(boolean semicircleRight) { + helper.setSemicircleRight(semicircleRight); } - public boolean isTopDashLine() { - return helper.isTopDashLine(); + public boolean isDashLineTop() { + return helper.isDashLineTop(); } - public void setTopDashLine(boolean topDashLine) { - helper.setTopDashLine(topDashLine); + public void setDashLineTop(boolean dashLineTop) { + helper.setDashLineTop(dashLineTop); } - public boolean isBottomDashLine() { - return helper.isBottomDashLine(); + public boolean DashLineBottom() { + return helper.isDashLineBottom(); } - public void setBottomDashLine(boolean bottomDashLine) { - helper.setBottomDashLine(bottomDashLine); + public void setDashLineBottom(boolean dashLineBottom) { + helper.setDashLineBottom(dashLineBottom); } - public boolean isLeftDashLine() { - return helper.isLeftDashLine(); + public boolean isDashLineLeft() { + return helper.isDashLineLeft(); } - public void setLeftDashLine(boolean leftDashLine) { - helper.setLeftDashLine(leftDashLine); + public void setDashLineLeft(boolean dashLineLeft) { + helper.setDashLineLeft(dashLineLeft); } - public boolean isRightDashLine() { - return helper.isRightDashLine(); + public boolean isDashLineRight() { + return helper.isDashLineRight(); } - public void setRightDashLine(boolean rightDashLine) { - helper.setRightDashLine(rightDashLine); + public void setDashLineRight(boolean dashLineRight) { + helper.setDashLineRight(dashLineRight); } - public float getTopDashLineMargin() { - return helper.getTopDashLineMargin(); + public float getDashLineMarginTop() { + return helper.getDashLineMarginTop(); } - public void setTopDashLineMargin(float topDashLineMargin) { - helper.setTopDashLineMargin(topDashLineMargin); + public void setDashLineMarginTop(float dashLineMarginTop) { + helper.setDashLineMarginTop(dashLineMarginTop); } - public float getBottomDashLineMargin() { - return helper.getBottomDashLineMargin(); + public float getDashLineMarginBottom() { + return helper.getDashLineMarginBottom(); } - public void setBottomDashLineMargin(float bottomDashLineMargin) { - helper.setBottomDashLineMargin(bottomDashLineMargin); + public void setDashLineMarginBottom(float dashLineMarginBottom) { + helper.setDashLineMarginBottom(dashLineMarginBottom); } - public float getLeftDashLineMargin() { - return helper.getLeftDashLineMargin(); + public float getDashLineMarginLeft() { + return helper.getDashLineMarginLeft(); } - public void setLeftDashLineMargin(float leftDashLineMargin) { - helper.setLeftDashLineMargin(leftDashLineMargin); + public void setDashLineMarginLeft(float dashLineMarginLeft) { + helper.setDashLineMarginLeft(dashLineMarginLeft); } - public float getRightDashLineMargin() { - return helper.getRightDashLineMargin(); + public float getDashLineMarginRight() { + return helper.getDashLineMarginRight(); } - public void setRightDashLineMargin(float rightDashLineMargin) { - helper.setRightDashLineMargin(rightDashLineMargin); + public void setDashLineMarginRight(float dashLineMarginRight) { + helper.setDashLineMarginRight(dashLineMarginRight); } } diff --git a/library/src/main/java/yyydjk/com/library/CouponViewHelper.java b/library/src/main/java/yyydjk/com/library/CouponViewHelper.java index 8acc065..4a6db46 100644 --- a/library/src/main/java/yyydjk/com/library/CouponViewHelper.java +++ b/library/src/main/java/yyydjk/com/library/CouponViewHelper.java @@ -78,28 +78,28 @@ public class CouponViewHelper { private int dashLineNumY; //开启顶部半圆曲线 - private boolean isTopSemicircle = true; + private boolean isSemicircleTop = true; //开启底部半圆曲线 - private boolean isBottomSemicircle = true; + private boolean isSemicircleBottom = true; //开启左边半圆曲线 - private boolean isLeftSemicircle = false; + private boolean isSemicircleLeft = false; //开启右边半圆曲线 - private boolean isRightSemicircle = false; + private boolean isSemicircleRight = false; //开启顶部虚线 - private boolean isTopDashLine = false; + private boolean isDashLineTop = false; //开启底部虚线 - private boolean isBottomDashLine = false; + private boolean isDashLineBottom = false; //开启左边虚线 - private boolean isLeftDashLine = true; + private boolean isDashLineLeft = true; //开启左边虚线 - private boolean isRightDashLine = true; + private boolean isDashLineRight = true; //view宽度 private int viewWidth; @@ -108,16 +108,16 @@ public class CouponViewHelper { private int viewHeight; //顶部虚线距离View顶部的距离 - private float topDashLineMargin = DEFAULT_DASH_LINE_MARGIN; + private float dashLineMarginTop = DEFAULT_DASH_LINE_MARGIN; //底部虚线距离View底部的距离 - private float bottomDashLineMargin = DEFAULT_DASH_LINE_MARGIN; + private float dashLineMarginBottom = DEFAULT_DASH_LINE_MARGIN; //左侧虚线距离View左侧的距离 - private float leftDashLineMargin = DEFAULT_DASH_LINE_MARGIN; + private float dashLineMarginLeft = DEFAULT_DASH_LINE_MARGIN; //右侧虚线距离View右侧的距离 - private float rightDashLineMargin = DEFAULT_DASH_LINE_MARGIN; + private float dashLineMarginRight = DEFAULT_DASH_LINE_MARGIN; public CouponViewHelper(View view, Context context, AttributeSet attrs, int defStyle) { @@ -133,19 +133,19 @@ public CouponViewHelper(View view, Context context, AttributeSet attrs, int defS dashLineLength = a.getDimensionPixelSize(R.styleable.CouponView_cv_dash_line_length, dp2Px(DEFAULT_DASH_LINE_LENGTH)); dashLineColor = a.getColor(R.styleable.CouponView_cv_dash_line_color, DEFAULT_DASH_LINE_COLOR); - isTopSemicircle = a.getBoolean(R.styleable.CouponView_cv_is_top_semicircle, isTopSemicircle); - isBottomSemicircle = a.getBoolean(R.styleable.CouponView_cv_is_bottom_semicircle, isBottomSemicircle); - isLeftSemicircle = a.getBoolean(R.styleable.CouponView_cv_is_left_semicircle, isLeftSemicircle); - isRightSemicircle = a.getBoolean(R.styleable.CouponView_cv_is_right_semicircle, isRightSemicircle); - isTopDashLine = a.getBoolean(R.styleable.CouponView_cv_is_top_dash_line, isTopDashLine); - isBottomDashLine = a.getBoolean(R.styleable.CouponView_cv_is_bottom_dash_line, isBottomDashLine); - isLeftDashLine = a.getBoolean(R.styleable.CouponView_cv_is_left_dash_line, isLeftDashLine); - isRightDashLine = a.getBoolean(R.styleable.CouponView_cv_is_right_dash_line, isRightDashLine); + isSemicircleTop = a.getBoolean(R.styleable.CouponView_cv_is_semicircle_top, isSemicircleTop); + isSemicircleBottom = a.getBoolean(R.styleable.CouponView_cv_is_semicircle_bottom, isSemicircleBottom); + isSemicircleLeft = a.getBoolean(R.styleable.CouponView_cv_is_semicircle_left, isSemicircleLeft); + isSemicircleRight = a.getBoolean(R.styleable.CouponView_cv_is_semicircle_right, isSemicircleRight); + isDashLineTop = a.getBoolean(R.styleable.CouponView_cv_is_dash_line_top, isDashLineTop); + isDashLineBottom = a.getBoolean(R.styleable.CouponView_cv_is_dash_line_bottom, isDashLineBottom); + isDashLineLeft = a.getBoolean(R.styleable.CouponView_cv_is_dash_line_left, isDashLineLeft); + isDashLineRight = a.getBoolean(R.styleable.CouponView_cv_is_dash_line_right, isDashLineRight); - topDashLineMargin = a.getDimensionPixelSize(R.styleable.CouponView_cv_top_dash_line_margin, dp2Px(DEFAULT_DASH_LINE_MARGIN)); - bottomDashLineMargin = a.getDimensionPixelSize(R.styleable.CouponView_cv_bottom_dash_line_margin, dp2Px(DEFAULT_DASH_LINE_MARGIN)); - leftDashLineMargin = a.getDimensionPixelSize(R.styleable.CouponView_cv_left_dash_line_margin, dp2Px(DEFAULT_DASH_LINE_MARGIN)); - rightDashLineMargin = a.getDimensionPixelSize(R.styleable.CouponView_cv_right_dash_line_margin, dp2Px(DEFAULT_DASH_LINE_MARGIN)); + dashLineMarginTop = a.getDimensionPixelSize(R.styleable.CouponView_cv_dash_line_margin_top, dp2Px(DEFAULT_DASH_LINE_MARGIN)); + dashLineMarginBottom = a.getDimensionPixelSize(R.styleable.CouponView_cv_dash_line_margin_bottom, dp2Px(DEFAULT_DASH_LINE_MARGIN)); + dashLineMarginLeft = a.getDimensionPixelSize(R.styleable.CouponView_cv_dash_line_margin_left, dp2Px(DEFAULT_DASH_LINE_MARGIN)); + dashLineMarginRight = a.getDimensionPixelSize(R.styleable.CouponView_cv_dash_line_margin_right, dp2Px(DEFAULT_DASH_LINE_MARGIN)); a.recycle(); init(); @@ -171,67 +171,67 @@ public void onSizeChanged(int w, int h) { } private void calculate() { - if (isTopSemicircle || isBottomSemicircle) { + if (isSemicircleTop || isSemicircleBottom) { remindSemicircleX = (int) ((viewWidth - semicircleGap) % (2 * semicircleRadius + semicircleGap)); semicircleNumX = (int) ((viewWidth - semicircleGap) / (2 * semicircleRadius + semicircleGap)); } - if (isLeftSemicircle || isRightSemicircle) { + if (isSemicircleLeft || isSemicircleRight) { remindSemicircleY = (int) ((viewHeight - semicircleGap) % (2 * semicircleRadius + semicircleGap)); semicircleNumY = (int) ((viewHeight - semicircleGap) / (2 * semicircleRadius + semicircleGap)); } - if (isTopDashLine || isBottomDashLine && remindDashLineX == 0) { - remindDashLineX = (int) ((viewWidth + dashLineGap - leftDashLineMargin - rightDashLineMargin) % (dashLineLength + dashLineGap)); - dashLineNumX = (int) ((viewWidth + dashLineGap - leftDashLineMargin - rightDashLineMargin) / (dashLineLength + dashLineGap)); + if (isDashLineTop || isDashLineBottom && remindDashLineX == 0) { + remindDashLineX = (int) ((viewWidth + dashLineGap - dashLineMarginLeft - dashLineMarginRight) % (dashLineLength + dashLineGap)); + dashLineNumX = (int) ((viewWidth + dashLineGap - dashLineMarginLeft - dashLineMarginRight) / (dashLineLength + dashLineGap)); } - if (isLeftDashLine || isRightDashLine) { - remindDashLineY = (int) ((viewHeight + dashLineGap - topDashLineMargin - bottomDashLineMargin) % (dashLineLength + dashLineGap)); - dashLineNumY = (int) ((viewHeight + dashLineGap - topDashLineMargin - bottomDashLineMargin) / (dashLineLength + dashLineGap)); + if (isDashLineLeft || isDashLineRight) { + remindDashLineY = (int) ((viewHeight + dashLineGap - dashLineMarginTop - dashLineMarginBottom) % (dashLineLength + dashLineGap)); + dashLineNumY = (int) ((viewHeight + dashLineGap - dashLineMarginTop - dashLineMarginBottom) / (dashLineLength + dashLineGap)); } } public void onDraw(Canvas canvas) { - if (isTopSemicircle) + if (isSemicircleTop) for (int i = 0; i < semicircleNumX; i++) { float x = semicircleGap + semicircleRadius + remindSemicircleX / 2 + (semicircleGap + semicircleRadius * 2) * i; canvas.drawCircle(x, 0, semicircleRadius, semicirclePaint); } - if (isBottomSemicircle) + if (isSemicircleBottom) for (int i = 0; i < semicircleNumX; i++) { float x = semicircleGap + semicircleRadius + remindSemicircleX / 2 + (semicircleGap + semicircleRadius * 2) * i; canvas.drawCircle(x, viewHeight, semicircleRadius, semicirclePaint); } - if (isLeftSemicircle) + if (isSemicircleLeft) for (int i = 0; i < semicircleNumY; i++) { float y = semicircleGap + semicircleRadius + remindSemicircleY / 2 + (semicircleGap + semicircleRadius * 2) * i; canvas.drawCircle(0, y, semicircleRadius, semicirclePaint); } - if (isRightSemicircle) + if (isSemicircleRight) for (int i = 0; i < semicircleNumY; i++) { float y = semicircleGap + semicircleRadius + remindSemicircleY / 2 + (semicircleGap + semicircleRadius * 2) * i; canvas.drawCircle(viewWidth, y, semicircleRadius, semicirclePaint); } - if (isTopDashLine) + if (isDashLineTop) for (int i = 0; i < dashLineNumX; i++) { - float x = leftDashLineMargin + remindDashLineX / 2 + (dashLineGap + dashLineLength) * i; - canvas.drawRect(x, topDashLineMargin, x + dashLineLength, topDashLineMargin + dashLineHeight, dashLinePaint); + float x = dashLineMarginLeft + remindDashLineX / 2 + (dashLineGap + dashLineLength) * i; + canvas.drawRect(x, dashLineMarginTop, x + dashLineLength, dashLineMarginTop + dashLineHeight, dashLinePaint); } - if (isBottomDashLine) + if (isDashLineBottom) for (int i = 0; i < dashLineNumX; i++) { - float x = leftDashLineMargin + remindDashLineX / 2 + (dashLineGap + dashLineLength) * i; - canvas.drawRect(x, viewHeight - dashLineHeight - bottomDashLineMargin, x + dashLineLength, viewHeight - bottomDashLineMargin, dashLinePaint); + float x = dashLineMarginLeft + remindDashLineX / 2 + (dashLineGap + dashLineLength) * i; + canvas.drawRect(x, viewHeight - dashLineHeight - dashLineMarginBottom, x + dashLineLength, viewHeight - dashLineMarginBottom, dashLinePaint); } - if (isLeftDashLine) + if (isDashLineLeft) for (int i = 0; i < dashLineNumY; i++) { - float y = topDashLineMargin + remindDashLineY / 2 + (dashLineGap + dashLineLength) * i; - canvas.drawRect(leftDashLineMargin, y, leftDashLineMargin + dashLineHeight, y + dashLineLength, dashLinePaint); + float y = dashLineMarginTop + remindDashLineY / 2 + (dashLineGap + dashLineLength) * i; + canvas.drawRect(dashLineMarginLeft, y, dashLineMarginLeft + dashLineHeight, y + dashLineLength, dashLinePaint); } - if (isRightDashLine) + if (isDashLineRight) for (int i = 0; i < dashLineNumY; i++) { - float y = topDashLineMargin + remindDashLineY / 2 + (dashLineGap + dashLineLength) * i; - canvas.drawRect(viewWidth - rightDashLineMargin - dashLineHeight, y, viewWidth - rightDashLineMargin, y + dashLineLength, dashLinePaint); + float y = dashLineMarginTop + remindDashLineY / 2 + (dashLineGap + dashLineLength) * i; + canvas.drawRect(viewWidth - dashLineMarginRight - dashLineHeight, y, viewWidth - dashLineMarginRight, y + dashLineLength, dashLinePaint); } } @@ -327,145 +327,145 @@ public void setDashLineColor(int dashLineColor) { } } - public boolean isTopSemicircle() { - return isTopSemicircle; + public boolean isSemicircleTop() { + return isSemicircleTop; } - public void setTopSemicircle(boolean topSemicircle) { - if (this.isTopSemicircle != topSemicircle) { - isTopSemicircle = topSemicircle; + public void setSemicircleTop(boolean semicircleTop) { + if (this.isSemicircleTop != semicircleTop) { + isSemicircleTop = semicircleTop; calculate(); view.invalidate(); } } - public boolean isBottomSemicircle() { - return isBottomSemicircle; + public boolean isSemicircleBottom() { + return isSemicircleBottom; } - public void setBottomSemicircle(boolean bottomSemicircle) { - if (isBottomSemicircle != bottomSemicircle) { - isBottomSemicircle = bottomSemicircle; + public void setSemicircleBottom(boolean semicircleBottom) { + if (isSemicircleBottom != semicircleBottom) { + isSemicircleBottom = semicircleBottom; calculate(); view.invalidate(); } } - public boolean isLeftSemicircle() { - return isLeftSemicircle; + public boolean isSemicircleLeft() { + return isSemicircleLeft; } - public void setLeftSemicircle(boolean leftSemicircle) { - if (isLeftSemicircle != leftSemicircle) { - isLeftSemicircle = leftSemicircle; + public void setSemicircleLeft(boolean semicircleLeft) { + if (isSemicircleLeft != semicircleLeft) { + isSemicircleLeft = semicircleLeft; calculate(); view.invalidate(); } } - public boolean isRightSemicircle() { - return isRightSemicircle; + public boolean isSemicircleRight() { + return isSemicircleRight; } - public void setRightSemicircle(boolean rightSemicircle) { - if (isRightSemicircle != rightSemicircle) { - isRightSemicircle = rightSemicircle; + public void setSemicircleRight(boolean semicircleRight) { + if (isSemicircleRight != semicircleRight) { + isSemicircleRight = semicircleRight; calculate(); view.invalidate(); } } - public boolean isTopDashLine() { - return isTopDashLine; + public boolean isDashLineTop() { + return isDashLineTop; } - public void setTopDashLine(boolean topDashLine) { - if (isTopDashLine != topDashLine) { - isTopDashLine = topDashLine; + public void setDashLineTop(boolean dashLineTop) { + if (isDashLineTop != dashLineTop) { + isDashLineTop = dashLineTop; calculate(); view.invalidate(); } } - public boolean isBottomDashLine() { - return isBottomDashLine; + public boolean isDashLineBottom() { + return isDashLineBottom; } - public void setBottomDashLine(boolean bottomDashLine) { - if (isBottomDashLine != bottomDashLine) { - isBottomDashLine = bottomDashLine; + public void setDashLineBottom(boolean dashLineBottom) { + if (isDashLineBottom != dashLineBottom) { + isDashLineBottom = dashLineBottom; calculate(); view.invalidate(); } } - public boolean isLeftDashLine() { - return isLeftDashLine; + public boolean isDashLineLeft() { + return isDashLineLeft; } - public void setLeftDashLine(boolean leftDashLine) { - if (isLeftDashLine != leftDashLine) { - isLeftDashLine = leftDashLine; + public void setDashLineLeft(boolean dashLineLeft) { + if (isDashLineLeft != dashLineLeft) { + isDashLineLeft = dashLineLeft; calculate(); view.invalidate(); } } - public boolean isRightDashLine() { - return isRightDashLine; + public boolean isDashLineRight() { + return isDashLineRight; } - public void setRightDashLine(boolean rightDashLine) { - if (isRightDashLine != rightDashLine) { - isRightDashLine = rightDashLine; + public void setDashLineRight(boolean dashLineRight) { + if (isDashLineRight != dashLineRight) { + isDashLineRight = dashLineRight; calculate(); view.invalidate(); } } - public float getTopDashLineMargin() { - return px2Dp(topDashLineMargin); + public float getDashLineMarginTop() { + return px2Dp(dashLineMarginTop); } - public void setTopDashLineMargin(float topDashLineMargin) { - if (this.topDashLineMargin != topDashLineMargin) { - this.topDashLineMargin = topDashLineMargin; + public void setDashLineMarginTop(float dashLineMarginTop) { + if (this.dashLineMarginTop != dashLineMarginTop) { + this.dashLineMarginTop = dashLineMarginTop; calculate(); view.invalidate(); } } - public float getBottomDashLineMargin() { - return px2Dp(bottomDashLineMargin); + public float getDashLineMarginBottom() { + return px2Dp(dashLineMarginBottom); } - public void setBottomDashLineMargin(float bottomDashLineMargin) { - if (this.bottomDashLineMargin != bottomDashLineMargin) { - this.bottomDashLineMargin = bottomDashLineMargin; + public void setDashLineMarginBottom(float dashLineMarginBottom) { + if (this.dashLineMarginBottom != dashLineMarginBottom) { + this.dashLineMarginBottom = dashLineMarginBottom; calculate(); view.invalidate(); } } - public float getLeftDashLineMargin() { - return px2Dp(leftDashLineMargin); + public float getDashLineMarginLeft() { + return px2Dp(dashLineMarginLeft); } - public void setLeftDashLineMargin(float leftDashLineMargin) { - if (this.leftDashLineMargin != leftDashLineMargin) { - this.leftDashLineMargin = leftDashLineMargin; + public void setDashLineMarginLeft(float dashLineMarginLeft) { + if (this.dashLineMarginLeft != dashLineMarginLeft) { + this.dashLineMarginLeft = dashLineMarginLeft; calculate(); view.invalidate(); } } - public float getRightDashLineMargin() { - return px2Dp(rightDashLineMargin); + public float getDashLineMarginRight() { + return px2Dp(dashLineMarginRight); } - public void setRightDashLineMargin(float rightDashLineMargin) { - if (this.rightDashLineMargin != rightDashLineMargin) { - this.rightDashLineMargin = rightDashLineMargin; + public void setDashLineMarginRight(float dashLineMarginRight) { + if (this.dashLineMarginRight != dashLineMarginRight) { + this.dashLineMarginRight = dashLineMarginRight; calculate(); view.invalidate(); } diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index e958d99..9d56568 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -8,17 +8,17 @@ - - - - - - - - - - - - + + + + + + + + + + + +