├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── p1.jpg
│ │ │ │ ├── p2.jpg
│ │ │ │ ├── p3.jpg
│ │ │ │ ├── p4.jpg
│ │ │ │ ├── p5.jpg
│ │ │ │ ├── p6.jpg
│ │ │ │ ├── p7.jpg
│ │ │ │ ├── p8.jpg
│ │ │ │ ├── p9.jpg
│ │ │ │ ├── boy.png
│ │ │ │ ├── girl.png
│ │ │ │ ├── len.png
│ │ │ │ ├── leo.png
│ │ │ │ ├── lep.png
│ │ │ │ ├── leq.png
│ │ │ │ ├── ler.png
│ │ │ │ ├── les.png
│ │ │ │ ├── mln.png
│ │ │ │ ├── mmz.png
│ │ │ │ ├── mna.png
│ │ │ │ ├── mnj.png
│ │ │ │ ├── msg.png
│ │ │ │ ├── oed.png
│ │ │ │ ├── oee.png
│ │ │ │ ├── p10.jpg
│ │ │ │ ├── p11.jpg
│ │ │ │ ├── p12.jpg
│ │ │ │ ├── p13.bmp
│ │ │ │ ├── p14.jpeg
│ │ │ │ ├── p15.jpg
│ │ │ │ ├── p16.jpg
│ │ │ │ ├── item_btn_bg.xml
│ │ │ │ └── item_bg.xml
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── attrs.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── lkd.jpg
│ │ │ │ ├── dabai.png
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── item_gallery.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── dalong
│ │ │ └── qqnearbypeople
│ │ │ ├── entity
│ │ │ └── People.java
│ │ │ ├── MainActivity.java
│ │ │ └── view
│ │ │ ├── RadarCircleView.java
│ │ │ ├── RadarViewLayout.java
│ │ │ ├── RadarView.java
│ │ │ └── GalleryRecyclerView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── dalong
│ │ │ └── qqnearbypeople
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── dalong
│ │ └── qqnearbypeople
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── img
└── nearby.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/img/nearby.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/img/nearby.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p6.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p7.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p8.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p9.jpg
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | "QQNearbyPeople "
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/boy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/boy.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/girl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/girl.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/len.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/len.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/leo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/leo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/lep.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/lep.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/leq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/leq.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ler.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/ler.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/les.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/les.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/mln.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/mln.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/mmz.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/mmz.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/mna.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/mna.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/mnj.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/mnj.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/msg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/msg.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/oed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/oed.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/oee.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/oee.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p10.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p11.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p11.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p12.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p12.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p13.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p13.bmp
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p14.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p14.jpeg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p15.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p15.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/p16.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/drawable/p16.jpg
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/lkd.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/mipmap-xhdpi/lkd.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/dabai.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/mipmap-xhdpi/dabai.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # QQNearbyPeople
2 | 高仿qq身边的人扫描界面
3 |
4 | #效果
5 | 
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yixiaolunhui/QQNearbyPeople/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 | 180dp
7 | 140dp
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/item_btn_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #e06086a3
8 | #1e6390
9 | #1fbaf3
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/item_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
10 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/test/java/com/dalong/qqnearbypeople/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dalong.qqnearbypeople;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /android/tools/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 | #}
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/dalong/qqnearbypeople/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.dalong.qqnearbypeople;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.dalong.qqnearbypeople", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.1"
6 | defaultConfig {
7 | applicationId "com.dalong.qqnearbypeople"
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.1.0'
28 | testCompile 'junit:junit:4.12'
29 | compile 'com.android.support:recyclerview-v7:24.2.1'
30 | compile 'com.zhy:base-rvadapter:3.0.3'
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dalong/qqnearbypeople/entity/People.java:
--------------------------------------------------------------------------------
1 | package com.dalong.qqnearbypeople.entity;
2 |
3 | /**
4 | * 附近的人
5 | * Created by dalong on 2016/12/20.
6 | */
7 |
8 | public class People {
9 | //名字
10 | private String name;
11 | //年龄
12 | private String age;
13 | //头像id
14 | private int portraitId;
15 | //false为男,true为女
16 | private boolean sex;
17 | //距离
18 | private float distance;
19 |
20 | public int getPortraitId() {
21 | return portraitId;
22 | }
23 |
24 | public void setPortraitId(int portraitId) {
25 | this.portraitId = portraitId;
26 | }
27 |
28 | public String getAge() {
29 | return age;
30 | }
31 |
32 | public void setAge(String age) {
33 | this.age = age;
34 | }
35 |
36 | public float getDistance() {
37 | return distance;
38 | }
39 |
40 | public void setDistance(float distance) {
41 | this.distance = distance;
42 | }
43 |
44 | public String getName() {
45 | return name;
46 | }
47 |
48 | public void setName(String name) {
49 | this.name = name;
50 | }
51 |
52 | public boolean getSex() {
53 | return sex;
54 | }
55 |
56 | public void setSex(boolean sex) {
57 | this.sex = sex;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
27 |
28 |
29 |
30 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_gallery.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
12 |
13 |
19 |
28 |
29 |
41 |
52 |
53 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dalong/qqnearbypeople/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dalong.qqnearbypeople;
2 |
3 | import android.os.Handler;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.util.SparseArray;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 | import com.dalong.qqnearbypeople.entity.People;
12 | import com.dalong.qqnearbypeople.view.GalleryRecyclerView;
13 | import com.dalong.qqnearbypeople.view.RadarViewLayout;
14 | import com.zhy.adapter.recyclerview.CommonAdapter;
15 | import com.zhy.adapter.recyclerview.base.ViewHolder;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | public class MainActivity extends AppCompatActivity {
21 | private int[] mImgs = {R.drawable.len, R.drawable.leo, R.drawable.lep,
22 | R.drawable.leq, R.drawable.ler, R.drawable.les, R.drawable.mln, R.drawable.mmz, R.drawable.mna,
23 | R.drawable.mnj, R.drawable.leo, R.drawable.leq};
24 | private String[] mNames = {"橘子", "花生", "菠菜", "萝卜", "豆角", "西红柿", "香蕉", "苹果",
25 | "小麦","大米","玉米","白菜"};
26 | private SparseArray mDatas = new SparseArray<>();
27 | private List mlist = new ArrayList<>();
28 | private RadarViewLayout mRadarViewLayout;
29 | private GalleryRecyclerView mGalleryRecyclerView;
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_main);
35 | initView();
36 | }
37 |
38 | private void initView() {
39 | mRadarViewLayout = (RadarViewLayout) findViewById(R.id.radarViewLayout);
40 | mGalleryRecyclerView = (GalleryRecyclerView) findViewById(R.id.gallery);
41 | new Handler().postDelayed(new Runnable() {
42 | @Override
43 | public void run() {
44 | initData();
45 | mRadarViewLayout.setDatas(mDatas);
46 | mRadarViewLayout.setCurrentShowItem(0);
47 |
48 | }
49 | }, 1000);
50 | mGalleryRecyclerView.setCanAlpha(true);
51 | mGalleryRecyclerView.setCanScale(true);
52 | mGalleryRecyclerView.setBaseScale(0.25f);
53 | mGalleryRecyclerView.setBaseAlpha(0.1f);
54 | mGalleryRecyclerView.setAdapter(new CommonAdapter(this, R.layout.item_gallery, mlist) {
55 | @Override
56 | public void convert(ViewHolder holder, final People s, int position) {
57 | holder.setText(R.id.name, s.getName());
58 | holder.setText(R.id.tv_distance, s.getAge()+" "+s.getDistance()+"km");
59 | holder.setImageResource(R.id.profile_image,s.getPortraitId());
60 | holder.getView(R.id.item_btn).setOnClickListener(new View.OnClickListener() {
61 | @Override
62 | public void onClick(View v) {
63 | Toast.makeText(mContext, s.getName(), Toast.LENGTH_SHORT).show();
64 | }
65 | });
66 | }
67 | });
68 | mGalleryRecyclerView.setOnViewSelectedListener(new GalleryRecyclerView.OnViewSelectedListener() {
69 | @Override
70 | public void onSelected(View view, final int position) {
71 | mRadarViewLayout.setCurrentShowItem(position);
72 | }
73 | });
74 |
75 | mRadarViewLayout.setOnRadarClickListener(new RadarViewLayout.OnRadarClickListener() {
76 | @Override
77 | public void onRadarItemClick(final int position) {
78 |
79 | //待完善
80 | }
81 | });
82 | }
83 |
84 |
85 | private void initData() {
86 | mlist.clear();
87 | mDatas.clear();
88 | for (int i = 0; i < mImgs.length; i++) {
89 | People info = new People();
90 | info.setPortraitId(mImgs[i]);
91 | info.setAge(((int) Math.random() * 25 + 16) + "岁");
92 | info.setName(mNames[i]);
93 | info.setSex(i % 3 == 0 ? false : true);
94 | info.setDistance(Math.round((Math.random() * 10) * 100) / 100);
95 | mDatas.put(i, info);
96 | mlist.add(info);
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dalong/qqnearbypeople/view/RadarCircleView.java:
--------------------------------------------------------------------------------
1 | package com.dalong.qqnearbypeople.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.Paint;
9 | import android.graphics.Rect;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 |
13 | /**
14 | * 扫描出现的圆形人 可能是图片也可能是纯色
15 | * Created by dalong on 2016/12/20.
16 | */
17 |
18 | public class RadarCircleView extends View {
19 | //画笔
20 | private Paint mPaint;
21 | //图片
22 | private Bitmap mBitmap;
23 | //半径
24 | private float radius = dp2px(getContext(),7);
25 | //位置X
26 | private float disX;
27 | //位置Y
28 | private float disY;
29 | //旋转的角度
30 | private float angle;
31 | //根据远近距离的不同计算得到的应该占的半径比例
32 | private float proportion;
33 | public RadarCircleView(Context context) {
34 | this(context,null);
35 | }
36 |
37 | public RadarCircleView(Context context, AttributeSet attrs) {
38 | this(context, attrs,0);
39 | }
40 |
41 | public RadarCircleView(Context context, AttributeSet attrs, int defStyleAttr) {
42 | super(context, attrs, defStyleAttr);
43 | init();
44 | }
45 |
46 | private void init() {
47 | mPaint = new Paint();
48 | mPaint.setColor(Color.parseColor("#FF90A2"));
49 | mPaint.setAntiAlias(true);
50 | }
51 |
52 |
53 | @Override
54 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
55 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
56 | setMeasuredDimension(measureSize(widthMeasureSpec), measureSize(heightMeasureSpec));
57 | }
58 |
59 | private int measureSize(int measureSpec) {
60 | int result = 0;
61 | int specMode = MeasureSpec.getMode(measureSpec);
62 | int specSize = MeasureSpec.getSize(measureSpec);
63 | if (specMode == MeasureSpec.EXACTLY) {
64 | result = specSize;
65 | } else {
66 | result = dp2px(getContext(),18);
67 | if (specMode == MeasureSpec.AT_MOST) {
68 | result = Math.min(result, specSize);
69 | }
70 | }
71 | return result;
72 | }
73 |
74 | /**
75 | * 将dp值转换为px值
76 | * @param context
77 | * @param dpValue
78 | * @return
79 | */
80 | public int dp2px(Context context, float dpValue) {
81 | final float scale = context.getResources().getDisplayMetrics().density;
82 | return (int) (dpValue * scale + 0.5f);
83 | }
84 |
85 | @Override
86 | protected void onDraw(Canvas canvas) {
87 | //画圆
88 | canvas.drawCircle(radius, radius, radius, mPaint);
89 | //如果mBitmap不为空再画小人图
90 | if (mBitmap != null) {
91 | canvas.drawBitmap(mBitmap, null, new Rect(0, 0, 2 * (int) radius, 2 * (int) radius), mPaint);
92 | }
93 | }
94 |
95 | /**
96 | * 设置画笔的颜色
97 | * @param resId
98 | */
99 | public void setPaintColor(int resId) {
100 | mPaint.setColor(resId);
101 | invalidate();
102 | }
103 |
104 | /**
105 | * 设置真实小人icon id
106 | * @param resId
107 | */
108 | public void setPortraitIcon(int resId) {
109 | mBitmap = BitmapFactory.decodeResource(getResources(), resId);
110 | invalidate();
111 | }
112 |
113 | /**
114 | * 清楚真实小人icon
115 | */
116 | public void clearPortaitIcon(){
117 | mBitmap = null;
118 | invalidate();
119 | }
120 |
121 |
122 |
123 | public float getProportion() {
124 | return proportion;
125 | }
126 |
127 | public void setProportion(float proportion) {
128 | this.proportion = proportion;
129 | }
130 |
131 | public float getAngle() {
132 | return angle;
133 | }
134 |
135 | public void setAngle(float angle) {
136 | this.angle = angle;
137 | }
138 |
139 | public float getDisX() {
140 | return disX;
141 | }
142 |
143 | public void setDisX(float disX) {
144 | this.disX = disX;
145 | }
146 |
147 | public float getDisY() {
148 | return disY;
149 | }
150 |
151 | public void setDisY(float disY) {
152 | this.disY = disY;
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dalong/qqnearbypeople/view/RadarViewLayout.java:
--------------------------------------------------------------------------------
1 | package com.dalong.qqnearbypeople.view;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.content.Context;
5 | import android.graphics.Color;
6 | import android.util.AttributeSet;
7 | import android.util.SparseArray;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.dalong.qqnearbypeople.R;
12 | import com.dalong.qqnearbypeople.entity.People;
13 |
14 | /**
15 | * Created by dalong on 2016/12/20.
16 | */
17 |
18 | public class RadarViewLayout extends ViewGroup implements RadarView.OnScanningListener {
19 | //控件的宽
20 | private int mWidth;
21 | //控件的高
22 | private int mHeight;
23 | //数据源
24 | private SparseArray mDatas;
25 | //记录展示的item所在的扫描位置角度
26 | private SparseArray scanAngleList = new SparseArray<>();
27 | //最小距离的item所在数据源中的位置
28 | private int minItemPosition;
29 | //当前展示的item
30 | private RadarCircleView currentShowChild;
31 | //最小距离的item
32 | private RadarCircleView minShowChild;
33 | public RadarViewLayout(Context context) {
34 | this(context,null);
35 | }
36 |
37 | public RadarViewLayout(Context context, AttributeSet attrs) {
38 | this(context, attrs,0);
39 | }
40 |
41 | public RadarViewLayout(Context context, AttributeSet attrs, int defStyleAttr) {
42 | super(context, attrs, defStyleAttr);
43 | }
44 |
45 | @Override
46 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
47 | setMeasuredDimension(measureSize(widthMeasureSpec), measureSize(heightMeasureSpec));
48 | mWidth = getMeasuredWidth();
49 | mHeight = getMeasuredHeight();
50 | mWidth = mHeight = Math.min(mWidth, mHeight);
51 | //测量每个children
52 | measureChildren(widthMeasureSpec, heightMeasureSpec);
53 | for (int i = 0; i < getChildCount(); i++) {
54 | View child = getChildAt(i);
55 | if (child.getId() == R.id.radarView) {
56 | //为雷达扫描图设置需要的属性
57 | ((RadarView) child).setOnScanningListener(this);
58 | //考虑到数据没有添加前扫描图在扫描,但是不会开始为CircleView布局
59 | if (mDatas != null && mDatas.size() > 0) {
60 | ((RadarView) child).setMaxScanItemCount(mDatas.size());
61 | ((RadarView) child).startScan();
62 | }
63 | continue;
64 | }
65 | }
66 | }
67 |
68 | /**
69 | * 测量宽高 默认给400
70 | * @param measureSpec
71 | * @return
72 | */
73 | private int measureSize(int measureSpec) {
74 | int result;
75 | int specMode = MeasureSpec.getMode(measureSpec);
76 | int specSize = MeasureSpec.getSize(measureSpec);
77 | if (specMode == MeasureSpec.EXACTLY) {
78 | result = specSize;
79 | } else {
80 | result = 400;
81 | if (specMode == MeasureSpec.AT_MOST) {
82 | result = Math.min(result, specSize);
83 | }
84 | }
85 | return result;
86 | }
87 |
88 |
89 | @Override
90 | protected void onLayout(boolean changed,int l, int t, int r, int b) {
91 | int childCount = getChildCount();
92 | /**
93 | * 首先放置扫描view的位置
94 | */
95 | View view = findViewById(R.id.radarView);
96 | if (view != null) {
97 | view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
98 | }
99 | //放置雷达图中需要展示的item圆点
100 | for (int i = 0; i < childCount; i++) {
101 | final int j = i;
102 | final View child = getChildAt(i);
103 | //如果是扫描view直接忽略
104 | if (child.getId() == R.id.radarView) {
105 | continue;
106 | }
107 | //设置CircleView小圆点的坐标信息
108 | //坐标 = 旋转角度 * 半径 * 根据远近距离的不同计算得到的应该占的半径比例
109 | if(child instanceof RadarCircleView){
110 | RadarCircleView radarCircleView=(RadarCircleView) child;
111 | radarCircleView.setDisX((float) Math.cos(Math.toRadians(scanAngleList.get(i - 1) - 5))
112 | * radarCircleView.getProportion() * mWidth / 2);
113 | radarCircleView.setDisY((float) Math.sin(Math.toRadians(scanAngleList.get(i - 1) - 5))
114 | * radarCircleView.getProportion() * mWidth / 2);
115 |
116 | //如果扫描角度记录SparseArray中的对应的item的值为0,
117 | // 说明还没有扫描到该item,跳过对该item的layout
118 | //(scanAngleList设置数据时全部设置的value=0,
119 | // 当onScanning时,value设置的值始终不会0,具体可以看onScanning中的实现)
120 | if (scanAngleList.get(i - 1) == 0) {
121 | continue;
122 | }
123 | //放置Circle小圆点
124 | child.layout((int)radarCircleView.getDisX() + mWidth / 2, (int) radarCircleView.getDisY() + mHeight / 2,
125 | (int) radarCircleView.getDisX() + child.getMeasuredWidth() + mWidth / 2,
126 | (int)radarCircleView.getDisY() + child.getMeasuredHeight() + mHeight / 2);
127 | //设置点击事件
128 | child.setOnClickListener(new OnClickListener() {
129 | @Override
130 | public void onClick(View v) {
131 | resetAnim(currentShowChild);
132 | currentShowChild = (RadarCircleView) child;
133 | //因为雷达图是childAt(0),所以这里需要作-1才是正确的Circle
134 | startAnim(currentShowChild, j - 1);
135 | if (mOnRadarClickListener != null) {
136 | mOnRadarClickListener.onRadarItemClick(j - 1);
137 | }
138 | }
139 | });
140 | }
141 |
142 |
143 |
144 | }
145 | }
146 |
147 | /**
148 | * 设置数据
149 | *
150 | * @param mDatas
151 | */
152 | public void setDatas(SparseArray mDatas) {
153 | this.mDatas = mDatas;
154 | float min = Float.MAX_VALUE;
155 | float max = Float.MIN_VALUE;
156 | //找到距离的最大值,最小值对应的minItemPosition
157 | for (int j = 0; j < mDatas.size(); j++) {
158 | People item = mDatas.get(j);
159 | if (item.getDistance() < min) {
160 | min = item.getDistance();
161 | minItemPosition = j;
162 | }
163 | if (item.getDistance() > max) {
164 | max = item.getDistance();
165 | }
166 | scanAngleList.put(j, 0f);
167 | }
168 | //根据数据源信息动态添加CircleView
169 | for (int i = 0; i < mDatas.size(); i++) {
170 | RadarCircleView circleView = new RadarCircleView(getContext());
171 | if (mDatas.get(i).getSex()) {
172 | circleView.setPaintColor(Color.parseColor("#FF90A2"));
173 | } else {
174 | circleView.setPaintColor(Color.parseColor("#43D5FF"));
175 | }
176 | //根据远近距离的不同计算得到的应该占的半径比例 0.312-0.832
177 | circleView.setProportion((mDatas.get(i).getDistance() / max + 0.6f) * 0.52f);
178 | if (minItemPosition == i) {
179 | minShowChild = circleView;
180 | }
181 | addView(circleView);
182 | }
183 | }
184 | /**
185 | * 雷达图没有扫描完毕时回调
186 | *
187 | * @param position
188 | * @param scanAngle
189 | */
190 | @Override
191 | public void onScanning(int position, float scanAngle) {
192 | if (scanAngle == 0) {
193 | scanAngleList.put(position, 1f);
194 | } else {
195 | scanAngleList.put(position, scanAngle);
196 | }
197 | requestLayout();
198 | }
199 | /**
200 | * 雷达图扫描完毕时回调
201 | */
202 | @Override
203 | public void onScanSuccess() {
204 | resetAnim(currentShowChild);
205 | currentShowChild = minShowChild;
206 | startAnim(currentShowChild, minItemPosition);
207 | }
208 |
209 | /**
210 | * 恢复CircleView小圆点原大小
211 | *
212 | * @param object
213 | */
214 | private void resetAnim(RadarCircleView object) {
215 | if (object != null) {
216 | object.clearPortaitIcon();
217 | ObjectAnimator.ofFloat(object, "scaleX", 1f).setDuration(300).start();
218 | ObjectAnimator.ofFloat(object, "scaleY", 1f).setDuration(300).start();
219 | }
220 |
221 | }
222 |
223 | /**
224 | * 放大CircleView小圆点大小
225 | *
226 | * @param object
227 | * @param position
228 | */
229 | private void startAnim(RadarCircleView object, int position) {
230 | if (object != null) {
231 | object.setPortraitIcon(mDatas.get(position).getPortraitId());
232 | ObjectAnimator.ofFloat(object, "scaleX", 2f).setDuration(300).start();
233 | ObjectAnimator.ofFloat(object, "scaleY", 2f).setDuration(300).start();
234 | }
235 | }
236 |
237 | /**
238 | * 根据position,放大指定的CircleView小圆点
239 | * @param position
240 | */
241 | public void setCurrentShowItem(int position) {
242 | RadarCircleView child = (RadarCircleView) getChildAt(position + 1);
243 | resetAnim(currentShowChild);
244 | currentShowChild = child;
245 | startAnim(currentShowChild, position);
246 | }
247 |
248 |
249 | /**
250 | * 雷达图中点击监听CircleView小圆点回调接口
251 | */
252 | public interface OnRadarClickListener {
253 | void onRadarItemClick(int position);
254 | }
255 | //雷达图中点击监听CircleView小圆点回调接口
256 | private OnRadarClickListener mOnRadarClickListener;
257 |
258 | public void setOnRadarClickListener(OnRadarClickListener mOnRadarClickListener) {
259 | this.mOnRadarClickListener = mOnRadarClickListener;
260 | }
261 |
262 | }
263 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dalong/qqnearbypeople/view/RadarView.java:
--------------------------------------------------------------------------------
1 | package com.dalong.qqnearbypeople.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Matrix;
10 | import android.graphics.Paint;
11 | import android.graphics.Rect;
12 | import android.graphics.SweepGradient;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 |
16 | import com.dalong.qqnearbypeople.R;
17 |
18 | /**
19 | * 扫描view
20 | * Created by dalong on 2016/12/20.
21 | */
22 |
23 | public class RadarView extends View {
24 |
25 | //圆环颜色
26 | public int mRingColor;
27 | //扫描背景色
28 | public int mScanBgColor;
29 | //圆环的看度
30 | public float mRingWidth;
31 | //圆环数量
32 | public int mRingNum;
33 | //扫描速度 越小越快 毫秒值
34 | public int mScanSpeed;
35 | //扫描角度
36 | private int mScanAngle;
37 | //圆环画笔
38 | private Paint mRingPaint;
39 | //中间图片
40 | private Paint mCicleIconPaint;
41 | //扫描画笔
42 | private Paint mScanPaint;
43 | //中间图片
44 | private Bitmap mCenterIcon;
45 | //宽
46 | private int mWidth;
47 | //高
48 | private int mHeight;
49 | //圆环比例
50 | private float mRingScale=1/13f;
51 |
52 | private SweepGradient mScanShader;
53 | //旋转需要的矩阵
54 | private Matrix matrix = new Matrix();
55 |
56 | private OnScanningListener mOnScanningListener;
57 | //是否开始回调
58 | private boolean startScan;
59 | //当前扫描的次数
60 | private int currentScanningCount;
61 | //当前扫描显示的item
62 | private int currentScanningItem;
63 | //最大扫描次数
64 | private int maxScanItemCount;
65 | private float currentScanAngle;
66 | public RadarView(Context context) {
67 | this(context,null);
68 | }
69 |
70 | public RadarView(Context context, AttributeSet attrs) {
71 | this(context, attrs,0);
72 | }
73 |
74 | public RadarView(Context context, AttributeSet attrs, int defStyleAttr) {
75 | super(context, attrs, defStyleAttr);
76 | TypedArray typedArray=context.obtainStyledAttributes(attrs, R.styleable.RadarView);
77 | mRingColor=typedArray.getColor(R.styleable.RadarView_mRingColor, Color.parseColor("#3C8EAE"));
78 | mScanBgColor=typedArray.getColor(R.styleable.RadarView_mScanBgColor, Color.parseColor("#84B5CA"));
79 | mRingWidth=typedArray.getDimensionPixelSize(R.styleable.RadarView_mRingWidth, 1);
80 | mRingNum=typedArray.getInteger(R.styleable.RadarView_mRingNum, 6);
81 | mScanSpeed=typedArray.getColor(R.styleable.RadarView_mScanSpeed, 20);
82 | mScanAngle=typedArray.getColor(R.styleable.RadarView_mScanAngle, 5);
83 | typedArray.recycle();
84 |
85 | //中间图片
86 | mCenterIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.dabai);
87 | //设置多个圆环画笔
88 | mRingPaint=new Paint();
89 | mRingPaint.setColor(mRingColor);
90 | mRingPaint.setAntiAlias(true);
91 | mRingPaint.setStrokeWidth(mRingWidth);
92 | mRingPaint.setStyle(Paint.Style.STROKE);
93 |
94 |
95 | //设置中间图片画笔
96 | mCicleIconPaint=new Paint();
97 | mCicleIconPaint.setColor(Color.WHITE);
98 | mCicleIconPaint.setAntiAlias(true);
99 |
100 |
101 | //扫描画笔
102 | mScanPaint = new Paint();
103 | mScanPaint.setStyle(Paint.Style.FILL_AND_STROKE);
104 |
105 | //启动扫描
106 | post(mRunnable);
107 | }
108 |
109 | @Override
110 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
111 | setMeasuredDimension(measureSize(widthMeasureSpec),measureSize(heightMeasureSpec));
112 | }
113 |
114 | /**
115 | * 测量宽高 默认给400
116 | * @param measureSpec
117 | * @return
118 | */
119 | private int measureSize(int measureSpec) {
120 | int result;
121 | int specMode = MeasureSpec.getMode(measureSpec);
122 | int specSize = MeasureSpec.getSize(measureSpec);
123 | if (specMode == MeasureSpec.EXACTLY) {
124 | result = specSize;
125 | } else {
126 | result = 400;
127 | if (specMode == MeasureSpec.AT_MOST) {
128 | result = Math.min(result, specSize);
129 | }
130 | }
131 | return result;
132 | }
133 |
134 | @Override
135 | protected void onDraw(Canvas canvas) {
136 | super.onDraw(canvas);
137 | // 这里设置宽高 主要思想是因为是方形 所以取最小的作为宽高值
138 | mWidth=getMeasuredWidth();
139 | mHeight=getMeasuredHeight();
140 | mWidth = mHeight = Math.min(mWidth, mHeight);
141 |
142 | // 绘制圆环
143 | drawRing(canvas);
144 | // 绘制扫描
145 | drawScan(canvas);
146 | // 绘制中间icon
147 | drawCenterIcon(canvas);
148 | }
149 |
150 | /**
151 | * 绘制中间icon
152 | * @param canvas
153 | */
154 | private void drawCenterIcon(Canvas canvas) {
155 | //这里以最中间的圆为区域设置这个中间图片 中间需要去除padding值
156 | float scale=0.8f;
157 | float radius=(mWidth-getPaddingLeft()-getPaddingRight())*mRingScale*scale;
158 | Rect rect=new Rect((int)(mWidth/2-radius),(int)(mHeight/2-radius),(int)(mWidth/2+radius),(int)(mHeight/2+radius));
159 | canvas.drawBitmap(mCenterIcon,null,rect,mCicleIconPaint);
160 |
161 | mCicleIconPaint.setColor(Color.WHITE);
162 | mCicleIconPaint.setStyle(Paint.Style.STROKE);
163 | mCicleIconPaint.setStrokeWidth(2);
164 | canvas.drawCircle(mWidth/2,mHeight/2,radius,mCicleIconPaint);
165 | }
166 |
167 | /**
168 | * 绘制圆环
169 | * @param canvas
170 | */
171 | private void drawRing(Canvas canvas) {
172 |
173 | /**
174 | * 这里根据设置的一共所有的圆环数量来进行遍历绘制 中间就是空间的中心, 绘制的半径就是中心向两边延伸,每次延伸设定的宽度(去除padding)与比例相乘
175 | */
176 | for (int i=0;i 0) {
135 | scrollToView(getCenterView());
136 | }
137 |
138 | /** if idle, notify listeners of new selected view **/
139 | notifyListener();
140 | } else if (newState == SCROLL_STATE_FLING) {
141 | mScrolling = true;
142 | }
143 |
144 | scrollState = newState;
145 | }
146 | });
147 | }
148 |
149 | /**
150 | * 通知回调并设置当前选中位置
151 | */
152 | private void notifyListener() {
153 | View view = getCenterView();
154 | int position = getChildAdapterPosition(view);
155 | /** if there is a listener and the index is not the same as the currently selected position, notify listener **/
156 | if (listener != null && position != selectedPosition) {
157 | listener.onSelected(view, position);
158 | }
159 | selectedPosition = position;
160 | }
161 |
162 | /**
163 | * 设置方向 水平 or 竖直
164 | * @param orientation LinearLayoutManager.HORIZONTAL or LinearLayoutManager.VERTICAL
165 | */
166 | public void setOrientation(Orientation orientation) {
167 | this.orientation = orientation;
168 | childViewMetrics = new ChildViewMetrics(orientation);
169 | mLinearLayoutManager=new LinearLayoutManager(getContext(), orientation.intValue(), false);
170 | setLayoutManager(mLinearLayoutManager);
171 | }
172 |
173 | /**
174 | * 设置选择position
175 | * @param position
176 | */
177 | public void setSelectPosition(int position){
178 | mLinearLayoutManager.scrollToPositionWithOffset(position,0);
179 | }
180 |
181 |
182 | /**
183 | * 设置选中回调接口
184 | * @param listener the OnViewSelectedListener
185 | */
186 | public void setOnViewSelectedListener(OnViewSelectedListener listener) {
187 | this.listener = listener;
188 | }
189 |
190 | /**
191 | * 设置两边是否可以缩放
192 | * @param enabled
193 | */
194 | public void setCanScale(boolean enabled) {
195 | this.scaleViews = enabled;
196 | }
197 |
198 | /**
199 | * 设置两边的透明度是否支持
200 | * @param enabled
201 | */
202 | public void setCanAlpha(boolean enabled) {
203 | this.alphaViews = enabled;
204 | }
205 |
206 |
207 | /**
208 | * 设置基数缩放值
209 | * @param baseScale
210 | */
211 | public void setBaseScale(float baseScale) {
212 | this.baseScale = 1f-baseScale;
213 | }
214 |
215 | /**
216 | * 设置基数透明度
217 | * @param baseAlpha
218 | */
219 | public void setBaseAlpha(float baseAlpha) {
220 | this.baseAlpha = 1f-baseAlpha;
221 | }
222 |
223 | /**
224 | * 更新views
225 | */
226 | private void updateViews() {
227 | for (int i = 0; i < getChildCount(); i++) {
228 | View child = getChildAt(i);
229 | setMarginsForChild(child);
230 | float percentage = getPercentageFromCenter(child);
231 | float scale = 1f - (baseScale * percentage);
232 | float alpha = 1f - (baseAlpha * percentage);
233 | //设置缩放
234 | if (scaleViews) {
235 | child.setScaleX(scale);
236 | child.setScaleY(scale);
237 | }
238 | //设置透明度
239 | if(alphaViews){
240 | child.setAlpha(alpha);
241 | }
242 | View view=child.findViewById(R.id.item_btn);
243 | if(view!=null){
244 | view.setAlpha(1f-(percentage)/(1-0.5625f));
245 | }
246 | }
247 | }
248 |
249 | /**
250 | * Adds the margins to a childView so a view will still center even if it's only a single child
251 | * @param child childView to set margins for
252 | */
253 | private void setMarginsForChild(View child) {
254 | int lastItemIndex = getLayoutManager().getItemCount() - 1;
255 | int childIndex = getChildAdapterPosition(child);
256 |
257 | int startMargin = 0;
258 | int endMargin = 0;
259 | int topMargin = 0;
260 | int bottomMargin = 0;
261 |
262 | if (orientation == Orientation.VERTICAL) {
263 | topMargin = childIndex == 0 ? getCenterLocation() : 0;
264 | bottomMargin = childIndex == lastItemIndex ? getCenterLocation() : 0;
265 | } else {
266 | startMargin = childIndex == 0 ? getCenterLocation() : 0;
267 | endMargin = childIndex == lastItemIndex ? getCenterLocation() : 0;
268 | }
269 |
270 | /** if sdk minimum level is 17, set RTL margins **/
271 | if (orientation == Orientation.HORIZONTAL && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
272 | ((ViewGroup.MarginLayoutParams) child.getLayoutParams()).setMarginStart(startMargin);
273 | ((ViewGroup.MarginLayoutParams) child.getLayoutParams()).setMarginEnd(endMargin);
274 | }
275 |
276 | /** If layout direction is RTL, swap the margins **/
277 | if (ViewCompat.getLayoutDirection(child) == ViewCompat.LAYOUT_DIRECTION_RTL)
278 | ((ViewGroup.MarginLayoutParams) child.getLayoutParams()).setMargins(endMargin, topMargin, startMargin, bottomMargin);
279 | else {
280 | ((ViewGroup.MarginLayoutParams) child.getLayoutParams()).setMargins(startMargin, topMargin, endMargin, bottomMargin);
281 | }
282 |
283 | /** if sdk minimum level is 18, check if view isn't undergoing a layout pass (this improves the feel of the view by a lot) **/
284 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
285 | if (!child.isInLayout())
286 | child.requestLayout();
287 | }
288 | }
289 |
290 | @Override
291 | public boolean dispatchTouchEvent(MotionEvent event) {
292 | long currentTime = System.currentTimeMillis();
293 |
294 | /** if touch events are being spammed, this is due to user scrolling right after a tap,
295 | * so set userScrolling to true **/
296 | if (mScrolling && scrollState == SCROLL_STATE_TOUCH_SCROLL) {
297 | if ((currentTime - lastScrollTime) < MINIMUM_SCROLL_EVENT_OFFSET_MS) {
298 | userScrolling = true;
299 | }
300 | }
301 |
302 | lastScrollTime = currentTime;
303 |
304 | int location = orientation == Orientation.VERTICAL ? (int)event.getY() : (int)event.getX();
305 |
306 | View targetView = getChildClosestToLocation(location);
307 |
308 | if (!userScrolling) {
309 | if (event.getAction() == MotionEvent.ACTION_UP) {
310 | if (targetView != getCenterView()) {
311 | scrollToView(targetView);
312 | return true;
313 | }
314 | }
315 | }
316 |
317 | return super.dispatchTouchEvent(event);
318 | }
319 |
320 | @Override
321 | public boolean onInterceptTouchEvent(MotionEvent event) {
322 | if(event.getAction()== MotionEvent.ACTION_DOWN){
323 | if(listem!=null)
324 | listem.onTouchDown();
325 | }
326 | int location = orientation == Orientation.VERTICAL ? (int)event.getY() : (int)event.getX();
327 | View targetView = getChildClosestToLocation(location);
328 | if (targetView != getCenterView()) {
329 | return true;
330 | }
331 | return super.onInterceptTouchEvent(event);
332 | }
333 |
334 | @Override
335 | public boolean onTouchEvent(MotionEvent e) {
336 | if(e.getAction()== MotionEvent.ACTION_DOWN){
337 | if(listem!=null)
338 | listem.onTouchDown();
339 | }
340 | return super.onTouchEvent(e);
341 | }
342 |
343 |
344 | public void setTouchDownlistem(TouchDownListem listem){
345 | this.listem=listem;
346 | }
347 | public interface TouchDownListem{
348 | void onTouchDown();
349 | }
350 | @Override
351 | public void scrollToPosition(int position) {
352 | childViewMetrics.size(getChildAt(0));
353 | smoothScrollBy(childViewMetrics.size(getChildAt(0)) * position);
354 | }
355 |
356 | private View getChildClosestToLocation(int location) {
357 | if (getChildCount() <= 0)
358 | return null;
359 |
360 | int closestPos = 9999;
361 | View closestChild = null;
362 |
363 | for (int i = 0; i < getChildCount(); i++) {
364 | View child = getChildAt(i);
365 |
366 | int childCenterLocation = (int) childViewMetrics.center(child);
367 | int distance = childCenterLocation - location;
368 |
369 | /** if child center is closer than previous closest, set it as closest child **/
370 | if (Math.abs(distance) < Math.abs(closestPos)) {
371 | closestPos = distance;
372 | closestChild = child;
373 | }
374 | }
375 |
376 | return closestChild;
377 | }
378 |
379 | /**
380 | * Check if the view is correctly centered (allow for 10px offset)
381 | * @param child the child view
382 | * @return true if correctly centered
383 | */
384 | private boolean isChildCorrectlyCentered(View child) {
385 | int childPosition = (int)childViewMetrics.center(child);
386 | return childPosition > (getCenterLocation() - 10) && childPosition < (getCenterLocation() + 10);
387 | }
388 |
389 | /**
390 | * 获取中间的view
391 | * @return
392 | */
393 | public View getCenterView() {
394 | return getChildClosestToLocation(getCenterLocation());
395 | }
396 |
397 | /**
398 | * 滚动指定view
399 | * @param child
400 | */
401 | private void scrollToView(View child) {
402 | if (child == null)
403 | return;
404 |
405 | stopScroll();
406 |
407 | int scrollDistance = getScrollDistance(child);
408 |
409 | if (scrollDistance != 0)
410 | smoothScrollBy(scrollDistance);
411 | }
412 |
413 | /**
414 | * 获取需要滚动的距离
415 | * @param child
416 | * @return
417 | */
418 | private int getScrollDistance(View child) {
419 | int childCenterLocation = (int) childViewMetrics.center(child);
420 | return childCenterLocation - getCenterLocation();
421 | }
422 |
423 | private float getPercentageFromCenter(View child) {
424 | float center = getCenterLocation();
425 | float childCenter = childViewMetrics.center(child);
426 |
427 | float offSet = Math.max(center, childCenter) - Math.min(center, childCenter);
428 | float maxOffset = (center + childViewMetrics.size(child));
429 |
430 | return (offSet / maxOffset);
431 | }
432 |
433 | /**
434 | * 获取中间位置
435 | * @return
436 | */
437 | private int getCenterLocation() {
438 | if (orientation == Orientation.VERTICAL)
439 | return getMeasuredHeight() / 2;
440 |
441 | return getMeasuredWidth() / 2;
442 | }
443 |
444 | public void smoothScrollBy(int distance) {
445 | if (orientation == Orientation.VERTICAL) {
446 | super.smoothScrollBy(0, distance);
447 | return;
448 | }
449 |
450 | super.smoothScrollBy(distance, 0);
451 | }
452 |
453 | public void scrollBy(int distance) {
454 | if (orientation == Orientation.VERTICAL) {
455 | super.scrollBy(0, distance);
456 | return;
457 | }
458 |
459 | super.scrollBy(distance, 0);
460 | }
461 |
462 | private void scrollTo(int position) {
463 | int currentScroll = getScrollOffset();
464 | scrollBy(position - currentScroll);
465 | }
466 |
467 | public int getScrollOffset() {
468 | if (orientation == Orientation.VERTICAL)
469 | return computeVerticalScrollOffset();
470 |
471 | return computeHorizontalScrollOffset();
472 | }
473 |
474 | @Override
475 | protected void onDetachedFromWindow() {
476 | super.onDetachedFromWindow();
477 | mHandler.removeCallbacksAndMessages(null);
478 | }
479 |
480 | /**
481 | * 绘制一个中间view
482 | * @param canvas
483 | */
484 | @Override
485 | protected void dispatchDraw(Canvas canvas) {
486 | super.dispatchDraw(canvas);
487 | }
488 |
489 |
490 | private static class ChildViewMetrics {
491 | private Orientation orientation;
492 |
493 | public ChildViewMetrics(Orientation orientation) {
494 | this.orientation = orientation;
495 | }
496 |
497 | public int size(View view) {
498 | if (orientation == Orientation.VERTICAL)
499 | return view.getHeight();
500 |
501 | return view.getWidth();
502 | }
503 |
504 | public float location(View view) {
505 | if (orientation == Orientation.VERTICAL)
506 | return view.getY();
507 |
508 | return view.getX();
509 | }
510 |
511 | public float center(View view) {
512 | return location(view) + (size(view) / 2);
513 | }
514 | }
515 |
516 | public enum Orientation {
517 | HORIZONTAL(LinearLayout.HORIZONTAL),
518 | VERTICAL(LinearLayout.VERTICAL);
519 |
520 | int value;
521 |
522 | Orientation(int value) {
523 | this.value = value;
524 | }
525 |
526 | public int intValue() {
527 | return value;
528 | }
529 | }
530 |
531 | /**
532 | * 中间view选中接口
533 | */
534 | public interface OnViewSelectedListener {
535 | void onSelected(View view, int position);
536 | }
537 | }
538 |
--------------------------------------------------------------------------------