├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── AnyShareOfAndroid.iml
├── README.md
├── RadarScanView
├── .gitignore
├── RadarScanView.iml
├── build.gradle
├── library.iml
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── guo
│ │ └── duoduo
│ │ └── library
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── guo
│ │ │ └── duoduo
│ │ │ └── library
│ │ │ └── RadarScanView.java
│ └── res
│ │ └── values
│ │ ├── attrs.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── guo
│ └── duoduo
│ └── library
│ └── ExampleUnitTest.java
├── app
├── .gitignore
├── app.iml
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── guo
│ │ └── duoduo
│ │ └── anyshareofandroid
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── guo
│ │ │ └── duoduo
│ │ │ └── anyshareofandroid
│ │ │ ├── MyApplication.java
│ │ │ ├── constant
│ │ │ └── Constant.java
│ │ │ ├── sdk
│ │ │ ├── accesspoint
│ │ │ │ ├── AccessPointManager.java
│ │ │ │ ├── WifiConnectManager.java
│ │ │ │ └── WifiManagerWrap.java
│ │ │ └── cache
│ │ │ │ └── Cache.java
│ │ │ ├── ui
│ │ │ ├── common
│ │ │ │ ├── BaseActivity.java
│ │ │ │ └── FragmentAdapter.java
│ │ │ ├── main
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── WelcomeActivity.java
│ │ │ ├── setting
│ │ │ │ ├── AboutActivity.java
│ │ │ │ ├── FileBrowseActivity.java
│ │ │ │ ├── fragment
│ │ │ │ │ ├── ReceivedApp.java
│ │ │ │ │ └── ReceivedPicture.java
│ │ │ │ └── view
│ │ │ │ │ └── ReceivedAppAdapter.java
│ │ │ ├── transfer
│ │ │ │ ├── FileSelectActivity.java
│ │ │ │ ├── RadarScanActivity.java
│ │ │ │ ├── ReceiveActivity.java
│ │ │ │ ├── fragment
│ │ │ │ │ ├── AppFragment.java
│ │ │ │ │ ├── OnSelectItemClickListener.java
│ │ │ │ │ └── PictureFragment.java
│ │ │ │ └── view
│ │ │ │ │ ├── AppSelectAdapter.java
│ │ │ │ │ ├── FileTransferAdapter.java
│ │ │ │ │ └── ImageSelectAdapter.java
│ │ │ ├── uientity
│ │ │ │ ├── AppInfo.java
│ │ │ │ ├── IInfo.java
│ │ │ │ ├── LocationPoint.java
│ │ │ │ └── PictureInfo.java
│ │ │ └── view
│ │ │ │ ├── CommonDialog.java
│ │ │ │ ├── CommonProgressDialog.java
│ │ │ │ ├── FloatWindowSmallView.java
│ │ │ │ └── MyWindowManager.java
│ │ │ └── utils
│ │ │ ├── ApkTools.java
│ │ │ ├── DeviceUtils.java
│ │ │ ├── NetworkUtils.java
│ │ │ ├── PreferenceUtils.java
│ │ │ ├── ToastUtils.java
│ │ │ └── ViewUtils.java
│ └── res
│ │ ├── anim
│ │ └── out_to_up.xml
│ │ ├── drawable
│ │ ├── btn_green_selector.xml
│ │ ├── btn_red_selector.xml
│ │ ├── btn_top_back_selector.xml
│ │ ├── common_dlg_fullbtn_selector.xml
│ │ ├── common_dlg_leftbtn_selector.xml
│ │ ├── common_dlg_rightbtn_selector.xml
│ │ ├── common_loading.xml
│ │ ├── list_bg_selector.xml
│ │ ├── progressbg.xml
│ │ ├── tab_left_selector.xml
│ │ ├── tab_mid_selector.xml
│ │ └── tab_right_selector.xml
│ │ ├── layout
│ │ ├── activity_about.xml
│ │ ├── activity_file.xml
│ │ ├── activity_file_browse.xml
│ │ ├── activity_file_transfering.xml
│ │ ├── activity_main.xml
│ │ ├── activity_radarscan.xml
│ │ ├── activity_receive.xml
│ │ ├── activity_welcome.xml
│ │ ├── fragment_received.xml
│ │ ├── view_app_item.xml
│ │ ├── view_common_dialog.xml
│ │ ├── view_common_dialog_message.xml
│ │ ├── view_common_progress_dialog.xml
│ │ ├── view_file_select.xml
│ │ ├── view_file_transfer_item.xml
│ │ ├── view_pic_item.xml
│ │ ├── view_received_app_item.xml
│ │ └── view_select.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ ├── icon_apk.png
│ │ ├── icon_image.png
│ │ ├── rocket_body.png
│ │ └── rocket_fire.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ ├── bg_cabin.jpg
│ │ ├── bg_head.9.png
│ │ ├── bg_pop_white.9.png
│ │ ├── btn_green.9.png
│ │ ├── btn_green_click.9.png
│ │ ├── btn_red.9.png
│ │ ├── btn_red_click.9.png
│ │ ├── btn_top_back.png
│ │ ├── btn_top_back_click.png
│ │ ├── common_dlg_conbg.9.png
│ │ ├── common_dlg_fullbtn_bg.9.png
│ │ ├── common_dlg_fullbtn_bg_click.9.png
│ │ ├── common_dlg_headbg.9.png
│ │ ├── common_dlg_leftbtn_bg.9.png
│ │ ├── common_dlg_leftbtn_bg_click.9.png
│ │ ├── common_dlg_rightbtn_bg.9.png
│ │ ├── common_dlg_rightbtn_bg_click.9.png
│ │ ├── common_loading_0.png
│ │ ├── editable_mode_checked_tag.png
│ │ ├── editable_mode_unchecked_tag.png
│ │ ├── ic_launcher.png
│ │ ├── icon_loading.png
│ │ ├── phone.png
│ │ ├── tab_callselect_left_normal.9.png
│ │ ├── tab_callselect_left_selected.9.png
│ │ ├── tab_callselect_mid_normal.9.png
│ │ ├── tab_callselect_mid_selected.9.png
│ │ ├── tab_callselect_right_normal.9.png
│ │ ├── tab_callselect_right_selected.9.png
│ │ └── watermelon.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── guo
│ └── duoduo
│ └── anyshareofandroid
│ └── ExampleUnitTest.java
├── build.gradle
├── filetransfer.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── httpServer
├── .gitignore
├── app.iml
├── build.gradle
├── httpServer.iml
├── libs
│ └── httpcore-4.3.2.jar
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── guo
│ │ └── duoduo
│ │ └── httpserver
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── guo
│ │ │ └── duoduo
│ │ │ └── httpserver
│ │ │ ├── cache
│ │ │ └── SdFileCache.java
│ │ │ ├── http
│ │ │ ├── FileBrowseHandler.java
│ │ │ ├── RequestListenerThread.java
│ │ │ └── WorkThread.java
│ │ │ ├── service
│ │ │ └── WebService.java
│ │ │ ├── ui
│ │ │ └── Send2PCActivity.java
│ │ │ └── utils
│ │ │ ├── Constant.java
│ │ │ └── Network.java
│ └── res
│ │ ├── layout
│ │ └── activity_send2pc.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── guo
│ └── duoduo
│ └── httpserver
│ └── ExampleUnitTest.java
├── p2pmanager
├── .gitignore
├── build.gradle
├── p2pmanager.iml
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── guo
│ │ └── duoduo
│ │ └── p2pmanager
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── guo
│ │ │ └── duoduo
│ │ │ └── p2pmanager
│ │ │ ├── p2pconstant
│ │ │ └── P2PConstant.java
│ │ │ ├── p2pcore
│ │ │ ├── CustomHandlerThread.java
│ │ │ ├── MelonCommunicate.java
│ │ │ ├── MelonHandler.java
│ │ │ ├── MelonManager.java
│ │ │ ├── P2PManager.java
│ │ │ ├── receive
│ │ │ │ ├── ReceiveManager.java
│ │ │ │ ├── ReceiveTask.java
│ │ │ │ └── Receiver.java
│ │ │ └── send
│ │ │ │ ├── OneByOneRunnable.java
│ │ │ │ ├── SendManager.java
│ │ │ │ ├── SendServer.java
│ │ │ │ ├── SendServerHandler.java
│ │ │ │ ├── SendTask.java
│ │ │ │ └── Sender.java
│ │ │ ├── p2pentity
│ │ │ ├── P2PFileInfo.java
│ │ │ ├── P2PNeighbor.java
│ │ │ ├── SigMessage.java
│ │ │ ├── SocketTransInfo.java
│ │ │ └── param
│ │ │ │ ├── ParamIPMsg.java
│ │ │ │ ├── ParamReceiveFiles.java
│ │ │ │ ├── ParamSendFiles.java
│ │ │ │ └── ParamTCPNotify.java
│ │ │ ├── p2pinterface
│ │ │ ├── Handler.java
│ │ │ ├── Melon_Callback.java
│ │ │ ├── ReceiveFile_Callback.java
│ │ │ └── SendFile_Callback.java
│ │ │ └── p2ptimer
│ │ │ ├── OSTimer.java
│ │ │ └── Timeout.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── guo
│ └── duoduo
│ └── p2pmanager
│ └── ExampleUnitTest.java
├── randomtextview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── randomtextview.iml
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── guo
│ │ └── duoduo
│ │ └── randomtextview
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── guo
│ │ │ └── duoduo
│ │ │ └── randomtextview
│ │ │ └── RandomTextView.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── guo
│ └── duoduo
│ └── randomtextview
│ └── ExampleUnitTest.java
├── rippleoutlayout
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── rippleoutlayout.iml
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── guo
│ │ └── duoduo
│ │ └── rippleoutlayout
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── guo
│ │ │ └── duoduo
│ │ │ └── rippleoutlayout
│ │ │ └── RippleOutLayout.java
│ └── res
│ │ └── values
│ │ ├── ripple_layout_attrs.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── guo
│ └── duoduo
│ └── rippleoutlayout
│ └── ExampleUnitTest.java
├── rippleview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── rippleview.iml
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── guo
│ │ └── duoduo
│ │ └── rippleoutview
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── guo
│ │ │ └── duoduo
│ │ │ └── rippleoutview
│ │ │ └── RippleView.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── guo
│ └── duoduo
│ └── rippleoutview
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | AnyShareOfAndroid
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
24 |
25 |
--------------------------------------------------------------------------------
/.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 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/AnyShareOfAndroid.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AnyShareOfAndroid
2 | 仿茄子快传 或者 360文件传输
3 | * 在局域网内进行文件(发送方的app、图片等文件,项目中只是进行了手机中的第三方app和手机图片的)的传输。
4 | * 如果没有接收方建立热点,发送方接入热点,然后进行文件的传输。
5 | * 添加android与pc之间的文件传输,通过在android设备中实现http server来完成(这样不需要在pc中安装应用,只需要浏览器就可以方便完成操作)
6 |
7 |
8 |
9 | ## 实现原理:
10 | * 设备发现:通过udp向255.255.255.255发送广播包
11 | * 文件传输:通过NIO socket。
12 | * android下httpServer的实现通过apache的httpcore。
13 |
14 | # 效果图
15 | 需要两部手机,连接在同一个wifi环境下,会相互发现,并且通过点击发现后的对方,建立连接,进而进行文件的传输。
16 |
17 | 
18 |
19 |
20 | ## 引用库
21 | * [雷达扫描图](https://github.com/gpfduoduo/RadarScanView) 作者:[本人](https://github.com/gpfduoduo)
22 | * compile 'com.android.support:appcompat-v7:22.2.0'
23 | * compile 'com.android.support:design:22.2.0'
24 | * compile 'com.android.support:support-v4:22.2.0'
25 | * compile 'com.github.bumptech.glide:glide:3.5.2'
26 | * compile 'com.android.support:support-v4:22.2.0'
27 | * compile 'com.android.support:recyclerview-v7:22.+'
28 | * compile 'com.github.bumptech.glide:glide:3.5.2'
29 | * compile project(':randomtextview')
30 | * compile project(':rippleview')
31 | * compile project(':rippleoutlayout')
32 | * compile project(':p2pmanager')
33 | * compile project(':httpServer') 作者[本人](https://github.com/gpfduoduo/HttpServerOnAndroid/)
34 |
35 | ## 感谢
36 | 杨蔚 及其 儿子
37 |
--------------------------------------------------------------------------------
/RadarScanView/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/RadarScanView/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | }
25 |
--------------------------------------------------------------------------------
/RadarScanView/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 D:\developtools\android sdk windows/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 p2pinterface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.p2pinterface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/RadarScanView/src/androidTest/java/com/guo/duoduo/library/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.library;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/RadarScanView/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/RadarScanView/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/RadarScanView/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/RadarScanView/src/test/java/com/guo/duoduo/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.library;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.guo.duoduo.anyshareofandroid"
9 | minSdkVersion 15
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 | compile project(':RadarScanView')
25 | compile project(':randomtextview')
26 | compile project(':rippleview')
27 | compile project(':rippleoutlayout')
28 | compile project(':p2pmanager')
29 | compile project(':httpServer')
30 | compile 'com.android.support:support-v4:23.1.0'
31 | compile 'com.android.support:appcompat-v7:23.1.0'
32 | compile 'com.android.support:design:23.1.0'
33 | compile 'com.android.support:recyclerview-v7:23.1.0'
34 | compile 'com.android.support:cardview-v7:23.1.0'
35 | compile 'com.github.bumptech.glide:glide:3.5.2'
36 | }
37 |
--------------------------------------------------------------------------------
/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 D:\developtools\android_sdk_windows/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 p2pinterface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.p2pinterface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/guo/duoduo/anyshareofandroid/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
23 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
36 |
39 |
42 |
46 |
50 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid;
2 |
3 |
4 | import android.app.Application;
5 | import android.content.Context;
6 | import android.graphics.Point;
7 | import android.view.Display;
8 | import android.view.WindowManager;
9 |
10 |
11 | /**
12 | * Created by 郭攀峰 on 2015/9/11.
13 | */
14 | public class MyApplication extends Application
15 | {
16 |
17 | private static MyApplication instance;
18 |
19 | public static int SCREEN_WIDTH;
20 |
21 |
22 | @Override
23 | public void onCreate()
24 | {
25 | super.onCreate();
26 |
27 | instance = this;
28 | Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
29 | .getDefaultDisplay();
30 | Point screen = new Point();
31 | display.getSize(screen);
32 | SCREEN_WIDTH = Math.min(screen.x, screen.y);
33 |
34 | initImageLoader();
35 | }
36 |
37 | private void initImageLoader()
38 | {
39 | // ImageLoaderConfig config = new ImageLoaderConfig()
40 | // .setLoadingPlaceholder(R.drawable.icon_loading)
41 | // .setCache(new MemoryCache())
42 | // .setLoadPolicy(new SerialPolicy());
43 | // SimpleImageLoader.getInstance().init(config);
44 | }
45 |
46 | public static MyApplication getInstance()
47 | {
48 | return instance;
49 | }
50 |
51 | @Override
52 | public void onTerminate()
53 | {
54 | super.onTerminate();
55 | }
56 |
57 | @Override
58 | public void onLowMemory()
59 | {
60 | super.onLowMemory();
61 | }
62 |
63 | @Override
64 | public void onTrimMemory(int level)
65 | {
66 | super.onTrimMemory(level);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/constant/Constant.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.constant;
2 |
3 |
4 | import com.guo.duoduo.anyshareofandroid.MyApplication;
5 | import com.guo.duoduo.anyshareofandroid.R;
6 |
7 |
8 | /**
9 | * Created by 郭攀峰 on 2015/9/15.
10 | */
11 | public class Constant
12 | {
13 | public static final String WIFI_HOT_SPOT_SSID_PREFIX = MyApplication.getInstance()
14 | .getString(R.string.app_name);
15 | public static final String FREE_SERVER = "192.168.43.1";
16 |
17 | public interface MSG
18 | {
19 | public static final int PICTURE_OK = 0;
20 | public static final int APP_OK = 1;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/sdk/cache/Cache.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.sdk.cache;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Created by 郭攀峰 on 2015/9/16.
11 | */
12 | public class Cache
13 | {
14 | public static List selectedList = new ArrayList<>();
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/common/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.common;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.MenuItem;
7 |
8 |
9 | /**
10 | * Created by 郭攀峰 on 2015/9/26.
11 | */
12 | public class BaseActivity extends AppCompatActivity
13 | {
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState)
16 | {
17 | super.onCreate(savedInstanceState);
18 | }
19 |
20 | @Override
21 | public boolean onOptionsItemSelected(MenuItem item)
22 | {
23 | if (item.getItemId() == android.R.id.home)
24 | {
25 | finish();
26 | return true;
27 | }
28 | return super.onOptionsItemSelected(item);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/common/FragmentAdapter.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.common;
2 |
3 |
4 | import java.util.List;
5 |
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentStatePagerAdapter;
9 |
10 |
11 | /**
12 | * Created by 郭攀峰 on 2015/9/16.
13 | */
14 | public class FragmentAdapter extends FragmentStatePagerAdapter
15 | {
16 |
17 | private List mFragments;
18 | private List mTitles;
19 |
20 | public FragmentAdapter(FragmentManager fm, List fragments,
21 | List titles)
22 | {
23 | super(fm);
24 | mFragments = fragments;
25 | mTitles = titles;
26 |
27 | }
28 |
29 | @Override
30 | public Fragment getItem(int position)
31 | {
32 | return mFragments.get(position);
33 | }
34 |
35 | @Override
36 | public int getCount()
37 | {
38 | return mFragments.size();
39 | }
40 |
41 | @Override
42 | public CharSequence getPageTitle(int position)
43 | {
44 | return mTitles.get(position);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/main/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.main;
2 |
3 |
4 | import android.content.Intent;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.EditText;
14 |
15 | import com.guo.duoduo.anyshareofandroid.R;
16 | import com.guo.duoduo.anyshareofandroid.sdk.cache.Cache;
17 | import com.guo.duoduo.anyshareofandroid.ui.setting.AboutActivity;
18 | import com.guo.duoduo.anyshareofandroid.ui.setting.FileBrowseActivity;
19 | import com.guo.duoduo.anyshareofandroid.ui.transfer.FileSelectActivity;
20 | import com.guo.duoduo.anyshareofandroid.ui.transfer.ReceiveActivity;
21 | import com.guo.duoduo.anyshareofandroid.utils.PreferenceUtils;
22 | import com.guo.duoduo.httpserver.ui.Send2PCActivity;
23 |
24 |
25 | public class MainActivity extends AppCompatActivity implements View.OnClickListener
26 | {
27 |
28 | private EditText nameEdit;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState)
32 | {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_main);
35 | Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
36 | setSupportActionBar(toolbar);
37 |
38 | toolbar.setOnMenuItemClickListener(onMenuItemClick);
39 |
40 | Button send = (Button) findViewById(R.id.activity_main_i_send);
41 | send.setOnClickListener(this);
42 | Button receive = (Button) findViewById(R.id.activity_main_i_receive);
43 | receive.setOnClickListener(this);
44 | Button send2PC = (Button) findViewById(R.id.main_i_send_2_pc);
45 | send2PC.setOnClickListener(this);
46 |
47 | nameEdit = (EditText) findViewById(R.id.activity_main_name_edit);
48 | nameEdit.setText((String) PreferenceUtils.getParam(MainActivity.this, "String",
49 | Build.DEVICE));
50 | }
51 |
52 | @Override
53 | public void onPause()
54 | {
55 | super.onPause();
56 | //记住用户修改的名字
57 | PreferenceUtils.setParam(MainActivity.this, "String", nameEdit.getText()
58 | .toString());
59 | }
60 |
61 | @Override
62 | public void onClick(View view)
63 | {
64 | switch (view.getId())
65 | {
66 | case R.id.activity_main_i_receive :
67 | Cache.selectedList.clear();
68 | startActivity(new Intent(MainActivity.this, ReceiveActivity.class)
69 | .putExtra("name", nameEdit.getText().toString()));
70 | break;
71 | case R.id.activity_main_i_send :
72 | Cache.selectedList.clear();
73 | startActivity(new Intent(MainActivity.this, FileSelectActivity.class)
74 | .putExtra("name", nameEdit.getText().toString()));
75 | break;
76 | case R.id.main_i_send_2_pc :
77 | startActivity(new Intent(MainActivity.this, Send2PCActivity.class));
78 | break;
79 | }
80 | }
81 |
82 | private Toolbar.OnMenuItemClickListener onMenuItemClick = new Toolbar.OnMenuItemClickListener()
83 | {
84 | @Override
85 | public boolean onMenuItemClick(MenuItem menuItem)
86 | {
87 | switch (menuItem.getItemId())
88 | {
89 | case R.id.menu_item_receive_directory :
90 | startActivity(new Intent(MainActivity.this, FileBrowseActivity.class));
91 | break;
92 | case R.id.menu_item_about :
93 | startActivity(new Intent(MainActivity.this, AboutActivity.class));
94 | break;
95 | }
96 | return true;
97 | }
98 | };
99 |
100 | @Override
101 | public boolean onCreateOptionsMenu(Menu menu)
102 | {
103 | // 為了讓 Toolbar 的 Menu 有作用,這邊的程式不可以拿掉
104 | getMenuInflater().inflate(R.menu.menu_main, menu);
105 | return true;
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/main/WelcomeActivity.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.main;
2 |
3 |
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.widget.ImageView;
8 |
9 | import com.guo.duoduo.anyshareofandroid.R;
10 | import com.guo.duoduo.p2pmanager.p2ptimer.OSTimer;
11 | import com.guo.duoduo.p2pmanager.p2ptimer.Timeout;
12 |
13 |
14 | public class WelcomeActivity extends Activity
15 | {
16 |
17 | private ImageView melon1;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState)
21 | {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_welcome);
24 |
25 | initWidget();
26 | Timeout timeout = new Timeout()
27 | {
28 | @Override
29 | public void onTimeOut()
30 | {
31 | startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
32 | finish();
33 | }
34 | };
35 |
36 | new OSTimer(null, timeout, 2 * 1000).start();
37 | }
38 |
39 | private void initWidget()
40 | {
41 | melon1 = (ImageView) findViewById(R.id.activity_welcome_melon1);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/setting/AboutActivity.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.setting;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.design.widget.CollapsingToolbarLayout;
6 | import android.support.v7.app.ActionBar;
7 | import android.support.v7.widget.Toolbar;
8 | import android.widget.TextView;
9 |
10 | import com.guo.duoduo.anyshareofandroid.R;
11 | import com.guo.duoduo.anyshareofandroid.ui.common.BaseActivity;
12 | import com.guo.duoduo.p2pmanager.p2pcore.P2PManager;
13 |
14 |
15 | public class AboutActivity extends BaseActivity
16 | {
17 |
18 | private CollapsingToolbarLayout collapsingToolbarLayout;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState)
22 | {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_about);
25 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
26 | setSupportActionBar(toolbar);
27 |
28 | ActionBar actionBar = getSupportActionBar();
29 | if (actionBar != null)
30 | actionBar.setDisplayHomeAsUpEnabled(true);
31 |
32 | collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.activity_about_collapsing_toolbar);
33 | collapsingToolbarLayout.setTitle(getString(R.string.menu_about));
34 |
35 | TextView receivePath = (TextView) findViewById(R.id.about_receive_path_content);
36 | receivePath.setText(P2PManager.getSaveDir());
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/setting/FileBrowseActivity.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.setting;
2 |
3 |
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import android.os.Bundle;
8 | import android.support.design.widget.TabLayout;
9 | import android.support.v4.view.ViewPager;
10 | import android.support.v7.app.ActionBar;
11 | import android.support.v7.widget.Toolbar;
12 |
13 | import com.guo.duoduo.anyshareofandroid.R;
14 | import com.guo.duoduo.anyshareofandroid.ui.common.BaseActivity;
15 | import com.guo.duoduo.anyshareofandroid.ui.setting.fragment.ReceivedApp;
16 | import com.guo.duoduo.anyshareofandroid.ui.setting.fragment.ReceivedPicture;
17 | import com.guo.duoduo.anyshareofandroid.ui.common.FragmentAdapter;
18 |
19 |
20 | public class FileBrowseActivity extends BaseActivity
21 | {
22 | private ViewPager mViewPager;
23 | private TabLayout mTabLayout;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState)
27 | {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_file_browse);
30 |
31 | Toolbar toolbar = (Toolbar) findViewById(R.id.activity_receive_browse_toolbar);
32 | setSupportActionBar(toolbar);
33 | ActionBar actionBar = getSupportActionBar();
34 | if (actionBar != null)
35 | actionBar.setDisplayHomeAsUpEnabled(true);
36 |
37 | initWidget();
38 | }
39 |
40 | private void initWidget()
41 | {
42 | List titles = new ArrayList<>();
43 | titles.add(getString(R.string.app));
44 | titles.add(getString(R.string.picture));
45 |
46 | mTabLayout = (TabLayout) findViewById(R.id.activity_receive_browse_tabLayout);
47 | mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(0)));
48 | mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(1)));
49 |
50 | mViewPager = (ViewPager) findViewById(R.id.activity_receive_browse_viewpager);
51 |
52 | List fragments = new ArrayList<>();
53 | fragments.add(ReceivedApp.newInstance());
54 | fragments.add(ReceivedPicture.newInstance());
55 |
56 | FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager(),
57 | fragments, titles);
58 | mViewPager.setAdapter(adapter);
59 |
60 | mTabLayout.setupWithViewPager(mViewPager);
61 | mTabLayout.setTabsFromPagerAdapter(adapter);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/setting/fragment/ReceivedApp.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.setting.fragment;
2 |
3 |
4 | import java.io.File;
5 | import java.util.ArrayList;
6 |
7 | import android.app.Activity;
8 | import android.os.Bundle;
9 | import android.support.v4.app.Fragment;
10 | import android.support.v7.widget.GridLayoutManager;
11 | import android.support.v7.widget.RecyclerView;
12 | import android.text.TextUtils;
13 | import android.util.Log;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.widget.TextView;
18 |
19 | import com.guo.duoduo.anyshareofandroid.R;
20 | import com.guo.duoduo.anyshareofandroid.ui.setting.view.ReceivedAppAdapter;
21 | import com.guo.duoduo.anyshareofandroid.ui.uientity.AppInfo;
22 | import com.guo.duoduo.anyshareofandroid.ui.uientity.IInfo;
23 | import com.guo.duoduo.anyshareofandroid.utils.ApkTools;
24 | import com.guo.duoduo.anyshareofandroid.utils.DeviceUtils;
25 | import com.guo.duoduo.p2pmanager.p2pconstant.P2PConstant;
26 | import com.guo.duoduo.p2pmanager.p2pcore.P2PManager;
27 |
28 |
29 | /**
30 | * show the received app files, click the item to install
31 | */
32 | public class ReceivedApp extends Fragment
33 | {
34 |
35 | private static final String tag = ReceivedApp.class.getSimpleName();
36 |
37 | private RecyclerView mRecyclerView;
38 | private ReceivedAppAdapter mAdapter;
39 | private ArrayList mAppList;
40 | private TextView mNoContentTextView;
41 | private View mView;
42 |
43 | public static ReceivedApp newInstance()
44 | {
45 | ReceivedApp fragment = new ReceivedApp();
46 | return fragment;
47 | }
48 |
49 | @Override
50 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
51 | Bundle savedInstanceState)
52 | {
53 | if (mView == null)
54 | {
55 | mView = inflater.inflate(R.layout.fragment_received, container, false);
56 | mRecyclerView = (RecyclerView) mView.findViewById(R.id.received_recyclerview);
57 | mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 4));
58 | mRecyclerView.setVisibility(View.GONE);
59 | mNoContentTextView = (TextView) mView.findViewById(R.id.received_textview);
60 | initData();
61 | }
62 | return mView;
63 | }
64 |
65 | @Override
66 | public void onAttach(Activity activity)
67 | {
68 | super.onAttach(activity);
69 | }
70 |
71 | @Override
72 | public void onDetach()
73 | {
74 | super.onDetach();
75 | }
76 |
77 | private void initData()
78 | {
79 | String appDir = P2PManager.getSavePath(P2PConstant.TYPE.APP);
80 | Log.d(tag, "app dir = " + appDir);
81 |
82 | if (!TextUtils.isEmpty(appDir))
83 | {
84 | File appFile = new File(appDir);
85 | if (appFile.exists() && appFile.isDirectory())
86 | {
87 | File[] appFileArray = appFile.listFiles();
88 | if (appFileArray != null && appFileArray.length > 0)
89 | {
90 | mRecyclerView.setVisibility(View.VISIBLE);
91 | mNoContentTextView.setVisibility(View.GONE);
92 | mAppList = new ArrayList<>();
93 | for (File app : appFileArray)
94 | {
95 | AppInfo appInfo = new AppInfo();
96 | if (app.isFile() && app.getAbsolutePath().endsWith(".apk"))
97 | {
98 | appInfo.appLabel = app.getName();
99 | appInfo.appSize = DeviceUtils.convertByte(app.length());
100 | appInfo.appIcon = ApkTools.geTApkIcon(getActivity(),
101 | app.getAbsolutePath());
102 | appInfo.appFilePath = app.getAbsolutePath();
103 |
104 | if (!mAppList.contains(appInfo))
105 | mAppList.add(appInfo);
106 | }
107 | }
108 |
109 | mAdapter = new ReceivedAppAdapter(getActivity(), mAppList);
110 | mRecyclerView.setAdapter(mAdapter);
111 | }
112 | }
113 | }
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/setting/fragment/ReceivedPicture.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.setting.fragment;
2 |
3 |
4 | import android.app.Activity;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.guo.duoduo.anyshareofandroid.R;
12 |
13 |
14 | /**
15 | * show the received images, click item to browse the big one
16 | */
17 | public class ReceivedPicture extends Fragment
18 | {
19 | public static ReceivedPicture newInstance()
20 | {
21 | ReceivedPicture fragment = new ReceivedPicture();
22 | return fragment;
23 | }
24 |
25 | @Override
26 | public void onCreate(Bundle savedInstanceState)
27 | {
28 | super.onCreate(savedInstanceState);
29 | }
30 |
31 | @Override
32 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
33 | Bundle savedInstanceState)
34 | {
35 | return inflater.inflate(R.layout.fragment_received, container, false);
36 | }
37 |
38 | @Override
39 | public void onAttach(Activity activity)
40 | {
41 | super.onAttach(activity);
42 | }
43 |
44 | @Override
45 | public void onDetach()
46 | {
47 | super.onDetach();
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/setting/view/ReceivedAppAdapter.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.setting.view;
2 |
3 |
4 | import java.io.File;
5 | import java.util.ArrayList;
6 |
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.graphics.drawable.BitmapDrawable;
10 | import android.net.Uri;
11 | import android.support.v7.widget.RecyclerView;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.ImageView;
16 | import android.widget.LinearLayout;
17 | import android.widget.TextView;
18 |
19 | import com.guo.duoduo.anyshareofandroid.R;
20 | import com.guo.duoduo.anyshareofandroid.ui.uientity.AppInfo;
21 | import com.guo.duoduo.anyshareofandroid.ui.uientity.IInfo;
22 |
23 |
24 | /**
25 | * Created by 郭攀峰 on 2015/10/11.
26 | */
27 | public class ReceivedAppAdapter extends RecyclerView.Adapter
28 | {
29 | private Context mContext;
30 | private ArrayList mAppInfoList;
31 |
32 | public ReceivedAppAdapter(Context context, ArrayList appInfoList)
33 | {
34 | mContext = context;
35 | mAppInfoList = appInfoList;
36 | }
37 |
38 | @Override
39 | public MyHolder onCreateViewHolder(ViewGroup parent, int viewType)
40 | {
41 | MyHolder myHolder = new MyHolder(LayoutInflater.from(mContext).inflate(
42 | R.layout.view_received_app_item, null));
43 |
44 | return myHolder;
45 | }
46 |
47 | @Override
48 | public void onBindViewHolder(MyHolder holder, final int position)
49 | {
50 | final AppInfo app = (AppInfo) mAppInfoList.get(position);
51 |
52 | if (app == null)
53 | return;
54 |
55 | holder.mIcon.setImageBitmap(((BitmapDrawable) app.getFileIcon()).getBitmap());
56 | holder.mName.setText(app.getFileName());
57 | holder.mSize.setText(app.getFileSize());
58 |
59 | holder.mLayout.setOnClickListener(new View.OnClickListener()
60 | {
61 | @Override
62 | public void onClick(View v)
63 | {
64 | // install app
65 | Intent intent = new Intent(Intent.ACTION_VIEW);
66 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
67 | intent.setDataAndType(Uri.fromFile(new File(app.getFilePath())),
68 | "application/vnd.android.package-archive");
69 | mContext.startActivity(intent);
70 | }
71 | });
72 | }
73 |
74 | @Override
75 | public int getItemCount()
76 | {
77 | return mAppInfoList.size();
78 | }
79 |
80 | static class MyHolder extends RecyclerView.ViewHolder
81 | {
82 | ImageView mIcon;
83 | TextView mName;
84 | TextView mSize;
85 | LinearLayout mLayout;
86 |
87 | public MyHolder(View view)
88 | {
89 | super(view);
90 | mIcon = (ImageView) view.findViewById(R.id.received_app_icon);
91 | mName = (TextView) view.findViewById(R.id.received_app_name);
92 | mSize = (TextView) view.findViewById(R.id.received_app_size);
93 | mLayout = (LinearLayout) view.findViewById(R.id.received_app_layout);
94 | }
95 |
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/transfer/FileSelectActivity.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.transfer;
2 |
3 |
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import android.content.Intent;
8 | import android.os.Build;
9 | import android.os.Bundle;
10 | import android.support.design.widget.FloatingActionButton;
11 | import android.support.design.widget.TabLayout;
12 | import android.support.v4.view.ViewPager;
13 | import android.support.v7.app.ActionBar;
14 | import android.support.v7.widget.Toolbar;
15 | import android.text.TextUtils;
16 | import android.view.View;
17 |
18 | import com.guo.duoduo.anyshareofandroid.R;
19 | import com.guo.duoduo.anyshareofandroid.sdk.cache.Cache;
20 | import com.guo.duoduo.anyshareofandroid.ui.common.BaseActivity;
21 | import com.guo.duoduo.anyshareofandroid.ui.transfer.fragment.AppFragment;
22 | import com.guo.duoduo.anyshareofandroid.ui.common.FragmentAdapter;
23 | import com.guo.duoduo.anyshareofandroid.ui.transfer.fragment.OnSelectItemClickListener;
24 | import com.guo.duoduo.anyshareofandroid.ui.transfer.fragment.PictureFragment;
25 | import com.guo.duoduo.anyshareofandroid.utils.ToastUtils;
26 |
27 |
28 | /**
29 | * Created by 郭攀峰 on 2015/9/15.
30 | */
31 | public class FileSelectActivity extends BaseActivity implements OnSelectItemClickListener
32 | {
33 | private ViewPager viewPager;
34 | private TabLayout tabLayout;
35 | private String userName = Build.DEVICE;
36 | private Toolbar toolbar;
37 | private String title;
38 |
39 | @Override
40 | protected void onCreate(Bundle savedInstanceState)
41 | {
42 | super.onCreate(savedInstanceState);
43 |
44 | setContentView(R.layout.activity_file);
45 | toolbar = (Toolbar) findViewById(R.id.activity_file_toolbar);
46 | setSupportActionBar(toolbar);
47 | ActionBar actionBar = getSupportActionBar();
48 | if (actionBar != null)
49 | actionBar.setDisplayHomeAsUpEnabled(true);
50 |
51 | title = toolbar.getTitle().toString();
52 | if (TextUtils.isEmpty(title))
53 | title = getString(R.string.file_select);
54 |
55 | Intent intent = getIntent();
56 | if (intent != null)
57 | {
58 | userName = intent.getStringExtra("name");
59 | }
60 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.activity_file_fab);
61 | fab.setOnClickListener(new View.OnClickListener()
62 | {
63 | @Override
64 | public void onClick(View view)
65 | {
66 | if (Cache.selectedList.size() > 0)
67 | startActivity(new Intent(FileSelectActivity.this,
68 | RadarScanActivity.class).putExtra("name", userName));
69 | else
70 | ToastUtils.showTextToast(getApplicationContext(),
71 | getString(R.string.please_select_file));
72 | }
73 | });
74 |
75 | List titles = new ArrayList<>();
76 | titles.add(getString(R.string.app));
77 | titles.add(getString(R.string.picture));
78 |
79 | tabLayout = (TabLayout) findViewById(R.id.activity_file_tabLayout);
80 | tabLayout.addTab(tabLayout.newTab().setText(titles.get(0)));
81 | tabLayout.addTab(tabLayout.newTab().setText(titles.get(1)));
82 |
83 | viewPager = (ViewPager) findViewById(R.id.activity_file_viewpager);
84 | List fragments = new ArrayList<>();
85 | fragments.add(new AppFragment());
86 | fragments.add(new PictureFragment());
87 |
88 | FragmentAdapter adapter = new FragmentAdapter(getSupportFragmentManager(),
89 | fragments, titles);
90 | viewPager.setAdapter(adapter);
91 |
92 | tabLayout.setupWithViewPager(viewPager);
93 | tabLayout.setTabsFromPagerAdapter(adapter);
94 | }
95 |
96 | @Override
97 | public void onResume()
98 | {
99 | super.onResume();
100 | }
101 |
102 | @Override
103 | protected void onDestroy()
104 | {
105 | super.onDestroy();
106 | Cache.selectedList.clear();
107 | }
108 |
109 | @Override
110 | public void onItemClicked(int type)
111 | {
112 | updateTitle();
113 | }
114 |
115 | private void updateTitle()
116 | {
117 | toolbar.setTitle(title + " / " + Cache.selectedList.size());
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/transfer/fragment/OnSelectItemClickListener.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.transfer.fragment;
2 |
3 |
4 | /**
5 | * Created by 郭攀峰 on 2015/9/17.
6 | */
7 | public interface OnSelectItemClickListener
8 | {
9 | public void onItemClicked(int type);
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/transfer/view/AppSelectAdapter.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.transfer.view;
2 |
3 |
4 | import java.io.File;
5 | import java.util.List;
6 |
7 | import android.content.Context;
8 | import android.graphics.drawable.BitmapDrawable;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ImageView;
14 | import android.widget.LinearLayout;
15 | import android.widget.TextView;
16 |
17 | import com.guo.duoduo.anyshareofandroid.R;
18 | import com.guo.duoduo.anyshareofandroid.sdk.cache.Cache;
19 | import com.guo.duoduo.anyshareofandroid.ui.uientity.IInfo;
20 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
21 |
22 |
23 | /**
24 | * Created by 郭攀峰 on 2015/9/15.
25 | */
26 | public class AppSelectAdapter extends RecyclerView.Adapter
27 | {
28 | private Context context;
29 | private List list;
30 |
31 | public interface OnItemClickListener
32 | {
33 | void onItemClick(View view, int position);
34 | }
35 |
36 | private OnItemClickListener onItemClickListener;
37 |
38 | public void setOnItemClickListener(OnItemClickListener listener)
39 | {
40 | onItemClickListener = listener;
41 | }
42 |
43 | public AppSelectAdapter(Context context, List list)
44 | {
45 | this.context = context;
46 | this.list = list;
47 | }
48 |
49 | @Override
50 | public AppSelectAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
51 | {
52 | MyViewHolder holder = new MyViewHolder(LayoutInflater.from(context).inflate(
53 | R.layout.view_app_item, null));
54 | return holder;
55 | }
56 |
57 | @Override
58 | public void onBindViewHolder(final AppSelectAdapter.MyViewHolder holder,
59 | final int position)
60 | {
61 | holder.imageView.setImageBitmap(((BitmapDrawable) list.get(position)
62 | .getFileIcon()).getBitmap());
63 |
64 | IInfo info = list.get(position);
65 | P2PFileInfo fileInfo = new P2PFileInfo();
66 | fileInfo.name = info.getFileName();
67 | fileInfo.type = info.getFileType();
68 | fileInfo.size = new File(info.getFilePath()).length();
69 | fileInfo.path = info.getFilePath();
70 |
71 | if (Cache.selectedList.contains(fileInfo))
72 | {
73 | holder.app_choice.setVisibility(View.VISIBLE);
74 | }
75 | else
76 | {
77 | holder.app_choice.setVisibility(View.GONE);
78 | }
79 |
80 | holder.appName.setText(list.get(position).getFileName());
81 | holder.appSize.setText(list.get(position).getFileSize());
82 |
83 | holder.itemLayout.setOnClickListener(new View.OnClickListener()
84 | {
85 | @Override
86 | public void onClick(View v)
87 | {
88 | if (onItemClickListener != null)
89 | {
90 | int pos = holder.getLayoutPosition();
91 | onItemClickListener.onItemClick(holder.itemLayout, pos);
92 | }
93 | }
94 | });
95 | }
96 |
97 | @Override
98 | public int getItemCount()
99 | {
100 | return list.size();
101 | }
102 |
103 | public IInfo getItem(int position)
104 | {
105 | return list.get(position);
106 | }
107 |
108 | class MyViewHolder extends RecyclerView.ViewHolder
109 | {
110 | ImageView imageView;
111 | ImageView app_choice;
112 | TextView appName;
113 | TextView appSize;
114 | LinearLayout itemLayout;
115 |
116 | public MyViewHolder(View view)
117 | {
118 | super(view);
119 | imageView = (ImageView) view.findViewById(R.id.AppIcon);
120 | appName = (TextView) view.findViewById(R.id.AppName);
121 | appSize = (TextView) view.findViewById(R.id.AppSize);
122 | app_choice = (ImageView) view.findViewById(R.id.app_choice);
123 | itemLayout = (LinearLayout) view.findViewById(R.id.app_item_layout);
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/transfer/view/FileTransferAdapter.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.transfer.view;
2 |
3 |
4 | import android.content.Context;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.BaseAdapter;
9 | import android.widget.ImageView;
10 | import android.widget.ProgressBar;
11 | import android.widget.TextView;
12 |
13 | import com.guo.duoduo.anyshareofandroid.R;
14 | import com.guo.duoduo.anyshareofandroid.sdk.cache.Cache;
15 | import com.guo.duoduo.anyshareofandroid.utils.DeviceUtils;
16 | import com.guo.duoduo.p2pmanager.p2pconstant.P2PConstant;
17 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
18 |
19 |
20 | /**
21 | * Created by 郭攀峰 on 2015/9/24.
22 | */
23 | public class FileTransferAdapter extends BaseAdapter
24 | {
25 |
26 | Context context;
27 | LayoutInflater layoutInflater;
28 |
29 | public FileTransferAdapter(Context context)
30 | {
31 | this.context = context;
32 | layoutInflater = layoutInflater.from(context);
33 | }
34 |
35 | @Override
36 | public int getCount()
37 | {
38 | return Cache.selectedList.size();
39 | }
40 |
41 | @Override
42 | public Object getItem(int position)
43 | {
44 | return Cache.selectedList.get(position);
45 | }
46 |
47 | @Override
48 | public long getItemId(int position)
49 | {
50 | return position;
51 | }
52 |
53 | @Override
54 | public View getView(int position, View convertView, ViewGroup parent)
55 | {
56 | ViewHolder holder;
57 |
58 | if (convertView == null)
59 | {
60 | convertView = layoutInflater.inflate(R.layout.view_file_transfer_item, null);
61 | holder = new ViewHolder();
62 | holder.file_image = (ImageView) convertView.findViewById(R.id.file_image);
63 | holder.file_name = (TextView) convertView.findViewById(R.id.file_name);
64 | holder.file_size = (TextView) convertView.findViewById(R.id.file_size);
65 | holder.file_trans_speed = (TextView) convertView
66 | .findViewById(R.id.file_trans_speed);
67 | holder.trans_progress = (ProgressBar) convertView
68 | .findViewById(R.id.trans_progress);
69 | convertView.setTag(holder);
70 | }
71 | else
72 | {
73 | holder = (ViewHolder) convertView.getTag();
74 | }
75 |
76 | P2PFileInfo file = Cache.selectedList.get(position);
77 | if (file != null)
78 | {
79 | if (file.type == P2PConstant.TYPE.APP)
80 | {
81 | holder.file_image.setImageResource(R.mipmap.icon_apk);
82 | }
83 | else if (file.type == P2PConstant.TYPE.PIC)
84 | {
85 | holder.file_image.setImageResource(R.mipmap.icon_image);
86 | }
87 |
88 | holder.file_name.setText(file.name);
89 | holder.file_size.setText(DeviceUtils.convertByte(file.size));
90 | holder.file_trans_speed.setText(file.percent + "%");
91 | holder.trans_progress.setProgress(file.percent);
92 | if (file.percent >= 100)
93 | {
94 | holder.trans_progress.setVisibility(View.INVISIBLE);
95 | holder.file_trans_speed.setText(context
96 | .getString(R.string.file_has_completed));
97 | holder.file_trans_speed.setTextColor(context.getResources().getColor(
98 | R.color.blue));
99 | }
100 | else
101 | {
102 | holder.trans_progress.setVisibility(View.VISIBLE);
103 | if (file.percent == 0)
104 | {
105 | holder.file_trans_speed
106 | .setText(context.getString(R.string.file_wait));
107 | holder.file_trans_speed.setTextColor(context.getResources().getColor(
108 | R.color.green));
109 | }
110 | }
111 | }
112 |
113 | return convertView;
114 | }
115 |
116 | private static class ViewHolder
117 | {
118 | public ImageView file_image;
119 | public TextView file_name;
120 | public TextView file_size;
121 | public TextView file_trans_speed;
122 | public ProgressBar trans_progress;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/transfer/view/ImageSelectAdapter.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.transfer.view;
2 |
3 |
4 | import java.io.File;
5 | import java.util.List;
6 |
7 | import android.content.Context;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ImageView;
13 |
14 | import com.bumptech.glide.Glide;
15 | import com.bumptech.glide.load.engine.DiskCacheStrategy;
16 | import com.bumptech.glide.load.engine.cache.DiskCache;
17 | import com.guo.duoduo.anyshareofandroid.R;
18 | import com.guo.duoduo.anyshareofandroid.sdk.cache.Cache;
19 | import com.guo.duoduo.anyshareofandroid.ui.uientity.IInfo;
20 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
21 |
22 |
23 | /**
24 | * Created by 郭攀峰 on 2015/9/16.
25 | */
26 | public class ImageSelectAdapter
27 | extends
28 | RecyclerView.Adapter
29 | {
30 |
31 | private static final String tag = ImageSelectAdapter.class.getSimpleName();
32 |
33 | private List list;
34 | private Context context;
35 |
36 | public ImageSelectAdapter(Context context, List list)
37 | {
38 | this.list = list;
39 | this.context = context;
40 | }
41 |
42 | public interface OnItemClickListener
43 | {
44 | void onItemClick(View view, int position);
45 | }
46 |
47 | private OnItemClickListener onItemClickListener;
48 |
49 | public void setOnItemClickListener(OnItemClickListener listener)
50 | {
51 | onItemClickListener = listener;
52 | }
53 |
54 | @Override
55 | public ImageSelectAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent,
56 | int viewType)
57 | {
58 | MyViewHolder holder = new MyViewHolder(LayoutInflater.from(context).inflate(
59 | R.layout.view_pic_item, null));
60 | return holder;
61 | }
62 |
63 | @Override
64 | public void onBindViewHolder(final ImageSelectAdapter.MyViewHolder holder,
65 | int position)
66 | {
67 | Glide.with(context).load(list.get(position).getFilePath()).into(holder.imageView);
68 |
69 | IInfo info = list.get(position);
70 | P2PFileInfo fileInfo = new P2PFileInfo();
71 | fileInfo.name = info.getFileName();
72 | fileInfo.type = info.getFileType();
73 | fileInfo.size = new File(info.getFilePath()).length();
74 | fileInfo.path = info.getFilePath();
75 |
76 | if (Cache.selectedList.contains(fileInfo))
77 | holder.pic_choice.setVisibility(View.VISIBLE);
78 | else
79 | holder.pic_choice.setVisibility(View.INVISIBLE);
80 |
81 | holder.imageView.setOnClickListener(new View.OnClickListener()
82 | {
83 | @Override
84 | public void onClick(View v)
85 | {
86 | if (onItemClickListener != null)
87 | {
88 | onItemClickListener.onItemClick(holder.imageView,
89 | holder.getLayoutPosition());
90 | }
91 | }
92 | });
93 |
94 | }
95 |
96 | @Override
97 | public int getItemCount()
98 | {
99 | return list.size();
100 | }
101 |
102 | public IInfo getItem(int position)
103 | {
104 | return list.get(position);
105 | }
106 |
107 | class MyViewHolder extends RecyclerView.ViewHolder
108 | {
109 | ImageView imageView;
110 | ImageView pic_choice;
111 |
112 | public MyViewHolder(View view)
113 | {
114 | super(view);
115 | imageView = (ImageView) view.findViewById(R.id.imageview);
116 | pic_choice = (ImageView) view.findViewById(R.id.pic_choice);
117 | }
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/uientity/AppInfo.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.uientity;
2 |
3 |
4 | import android.graphics.drawable.Drawable;
5 |
6 | import com.guo.duoduo.p2pmanager.p2pconstant.P2PConstant;
7 |
8 |
9 | /**
10 | * Created by 郭攀峰 on 2015/9/15.
11 | */
12 | public class AppInfo implements IInfo
13 | {
14 | public int type = P2PConstant.TYPE.APP;
15 | public Drawable appIcon;
16 | public String appLabel;
17 | public String pkgName;
18 | public String appSize;
19 | public String appFilePath;
20 |
21 | @Override
22 | public String getFilePath()
23 | {
24 | return appFilePath;
25 | }
26 |
27 | @Override
28 | public String getFileSize()
29 | {
30 | return appSize;
31 | }
32 |
33 | @Override
34 | public int getFileType()
35 | {
36 | return type;
37 | }
38 |
39 | @Override
40 | public Drawable getFileIcon()
41 | {
42 | return appIcon;
43 | }
44 |
45 | @Override
46 | public String getFileName()
47 | {
48 | return appLabel;
49 | }
50 |
51 | @Override
52 | public boolean equals(Object o)
53 | {
54 | if (getFilePath() != null && ((AppInfo) o).getFilePath() != null)
55 | return getFilePath().equals(((AppInfo) o).getFilePath());
56 | else
57 | return false;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/uientity/IInfo.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.uientity;
2 |
3 |
4 | import android.graphics.drawable.Drawable;
5 |
6 | /**
7 | * Created by 郭攀峰 on 2015/9/16.
8 | */
9 | public interface IInfo
10 | {
11 |
12 | public String getFilePath();
13 |
14 | public String getFileSize();
15 |
16 | public int getFileType();
17 |
18 | public Drawable getFileIcon();
19 |
20 | public String getFileName();
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/uientity/LocationPoint.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.uientity;
2 |
3 |
4 | /**
5 | * Created by 郭攀峰 on 2015/9/26.
6 | */
7 | public class LocationPoint
8 | {
9 | public int x;
10 | public int y;
11 |
12 | public LocationPoint(int x, int y)
13 | {
14 | this.x = x;
15 | this.y = y;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/uientity/PictureInfo.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.uientity;
2 |
3 |
4 | import android.graphics.drawable.Drawable;
5 |
6 | import com.guo.duoduo.p2pmanager.p2pconstant.P2PConstant;
7 |
8 |
9 | /**
10 | * Created by 郭攀峰 on 2015/9/15.
11 | */
12 | public class PictureInfo implements IInfo
13 | {
14 | public int type = P2PConstant.TYPE.PIC;
15 | public String picPath;
16 | public String picSize;
17 | public String picName;
18 |
19 | @Override
20 | public String getFilePath()
21 | {
22 | return picPath;
23 | }
24 |
25 | @Override
26 | public String getFileSize()
27 | {
28 | return picSize;
29 | }
30 |
31 | @Override
32 | public int getFileType()
33 | {
34 | return type;
35 | }
36 |
37 | @Override
38 | public Drawable getFileIcon()
39 | {
40 | return null;
41 | }
42 |
43 | @Override
44 | public String getFileName()
45 | {
46 | return picName;
47 | }
48 |
49 | @Override
50 | public boolean equals(Object o)
51 | {
52 | if (getFilePath() != null && ((PictureInfo) o).getFilePath() != null)
53 | return getFilePath().equals(((PictureInfo) o).getFilePath());
54 | else
55 | return false;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/view/CommonProgressDialog.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.view;
2 |
3 |
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.widget.ProgressBar;
7 | import android.widget.TextView;
8 |
9 | import com.guo.duoduo.anyshareofandroid.R;
10 |
11 |
12 | public class CommonProgressDialog extends Dialog
13 | {
14 | private TextView mMessage;
15 | private ProgressBar mProgress;
16 |
17 | public CommonProgressDialog(Context context)
18 | {
19 | super(context, R.style.progressDialogTheme);
20 | setContentView(R.layout.view_common_progress_dialog);
21 | init();
22 | }
23 |
24 | public void init()
25 | {
26 | mMessage = (TextView) findViewById(R.id.comm_progress_dialog_msg);
27 | mProgress = (ProgressBar) findViewById(R.id.comm_progress_dialog_progress);
28 | }
29 |
30 | public void setMessage(CharSequence msg)
31 | {
32 | mMessage.setText(msg);
33 | }
34 |
35 | public void setProgress(int progress)
36 | {
37 | mProgress.setProgress(progress);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/view/FloatWindowSmallView.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.view;
2 |
3 |
4 | import android.animation.TypeEvaluator;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.graphics.drawable.Drawable;
8 | import android.view.LayoutInflater;
9 | import android.view.WindowManager;
10 | import android.widget.ImageView;
11 | import android.widget.LinearLayout;
12 |
13 | import com.guo.duoduo.anyshareofandroid.R;
14 | import com.guo.duoduo.anyshareofandroid.ui.uientity.LocationPoint;
15 |
16 |
17 | public class FloatWindowSmallView extends LinearLayout
18 | {
19 |
20 | private static final String tag = FloatWindowSmallView.class.getSimpleName();
21 |
22 | private static final int DURATION_TIME = 800;
23 | /** 用于更新小悬浮窗的位置 */
24 | private WindowManager windowManager;
25 | /** 被移动的图标 */
26 | private ImageView floatImg;
27 | /** 小悬浮窗的参数 */
28 | private WindowManager.LayoutParams mParams;
29 | private Context context;
30 | private float xTo;
31 | private float yTo;
32 |
33 | public FloatWindowSmallView(Context context, Drawable icon, float xto, float yto)
34 | {
35 | super(context);
36 | this.context = context;
37 | xTo = xto;
38 | yTo = yto;
39 | windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
40 | LayoutInflater.from(context).inflate(R.layout.view_file_select, this);
41 | floatImg = (ImageView) findViewById(R.id.float_img);
42 | floatImg.setImageDrawable(icon);
43 | }
44 |
45 | /** 用于移动图标 */
46 | public void launchImg()
47 | {
48 | LocationPoint start = new LocationPoint(mParams.x, mParams.y);
49 | LocationPoint end = new LocationPoint(0, 0);
50 | ValueAnimator locationAnimation = ValueAnimator.ofObject(new PointEvaluator(),
51 | start, end);
52 |
53 | locationAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
54 | {
55 | @Override
56 | public void onAnimationUpdate(ValueAnimator animation)
57 | {
58 | LocationPoint location = (LocationPoint) animation.getAnimatedValue();
59 | mParams.x = location.x;
60 | mParams.y = location.y;
61 |
62 | if (location.x == 0 && location.y == 0)
63 | {
64 | MyWindowManager.removeSmallWindow(context);
65 | }
66 | else
67 | {
68 | windowManager.updateViewLayout(FloatWindowSmallView.this, mParams);
69 | }
70 | }
71 | });
72 |
73 | locationAnimation.setDuration(DURATION_TIME);
74 | locationAnimation.start();
75 | }
76 |
77 | /** 将小悬浮窗的参数传入,用于更新小悬浮窗的位置 */
78 | public void setParams(WindowManager.LayoutParams params)
79 | {
80 | mParams = params;
81 | }
82 |
83 | public static class PointEvaluator implements TypeEvaluator
84 | {
85 |
86 | @Override
87 | public Object evaluate(float fraction, Object startValue, Object endValue)
88 | {
89 | LocationPoint startPoint = (LocationPoint) startValue;
90 | LocationPoint endPoint = (LocationPoint) endValue;
91 | float x = startPoint.x + fraction * (endPoint.x - startPoint.x);
92 | float y = startPoint.y + fraction * (endPoint.y - startPoint.y);
93 | LocationPoint point = new LocationPoint((int) x, (int) y);
94 | return point;
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/ui/view/MyWindowManager.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.ui.view;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.PixelFormat;
6 | import android.graphics.drawable.Drawable;
7 | import android.view.Gravity;
8 | import android.view.WindowManager;
9 | import android.view.WindowManager.LayoutParams;
10 |
11 |
12 | public class MyWindowManager
13 | {
14 |
15 | /** 小悬浮窗View的实例 */
16 | private static FloatWindowSmallView smallWindow;
17 | /** 小悬浮窗View的参数 */
18 | private static LayoutParams smallWindowParams;
19 | /** 用于控制在屏幕上添加或移除悬浮窗 */
20 | private static WindowManager mWindowManager;
21 |
22 | public static boolean isWindowShowing()
23 | {
24 | return smallWindow != null;
25 | }
26 |
27 | public static void createSmallWindow(Context context, float x, float y, float xto,
28 | float yto, Drawable icon)
29 | {
30 | WindowManager windowManager = getWindowManager(context);
31 |
32 | if (smallWindow == null)
33 | {
34 | smallWindow = new FloatWindowSmallView(context, icon, xto, yto);
35 | if (smallWindowParams == null)
36 | {
37 | smallWindowParams = new LayoutParams();
38 | smallWindowParams.type = LayoutParams.TYPE_TOAST; //不需要权限就可以通过WindowManager显示浮动View
39 | smallWindowParams.format = PixelFormat.RGB_565;
40 | smallWindowParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL
41 | | LayoutParams.FLAG_NOT_FOCUSABLE;
42 | smallWindowParams.gravity = Gravity.LEFT | Gravity.TOP;//必须是left
43 | smallWindowParams.width = LayoutParams.WRAP_CONTENT;
44 | smallWindowParams.height = LayoutParams.WRAP_CONTENT;
45 | smallWindowParams.x = (int) x;
46 | smallWindowParams.y = (int) y;
47 | }
48 | smallWindow.setParams(smallWindowParams);
49 | windowManager.addView(smallWindow, smallWindowParams);
50 | }
51 |
52 | smallWindow.launchImg();
53 | }
54 |
55 | private static WindowManager getWindowManager(Context context)
56 | {
57 | if (mWindowManager == null)
58 | {
59 | mWindowManager = (WindowManager) context
60 | .getSystemService(Context.WINDOW_SERVICE);
61 | }
62 | return mWindowManager;
63 | }
64 |
65 | /** 将小悬浮窗从屏幕上移除。 */
66 | public static void removeSmallWindow(Context context)
67 | {
68 | if (smallWindow != null)
69 | {
70 | WindowManager windowManager = getWindowManager(context);
71 | windowManager.removeView(smallWindow);
72 | smallWindowParams = null;
73 | smallWindow = null;
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/utils/ApkTools.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.utils;
2 |
3 |
4 | import java.io.File;
5 | import java.lang.reflect.Constructor;
6 | import java.lang.reflect.Field;
7 | import java.lang.reflect.Method;
8 |
9 | import android.content.Context;
10 | import android.content.pm.ApplicationInfo;
11 | import android.content.res.Resources;
12 | import android.graphics.drawable.Drawable;
13 | import android.util.DisplayMetrics;
14 |
15 |
16 | public class ApkTools
17 | {
18 |
19 | public static Drawable geTApkIcon(Context context, String Path)
20 | {
21 | // 未安装的程序通过apk文件获取icon
22 | String apkPath = Path; // apk 文件所在的路径
23 | String PATH_PackageParser = "android.content.pm.PackageParser";
24 | String PATH_AssetManager = "android.content.res.AssetManager";
25 | try
26 | {
27 | Class> pkgParserCls = Class.forName(PATH_PackageParser);
28 | Class>[] typeArgs = {String.class};
29 | Constructor> pkgParserCt = pkgParserCls.getConstructor(typeArgs);
30 | Object[] valueArgs = {apkPath};
31 | Object pkgParser = pkgParserCt.newInstance(valueArgs);
32 | DisplayMetrics metrics = new DisplayMetrics();
33 | metrics.setToDefaults();
34 | typeArgs = new Class>[]{File.class, String.class, DisplayMetrics.class,
35 | int.class};
36 | Method pkgParser_parsePackageMtd = pkgParserCls.getDeclaredMethod(
37 | "parsePackage", typeArgs);
38 | valueArgs = new Object[]{new File(apkPath), apkPath, metrics, 0};
39 | Object pkgParserPkg = pkgParser_parsePackageMtd.invoke(pkgParser, valueArgs);
40 | Field appInfoFld = pkgParserPkg.getClass()
41 | .getDeclaredField("applicationInfo");
42 | ApplicationInfo info = (ApplicationInfo) appInfoFld.get(pkgParserPkg);
43 | Class> assetMagCls = Class.forName(PATH_AssetManager);
44 | Object assetMag = assetMagCls.newInstance();
45 | typeArgs = new Class[1];
46 | typeArgs[0] = String.class;
47 | Method assetMag_addAssetPathMtd = assetMagCls.getDeclaredMethod(
48 | "addAssetPath", typeArgs);
49 | valueArgs = new Object[1];
50 | valueArgs[0] = apkPath;
51 | assetMag_addAssetPathMtd.invoke(assetMag, valueArgs);
52 | Resources res = context.getResources();
53 | typeArgs = new Class[3];
54 | typeArgs[0] = assetMag.getClass();
55 | typeArgs[1] = res.getDisplayMetrics().getClass();
56 | typeArgs[2] = res.getConfiguration().getClass();
57 | Constructor resCt = Resources.class.getConstructor(typeArgs);
58 | valueArgs = new Object[3];
59 | valueArgs[0] = assetMag;
60 | valueArgs[1] = res.getDisplayMetrics();
61 | valueArgs[2] = res.getConfiguration();
62 | res = (Resources) resCt.newInstance(valueArgs);
63 | if (info != null)
64 | {
65 | if (info.icon != 0)
66 | {
67 | Drawable icon = res.getDrawable(info.icon);
68 | return icon;
69 | }
70 | }
71 | }
72 | catch (Exception e)
73 | {
74 | e.printStackTrace();
75 | }
76 | return null;
77 |
78 | }
79 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/utils/PreferenceUtils.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.utils;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 |
7 |
8 | /**
9 | * Created by 郭攀峰 on 2015/9/19.
10 | */
11 | public class PreferenceUtils
12 | {
13 | private static final String FILE_NAME = "melon_share";
14 |
15 | /**
16 | * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
17 | *
18 | * @param context
19 | * @param key "String", "Integer", "Boolean", "Float", "Long"
20 | * @param object
21 | */
22 | public static void setParam(Context context, String key, Object object)
23 | {
24 |
25 | String type = object.getClass().getSimpleName();
26 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
27 | Context.MODE_PRIVATE);
28 | SharedPreferences.Editor editor = sp.edit();
29 |
30 | if ("String".equals(type))
31 | {
32 | editor.putString(key, (String) object);
33 | }
34 | else if ("Integer".equals(type))
35 | {
36 | editor.putInt(key, (Integer) object);
37 | }
38 | else if ("Boolean".equals(type))
39 | {
40 | editor.putBoolean(key, (Boolean) object);
41 | }
42 | else if ("Float".equals(type))
43 | {
44 | editor.putFloat(key, (Float) object);
45 | }
46 | else if ("Long".equals(type))
47 | {
48 | editor.putLong(key, (Long) object);
49 | }
50 |
51 | editor.commit();
52 | }
53 |
54 | /**
55 | * 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
56 | *
57 | * @param context
58 | * @param key "String", "Integer", "Boolean", "Float", "Long"
59 | * @param defaultObject
60 | * @return
61 | */
62 | public static Object getParam(Context context, String key, Object defaultObject)
63 | {
64 | String type = defaultObject.getClass().getSimpleName();
65 | SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
66 | Context.MODE_PRIVATE);
67 |
68 | if ("String".equals(type))
69 | {
70 | return sp.getString(key, (String) defaultObject);
71 | }
72 | else if ("Integer".equals(type))
73 | {
74 | return sp.getInt(key, (Integer) defaultObject);
75 | }
76 | else if ("Boolean".equals(type))
77 | {
78 | return sp.getBoolean(key, (Boolean) defaultObject);
79 | }
80 | else if ("Float".equals(type))
81 | {
82 | return sp.getFloat(key, (Float) defaultObject);
83 | }
84 | else if ("Long".equals(type))
85 | {
86 | return sp.getLong(key, (Long) defaultObject);
87 | }
88 |
89 | return null;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/utils/ToastUtils.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.utils;
2 |
3 |
4 | import android.content.Context;
5 | import android.os.Handler;
6 | import android.os.Looper;
7 | import android.view.Gravity;
8 | import android.widget.Toast;
9 |
10 |
11 | /**
12 | * Created by 郭攀峰 on 2015/9/15.
13 | */
14 | public class ToastUtils
15 | {
16 |
17 | private static Toast toast = null;
18 |
19 | /** show toast, keep only one instance, modify 2014-2-10 */
20 | private static Handler handler = new Handler(Looper.getMainLooper());
21 |
22 | public static void showTextToast(Context context, String msg)
23 | {
24 | /*
25 | * if (toast == null) { toast = Toast.makeText(NetAPP.getContext(), msg,
26 | * Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, 0, 150); } else
27 | * { toast.setText(msg); } toast.show();
28 | */
29 | showMessage(context, msg, Toast.LENGTH_SHORT);
30 | }
31 |
32 | public static void showMessage(final Context act, final String msg, final int len)
33 | {
34 | new Thread(new Runnable()
35 | {
36 | public void run()
37 | {
38 | handler.post(new Runnable()
39 | {
40 | @Override
41 | public void run()
42 | {
43 | if (toast != null)
44 | {
45 | // toast.cancel();
46 | toast.setText(msg);
47 | // toast.setDuration(len);
48 | }
49 | else
50 | {
51 | toast = Toast.makeText(act, msg, len);
52 | toast.setGravity(Gravity.BOTTOM, 0, 100);
53 | }
54 | toast.show();
55 | }
56 | });
57 | }
58 | }).start();
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/guo/duoduo/anyshareofandroid/utils/ViewUtils.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid.utils;
2 |
3 |
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.util.Log;
7 | import android.view.View;
8 |
9 |
10 | /**
11 | * Created by 郭攀峰 on 2015/9/26.
12 | */
13 | public class ViewUtils
14 | {
15 |
16 | private final static String tag = ViewUtils.class.getSimpleName();
17 |
18 | /** 获取每一个item在屏幕上的位置 */
19 | public static int[] getViewItemLocation(View view)
20 | {
21 | int[] location = new int[2]; //each item location
22 | view.getLocationInWindow(location);
23 |
24 | return location;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/out_to_up.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/btn_green_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/btn_red_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/btn_top_back_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/common_dlg_fullbtn_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/common_dlg_leftbtn_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/common_dlg_rightbtn_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/common_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/list_bg_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/progressbg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
10 |
11 |
12 | -
13 |
14 |
15 |
16 |
17 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_left_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_mid_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_right_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_file.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
23 |
24 |
28 |
29 |
30 |
35 |
36 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_file_browse.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
24 |
25 |
29 |
30 |
31 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_file_transfering.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
21 |
22 |
23 |
24 |
28 |
29 |
37 |
38 |
39 |
42 |
43 |
48 |
49 |
50 |
51 |
52 |
53 |
61 |
62 |
70 |
71 |
72 |
73 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_radarscan.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
22 |
23 |
24 |
28 |
29 |
34 |
35 |
38 |
39 |
45 |
46 |
52 |
53 |
54 |
59 |
60 |
65 |
66 |
71 |
72 |
80 |
81 |
82 |
83 |
84 |
91 |
92 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_receive.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
22 |
23 |
24 |
25 |
31 |
32 |
33 |
39 |
40 |
46 |
47 |
48 |
54 |
55 |
56 |
57 |
62 |
63 |
70 |
71 |
78 |
79 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_welcome.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_received.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
12 |
13 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_app_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
22 |
23 |
31 |
32 |
33 |
42 |
43 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_common_dialog.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
17 |
18 |
24 |
25 |
32 |
33 |
34 |
38 |
39 |
48 |
49 |
53 |
54 |
61 |
62 |
70 |
71 |
77 |
78 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_common_dialog_message.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_common_progress_dialog.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
17 |
18 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_file_select.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_file_transfer_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
19 |
20 |
28 |
29 |
40 |
41 |
50 |
51 |
52 |
57 |
58 |
68 |
69 |
70 |
71 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_pic_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_received_app_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
27 |
28 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_select.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/icon_apk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-hdpi/icon_apk.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/icon_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-hdpi/icon_image.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/rocket_body.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-hdpi/rocket_body.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/rocket_fire.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-hdpi/rocket_fire.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/bg_cabin.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/bg_cabin.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/bg_head.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/bg_head.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/bg_pop_white.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/bg_pop_white.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/btn_green.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/btn_green.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/btn_green_click.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/btn_green_click.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/btn_red.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/btn_red.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/btn_red_click.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/btn_red_click.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/btn_top_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/btn_top_back.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/btn_top_back_click.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/btn_top_back_click.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/common_dlg_conbg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/common_dlg_conbg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/common_dlg_fullbtn_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/common_dlg_fullbtn_bg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/common_dlg_fullbtn_bg_click.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/common_dlg_fullbtn_bg_click.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/common_dlg_headbg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/common_dlg_headbg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/common_dlg_leftbtn_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/common_dlg_leftbtn_bg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/common_dlg_leftbtn_bg_click.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/common_dlg_leftbtn_bg_click.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/common_dlg_rightbtn_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/common_dlg_rightbtn_bg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/common_dlg_rightbtn_bg_click.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/common_dlg_rightbtn_bg_click.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/common_loading_0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/common_loading_0.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/editable_mode_checked_tag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/editable_mode_checked_tag.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/editable_mode_unchecked_tag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/editable_mode_unchecked_tag.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/icon_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/icon_loading.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/phone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/phone.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/tab_callselect_left_normal.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/tab_callselect_left_normal.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/tab_callselect_left_selected.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/tab_callselect_left_selected.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/tab_callselect_mid_normal.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/tab_callselect_mid_normal.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/tab_callselect_mid_selected.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/tab_callselect_mid_selected.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/tab_callselect_right_normal.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/tab_callselect_right_normal.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/tab_callselect_right_selected.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/tab_callselect_right_selected.9.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/watermelon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xhdpi/watermelon.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 | #333333
9 | #999999
10 | #666666
11 | #cccccc
12 |
13 |
14 | #00000000
15 | #ffffffff
16 | #000000
17 | #999999
18 | #444444
19 | #cccccc
20 | #28b67f
21 | #f22020
22 | #00ffff
23 | #FF4E2C
24 | #FFA02F
25 | #007AFF
26 | #ffedf9fd
27 | #f64c3a
28 | #66000000
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 180dp
6 | 16dp
7 | 50dp
8 | 300dp
9 | 5dp
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 西瓜快传
3 | 关于
4 | 接收目录
5 |
6 | 点解设置查看具体使用说明
7 | 设置
8 |
9 | 我要发送
10 | 我要接收
11 | 传文件到电脑
12 | 输入昵称
13 |
14 | 扫描好友
15 |
16 | 创建WiFi热点失败
17 | 正在创建WiFi热点
18 |
19 | 选择文件
20 | 图片
21 | 应用
22 |
23 | 发送端连接到: %s
24 |
25 | 请选择文件
26 | 正在传输
27 | 你确定要退出吗?
28 | 确定
29 |
30 | 对端 %s 退出
31 | 发送完成
32 | 已完成
33 | 等待
34 | 正在发送
35 | 正在接收
36 | 接收完成
37 |
38 | 使用
39 | 1. 在有WiFi的情况下,两个设备同时接入该WiFi\n2. 接收端点击我要接收,发送端点击我要发送\n3. 然后发送端会发现接收端,此时发送端点击发现的图标,接收端显示发送端的图标\n4. 接收端点击显示的图标,就开始进行文件传输了\n5. 若没有WiFi,接收端点击我要接收,此时接收端会建立WiFi热点,发送端连接此热点即可\n
40 | 感谢
41 | 同事 杨蔚\n老婆 方泰
42 |
43 | 引用库
44 | com.android.support:support-v4:22.2.0\ncom.android.support:appcompat-v7:22.2.0\ncom.android.support:design:22.2.0\ncom.android.support:recyclerview-v7:22.+\ncom.android.support:cardview-v7:22.0.0\ncom.github.bumptech.glide:glide:3.5.2\nRadarScanView\nrandomtextview\nrippleview\nrippleoutlayout\np2pmanager\nhttpServer\n
45 |
46 | 接收路径
47 |
48 | 无接收内容...
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
28 |
29 |
36 |
37 |
44 |
45 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/test/java/com/guo/duoduo/anyshareofandroid/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.anyshareofandroid;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/filetransfer.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/filetransfer.gif
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Sep 11 22:52:19 CST 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.4-all.zip
7 | distributionUrl=file\:/D:/developtools/gradle-2.8-all.zip
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/httpServer/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/httpServer/app.iml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/httpServer/app.iml
--------------------------------------------------------------------------------
/httpServer/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:support-v4:22.2.0'
24 | compile 'com.android.support:appcompat-v7:22.2.0'
25 | compile 'com.android.support:design:22.2.0'
26 | compile files('libs/httpcore-4.3.2.jar')
27 | }
28 |
--------------------------------------------------------------------------------
/httpServer/libs/httpcore-4.3.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/httpServer/libs/httpcore-4.3.2.jar
--------------------------------------------------------------------------------
/httpServer/src/androidTest/java/com/guo/duoduo/httpserver/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.httpserver;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/httpServer/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/httpServer/src/main/java/com/guo/duoduo/httpserver/cache/SdFileCache.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.httpserver.cache;
2 |
3 |
4 | import java.util.concurrent.ConcurrentHashMap;
5 |
6 |
7 | /**
8 | * Created by Guo.Duo duo on 2015/9/5.
9 | */
10 | public class SdFileCache
11 | {
12 | public static ConcurrentHashMap fileMap = new ConcurrentHashMap();
13 |
14 | public static void addSdFile(String name, String path)
15 | {
16 | if (!isContainFile(name))
17 | fileMap.put(name, path);
18 | }
19 |
20 | public static boolean isContainFile(String name)
21 | {
22 | return fileMap.containsKey(name);
23 | }
24 |
25 | public static String getFilePath(String name)
26 | {
27 | if (isContainFile(name))
28 | return fileMap.get(name);
29 | else
30 | return null;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/httpServer/src/main/java/com/guo/duoduo/httpserver/http/WorkThread.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.httpserver.http;
2 |
3 |
4 | import java.io.IOException;
5 |
6 | import org.apache.http.HttpException;
7 | import org.apache.http.HttpServerConnection;
8 | import org.apache.http.protocol.BasicHttpContext;
9 | import org.apache.http.protocol.HttpContext;
10 | import org.apache.http.protocol.HttpService;
11 |
12 |
13 | /**
14 | * Created by Guo.Duo duo on 2015/9/5.
15 | */
16 | public class WorkThread extends Thread
17 | {
18 |
19 | private final HttpService httpService;
20 | private final HttpServerConnection connection;
21 |
22 | public WorkThread(HttpService httpService, HttpServerConnection connection)
23 | {
24 | this.httpService = httpService;
25 | this.connection = connection;
26 | }
27 |
28 | @Override
29 | public void run()
30 | {
31 | HttpContext context = new BasicHttpContext();
32 |
33 | try
34 | {
35 |
36 | while (!Thread.interrupted() && connection.isOpen())
37 | {
38 | httpService.handleRequest(connection, context);
39 | }
40 | }
41 | catch (HttpException e)
42 | {
43 | e.printStackTrace();
44 | interrupted();
45 | }
46 | catch (IOException e)
47 | {
48 | e.printStackTrace();
49 | interrupted();
50 | }
51 | finally
52 | {
53 | try
54 | {
55 | connection.shutdown();
56 | }
57 | catch (IOException e)
58 | {
59 | e.printStackTrace();
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/httpServer/src/main/java/com/guo/duoduo/httpserver/service/WebService.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.httpserver.service;
2 |
3 |
4 | import android.app.Service;
5 | import android.content.Intent;
6 | import android.os.IBinder;
7 |
8 | import com.guo.duoduo.httpserver.http.RequestListenerThread;
9 | import com.guo.duoduo.httpserver.utils.Constant;
10 |
11 |
12 | public class WebService extends Service
13 | {
14 |
15 | private RequestListenerThread thread;
16 |
17 | public WebService()
18 | {
19 | }
20 |
21 | @Override
22 | public void onCreate()
23 | {
24 | super.onCreate();
25 |
26 | thread = new RequestListenerThread(Constant.Config.PORT, Constant.Config.Web_Root);
27 | thread.setDaemon(false);
28 | thread.start();
29 | }
30 |
31 | @Override
32 | public void onDestroy()
33 | {
34 | super.onDestroy();
35 |
36 | new Thread()
37 | {
38 | public void run()
39 | {
40 | if (thread != null)
41 | thread.destroy();
42 | }
43 | }.start();
44 | }
45 |
46 | @Override
47 | public IBinder onBind(Intent intent)
48 | {
49 | throw new UnsupportedOperationException("Not yet implemented");
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/httpServer/src/main/java/com/guo/duoduo/httpserver/ui/Send2PCActivity.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.httpserver.ui;
2 |
3 |
4 | import java.lang.ref.WeakReference;
5 |
6 | import android.content.Intent;
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.os.Message;
10 | import android.support.v7.app.ActionBar;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.support.v7.widget.Toolbar;
13 | import android.text.TextUtils;
14 | import android.view.MenuItem;
15 | import android.widget.TextView;
16 |
17 | import com.guo.duoduo.httpserver.R;
18 | import com.guo.duoduo.httpserver.service.WebService;
19 | import com.guo.duoduo.httpserver.utils.Constant;
20 | import com.guo.duoduo.httpserver.utils.Network;
21 |
22 |
23 | public class Send2PCActivity extends AppCompatActivity
24 | {
25 |
26 | private TextView hint;
27 | private MainHandler handler;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState)
31 | {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_send2pc);
34 |
35 | Toolbar toolbar = (Toolbar) findViewById(R.id.activity_send2pc_toolbar);
36 | setSupportActionBar(toolbar);
37 | ActionBar actionBar = getSupportActionBar();
38 | if (actionBar != null)
39 | actionBar.setDisplayHomeAsUpEnabled(true);
40 |
41 | handler = new MainHandler(this);
42 |
43 | initView();
44 |
45 | startService(new Intent(getApplicationContext(), WebService.class));
46 | }
47 |
48 | private void initView()
49 | {
50 | hint = (TextView) findViewById(R.id.hint);
51 |
52 | String ip = Network.getLocalIp(getApplicationContext());
53 | if (TextUtils.isEmpty(ip))
54 | {
55 | Message msg = new Message();
56 | msg.what = Constant.MSG.GET_NETWORK_ERROR;
57 | handler.sendMessage(msg);
58 | }
59 | else
60 | {
61 | hint.setText("在PC的浏览器中输入IP:http://" + ip + ":" + Constant.Config.PORT
62 | + Constant.Config.Web_Root + " " + "回车即可");
63 | }
64 | }
65 |
66 | @Override
67 | public boolean onOptionsItemSelected(MenuItem item)
68 | {
69 | if (item.getItemId() == android.R.id.home)
70 | {
71 | finish();
72 | return true;
73 | }
74 | return super.onOptionsItemSelected(item);
75 | }
76 |
77 | @Override
78 | public void onDestroy()
79 | {
80 | super.onDestroy();
81 | handler.removeCallbacksAndMessages(null);
82 | stopService(new Intent(getApplicationContext(), WebService.class));
83 | }
84 |
85 | private static class MainHandler extends Handler
86 | {
87 | private WeakReference weakReference;
88 |
89 | public MainHandler(Send2PCActivity activity)
90 | {
91 | weakReference = new WeakReference(activity);
92 | }
93 |
94 | @Override
95 | public void handleMessage(Message msg)
96 | {
97 | final Send2PCActivity activity = weakReference.get();
98 | if (activity == null)
99 | return;
100 |
101 | switch (msg.what)
102 | {
103 | case Constant.MSG.GET_NETWORK_ERROR :
104 | activity.hint.setText("手机网络地址获取失败,即将退出程序");
105 | activity.handler.postDelayed(new Runnable()
106 | {
107 | @Override
108 | public void run()
109 | {
110 | activity.finish();
111 | android.os.Process.killProcess(android.os.Process.myPid());
112 | }
113 | }, 2 * 1000);
114 | break;
115 | }
116 | }
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/httpServer/src/main/java/com/guo/duoduo/httpserver/utils/Constant.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.httpserver.utils;
2 |
3 |
4 | import java.util.Hashtable;
5 | import java.util.StringTokenizer;
6 |
7 | /**
8 | * Created by Guo.Duo duo on 2015/9/4.
9 | */
10 | public class Constant
11 | {
12 |
13 | /** 缓冲字节长度=1024*4B */
14 | public static final int BUFFER_LENGTH = 4096;
15 |
16 | public static final String MIME_PLAINTEXT = "text/plain";
17 | public static final String MIME_HTML = "text/html";
18 | public static final String MIME_DEFAULT_BINARY = "application/octet-stream";
19 | public static final String MIME_XML = "text/xml";
20 |
21 | public static final String ENCODING = "UTF-8";
22 |
23 |
24 | public static Hashtable theMimeTypes = new Hashtable();
25 | static
26 | {
27 | StringTokenizer st = new StringTokenizer(
28 | "css text/css "+
29 | "js text/javascript "+
30 | "htm text/html "+
31 | "html text/html "+
32 | "txt text/plain "+
33 | "asc text/plain "+
34 | "gif image/gif "+
35 | "jpg image/jpeg "+
36 | "jpeg image/jpeg "+
37 | "png image/png "+
38 | "mp3 audio/mpeg "+
39 | "m3u audio/mpeg-url " +
40 | "pdf application/pdf "+
41 | "doc application/msword "+
42 | "ogg application/x-ogg "+
43 | "zip application/octet-stream "+
44 | "exe application/octet-stream "+
45 | "class application/octet-stream " );
46 | while ( st.hasMoreTokens())
47 | theMimeTypes.put( st.nextToken(), st.nextToken());
48 | }
49 |
50 | public static interface MSG
51 | {
52 | public static final int GET_NETWORK_ERROR = -1;
53 | public static final int GET_NETWORK_OK = 0;
54 | }
55 |
56 | public static interface Config
57 | {
58 | public static final int PORT = 5000;
59 | public static final String Web_Root = "/";
60 |
61 | }
62 |
63 | public static interface Http
64 | {
65 | public static final String BROWSE = "*";
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/httpServer/src/main/java/com/guo/duoduo/httpserver/utils/Network.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.httpserver.utils;
2 |
3 |
4 | import android.content.Context;
5 | import android.net.wifi.WifiInfo;
6 | import android.net.wifi.WifiManager;
7 |
8 |
9 | /**
10 | * Created by Guo.Duo duo on 2015/9/4.
11 | */
12 | public class Network
13 | {
14 | public static String getLocalIp(Context context)
15 | {
16 | WifiManager wifiManager = (WifiManager) context
17 | .getSystemService(Context.WIFI_SERVICE);//获取WifiManager
18 |
19 | //检查wifi是否开启
20 | if (!wifiManager.isWifiEnabled())
21 | {
22 | return null;
23 | }
24 |
25 | WifiInfo wifiinfo = wifiManager.getConnectionInfo();
26 |
27 | String ip = intToIp(wifiinfo.getIpAddress());
28 |
29 | return ip;
30 | }
31 |
32 | private static String intToIp(int paramInt)
33 | {
34 | return (paramInt & 0xFF) + "." + (0xFF & paramInt >> 8) + "."
35 | + (0xFF & paramInt >> 16) + "." + (0xFF & paramInt >> 24);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/httpServer/src/main/res/layout/activity_send2pc.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
21 |
22 |
23 |
24 |
28 |
29 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/httpServer/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/httpServer/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/httpServer/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/httpServer/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/httpServer/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/httpServer/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/httpServer/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/httpServer/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gpfduoduo/AnyShareOfAndroid/7d0d52d492a4c54a6aef2f8af7cd59be8f83f572/httpServer/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/httpServer/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/httpServer/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 |
--------------------------------------------------------------------------------
/httpServer/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/httpServer/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | HttpServer
3 |
4 | Hello world!
5 | Settings
6 |
7 |
--------------------------------------------------------------------------------
/httpServer/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/httpServer/src/test/java/com/guo/duoduo/httpserver/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.httpserver;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/p2pmanager/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/p2pmanager/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | }
24 |
--------------------------------------------------------------------------------
/p2pmanager/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 D:\developtools\android_sdk_windows/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 |
--------------------------------------------------------------------------------
/p2pmanager/src/androidTest/java/com/guo/duoduo/p2pmanager/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/p2pmanager/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pconstant/P2PConstant.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pconstant;
2 |
3 |
4 | /**
5 | * Created by 郭攀峰 on 2015/9/19.
6 | */
7 | public class P2PConstant
8 | {
9 |
10 | public static final int BUFFER_LENGTH = 8192;
11 | public static final int PORT = 10000;
12 |
13 | public static final String FORMAT = "gbk";
14 |
15 | public static final String MSG_SEPARATOR = "\0";
16 |
17 | public static final String MULTI_ADDRESS = "255.255.255.255";
18 |
19 | public static final String FILE_SHARE_SAVE_PATH = "西瓜快传";
20 |
21 | public static final int MAXIMUM_POOL_SIZE = 4;
22 |
23 | public interface TYPE
24 | {
25 | public static final int APP = 0;
26 | public static final int PIC = 1;
27 | }
28 |
29 | public interface UI_MSG
30 | {
31 | public static final int ADD_NEIGHBOR = 1000;
32 | public static final int REMOVE_NEIGHBOR = 10001;
33 | }
34 |
35 | public interface CommandNum
36 | {
37 | public static final int ON_LINE = 0;
38 | public static final int OFF_LINE = 1;
39 | public static final int ON_LINE_ANS = 2;
40 |
41 | public static final int SEND_FILE_REQ = 3;
42 | public static final int RECEIVE_FILE_ACK = 4;
43 | public static final int SEND_FILE_START = 5;
44 |
45 | public static final int SEND_TCP_ESTABLISHED = 6;
46 | public static final int SEND_LINK_ERROR = 7;
47 | public static final int SEND_PERCENTS = 8;
48 | public static final int SEND_OVER = 9;
49 |
50 | public static final int RECEIVE_TCP_ESTABLISHED = 10;
51 | public static final int RECEIVE_PERCENT = 11;
52 | public static final int RECEIVE_OVER = 12;
53 |
54 | public static final int RECEIVE_ABORT_SELF = 13;
55 | public static final int SEND_ABORT_SELF = 14;
56 |
57 | }
58 |
59 | public interface Src
60 | {
61 | public static final int MANAGER = 90;
62 | public static final int COMMUNICATE = 91;
63 | public static final int SEND_TCP_THREAD = 92;
64 | public static final int RECEIVE_TCP_THREAD = 92;
65 | }
66 |
67 | public interface Recipient
68 | {
69 | public static final int NEIGHBOR = 100;
70 | public static final int FILE_SEND = 101;
71 | public static final int FILE_RECEIVE = 102;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pcore/MelonManager.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pcore;
2 |
3 |
4 | import java.net.InetAddress;
5 | import java.util.HashMap;
6 |
7 | import android.util.Log;
8 |
9 | import com.guo.duoduo.p2pmanager.p2pconstant.P2PConstant;
10 | import com.guo.duoduo.p2pmanager.p2pentity.P2PNeighbor;
11 | import com.guo.duoduo.p2pmanager.p2pentity.SigMessage;
12 | import com.guo.duoduo.p2pmanager.p2pentity.param.ParamIPMsg;
13 | import com.guo.duoduo.p2pmanager.p2ptimer.OSTimer;
14 | import com.guo.duoduo.p2pmanager.p2ptimer.Timeout;
15 |
16 |
17 | /**
18 | * Created by 郭攀峰 on 2015/9/19.
19 | */
20 | public class MelonManager
21 | {
22 |
23 | private static final String tag = MelonManager.class.getSimpleName();
24 |
25 | private P2PManager p2PManager;
26 | private MelonHandler p2PHandler;
27 | private MelonCommunicate sigCommunicate;
28 |
29 | private HashMap mNeighbors;
30 |
31 | public MelonManager(P2PManager manager, MelonHandler handler,
32 | MelonCommunicate communicate)
33 | {
34 | p2PHandler = handler;
35 | p2PManager = manager;
36 | sigCommunicate = communicate;
37 |
38 | mNeighbors = new HashMap();
39 | }
40 |
41 | public void sendBroadcast()
42 | {
43 | Timeout timeout = new Timeout()
44 | {
45 | @Override
46 | public void onTimeOut()
47 | {
48 | Log.d(tag, "broadcast 广播 msg");
49 |
50 | sigCommunicate.BroadcastMSG(P2PConstant.CommandNum.ON_LINE,
51 | P2PConstant.Recipient.NEIGHBOR);
52 | }
53 | };
54 | //发送两个广播消息
55 | new OSTimer(p2PHandler, timeout, 250).start();
56 | new OSTimer(p2PHandler, timeout, 500).start();
57 | }
58 |
59 | public void dispatchMSG(ParamIPMsg ipmsg)
60 | {
61 | switch (ipmsg.peerMSG.commandNum)
62 | {
63 | case P2PConstant.CommandNum.ON_LINE : //收到上线广播
64 | Log.d(tag, "receive on_line and send on_line_ans message");
65 | addNeighbor(ipmsg.peerMSG, ipmsg.peerIAddr);
66 | //回复我上线
67 | p2PHandler.send2Neighbor(ipmsg.peerIAddr,
68 | P2PConstant.CommandNum.ON_LINE_ANS, null);
69 | break;
70 | case P2PConstant.CommandNum.ON_LINE_ANS : //收到对方上线的回复
71 | Log.d(tag, "received on_line_ans message");
72 | addNeighbor(ipmsg.peerMSG, ipmsg.peerIAddr);
73 | break;
74 | case P2PConstant.CommandNum.OFF_LINE :
75 | delNeighbor(ipmsg.peerIAddr.getHostAddress());
76 | break;
77 |
78 | }
79 | }
80 |
81 | public void offLine()
82 | {
83 | Timeout timeOut = new Timeout()
84 | {
85 | @Override
86 | public void onTimeOut()
87 | {
88 | sigCommunicate.BroadcastMSG(P2PConstant.CommandNum.OFF_LINE,
89 | P2PConstant.Recipient.NEIGHBOR);
90 | }
91 | };
92 | timeOut.onTimeOut();
93 | new OSTimer(p2PHandler, timeOut, 250);
94 | new OSTimer(p2PHandler, timeOut, 500);
95 | }
96 |
97 | public HashMap getNeighbors()
98 | {
99 | return mNeighbors;
100 | }
101 |
102 | private void addNeighbor(SigMessage sigMessage, InetAddress address)
103 | {
104 | String ip = address.getHostAddress();
105 | P2PNeighbor neighbor = mNeighbors.get(ip);
106 | if (neighbor == null)
107 | {
108 | neighbor = new P2PNeighbor();
109 | neighbor.alias = sigMessage.senderAlias;
110 | neighbor.ip = ip;
111 | neighbor.inetAddress = address;
112 | mNeighbors.put(ip, neighbor);
113 |
114 | p2PManager.getHandler().sendMessage(
115 | p2PManager.getHandler().obtainMessage(P2PConstant.UI_MSG.ADD_NEIGHBOR,
116 | neighbor));
117 | }
118 | }
119 |
120 | private void delNeighbor(String ip)
121 | {
122 | P2PNeighbor neighbor = mNeighbors.get(ip);
123 | if (neighbor != null)
124 | {
125 | mNeighbors.remove(ip);
126 | p2PManager.getHandler().sendMessage(
127 | p2PManager.getHandler().obtainMessage(P2PConstant.UI_MSG.REMOVE_NEIGHBOR,
128 | neighbor));
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pcore/receive/ReceiveManager.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pcore.receive;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pconstant.P2PConstant;
5 | import com.guo.duoduo.p2pmanager.p2pcore.MelonHandler;
6 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
7 | import com.guo.duoduo.p2pmanager.p2pentity.P2PNeighbor;
8 | import com.guo.duoduo.p2pmanager.p2pentity.param.ParamIPMsg;
9 | import com.guo.duoduo.p2pmanager.p2pentity.param.ParamReceiveFiles;
10 |
11 | /**
12 | * Created by 郭攀峰 on 2015/9/20.
13 | */
14 | public class ReceiveManager
15 | {
16 |
17 | protected MelonHandler p2PHandler;
18 | private Receiver receiver;
19 |
20 | public ReceiveManager(MelonHandler handler)
21 | {
22 | p2PHandler = handler;
23 | }
24 |
25 | public void init()
26 | {
27 | if (receiver != null)
28 | receiver = null;
29 | }
30 |
31 | public void disPatchMsg(int cmd, Object obj, int src)
32 | {
33 | switch (src)
34 | {
35 | case P2PConstant.Src.COMMUNICATE :
36 | {
37 | ParamIPMsg paramIPMsg = (ParamIPMsg) obj;
38 | if (cmd == P2PConstant.CommandNum.SEND_FILE_REQ)
39 | {
40 | invoke(paramIPMsg);
41 | }
42 | else
43 | {
44 | if (receiver != null)
45 | receiver.dispatchCommMSG(cmd, paramIPMsg);
46 | }
47 | break;
48 | }
49 | case P2PConstant.Src.MANAGER :
50 | if (receiver != null)
51 | receiver.dispatchUIMSG(cmd, obj);
52 | break;
53 | case P2PConstant.Src.RECEIVE_TCP_THREAD :
54 | if (cmd == P2PConstant.CommandNum.RECEIVE_PERCENT)
55 | if (receiver != null)
56 | receiver.flagPercent = false;
57 | if (receiver != null)
58 | receiver.dispatchTCPMSG(cmd, obj);
59 | break;
60 | }
61 | }
62 |
63 | public void quit()
64 | {
65 | init();
66 | }
67 |
68 | private void invoke(ParamIPMsg paramIPMsg)
69 | {
70 | String peerIP = paramIPMsg.peerIAddr.getHostAddress();
71 |
72 | String[] strArray = paramIPMsg.peerMSG.addition.split(P2PConstant.MSG_SEPARATOR);
73 | P2PFileInfo[] files = new P2PFileInfo[strArray.length];
74 | for (int i = 0; i < strArray.length; i++)
75 | {
76 | files[i] = new P2PFileInfo(strArray[i]);
77 | }
78 |
79 | P2PNeighbor neighbor = p2PHandler.getNeighborManager().getNeighbors().get(peerIP);
80 |
81 | receiver = new Receiver(this, neighbor, files);
82 |
83 | ParamReceiveFiles paramReceiveFiles = new ParamReceiveFiles(neighbor, files);
84 | if (p2PHandler != null)
85 | p2PHandler.send2UI(P2PConstant.CommandNum.SEND_FILE_REQ, paramReceiveFiles);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pcore/receive/Receiver.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pcore.receive;
2 |
3 |
4 | import android.util.Log;
5 |
6 | import com.guo.duoduo.p2pmanager.p2pconstant.P2PConstant;
7 | import com.guo.duoduo.p2pmanager.p2pcore.MelonHandler;
8 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
9 | import com.guo.duoduo.p2pmanager.p2pentity.P2PNeighbor;
10 | import com.guo.duoduo.p2pmanager.p2pentity.param.ParamIPMsg;
11 |
12 | /**
13 | * Created by 郭攀峰 on 2015/9/21.
14 | */
15 | public class Receiver
16 | {
17 | private static final String tag = Receiver.class.getSimpleName();
18 | public ReceiveManager receiveManager;
19 | public P2PNeighbor neighbor;
20 | public P2PFileInfo[] files;
21 | public MelonHandler p2PHandler;
22 | protected ReceiveTask receiveTask = null;
23 | boolean flagPercent = false;
24 |
25 | public Receiver(ReceiveManager receiveManager, P2PNeighbor neighbor,
26 | P2PFileInfo[] files)
27 | {
28 | this.receiveManager = receiveManager;
29 | this.neighbor = neighbor;
30 | this.files = files;
31 | p2PHandler = receiveManager.p2PHandler;
32 | }
33 |
34 | public void dispatchCommMSG(int cmd, ParamIPMsg ipMsg)
35 | {
36 | switch (cmd)
37 | {
38 | case P2PConstant.CommandNum.SEND_FILE_START : //接收端收到开始发送文件的消息
39 | //开始tcp
40 | Log.d(tag, "start receiver task");
41 | receiveTask = new ReceiveTask(p2PHandler, this);
42 | receiveTask.start();
43 | break;
44 | case P2PConstant.CommandNum.SEND_ABORT_SELF : //发送者退出
45 | clearSelf();
46 | if (p2PHandler != null)
47 | {
48 | p2PHandler.send2UI(cmd, ipMsg);
49 | }
50 | break;
51 | }
52 | }
53 |
54 | public void dispatchTCPMSG(int cmd, Object obj)
55 | {
56 | switch (cmd)
57 | {
58 | case P2PConstant.CommandNum.RECEIVE_TCP_ESTABLISHED :
59 | break;
60 | case P2PConstant.CommandNum.RECEIVE_PERCENT :
61 | if(p2PHandler != null)
62 | p2PHandler.send2UI(P2PConstant.CommandNum.RECEIVE_PERCENT, obj);
63 | break;
64 | case P2PConstant.CommandNum.RECEIVE_OVER :
65 | clearSelf();
66 | if(p2PHandler != null)
67 | p2PHandler.send2UI(P2PConstant.CommandNum.RECEIVE_OVER, null);
68 | break;
69 | }
70 | }
71 |
72 | public void dispatchUIMSG(int cmd, Object obj)
73 | {
74 | switch (cmd)
75 | {
76 | case P2PConstant.CommandNum.RECEIVE_FILE_ACK : //发送接收文件的消息给发送者
77 | if (p2PHandler != null)
78 | p2PHandler.send2Sender(neighbor.inetAddress, cmd, null);
79 | break;
80 | case P2PConstant.CommandNum.RECEIVE_ABORT_SELF : //接收者退出
81 | clearSelf();
82 | //通知发送者接收者已经推出
83 | if (p2PHandler != null)
84 | p2PHandler.send2Sender(neighbor.inetAddress, cmd, null);
85 | break;
86 | }
87 | }
88 |
89 | private void clearSelf()
90 | {
91 | receiveManager.init();
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pcore/send/OneByOneRunnable.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pcore.send;
2 |
3 |
4 | import java.util.concurrent.locks.Condition;
5 | import java.util.concurrent.locks.ReentrantLock;
6 |
7 |
8 | /**
9 | * Created by 郭攀峰 on 2015/9/22.
10 | */
11 | public class OneByOneRunnable implements Runnable
12 | {
13 | private boolean isPaused;
14 | private ReentrantLock pauseLock = new ReentrantLock();
15 | private Condition unpaused = pauseLock.newCondition();
16 |
17 | public void waitRun()
18 | {
19 | pauseLock.lock();
20 | try
21 | {
22 | while (isPaused)
23 | unpaused.await();
24 | }
25 | catch (InterruptedException e)
26 | {
27 | e.printStackTrace();
28 | }
29 | finally
30 | {
31 | pauseLock.unlock();
32 | }
33 | }
34 |
35 | public void pause()
36 | {
37 | pauseLock.lock();
38 | try
39 | {
40 | isPaused = true;
41 | }
42 | finally
43 | {
44 | pauseLock.unlock();
45 | }
46 | }
47 |
48 | public void resume()
49 | {
50 | pauseLock.lock();
51 | try
52 | {
53 | isPaused = false;
54 | unpaused.signalAll();
55 | }
56 | finally
57 | {
58 | pauseLock.unlock();
59 | }
60 | }
61 |
62 | @Override
63 | public void run()
64 | {
65 |
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pcore/send/SendServerHandler.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pcore.send;
2 |
3 |
4 | import java.io.IOException;
5 | import java.nio.channels.SelectionKey;
6 | import java.nio.channels.ServerSocketChannel;
7 | import java.nio.channels.SocketChannel;
8 | import java.util.concurrent.BlockingQueue;
9 | import java.util.concurrent.LinkedBlockingDeque;
10 | import java.util.concurrent.ThreadPoolExecutor;
11 | import java.util.concurrent.TimeUnit;
12 |
13 | import android.util.Log;
14 |
15 | import com.guo.duoduo.p2pmanager.p2pconstant.P2PConstant;
16 | import com.guo.duoduo.p2pmanager.p2pinterface.Handler;
17 |
18 |
19 | /**
20 | * Created by 郭攀峰 on 2015/9/21.
21 | */
22 | public class SendServerHandler implements Handler
23 | {
24 | private static final String tag = SendServerHandler.class.getSimpleName();
25 |
26 | static final int CORE_POOL_SIZE = P2PConstant.MAXIMUM_POOL_SIZE;
27 | static final int KEEP_ALIVE_TIME = 1;
28 | static final TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS;
29 |
30 | SendManager sendManager;
31 | BlockingQueue sendBlockingQueue;
32 | ThreadPoolExecutor sendThreadPool;
33 |
34 | public SendServerHandler(SendManager sendManager)
35 | {
36 | this.sendManager = sendManager;
37 | sendBlockingQueue = new LinkedBlockingDeque<>();
38 | sendThreadPool = new ThreadPoolExecutor(CORE_POOL_SIZE,
39 | P2PConstant.MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT,
40 | sendBlockingQueue);
41 | sendThreadPool.allowCoreThreadTimeOut(true);
42 | }
43 |
44 | @Override
45 | public void handleAccept(SelectionKey key) throws IOException
46 | {
47 | Log.d(tag, "handle accept");
48 |
49 | ServerSocketChannel serverSocketChannel = (ServerSocketChannel) key.channel();
50 | //获取客户端连接的通道
51 | SocketChannel socketChannel = serverSocketChannel.accept();
52 | String peerIp = socketChannel.socket().getInetAddress().getHostAddress();
53 | Sender sender = sendManager.getSender(peerIp);
54 | if (sender == null)
55 | {
56 | socketChannel.close();
57 | return;
58 | }
59 | //设置为非阻塞
60 | socketChannel.configureBlocking(false);
61 |
62 | SendTask sendTask = new SendTask(sender, socketChannel);
63 | if (sendTask.prepare() == SendTask.TRANS_START)
64 | {
65 | //在和客户端连接成功之后,为了可以给客户端写数据,需要给通道设置写的权限
66 | socketChannel.register(key.selector(), SelectionKey.OP_WRITE, sendTask); //将task attach到key中
67 | }
68 | else
69 | {
70 | socketChannel.close();
71 | return;
72 | }
73 | sender.mSendTasks.add(sendTask);
74 | sendTask.notifySender(P2PConstant.CommandNum.SEND_TCP_ESTABLISHED, null);
75 | }
76 |
77 | @Override
78 | public void handleRead(SelectionKey key) throws IOException
79 | {
80 |
81 | }
82 |
83 | @Override
84 | public void handleWrite(SelectionKey key) throws IOException
85 | {
86 | Log.d(tag, "handle write");
87 |
88 | SendTask sendTask = (SendTask) key.attachment();
89 | key.cancel();
90 |
91 | sendTask.waitRun();
92 | sendThreadPool.execute(sendTask);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pentity/P2PFileInfo.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pentity;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pcore.P2PManager;
5 |
6 | import java.io.File;
7 |
8 |
9 | /**
10 | * Created by 郭攀峰 on 2015/9/16.
11 | * android设备中的文件
12 | */
13 | public class P2PFileInfo
14 | {
15 | public String path;
16 | public String name;
17 | public long size;
18 | public int type;
19 | public int percent;
20 | public boolean success;
21 | public long LengthNeeded = 0;
22 |
23 | public P2PFileInfo()
24 | {
25 |
26 | }
27 |
28 | public int getPercent()
29 | {
30 | return percent;
31 | }
32 |
33 | public void setPercent(int percent)
34 | {
35 | this.percent = percent;
36 | if (percent == 100)
37 | {
38 | success = true;
39 | }
40 | }
41 |
42 | @Override
43 | public boolean equals(Object o)
44 | {
45 | return (((P2PFileInfo) (o)).name.equals(name))
46 | && (((P2PFileInfo) (o)).size == size) && (((P2PFileInfo) (o)).type == type)
47 | && (((P2PFileInfo) (o)).path.equals(path));
48 | }
49 |
50 | public P2PFileInfo(String string)
51 | {
52 | String str[] = string.split(":");
53 | name = str[0];
54 | size = Long.parseLong(str[1]);
55 | type = Integer.parseInt(str[2]);
56 |
57 | path = P2PManager.getSavePath(type) + File.separator + name;
58 | }
59 |
60 | @Override
61 | public String toString()
62 | {
63 | return name + ":" + size + ":" + type + "\0";
64 | }
65 |
66 | public P2PFileInfo duplicate()
67 | {
68 | P2PFileInfo file = new P2PFileInfo();
69 |
70 | file.name = this.name;
71 | file.size = this.size;
72 | file.path = this.path;
73 | file.type = this.type;
74 | file.percent = this.percent;
75 | file.success = this.success;
76 | file.LengthNeeded = this.LengthNeeded;
77 |
78 | return file;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pentity/P2PNeighbor.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pentity;
2 |
3 |
4 | import java.net.InetAddress;
5 |
6 | /**
7 | * Created by 郭攀峰 on 2015/9/19.
8 | * 局域网的用户
9 | */
10 | public class P2PNeighbor
11 | {
12 | public String alias;
13 | public String ip;
14 | public InetAddress inetAddress;
15 |
16 | @Override
17 | public boolean equals(Object obj)
18 | {
19 | if (obj == null)
20 | return false;
21 |
22 | P2PNeighbor s = (P2PNeighbor) obj;
23 |
24 | if ((s.ip == null))
25 | return false;
26 |
27 | return (this.ip.equals(s.ip));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pentity/SigMessage.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pentity;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pconstant.P2PConstant;
5 |
6 | import java.util.Date;
7 |
8 |
9 | /**
10 | * Created by 郭攀峰 on 2015/9/17.
11 | * 局域网用户之间的upd消息
12 | */
13 | public class SigMessage
14 | {
15 | /**
16 | * 发送包的编号 时间即编号
17 | */
18 | public String packetNum;
19 | /**
20 | * 发送者的昵称
21 | */
22 | public String senderAlias;
23 | /**
24 | * 发送者的ip地址
25 | */
26 | public String senderIp;
27 | /**
28 | *
29 | */
30 | public int commandNum;
31 | /**
32 | *
33 | */
34 | public int recipient;
35 | /**
36 | * 内容
37 | */
38 | public String addition;
39 |
40 | public SigMessage()
41 | {
42 | this.packetNum = getTime();
43 | }
44 |
45 | public SigMessage(String protocolString)
46 | {
47 | protocolString = protocolString.trim();
48 | String[] args = protocolString.split(":");
49 |
50 | packetNum = args[0];
51 | senderAlias = args[1];
52 | senderIp = args[2];
53 | commandNum = Integer.parseInt(args[3]);
54 | recipient = Integer.parseInt(args[4]);
55 | if (args.length > 5)
56 | addition = args[5];
57 | else
58 | addition = null;
59 |
60 | for (int i = 6; i < args.length; i++)
61 | {
62 | addition += (":" + args[i]);
63 | }
64 | }
65 |
66 | public String toProtocolString()
67 | {
68 | StringBuffer sb = new StringBuffer();
69 | sb.append(packetNum);
70 | sb.append(":");
71 | sb.append(senderAlias);
72 | sb.append(":");
73 | sb.append(senderIp);
74 | sb.append(":");
75 | sb.append(commandNum);
76 | sb.append(":");
77 | sb.append(recipient);
78 | sb.append(":");
79 | sb.append(addition);
80 | sb.append(P2PConstant.MSG_SEPARATOR);
81 |
82 | return sb.toString();
83 | }
84 |
85 | private String getTime()
86 | {
87 | Date nowDate = new Date();
88 | return Long.toString(nowDate.getTime());
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pentity/SocketTransInfo.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pentity;
2 |
3 |
4 | /**
5 | * Created by 郭攀峰 on 2015/9/21.
6 | */
7 | public class SocketTransInfo
8 | {
9 | public long Offset;
10 | public long Length;
11 | public long Transferred;
12 | public int P2PFile_Idx;
13 | public int Index;
14 |
15 | public SocketTransInfo(int idx)
16 | {
17 | P2PFile_Idx = idx;
18 | Length = 0; // need not to be transferred
19 | Transferred = 0;
20 | }
21 |
22 | @Override
23 | public String toString()
24 | {
25 | return Index + ":" + P2PFile_Idx + ":" + Offset + ":" + Length;
26 | }
27 |
28 | public SocketTransInfo(String protocolString)
29 | {
30 | String[] args = protocolString.split(":");
31 | Index = Integer.parseInt(args[0]);
32 | P2PFile_Idx = Integer.parseInt(args[1]);
33 | Offset = Long.parseLong(args[2]);
34 | Length = Long.parseLong(args[3]);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pentity/param/ParamIPMsg.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pentity.param;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pentity.SigMessage;
5 |
6 | import java.net.InetAddress;
7 |
8 |
9 | /**
10 | * Created by 郭攀峰 on 2015/9/20.
11 | */
12 | public class ParamIPMsg
13 | {
14 | public SigMessage peerMSG;
15 | public InetAddress peerIAddr;
16 | public int peerPort;
17 |
18 | public ParamIPMsg(String msg, InetAddress addr, int port)
19 | {
20 | peerMSG = new SigMessage(msg);
21 | peerIAddr = addr;
22 | peerPort = port;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pentity/param/ParamReceiveFiles.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pentity.param;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
5 | import com.guo.duoduo.p2pmanager.p2pentity.P2PNeighbor;
6 |
7 | /**
8 | * Created by 郭攀峰 on 2015/9/20.
9 | */
10 | public class ParamReceiveFiles
11 | {
12 | public P2PNeighbor Neighbor;
13 | public P2PFileInfo[] Files;
14 |
15 | public ParamReceiveFiles(P2PNeighbor dest, P2PFileInfo[] files)
16 | {
17 | Neighbor = dest;
18 | Files = files;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pentity/param/ParamSendFiles.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pentity.param;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
5 | import com.guo.duoduo.p2pmanager.p2pentity.P2PNeighbor;
6 |
7 | /**
8 | * Created by 郭攀峰 on 2015/9/20.
9 | */
10 | public class ParamSendFiles
11 | {
12 | public P2PNeighbor[] neighbors;
13 | public P2PFileInfo[] files;
14 |
15 | public ParamSendFiles(P2PNeighbor[] neighbors, P2PFileInfo[] files)
16 | {
17 | this.neighbors = neighbors;
18 | this.files = files;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pentity/param/ParamTCPNotify.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pentity.param;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pentity.P2PNeighbor;
5 |
6 | /**
7 | * Created by 郭攀峰 on 2015/9/22.
8 | */
9 | public class ParamTCPNotify
10 | {
11 | public P2PNeighbor Neighbor;
12 | public Object Obj;
13 |
14 | public ParamTCPNotify(P2PNeighbor dest, Object obj)
15 | {
16 | Neighbor = dest;
17 | Obj = obj;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pinterface/Handler.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pinterface;
2 |
3 |
4 | import java.io.IOException;
5 | import java.nio.channels.SelectionKey;
6 |
7 |
8 | /**
9 | * Created by 郭攀峰 on 2015/9/22.
10 | * 处理NIO client与server交互
11 | */
12 | public interface Handler
13 | {
14 | /**
15 | * 处理客户端请求连接
16 | *
17 | * @param key
18 | * @throws IOException
19 | */
20 | void handleAccept(SelectionKey key) throws IOException;
21 |
22 | void handleRead(SelectionKey key) throws IOException;
23 |
24 | /**
25 | * 处理发送端写文件
26 | * @param key
27 | * @throws IOException
28 | */
29 | void handleWrite(SelectionKey key) throws IOException;
30 | }
31 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pinterface/Melon_Callback.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pinterface;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pentity.P2PNeighbor;
5 |
6 | /**
7 | * Created by 郭攀峰 on 2015/9/19.
8 | * 局域网好友上线和掉线
9 | */
10 | public interface Melon_Callback
11 | {
12 | /**
13 | * 局域网发现好友
14 | * @param melon
15 | */
16 | public void Melon_Found(P2PNeighbor melon);
17 |
18 | /**
19 | * 局域网好友离开
20 | * @param melon
21 | */
22 | public void Melon_Removed(P2PNeighbor melon);
23 | }
24 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pinterface/ReceiveFile_Callback.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pinterface;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
5 | import com.guo.duoduo.p2pmanager.p2pentity.P2PNeighbor;
6 |
7 | /**
8 | * Created by 郭攀峰 on 2015/9/20.
9 | * 我要接受实现的接收回掉
10 | */
11 | public interface ReceiveFile_Callback
12 | {
13 | public boolean QueryReceiving(P2PNeighbor src, P2PFileInfo files[]);
14 |
15 | public void BeforeReceiving(P2PNeighbor src, P2PFileInfo files[]);
16 |
17 | public void OnReceiving(P2PFileInfo files);
18 |
19 | public void AfterReceiving();
20 |
21 | public void AbortReceiving(int error, String alias);
22 | }
23 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2pinterface/SendFile_Callback.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2pinterface;
2 |
3 |
4 | import com.guo.duoduo.p2pmanager.p2pentity.P2PFileInfo;
5 | import com.guo.duoduo.p2pmanager.p2pentity.P2PNeighbor;
6 |
7 | /**
8 | * Created by 郭攀峰 on 2015/9/20.
9 | * 我要发送实现的发送回调
10 | */
11 | public interface SendFile_Callback
12 | {
13 | public void BeforeSending();
14 |
15 | public void OnSending(P2PFileInfo file, P2PNeighbor dest);
16 |
17 | public void AfterSending(P2PNeighbor dest);
18 |
19 | public void AfterAllSending();
20 |
21 | public void AbortSending(int error, P2PNeighbor dest);
22 | }
23 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2ptimer/OSTimer.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2ptimer;
2 |
3 |
4 | import android.os.Handler;
5 |
6 |
7 | /**
8 | * Created by 郭攀峰 on 2015/9/19.
9 | * 一个通用的定时器
10 | */
11 | public class OSTimer implements Runnable
12 | {
13 | private Handler mHandler;
14 | private int mInterval;
15 | private Timeout mTimeout;
16 |
17 | private boolean isCycle = false;
18 | private boolean isCancel = false;
19 |
20 | public OSTimer(Handler handler, Timeout timeout, int interval)
21 | {
22 | mTimeout = timeout;
23 | mInterval = interval;
24 | isCycle = false;
25 | if (handler != null)
26 | mHandler = handler;
27 | else
28 | mHandler = new Handler();
29 | }
30 |
31 | public void start()
32 | {
33 | if (mHandler != null)
34 | mHandler.postDelayed(this, mInterval);
35 | }
36 |
37 | public void cancel()
38 | {
39 | isCancel = true;
40 | }
41 |
42 | @Override
43 | public void run()
44 | {
45 | if (!isCancel)
46 | {
47 | if (mTimeout != null)
48 | mTimeout.onTimeOut();
49 | if (isCycle)
50 | start();
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/java/com/guo/duoduo/p2pmanager/p2ptimer/Timeout.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager.p2ptimer;
2 |
3 |
4 | /**
5 | * Created by 郭攀峰 on 2015/9/19.
6 | */
7 | public interface Timeout
8 | {
9 | /**
10 | * 定时器时间到了
11 | */
12 | public void onTimeOut();
13 | }
14 |
--------------------------------------------------------------------------------
/p2pmanager/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | P2PManager
3 |
4 |
--------------------------------------------------------------------------------
/p2pmanager/src/test/java/com/guo/duoduo/p2pmanager/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.p2pmanager;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/randomtextview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/randomtextview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile project(':rippleview')
25 | }
26 |
--------------------------------------------------------------------------------
/randomtextview/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 D:\developtools\android_sdk_windows/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 p2pinterface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.p2pinterface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/randomtextview/src/androidTest/java/com/guo/duoduo/randomtextview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.randomtextview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/randomtextview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/randomtextview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RandomTextView
3 |
4 |
--------------------------------------------------------------------------------
/randomtextview/src/test/java/com/guo/duoduo/randomtextview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.randomtextview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/rippleoutlayout/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/rippleoutlayout/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | }
24 |
--------------------------------------------------------------------------------
/rippleoutlayout/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 D:\developtools\android_sdk_windows/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 p2pinterface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.p2pinterface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/rippleoutlayout/src/androidTest/java/com/guo/duoduo/rippleoutlayout/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.rippleoutlayout;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/rippleoutlayout/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/rippleoutlayout/src/main/res/values/ripple_layout_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/rippleoutlayout/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RippleOutLayout
3 |
4 |
--------------------------------------------------------------------------------
/rippleoutlayout/src/test/java/com/guo/duoduo/rippleoutlayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.rippleoutlayout;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.Test;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/rippleview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/rippleview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion "22.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | }
25 |
--------------------------------------------------------------------------------
/rippleview/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 D:\developtools\android_sdk_windows/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 p2pinterface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.p2pinterface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/rippleview/src/androidTest/java/com/guo/duoduo/rippleoutview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.rippleoutview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/rippleview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/rippleview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RippleOutView
3 |
4 |
--------------------------------------------------------------------------------
/rippleview/src/test/java/com/guo/duoduo/rippleoutview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.guo.duoduo.rippleoutview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':RadarScanView', ':randomtextview', ':rippleview', ':rippleoutlayout', ':p2pmanager', 'httpServer'
--------------------------------------------------------------------------------