From 14730de070b3ab2811abec9192fe405e501d5085 Mon Sep 17 00:00:00 2001
From: CaMnter <yuanyu.camnter@gmail.com>
Date: Fri, 18 Mar 2016 14:41:50 +0800
Subject: [PATCH] Update demo

---
 app/build.gradle                                   |  1 +
 app/src/main/AndroidManifest.xml                   |  3 +-
 .../demo/MainActivity.java                         | 57 +++++++++++++++-------
 .../demo/ShowActivity.java                         | 18 +++++++
 .../demo/StyleActivity.java                        | 35 ++++++++++---
 .../demo/adapter/MainAdapter.java                  | 36 ++++++++++++++
 app/src/main/res/layout/activity_main.xml          | 44 ++---------------
 app/src/main/res/layout/activity_show.xml          | 31 ++++++++++++
 app/src/main/res/layout/activity_style.xml         | 28 +++++++++++
 app/src/main/res/layout/item_main.xml              | 15 ++++++
 app/src/main/res/values/strings.xml                |  4 ++
 app/src/main/res/values/styles.xml                 |  6 ++-
 12 files changed, 212 insertions(+), 66 deletions(-)
 create mode 100644 app/src/main/java/com/camnter/easycountdowntextureview/demo/ShowActivity.java
 create mode 100644 app/src/main/java/com/camnter/easycountdowntextureview/demo/adapter/MainAdapter.java
 create mode 100644 app/src/main/res/layout/activity_show.xml
 create mode 100644 app/src/main/res/layout/item_main.xml

diff --git a/app/build.gradle b/app/build.gradle
index 4c37ef6..368bc09 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -23,5 +23,6 @@ dependencies {
     compile fileTree(include: ['*.jar'], dir: 'libs')
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:23.2.0'
+    compile 'com.camnter.easyrecyclerview:easyrecyclerview:1.2'
     compile project(':library')
 }
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 63249dd..19a46e9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -15,7 +15,8 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-        <activity android:name=".StyleActivity" />
+        <activity android:name=".StyleActivity"  />
+        <activity android:name=".ShowActivity"  />
     </application>
 
 </manifest>
\ No newline at end of file
diff --git a/app/src/main/java/com/camnter/easycountdowntextureview/demo/MainActivity.java b/app/src/main/java/com/camnter/easycountdowntextureview/demo/MainActivity.java
index df83325..327daa8 100644
--- a/app/src/main/java/com/camnter/easycountdowntextureview/demo/MainActivity.java
+++ b/app/src/main/java/com/camnter/easycountdowntextureview/demo/MainActivity.java
@@ -1,34 +1,57 @@
 package com.camnter.easycountdowntextureview.demo;
 
+import android.content.Intent;
 import android.os.Bundle;
 import android.support.v7.app.AppCompatActivity;
 import android.view.View;
 
-import com.camnter.easycountdowntextureview.EasyCountDownTextureView;
+import com.camnter.easycountdowntextureview.demo.adapter.MainAdapter;
+import com.camnter.easyrecyclerview.holder.EasyRecyclerViewHolder;
+import com.camnter.easyrecyclerview.widget.EasyRecyclerView;
+import com.camnter.easyrecyclerview.widget.decorator.EasyDividerItemDecoration;
 
-public class MainActivity extends AppCompatActivity implements View.OnClickListener {
+import java.util.ArrayList;
 
-    EasyCountDownTextureView edtv;
+public class MainActivity extends AppCompatActivity {
+
+    private EasyRecyclerView mainRv;
+    private MainAdapter mainAdapter;
+    private ArrayList<Class> classes;
 
     @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);
+        this.initViews();
+        this.initData();
+        this.initListeners();
     }
 
