Skip to content

Commit 983d71b

Browse files
committed
Initial commit
0 parents  commit 983d71b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1354
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea
5+
.DS_Store
6+
/build
7+
/captures

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
WaveSideBar project
2+
===================
3+
4+
一个快速跳跃分组的侧边栏控件,示例中配合RecyclerView实现。
5+
因为控件中使用了`path.op`,所以level>=19,如在项目中使用,请自行修改该处实现以兼容更低版本。
6+
7+
<img src="./preview/simple.gif">
8+
9+
波浪的实现采用了三段二次贝塞尔曲线,附一张手稿草图,仅供参考。
10+
11+
<img src="./preview/design.png">
12+
13+
Usage
14+
---
15+
#### **use `WaveSideBarView` in the layout file**
16+
17+
```xml
18+
<cc.solart.wave.WaveSideBarView
19+
android:id="@+id/side_view"
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent"/>
22+
```
23+
24+
#### **set `OnTouchLetterChangeListener`**
25+
26+
```java
27+
mSideBarView.setOnTouchLetterChangeListener(new WaveSideBarView.OnTouchLetterChangeListener() {
28+
@Override
29+
public void onLetterChange(String letter) {
30+
int pos = adapter.getLetterPosition(letter);
31+
32+
if (pos != -1) {
33+
mRecyclerView.scrollToPosition(pos);
34+
}
35+
}
36+
});
37+
```
38+
39+
40+
Thanks
41+
------
42+
used PinnedHeaderDecoration in
43+
[RecyclerItemDecoration](https://github.com/dinuscxj/RecyclerItemDecoration)
44+
45+
License
46+
---
47+
48+
No fucking license. just enjoy it!

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.2"
6+
7+
defaultConfig {
8+
applicationId "cc.solart.wavesidebar"
9+
minSdkVersion 19
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
testCompile 'junit:junit:4.12'
25+
compile 'com.android.support:appcompat-v7:23.3.0'
26+
compile 'cc.solart:turbo-recyclerview-helper:1.0.3-beta'
27+
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
28+
compile project(':wave')
29+
}

app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/imilk/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cc.solart.wavesidebar;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

app/src/main/AndroidManifest.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="cc.solart.wavesidebar">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN" />
14+
15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
17+
</activity>
18+
</application>
19+
20+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cc.solart.wavesidebar;
2+
3+
import java.util.Comparator;
4+
5+
import cc.solart.wavesidebar.bean.City;
6+
7+
public class LetterComparator implements Comparator<City> {
8+
9+
@Override
10+
public int compare(City l, City r) {
11+
if (l == null || r == null) {
12+
return 0;
13+
}
14+
15+
String lhsSortLetters = l.pys.substring(0, 1).toUpperCase();
16+
String rhsSortLetters = r.pys.substring(0, 1).toUpperCase();
17+
if (lhsSortLetters == null || rhsSortLetters == null) {
18+
return 0;
19+
}
20+
return lhsSortLetters.compareTo(rhsSortLetters);
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package cc.solart.wavesidebar;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.support.v7.widget.LinearLayoutManager;
6+
import android.support.v7.widget.RecyclerView;
7+
8+
import com.google.gson.Gson;
9+
import com.google.gson.reflect.TypeToken;
10+
11+
import java.lang.reflect.Type;
12+
import java.util.ArrayList;
13+
import java.util.Collections;
14+
import java.util.List;
15+
16+
import cc.solart.wave.WaveSideBarView;
17+
import cc.solart.wavesidebar.adapter.CityAdapter;
18+
import cc.solart.wavesidebar.bean.City;
19+
20+
public class MainActivity extends AppCompatActivity {
21+
22+
RecyclerView mRecyclerView;
23+
WaveSideBarView mSideBarView;
24+
CityAdapter adapter;
25+
26+
@Override
27+
protected void onCreate(Bundle savedInstanceState) {
28+
super.onCreate(savedInstanceState);
29+
setContentView(R.layout.activity_main);
30+
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
31+
mSideBarView = (WaveSideBarView) findViewById(R.id.side_view);
32+
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
33+
34+
final PinnedHeaderDecoration decoration = new PinnedHeaderDecoration();
35+
decoration.registerTypePinnedHeader(1, new PinnedHeaderDecoration.PinnedHeaderCreator() {
36+
@Override
37+
public boolean create(RecyclerView parent, int adapterPosition) {
38+
return true;
39+
}
40+
});
41+
mRecyclerView.addItemDecoration(decoration);
42+
43+
44+
new Thread(new Runnable() {
45+
@Override
46+
public void run() {
47+
Type listType = new TypeToken<ArrayList<City>>() {
48+
}.getType();
49+
Gson gson = new Gson();
50+
final List<City> list = gson.fromJson(City.DATA, listType);
51+
Collections.sort(list, new LetterComparator());
52+
runOnUiThread(new Runnable() {
53+
@Override
54+
public void run() {
55+
adapter = new CityAdapter(MainActivity.this, list);
56+
mRecyclerView.setAdapter(adapter);
57+
}
58+
});
59+
}
60+
}).start();
61+
62+
mSideBarView.setOnTouchLetterChangeListener(new WaveSideBarView.OnTouchLetterChangeListener() {
63+
@Override
64+
public void onLetterChange(String letter) {
65+
int pos = adapter.getLetterPosition(letter);
66+
67+
if (pos != -1) {
68+
mRecyclerView.scrollToPosition(pos);
69+
}
70+
}
71+
});
72+
73+
}
74+
75+
76+
77+
78+
}

0 commit comments

Comments
 (0)