From d2497ae8721c89c29eefd47cfbec1f00d6cd2f86 Mon Sep 17 00:00:00 2001 From: nukc <353932158@qq.com> Date: Wed, 15 Nov 2017 10:55:18 +0800 Subject: [PATCH] feat: support inject RecyclerView #10 --- README-en.md | 2 +- README.md | 2 +- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 3 +- .../github/nukc/sample/InjectRvActivity.java | 58 +++++++++++++++++++ .../com/github/nukc/sample/MainActivity.java | 7 +++ .../main/res/layout/activity_inject_rv.xml | 10 ++++ app/src/main/res/layout/activity_main.xml | 6 ++ app/src/main/res/layout/item_sample.xml | 17 ++++++ bintray.gradle | 2 +- library/build.gradle | 4 +- .../com/github/nukc/stateview/StateView.java | 1 + 12 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/github/nukc/sample/InjectRvActivity.java create mode 100644 app/src/main/res/layout/activity_inject_rv.xml create mode 100644 app/src/main/res/layout/item_sample.xml diff --git a/README-en.md b/README-en.md index eae5b8e..d812470 100644 --- a/README-en.md +++ b/README-en.md @@ -15,7 +15,7 @@ StateView is an invisible, zero-sized View that can be used to lazily inflate lo add the dependency to your build.gradle: ```groovy - compile 'com.github.nukc.stateview:library:1.3.2' + compile 'com.github.nukc.stateview:library:1.3.3' // animator providers compile 'com.github.nukc.stateview:animations:1.0.1' diff --git a/README.md b/README.md index 9c9fb09..1bc6367 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ StateView 一个轻量级的控件, 继承自 `View`, 吸收了 `ViewStub` 的 ```groovy - compile 'com.github.nukc.stateview:library:1.3.2' + compile 'com.github.nukc.stateview:library:1.3.3' // animator providers compile 'com.github.nukc.stateview:animations:1.0.1' diff --git a/app/build.gradle b/app/build.gradle index 4418009..5572d5d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,5 +29,6 @@ dependencies { compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:design:25.3.1' compile 'com.android.support:support-v4:25.3.1' + compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3' testCompile 'junit:junit:4.12' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 701ee9d..24e2bad 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,7 +23,8 @@ - + + \ No newline at end of file diff --git a/app/src/main/java/com/github/nukc/sample/InjectRvActivity.java b/app/src/main/java/com/github/nukc/sample/InjectRvActivity.java new file mode 100644 index 0000000..4fe7d07 --- /dev/null +++ b/app/src/main/java/com/github/nukc/sample/InjectRvActivity.java @@ -0,0 +1,58 @@ +package com.github.nukc.sample; + +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +public class InjectRvActivity extends BaseActivity { + + @Override + protected int setContentView() { + return R.layout.activity_inject_rv; + } + + @Override + protected View injectTarget() { + RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + recyclerView.setAdapter(new SampleAdapter(20)); + return recyclerView; + } + + private static class SampleAdapter extends RecyclerView.Adapter { + + private int mCount; + + public SampleAdapter(int count) { + mCount = count; + } + + @Override + public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample, parent, false); + return new SampleHolder(view); + } + + @Override + public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { + ((SampleHolder) holder).mTextView.setText(position + ""); + } + + @Override + public int getItemCount() { + return mCount; + } + + static class SampleHolder extends RecyclerView.ViewHolder { + TextView mTextView; + + public SampleHolder(View itemView) { + super(itemView); + mTextView = (TextView) itemView.findViewById(R.id.text); + } + } + } +} diff --git a/app/src/main/java/com/github/nukc/sample/MainActivity.java b/app/src/main/java/com/github/nukc/sample/MainActivity.java index 2bb5b77..a7f2730 100644 --- a/app/src/main/java/com/github/nukc/sample/MainActivity.java +++ b/app/src/main/java/com/github/nukc/sample/MainActivity.java @@ -60,5 +60,12 @@ public void onClick(View v) { startActivity(new Intent(MainActivity.this, AnimatorActivity.class)); } }); + + findViewById(R.id.btn_recycler_view).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startActivity(new Intent(MainActivity.this, InjectRvActivity.class)); + } + }); } } diff --git a/app/src/main/res/layout/activity_inject_rv.xml b/app/src/main/res/layout/activity_inject_rv.xml new file mode 100644 index 0000000..dbec9e6 --- /dev/null +++ b/app/src/main/res/layout/activity_inject_rv.xml @@ -0,0 +1,10 @@ + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a5a6220..5bc8ef4 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -51,4 +51,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Animation View"/> + +