Skip to content
Browse files

v1.0

  • Loading branch information...
1 parent 842b9ca commit e36b4407dcc688d5df73757c6e988b21470e00da @CaMnter committed
View
1 app/src/main/AndroidManifest.xml
@@ -15,6 +15,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+ <activity android:name=".StyleActivity" />
</application>
</manifest>
View
22 app/src/main/java/com/camnter/easycountdowntextureview/demo/MainActivity.java
@@ -2,13 +2,33 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
+import android.view.View;
-public class MainActivity extends AppCompatActivity {
+import com.camnter.easycountdowntextureview.EasyCountDownTextureView;
+
+public class MainActivity extends AppCompatActivity implements View.OnClickListener {
+
+ EasyCountDownTextureView edtv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
+ this.findViewById(R.id.style_bt).setOnClickListener(this);
+ this.edtv = (EasyCountDownTextureView) this.findViewById(R.id.edtv);
}
+ /**
+ * Called when a view has been clicked.
+ *
+ * @param v The view that was clicked.
+ */
+ @Override
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.style_bt:
+ StyleActivity.startActivity(this);
+ break;
+ }
+ }
}
View
25 app/src/main/java/com/camnter/easycountdowntextureview/demo/StyleActivity.java
@@ -0,0 +1,25 @@
+package com.camnter.easycountdowntextureview.demo;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+
+/**
+ * Description:StyleActivity
+ * Created by:CaMnter
+ * Time:2016-03-17 17:20
+ */
+public class StyleActivity extends AppCompatActivity {
+
+ public static void startActivity(Context context) {
+ context.startActivity(new Intent(context, StyleActivity.class));
+ }
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ this.setContentView(R.layout.activity_style);
+ }
+}
View
27 app/src/main/res/layout/activity_main.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout 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"
@@ -13,6 +14,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_marginBottom="50dp"
android:background="#ffffffff">
<ImageView
@@ -23,14 +25,27 @@
android:src="@mipmap/bg_fruit" />
<com.camnter.easycountdowntextureview.EasyCountDownTextureView
+ android:id="@+id/edtv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:paddingEnd="6dp"
- android:paddingLeft="6dp"
- android:paddingRight="6dp"
- android:paddingStart="6dp" />
+ app:easyCountHour="6"
+ app:easyCountMinute="6"
+ app:easyCountSecond="26" />
</RelativeLayout>
+ <Button
+ android:id="@+id/style_bt"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true"
+ android:layout_margin="16dp"
+ android:paddingBottom="4dp"
+ android:paddingEnd="8dp"
+ android:paddingLeft="8dp"
+ android:paddingRight="8dp"
+ android:paddingStart="8dp"
+ android:paddingTop="4dp"
+ android:text="@string/style_bt" />
-</LinearLayout>
+</RelativeLayout>
View
31 app/src/main/res/layout/activity_style.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout 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"
+ android:paddingBottom="@dimen/activity_vertical_margin"
+ android:paddingLeft="@dimen/activity_horizontal_margin"
+ android:paddingRight="@dimen/activity_horizontal_margin"
+ android:paddingTop="@dimen/activity_vertical_margin"
+ tools:context="com.camnter.easycountdowntextureview.demo.MainActivity">
+
+ <com.camnter.easycountdowntextureview.EasyCountDownTextureView
+ android:layout_width="132dp"
+ android:layout_height="36dp"
+ app:easyCountBackgroundColor="#ffdddddd"
+ app:easyCountColonColor="#ffdddddd"
+ app:easyCountColonSize="20sp"
+ app:easyCountHour="6"
+ app:easyCountMinute="6"
+ app:easyCountRectHeight="34dp"
+ app:easyCountRectRadius="5dp"
+ app:easyCountRectSpacing="12dp"
+ app:easyCountRectWidth="36dp"
+ app:easyCountSecond="26"
+ app:easyCountTimeColor="#ff3A94FF"
+ app:easyCountTimeSize="20sp" />
+
+
+</RelativeLayout>
View
3 app/src/main/res/values/strings.xml
@@ -1,3 +1,4 @@
<resources>
- <string name="app_name">EasyCountDownSurfaceView</string>
+ <string name="app_name">EasyCountDownTextureView</string>
+ <string name="style_bt">Style</string>
</resources>
View
2 build.gradle
@@ -7,6 +7,8 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
+ classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
+ classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
View
89 library/build.gradle
@@ -23,3 +23,92 @@ dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
}
+
+// ---------
+
+apply plugin: 'com.android.library'
+apply plugin: 'com.github.dcendents.android-maven'
+apply plugin: 'com.jfrog.bintray'
+// #CONFIG# // project version
+version = "1.0"
+// #CONFIG# // project homepage
+def siteUrl = 'https://github.com/camnter/EasyCountDownTextureView'
+// #CONFIG# // project git
+def gitUrl = 'https://github.com/camnter/EasyCountDownTextureView.git'
+// #CONFIG# // Maven Group ID for the artifact (package name is ok)
+group = "com.camnter.easycountdowntextureview"
+
+install {
+ repositories.mavenInstaller {
+ // This generates POM.xml with proper parameters
+ pom {
+ project {
+ packaging 'aar'
+ // <Your library description>
+ name 'A easy arc loading For Android'
+ url siteUrl
+ licenses {
+ license {
+ name 'The Apache Software License, Version 2.0'
+ url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+ }
+ }
+ developers {
+ developer {
+ // <your user ID>
+ id 'CaMnter'
+ // <your name>
+ name 'YuanYuZhang'
+ // <your email>
+ email '421482590@qq.com'
+ }
+ }
+ scm {
+ connection gitUrl
+ developerConnection gitUrl
+ url siteUrl
+ }
+ }
+ }
+ }
+}
+task sourcesJar(type: Jar) {
+ from android.sourceSets.main.java.srcDirs
+ classifier = 'sources'
+}
+
+
+task javadoc(type: Javadoc) {
+ source = android.sourceSets.main.java.srcDirs
+ classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
+}
+
+task javadocJar(type: Jar, dependsOn: javadoc) {
+ classifier = 'javadoc'
+ from javadoc.destinationDir
+}
+
+artifacts {
+ archives javadocJar
+ archives sourcesJar
+}
+
+
+
+Properties properties = new Properties()
+properties.load(project.rootProject.file('local.properties').newDataInputStream())
+bintray {
+ user = properties.getProperty("bintray.user")
+ key = properties.getProperty("bintray.apikey")
+ configurations = ['archives']
+ pkg {
+ repo = "maven"
+ name = "EasyCountDownTextureView" // project name in jcenter
+ websiteUrl = siteUrl
+ vcsUrl = gitUrl
+ licenses = ["Apache-2.0"]
+ publish = true
+ }
+}
+
+// ---------------
View
51 library/src/main/java/com/camnter/easycountdowntextureview/EasyCountDownTextureView.java
@@ -36,12 +36,16 @@
private static final int COUNT_DOWN_INTERVAL = 1000;
- private long mMillisInFuture = 1000 * 60 * 6L + 1000 * 60 * 60 * 6L + 1000 * 30L;
+ private static final long ONE_HOUR = 1000 * 60 * 60L;
+ private static final long ONE_MINUTE = 1000 * 60L;
+ private static final long ONE_SECOND = 1000L;
+
+ private long mMillisInFuture = 0L;
/**************
* Default dp *
**************/
- private static final float DEFAULT_BACKGROUND_PAINT_WIDTH = 0.66f;
+ private static final float DEFAULT_BACKGROUND_PAINT_WIDTH = 0.01f;
private static final float DEFAULT_COLON_PAINT_WIDTH = 0.66f;
private static final float DEFAULT_TIME_PAINT_WIDTH = 0.77f;
private static final float DEFAULT_ROUND_RECT_RADIUS = 2.66f;
@@ -53,7 +57,7 @@
// 66dp
private static final float DEFAULT_VIEW_WIDTH = DEFAULT_RECT_WIDTH * 3 + DEFAULT_RECT_SPACING * 2;
- // 18dp
+ // 17dp
private static final float DEFAULT_VIEW_HEIGHT = DEFAULT_RECT_HEIGHT;
/**************
@@ -74,6 +78,9 @@
private float secondTranslateX;
private float secondTranslateColonX;
+ private int timeHour;
+ private int timeMinute;
+ private int timeSecond;
private int viewWidth;
private int viewHeight;
@@ -120,12 +127,15 @@ private void init(Context context, AttributeSet attrs) {
this.mMetrics = this.getResources().getDisplayMetrics();
this.defaultWrapContentWidth = this.dp2px(DEFAULT_VIEW_WIDTH);
this.defaultWrapContentHeight = this.dp2px(DEFAULT_VIEW_HEIGHT);
- this.setTime(this.mMillisInFuture);
this.setSurfaceTextureListener(this);
this.setOpaque(false);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EasyCountDownTextureView);
+ this.timeHour = a.getInteger(R.styleable.EasyCountDownTextureView_easyCountHour, 0);
+ this.timeMinute = a.getInteger(R.styleable.EasyCountDownTextureView_easyCountMinute, 0);
+ this.timeSecond = a.getInteger(R.styleable.EasyCountDownTextureView_easyCountSecond, 0);
+
this.backgroundPaint = new Paint();
this.backgroundPaint.setAntiAlias(true);
this.backgroundPaint.setColor(a.getColor(R.styleable.EasyCountDownTextureView_easyCountBackgroundColor, DEFAULT_COLOR_BACKGROUND));
@@ -161,6 +171,13 @@ private void init(Context context, AttributeSet attrs) {
this.rectRadius = a.getDimension(R.styleable.EasyCountDownTextureView_easyCountRectRadius, this.dp2px(DEFAULT_ROUND_RECT_RADIUS));
a.recycle();
+
+ this.updateTime();
+ }
+
+ private void updateTime(){
+ this.mMillisInFuture = this.timeHour * ONE_HOUR + this.timeMinute * ONE_MINUTE + this.timeSecond * ONE_SECOND;
+ this.setTime(this.mMillisInFuture);
}
private void refitBackgroundAttribute() {
@@ -224,6 +241,21 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
this.invalidate();
}
+ public void setTimeHour(int timeHour) {
+ this.timeHour = timeHour;
+ this.updateTime();
+ }
+
+ public void setTimeMinute(int timeMinute) {
+ this.timeMinute = timeMinute;
+ this.updateTime();
+ }
+
+ public void setTimeSecond(int timeSecond) {
+ this.timeSecond = timeSecond;
+ this.updateTime();
+ }
+
public void setRectWidth(float rectWidthDp) {
this.rectWidth = this.dp2px(rectWidthDp);
this.refitBackgroundAttribute();
@@ -313,13 +345,11 @@ public EasyThread() {
}
public synchronized final void stopThread() {
- System.out.println("stopThread");
this.running = false;
}
@Override
public void run() {
- System.out.println("Run");
while (!completed) {
while (running) {
Canvas canvas = null;
@@ -327,11 +357,14 @@ public void run() {
synchronized (EasyCountDownTextureView.this) {
canvas = EasyCountDownTextureView.this.lockCanvas();
if (canvas == null) continue;
+ timeHour = mCalendar.get(Calendar.HOUR_OF_DAY);
+ timeMinute = mCalendar.get(Calendar.MINUTE);
+ timeSecond = mCalendar.get(Calendar.SECOND);
this.drawTimeAndBackground(
canvas,
- String.format(locale, LESS_THAN_TEN_FORMAT, mCalendar.get(Calendar.HOUR_OF_DAY)),
- String.format(locale, LESS_THAN_TEN_FORMAT, mCalendar.get(Calendar.MINUTE)),
- String.format(locale, LESS_THAN_TEN_FORMAT, mCalendar.get(Calendar.SECOND))
+ String.format(locale, LESS_THAN_TEN_FORMAT, timeHour),
+ String.format(locale, LESS_THAN_TEN_FORMAT, timeMinute),
+ String.format(locale, LESS_THAN_TEN_FORMAT, timeSecond)
);
// refresh time
mMillisInFuture -= 1000;
View
3 library/src/main/res/values/attrs.xml
@@ -10,5 +10,8 @@
<attr name="easyCountBackgroundColor" format="color" />
<attr name="easyCountColonSize" format="dimension" />
<attr name="easyCountTimeSize" format="dimension" />
+ <attr name="easyCountHour" format="integer" />
+ <attr name="easyCountMinute" format="integer" />
+ <attr name="easyCountSecond" format="integer" />
</declare-styleable>
</resources>

0 comments on commit e36b440

Please sign in to comment.
Something went wrong with that request. Please try again.