-    /**
-     * 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;
-        }
+    private void initViews() {
+        this.mainRv = (EasyRecyclerView) this.findViewById(R.id.main_rv);
+        EasyDividerItemDecoration decoration = new EasyDividerItemDecoration(this, EasyDividerItemDecoration.VERTICAL_LIST);
+        decoration.bottomDivider = true;
+        this.mainRv.addItemDecoration(decoration);
+    }
+
+    private void initData() {
+        this.classes = new ArrayList<>();
+        this.classes.add(ShowActivity.class);
+        this.classes.add(StyleActivity.class);
+
+        this.mainAdapter = new MainAdapter();
+        this.mainAdapter.setList(this.classes);
+        this.mainRv.setAdapter(this.mainAdapter);
+    }
+
+    private void initListeners() {
+        this.mainAdapter.setOnItemClickListener(new EasyRecyclerViewHolder.OnItemClickListener() {
+            @Override
+            public void onItemClick(View view, int i) {
+                Class c = MainActivity.this.classes.get(i);
+                MainActivity.this.startActivity(new Intent(MainActivity.this, c));
+            }
+        });
     }
+
 }
diff --git a/app/src/main/java/com/camnter/easycountdowntextureview/demo/ShowActivity.java b/app/src/main/java/com/camnter/easycountdowntextureview/demo/ShowActivity.java
new file mode 100644
index 0000000..7bd9ebc
--- /dev/null
+++ b/app/src/main/java/com/camnter/easycountdowntextureview/demo/ShowActivity.java
@@ -0,0 +1,18 @@
+package com.camnter.easycountdowntextureview.demo;
+
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+
+/**
+ * Description：ShowActivity
+ * Created by：CaMnter
+ * Time：2016-03-18 13:28
+ */
+public class ShowActivity extends AppCompatActivity {
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        this.setContentView(R.layout.activity_show);
+    }
+}
diff --git a/app/src/main/java/com/camnter/easycountdowntextureview/demo/StyleActivity.java b/app/src/main/java/com/camnter/easycountdowntextureview/demo/StyleActivity.java
index fd3dabd..471b00f 100644
--- a/app/src/main/java/com/camnter/easycountdowntextureview/demo/StyleActivity.java
+++ b/app/src/main/java/com/camnter/easycountdowntextureview/demo/StyleActivity.java
@@ -1,25 +1,48 @@
 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;
+import android.view.View;
+
+import com.camnter.easycountdowntextureview.EasyCountDownTextureView;
 
 /**
  * Description：StyleActivity
  * Created by：CaMnter
  * Time：2016-03-17 17:20
  */
