├── .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 | 12 | 13 | 14 | 15 | 16 | 28 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 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 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /AnyShareOfAndroid.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 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 | ![image](https://github.com/gpfduoduo/AnyShareOfAndroid/blob/master/filetransfer.gif "效果图") 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 |