-public class StyleActivity extends AppCompatActivity {
+public class StyleActivity extends AppCompatActivity implements View.OnClickListener {
 
-    public static void startActivity(Context context) {
-        context.startActivity(new Intent(context, StyleActivity.class));
-    }
+    private EasyCountDownTextureView styleTv;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         this.setContentView(R.layout.activity_style);
+        this.styleTv = (EasyCountDownTextureView) this.findViewById(R.id.style_tv);
+        this.findViewById(R.id.style_hour_bt).setOnClickListener(this);
+        this.findViewById(R.id.style_minute_bt).setOnClickListener(this);
+        this.findViewById(R.id.style_second_bt).setOnClickListener(this);
+    }
+
+    /**
+     * 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_hour_bt:
+                this.styleTv.setTimeHour(1);
+                break;
+            case R.id.style_minute_bt:
+                this.styleTv.setTimeMinute(1);
+                break;
+            case R.id.style_second_bt:
+                this.styleTv.setTimeSecond(1);
+                break;
+        }
     }
 }
diff --git a/app/src/main/java/com/camnter/easycountdowntextureview/demo/adapter/MainAdapter.java b/app/src/main/java/com/camnter/easycountdowntextureview/demo/adapter/MainAdapter.java
new file mode 100644
index 0000000..770ddda
--- /dev/null
+++ b/app/src/main/java/com/camnter/easycountdowntextureview/demo/adapter/MainAdapter.java
@@ -0,0 +1,36 @@
+package com.camnter.easycountdowntextureview.demo.adapter;
+
+import android.widget.TextView;
+
+import com.camnter.easycountdowntextureview.demo.R;
+import com.camnter.easyrecyclerview.adapter.EasyRecyclerViewAdapter;
+import com.camnter.easyrecyclerview.holder.EasyRecyclerViewHolder;
+
+/**
+ * Description：MainAdapter
+ * Created by：CaMnter
+ * Time：2016-03-18 13:21
+ */
+public class MainAdapter extends EasyRecyclerViewAdapter {
+
+    @Override
+    public int[] getItemLayouts() {
+        return new int[]{R.layout.item_main};
+    }
+
+
+    @Override
+    public void onBindRecycleViewHolder(EasyRecyclerViewHolder viewHolder, int position) {
+        Class c = (Class) this.getList().get(position);
+        if (c == null) return;
+        TextView textView = viewHolder.findViewById(R.id.main_item_tv);
+        textView.setText(c.getSimpleName());
+    }
+
+
+    @Override
+    public int getRecycleViewItemType(int position) {
+        return 0;
+    }
+
+}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index aca61e3..f710862 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,51 +1,13 @@
 <?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">
 
-    <RelativeLayout
+    <com.camnter.easyrecyclerview.widget.EasyRecyclerView
+        android:id="@+id/main_rv"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_marginBottom="50dp"
-        android:background="#ffffffff">
-
-        <ImageView
-            android:layout_width="196dp"
-            android:layout_height="158dp"
-            android:layout_marginTop="26dp"
-            android:scaleType="centerCrop"
-            android:src="@mipmap/bg_fruit" />
-
-        <com.camnter.easycountdowntextureview.EasyCountDownTextureView
-            android:id="@+id/edtv"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            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" />
+        android:layout_height="match_parent" />
 
 </RelativeLayout>
diff --git a/app/src/main/res/layout/activity_show.xml b/app/src/main/res/layout/activity_show.xml
new file mode 100644
index 0000000..5c3399b
--- /dev/null
+++ b/app/src/main/res/layout/activity_show.xml
@@ -0,0 +1,31 @@
+<?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"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:padding="16dp">
+
+    <RelativeLayout
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginBottom="50dp"
+        android:background="#ffffffff">
+
+        <ImageView
+            android:layout_width="196dp"
+            android:layout_height="158dp"
+            android:layout_marginTop="26dp"
+            android:scaleType="centerCrop"
+            android:src="@mipmap/bg_fruit" />
+
+        <com.camnter.easycountdowntextureview.EasyCountDownTextureView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            app:easyCountHour="6"
+            app:easyCountMinute="6"
+            app:easyCountSecond="26" />
+
+    </RelativeLayout>
+
+</LinearLayout>
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_style.xml b/app/src/main/res/layout/activity_style.xml
index 0f86625..7f64b88 100644
--- a/app/src/main/res/layout/activity_style.xml
+++ b/app/src/main/res/layout/activity_style.xml
@@ -12,6 +12,7 @@
     tools:context="com.camnter.easycountdowntextureview.demo.MainActivity">
 
     <com.camnter.easycountdowntextureview.EasyCountDownTextureView
+        android:id="@+id/style_tv"
         android:layout_width="132dp"
         android:layout_height="36dp"
         app:easyCountBackgroundColor="#ffdddddd"
@@ -27,5 +28,32 @@
         app:easyCountTimeColor="#ff3A94FF"
         app:easyCountTimeSize="20sp" />
 
+    <Button
+        android:id="@+id/style_hour_bt"
+        style="@style/StyleButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:text="@string/style_hour_bt" />
+
+    <Button
+        android:id="@+id/style_minute_bt"
+        style="@style/StyleButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_toEndOf="@id/style_hour_bt"
+        android:layout_toRightOf="@id/style_hour_bt"
+        android:text="@string/style_minute_bt" />
+
+    <Button
+        android:id="@+id/style_second_bt"
+        style="@style/StyleButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_toEndOf="@id/style_minute_bt"
+        android:layout_toRightOf="@id/style_minute_bt"
+        android:text="@string/style_second_bt" />
 
 </RelativeLayout>
diff --git a/app/src/main/res/layout/item_main.xml b/app/src/main/res/layout/item_main.xml
new file mode 100644
index 0000000..c91ed08
--- /dev/null
+++ b/app/src/main/res/layout/item_main.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical" android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <TextView
+        android:id="@+id/main_item_tv"
+        android:textSize="15sp"
+        android:padding="15dp"
+        android:textStyle="bold"
+        android:textColor="#ff58be13"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 911bab3..821ed36 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,4 +1,8 @@
 <resources>
     <string name="app_name">EasyCountDownTextureView</string>
     <string name="style_bt">Style</string>
+
+    <string name="style_hour_bt">H = 01</string>
+    <string name="style_minute_bt">M = 01</string>
+    <string name="style_second_bt">S = 01</string>
 </resources>
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 9ec80a4..2c5b88b 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -8,8 +8,12 @@
         <item name="colorAccent">@color/colorAccent</item>
     </style>
 
-    <style name="SurfaceViewStyle">
+    <style name="StyleButton">
         <item name="android:layout_margin">16dp</item>
+        <item name="android:paddingTop">4dp</item>
+        <item name="android:paddingBottom">4dp</item>
+        <item name="android:paddingLeft">8dp</item>
+        <item name="android:paddingRight">8dp</item>
     </style>
 
 </resources>
