├── .gitignore ├── COPYING.WTFPL ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── pl │ │ └── universalcopy │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── xposed_init │ ├── java │ │ └── com │ │ │ └── pl │ │ │ └── universalcopy │ │ │ ├── BaseActivity.java │ │ │ ├── Constant.java │ │ │ ├── DonateActivity.java │ │ │ ├── GlobalCopyTile.java │ │ │ ├── HowToUseActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── NotifyService.java │ │ │ ├── UCXPApp.java │ │ │ ├── UniversalCopyActiity.java │ │ │ ├── WakeUpBR.java │ │ │ ├── copy │ │ │ ├── CopyActivity.java │ │ │ ├── CopyNode.java │ │ │ └── CopyNodeView.java │ │ │ ├── utils │ │ │ ├── ClipboardUtils.java │ │ │ ├── CountLinkMovementMethod.java │ │ │ ├── IOUtil.java │ │ │ ├── SPHelper.java │ │ │ ├── StatusBarCompat.java │ │ │ ├── ToastUtil.java │ │ │ └── ViewUtil.java │ │ │ └── xposed │ │ │ ├── Filter.java │ │ │ ├── Logger.java │ │ │ ├── XposedEnable.java │ │ │ ├── XposedKeyUpHandler.java │ │ │ ├── XposedUniversalCopy.java │ │ │ └── XposedUniversalCopyHandler.java │ └── res │ │ ├── drawable-xhdpi │ │ └── notify_copy.png │ │ ├── drawable │ │ ├── borders.xml │ │ ├── button_background.xml │ │ └── universal_copy_node_bg_n.xml │ │ ├── layout │ │ ├── activity_copy_overlay.xml │ │ ├── activity_donate.xml │ │ ├── activity_how_to_use.xml │ │ ├── activity_main.xml │ │ └── dialog_copy_text_editor.xml │ │ ├── menu │ │ └── universal_copy.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ ├── ic_arrow_back_white_24dp.png │ │ ├── ic_close_white_24dp.png │ │ ├── ic_edit_white_24dp.png │ │ ├── ic_float_copy.png │ │ ├── ic_fullscreen_white_24dp.png │ │ ├── ic_launcher.png │ │ ├── universal_copy.png │ │ └── universal_select_all.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── raw │ │ ├── alipay.jpg │ │ └── wechat.jpg │ │ ├── values-v11 │ │ └── styles.xml │ │ ├── values-v19 │ │ ├── dimens.xml │ │ └── styles.xml │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── colors_material.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── pl │ └── universalcopy │ └── ExampleUnitTest.java ├── build.gradle ├── gif └── demo.gif ├── gradle.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea 3 | .gradle 4 | gradle 5 | /local.properties 6 | /.idea/workspace.xml 7 | /.idea/libraries 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | -------------------------------------------------------------------------------- /COPYING.WTFPL: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ###全局复制Xposed版 2 | 3 | 本应用是从[Bigbang项目](https://github.com/l465659833/Bigbang)中抽出来的独立功能,想体验完整高效文字处理体验,可以下载[](http://www.coolapk.com/apk/com.forfan.bigbang) 4 | 5 | 6 | ###使用效果图 7 | ![点击触发](https://raw.githubusercontent.com/l465659833/UniversalCopy_xposed/master/gif/demo.gif) 8 | 9 | 10 | ###说明 11 | 原理其实很简单,就是遍历View,把其中的文字取出来(TextView),让用户可以选择。 12 | 但是有些自定义View,就无法直接取得文字,需要特殊适配,目前只针对微信做了特殊适配。感兴趣的朋友可以帮忙一起做适配。 13 | 14 | 15 | ##License 16 | 17 | 18 | ![DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE](http://www.wtfpl.net/wp-content/uploads/2012/12/logo-220x1601.png) 19 | 20 | 21 | ``` 22 | Copyright © 2016 l465659833 23 | This work is free. You can redistribute it and/or modify it under the 24 | terms of the Do What The Fuck You Want To Public License, Version 2, 25 | as published by Sam Hocevar. See the COPYING file for more details. 26 | 27 | ``` 28 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | def releaseTime() { 3 | return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC")) 4 | } 5 | android { 6 | compileSdkVersion 26 7 | buildToolsVersion "26.0.2" 8 | defaultConfig { 9 | applicationId "com.pl.universalcopy" 10 | minSdkVersion 14 11 | targetSdkVersion 24 12 | versionCode 3 13 | versionName "1.3.0" 14 | } 15 | buildTypes { 16 | debug { 17 | minifyEnabled false 18 | shrinkResources false 19 | manifestPlaceholders = [UMENG_CHANNEL_VALUE: "for_test"] 20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 21 | debuggable true 22 | } 23 | release { 24 | minifyEnabled true 25 | shrinkResources true 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | applicationVariants.all { variant -> 28 | variant.outputs.each { output -> 29 | def outputFile = output.outputFileName 30 | if (outputFile != null && outputFile.contains("release")) { 31 | if (outputFile.endsWith('.apk')) { 32 | // 输出apk名称为boohee_v1.0_2015-01-15_wandoujia.apk 33 | def fileName = "UC_XP_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors[0].name}.apk" 34 | output.outputFileName = fileName 35 | } 36 | } 37 | } 38 | } 39 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 40 | debuggable false 41 | } 42 | } 43 | flavorDimensions "universal_copy" 44 | productFlavors { 45 | coolapk {} 46 | } 47 | productFlavors.all { flavor -> 48 | flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] 49 | } 50 | } 51 | 52 | dependencies { 53 | compile fileTree(dir: 'libs', include: ['*.jar']) 54 | provided 'de.robv.android.xposed:api:82' 55 | compile 'com.android.support:design:26.1.0' 56 | compile 'com.android.support:appcompat-v7:26.1.0' 57 | compile 'com.umeng.analytics:analytics:latest.integration' 58 | } 59 | -------------------------------------------------------------------------------- /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 F:\Java\android\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # 对亍使用 4.0.3 以上 android-sdk 进行顷目编译时产生异常癿情况时,加入以下内容: 20 | -dontwarn cn.waps.** 21 | -ignorewarnings 22 | -optimizationpasses 5 # 指定代码的压缩级别 23 | -dontusemixedcaseclassnames # 是否使用大小写混合 24 | -dontpreverify # 混淆时是否做预校验 25 | -verbose # 混淆时是否记录日志 26 | -dontskipnonpubliclibraryclasses 27 | -dontwarn org.apache.http.** 28 | -dontwarn android.net.http.AndroidHttpClient 29 | -dontwarn com.google.android.gms.** 30 | -dontwarn com.android.volley.toolbox.** 31 | -dontwarn android.support.* 32 | 33 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* # 混淆时所采用的算法 34 | 35 | -keep public class * extends android.app.Activity # 保持哪些类不被混淆 36 | -keep public class * extends android.app.Application # 保持哪些类不被混淆 37 | -keep public class * extends android.app.Service # 保持哪些类不被混淆 38 | -keep public class * extends android.content.BroadcastReceiver # 保持哪些类不被混淆 39 | -keep public class * extends android.content.ContentProvider # 保持哪些类不被混淆 40 | -keep public class * extends android.app.backup.BackupAgentHelper # 保持哪些类不被混淆 41 | -keep public class * extends android.preference.Preference # 保持哪些类不被混淆 42 | -keep public class com.android.vending.licensing.ILicensingService # 保持哪些类不被混淆 43 | 44 | -keepclasseswithmembernames class * { # 保持 native 方法不被混淆 45 | native ; 46 | } 47 | -keepclasseswithmembers class * { # 保持自定义控件类不被混淆 48 | public (android.content.Context, android.util.AttributeSet); 49 | } 50 | -keepclasseswithmembers class * { # 保持自定义控件类不被混淆 51 | public (android.content.Context); 52 | } 53 | -keepclasseswithmembers class * {# 保持自定义控件类不被混淆 54 | public (android.content.Context, android.util.AttributeSet, int); 55 | } 56 | -keepclassmembers class * extends android.app.Activity { # 保持自定义控件类不被混淆 57 | public void *(android.view.View); 58 | } 59 | # keep setters in Views so that animations can still work. 60 | -keepclassmembers public class * extends android.view.View { 61 | void set*(***); 62 | *** get*(); 63 | } 64 | -keepclassmembers enum * { # 保持枚举 enum 类不被混淆 65 | public static **[] values(); 66 | public static ** valueOf(java.lang.String); 67 | } 68 | -keep class * implements android.os.Parcelable { # 保持 Parcelable 不被混淆 69 | public static final android.os.Parcelable$Creator *; 70 | } 71 | -keepclassmembers class * implements android.os.Parcelable { 72 | public ; 73 | private ; 74 | } 75 | 76 | -keep public class cn.waps.** {*;} 77 | -keep public interface cn.waps.** {*;} 78 | 79 | -keepclassmembers class * { 80 | public (org.json.JSONObject); 81 | } 82 | 83 | -keepclassmembers class ** { 84 | public void onEvent*(**); 85 | } 86 | -keep public class com.forfan.bigbang.R$*{ 87 | public static final int *; 88 | } 89 | 90 | -keepclassmembers enum * { 91 | public static **[] values(); 92 | public static ** valueOf(java.lang.String); 93 | } 94 | 95 | -keep public class com.umeng.fb.ui.ThreadView { } 96 | 97 | -keep class com.qhad.** {*;} 98 | 99 | -keep class com.qq.e.** { 100 | public protected *; 101 | } 102 | -keep class android.support.v4.app.NotificationCompat**{ 103 | public *; 104 | } 105 | 106 | -dontwarn javax.annotation.** 107 | -dontwarn javax.inject.** 108 | # OkHttp3 109 | -dontwarn okhttp3.logging.** 110 | -keep class okhttp3.internal.**{*;} 111 | -dontwarn okio.** 112 | # Retrofit 113 | -dontwarn retrofit2.** 114 | -keep class retrofit2.** { *; } 115 | #-keepattributes Signature-keepattributes Exceptions 116 | # RxJava RxAndroid 117 | -dontwarn sun.misc.** 118 | -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* { 119 | long producerIndex; 120 | long consumerIndex; 121 | } 122 | -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef { 123 | rx.internal.util.atomic.LinkedQueueNode producerNode; 124 | } 125 | -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef { 126 | rx.internal.util.atomic.LinkedQueueNode consumerNode; 127 | } 128 | 129 | # Gson 130 | -keep class com.google.gson.** {*;} 131 | -keep class com.google.gson.stream.** { *; } 132 | -keepattributes EnclosingMethod 133 | -keep class com.forfan.bigbang.entity.**{*;} 134 | -keep class com.microsoft.projectoxford.vision.contract.**{*;} 135 | 136 | 137 | # Platform calls Class.forName on types which do not exist on Android to determine platform. 138 | -dontnote retrofit2.Platform 139 | # Platform used when running on RoboVM on iOS. Will not be used at runtime. 140 | -dontnote retrofit2.Platform$IOS$MainThreadExecutor 141 | # Platform used when running on Java 8 VMs. Will not be used at runtime. 142 | -dontwarn retrofit2.Platform$Java8 143 | # Retain generic type information for use by reflection by converters and adapters. 144 | -keepattributes Signature 145 | # Retain declared checked exceptions for use by a Proxy instance. 146 | -keepattributes Exceptions 147 | 148 | -keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* { 149 | long producerIndex; 150 | long consumerIndex; 151 | } 152 | -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef { 153 | rx.internal.util.atomic.LinkedQueueNode producerNode; 154 | } 155 | -keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef { 156 | rx.internal.util.atomic.LinkedQueueNode consumerNode; 157 | } 158 | 159 | -keep class com.pl.universalcopy.xposed.* { *; } 160 | -keep class com.pl.universalcopy.xposed.** { *; } 161 | 162 | -keep class com.pl.universalcopy.copy.* { *; } 163 | -keep class com.pl.universalcopy.copy.** { *; } 164 | 165 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/pl/universalcopy/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.pl.universalcopy", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 19 | 20 | 21 | 24 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 46 | 47 | 50 | 53 | 56 | 57 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 74 | 75 | 78 | 79 | 86 | 87 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /app/src/main/assets/xposed_init: -------------------------------------------------------------------------------- 1 | com.pl.universalcopy.xposed.XposedUniversalCopy 2 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.DialogFragment; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v4.app.FragmentManager; 7 | import android.support.v4.app.FragmentTransaction; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.view.MenuItem; 10 | 11 | import com.umeng.analytics.MobclickAgent; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * Created by penglu on 2016/4/27. 17 | */ 18 | public class BaseActivity extends AppCompatActivity { 19 | 20 | private Fragment currentFragment; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | // setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 26 | } 27 | 28 | public void switchFragment(Fragment fragment){ 29 | if (currentFragment!=null&¤tFragment==fragment){ 30 | return; 31 | } 32 | FragmentManager fm=getSupportFragmentManager(); 33 | FragmentTransaction ft=fm.beginTransaction(); 34 | if (currentFragment!=null){ 35 | ft.hide(currentFragment); 36 | } 37 | ft.show(fragment); 38 | ft.commitAllowingStateLoss(); 39 | currentFragment=fragment; 40 | } 41 | 42 | @Override 43 | protected void onResume() { 44 | super.onResume(); 45 | try { 46 | MobclickAgent.onResume(this); 47 | } catch (Throwable e) { 48 | } 49 | } 50 | 51 | @Override 52 | protected void onPause() { 53 | try { 54 | MobclickAgent.onPause(this); 55 | } catch (Throwable e) { 56 | } 57 | super.onPause(); 58 | } 59 | 60 | public void registerFragment(int id, Fragment fragment){ 61 | if (currentFragment==fragment){ 62 | return; 63 | 64 | } 65 | FragmentManager fm=getSupportFragmentManager(); 66 | FragmentTransaction ft=fm.beginTransaction(); 67 | if (currentFragment!=null){ 68 | ft.hide(currentFragment); 69 | } 70 | ft.add(id,fragment,fragment.getClass().getName()); 71 | ft.commit(); 72 | currentFragment=fragment; 73 | } 74 | 75 | @Override 76 | public boolean onOptionsItemSelected(MenuItem item) { 77 | switch (item.getItemId()) { 78 | case android.R.id.home: 79 | onBackPressed(); 80 | return true; 81 | } 82 | return (super.onOptionsItemSelected(item)); 83 | } 84 | 85 | protected void recoverFragment(String currentFragmentTag){ 86 | if (currentFragmentTag==null){ 87 | return; 88 | } 89 | FragmentManager fm=getSupportFragmentManager(); 90 | FragmentTransaction ft=fm.beginTransaction(); 91 | List fragments=fm.getFragments(); 92 | for (Fragment fragment:fragments){ 93 | if (fragment.getTag().equals(currentFragmentTag)){ 94 | ft.show(fragment); 95 | }else { 96 | ft.hide(fragment); 97 | } 98 | } 99 | ft.commitAllowingStateLoss(); 100 | Fragment current=fm.findFragmentByTag(currentFragmentTag); 101 | switchFragment(current); 102 | } 103 | 104 | 105 | @Override 106 | protected void onSaveInstanceState(Bundle outState) { 107 | removeDialogFragment(); 108 | super.onSaveInstanceState(outState); 109 | } 110 | 111 | protected void removeDialogFragment(){ 112 | FragmentManager fm=getSupportFragmentManager(); 113 | FragmentTransaction ft=fm.beginTransaction(); 114 | List fragments=fm.getFragments(); 115 | if (fragments==null){ 116 | return; 117 | } 118 | for (Fragment fragment:fragments){ 119 | if (fragment instanceof DialogFragment){ 120 | ft.remove(fragment); 121 | } 122 | } 123 | ft.commitAllowingStateLoss(); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/Constant.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | /** 4 | * Created by dim on 16/11/4. 5 | */ 6 | 7 | public class Constant { 8 | 9 | public static final String SP_NAME = "sp_name"; 10 | public static final String PACKAGE_NAME = "com.pl.universalcopy"; 11 | public static final String OUT_SIDE_CALL_ACTIVITY_NAME = "com.pl.universalcopy.UniversalCopyActiity"; 12 | 13 | //xp全局复制 14 | public static final String UNIVERSAL_COPY_BROADCAST_XP="com_pl_universal_copy_broadcast_xp"; 15 | public static final String UNIVERSAL_COPY_BROADCAST_XP_DELAY="com_pl_universal_copy_broadcast_xp_delay"; 16 | public static final String IS_FULL_SCREEN_COPY="is_full_screen_copy"; 17 | public static final String IS_UNIVERSAL_COPY_FOREGROUND="is_universal_copy_foreground"; 18 | public static final String IS_UNIVERSAL_COPY_ENABLE="is_universal_copy_enable"; 19 | 20 | 21 | public static final String TOTAL_SWITCH=IS_UNIVERSAL_COPY_ENABLE; 22 | public static final String OPEN_NOTIFY=IS_UNIVERSAL_COPY_FOREGROUND; 23 | public static final String MONITOR_CLICK="monitor_click"; 24 | public static final String MONITOR_LONG_CLICK="monitor_long_click"; 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/DonateActivity.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.os.Environment; 7 | import android.support.v7.widget.Toolbar; 8 | import android.text.Html; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.TextView; 12 | 13 | 14 | import com.pl.universalcopy.utils.CountLinkMovementMethod; 15 | import com.pl.universalcopy.utils.IOUtil; 16 | import com.pl.universalcopy.utils.StatusBarCompat; 17 | import com.pl.universalcopy.utils.ToastUtil; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | 23 | /** 24 | * Created by wangyan-pd on 2016/11/19. 25 | */ 26 | 27 | public class DonateActivity extends BaseActivity { 28 | private static final String SAVE_PIC_PATH= Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED) ? Environment.getExternalStorageDirectory().getAbsolutePath() : "/mnt/sdcard";//保存到SD卡 29 | private static final String SAVE_REAL_PATH = SAVE_PIC_PATH+ "/Pictures";//保存的确切位置 30 | public static String zhifubao="https://mobilecodec.alipay.com/client_download.htm?qrcode=ap13zwff7wggcfdn80"; 31 | 32 | private TextView donateMsg; 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | super.onCreate(savedInstanceState); 36 | StatusBarCompat.setupStatusBarView(this, (ViewGroup) getWindow().getDecorView(), true, R.color.colorPrimary); 37 | setContentView(R.layout.activity_donate); 38 | 39 | 40 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 41 | setSupportActionBar(toolbar); 42 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 43 | getSupportActionBar().setTitle(R.string.donate); 44 | 45 | 46 | findViewById(R.id.image).setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View v) { 49 | File file = new File(SAVE_REAL_PATH,"alipay.jpg"); 50 | if(file.exists()){ 51 | ToastUtil.show(R.string.picture_saved); 52 | sendBrodcast4Update(file); 53 | return; 54 | }else { 55 | InputStream is=getResources().openRawResource(R.raw.alipay); 56 | try { 57 | IOUtil.saveToFile(is,file); 58 | ToastUtil.show(R.string.picture_saved); 59 | sendBrodcast4Update(file); 60 | } catch (IOException e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | 65 | } 66 | }); 67 | findViewById(R.id.image1).setOnClickListener(new View.OnClickListener() { 68 | @Override 69 | public void onClick(View v) { 70 | File file = new File(SAVE_REAL_PATH,"wechat.jpg"); 71 | if(file.exists()){ 72 | ToastUtil.show(R.string.picture_saved); 73 | sendBrodcast4Update(file); 74 | return; 75 | }else { 76 | InputStream is=getResources().openRawResource(R.raw.wechat); 77 | try { 78 | IOUtil.saveToFile(is,file); 79 | ToastUtil.show(R.string.picture_saved); 80 | sendBrodcast4Update(file); 81 | } catch (IOException e) { 82 | e.printStackTrace(); 83 | } 84 | } 85 | 86 | } 87 | }); 88 | 89 | String donate=getString(R.string.donate_now); 90 | 91 | 92 | donateMsg= (TextView) findViewById(R.id.donate_msg); 93 | donateMsg.setText(Html.fromHtml(getString(R.string.thinks_for_donate) 94 | +"

"+donate+"")); 95 | donateMsg.setMovementMethod(CountLinkMovementMethod.getInstance()); 96 | } 97 | 98 | private void sendBrodcast4Update(File file) { 99 | Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); 100 | Uri uri = Uri.fromFile(file); 101 | intent.setData(uri); 102 | sendBroadcast(intent); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/GlobalCopyTile.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.content.Intent; 4 | import android.service.quicksettings.TileService; 5 | 6 | 7 | /** 8 | * Created by wangyan-pd on 2017/1/12. 9 | */ 10 | 11 | public class GlobalCopyTile extends TileService { 12 | private final int STATE_OFF = 0; 13 | private final int STATE_ON = 1; 14 | private int toggleState = STATE_ON; 15 | 16 | @Override 17 | public void onStartListening() { 18 | super.onStartListening(); 19 | } 20 | 21 | @Override 22 | public void onTileAdded() { 23 | super.onTileAdded(); 24 | } 25 | 26 | @Override 27 | public void onClick() { 28 | Intent intent = new Intent(); 29 | intent.setClass(this, UniversalCopyActiity.class); 30 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 31 | startActivityAndCollapse(intent); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/HowToUseActivity.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.Toolbar; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.LinearLayout; 10 | import android.widget.TextView; 11 | 12 | import com.pl.universalcopy.utils.StatusBarCompat; 13 | 14 | 15 | public class HowToUseActivity extends BaseActivity { 16 | public static final String GO_TO_OPEN_FROM_OUTER="go_to_open_from_outer"; 17 | 18 | private View introMenu; 19 | private LinearLayout introContent; 20 | 21 | private TextView introTitle; 22 | private TextView introMsg; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_how_to_use); 28 | 29 | StatusBarCompat.setupStatusBarView(this, (ViewGroup) getWindow().getDecorView(), true, R.color.colorPrimary); 30 | 31 | 32 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 33 | setSupportActionBar(toolbar); 34 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 35 | getSupportActionBar().setTitle(R.string.introduction); 36 | 37 | introMenu= (View) findViewById(R.id.intro_menu); 38 | introContent= (LinearLayout) findViewById(R.id.intro_content); 39 | 40 | introTitle = (TextView) findViewById(R.id.intro_title); 41 | introMsg = (TextView) findViewById(R.id.intro_msg); 42 | 43 | 44 | findViewById(R.id.overall_intro).setOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View v) { 47 | introMenu.setVisibility(View.GONE); 48 | introContent.setVisibility(View.VISIBLE); 49 | introTitle.setText(R.string.overall_intro); 50 | introMsg.setText(R.string.overall_intro_msg); 51 | } 52 | }); 53 | 54 | 55 | findViewById(R.id.about_universal_copy).setOnClickListener(new View.OnClickListener() { 56 | @Override 57 | public void onClick(View v) { 58 | introMenu.setVisibility(View.GONE); 59 | introContent.setVisibility(View.VISIBLE); 60 | introTitle.setText(R.string.about_universal_copy); 61 | introMsg.setText(R.string.about_universal_copy_msg); 62 | } 63 | }); 64 | 65 | findViewById(R.id.about_xposed).setOnClickListener(new View.OnClickListener() { 66 | @Override 67 | public void onClick(View v) { 68 | introMenu.setVisibility(View.GONE); 69 | introContent.setVisibility(View.VISIBLE); 70 | introTitle.setText(R.string.about_xposed); 71 | introMsg.setText(R.string.about_xposed_msg); 72 | } 73 | }); 74 | 75 | findViewById(R.id.open_from_outside).setOnClickListener(new View.OnClickListener() { 76 | @Override 77 | public void onClick(View v) { 78 | introMenu.setVisibility(View.GONE); 79 | introContent.setVisibility(View.VISIBLE); 80 | introTitle.setText(R.string.open_from_outside); 81 | introMsg.setText(R.string.open_from_outside_msg); 82 | } 83 | }); 84 | 85 | 86 | 87 | Intent intent = getIntent(); 88 | boolean goToOpenFromOuter=intent.getBooleanExtra(GO_TO_OPEN_FROM_OUTER,false); 89 | if (goToOpenFromOuter){ 90 | findViewById(R.id.open_from_outside).performClick(); 91 | } 92 | } 93 | 94 | 95 | @Override 96 | public void onBackPressed() { 97 | if (introMenu.getVisibility()==View.VISIBLE){ 98 | super.onBackPressed(); 99 | }else { 100 | introMenu.setVisibility(View.VISIBLE); 101 | introContent.setVisibility(View.GONE); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.support.v7.widget.SwitchCompat; 7 | import android.view.KeyEvent; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.BaseAdapter; 11 | import android.widget.CompoundButton; 12 | 13 | import com.pl.universalcopy.utils.SPHelper; 14 | import com.pl.universalcopy.utils.StatusBarCompat; 15 | 16 | public class MainActivity extends BaseActivity { 17 | 18 | private SwitchCompat monitorLongClickSwitch; 19 | private SwitchCompat monitorClickSwitch; 20 | private SwitchCompat notifySwitch; 21 | private SwitchCompat totalSwitchSwitch; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | 27 | StatusBarCompat.setupStatusBarView(this, (ViewGroup) getWindow().getDecorView(), true, R.color.colorPrimary); 28 | setContentView(R.layout.activity_main); 29 | startNotifyService(); 30 | 31 | totalSwitchSwitch= (SwitchCompat) findViewById(R.id.total_switch_switch); 32 | notifySwitch= (SwitchCompat) findViewById(R.id.notify_switch); 33 | monitorClickSwitch= (SwitchCompat) findViewById(R.id.key_trigger_switch); 34 | monitorLongClickSwitch= (SwitchCompat) findViewById(R.id.long_key_trigger_switch); 35 | 36 | findViewById(R.id.total_switch_rl).setOnClickListener(mOnClickListener); 37 | findViewById(R.id.notify_rl).setOnClickListener(mOnClickListener); 38 | findViewById(R.id.key_trigger_rl).setOnClickListener(mOnClickListener); 39 | findViewById(R.id.long_key_trigger_rl).setOnClickListener(mOnClickListener); 40 | findViewById(R.id.donate_rl).setOnClickListener(mOnClickListener); 41 | findViewById(R.id.guide_rl).setOnClickListener(mOnClickListener); 42 | 43 | totalSwitchSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 44 | @Override 45 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 46 | SPHelper.save(Constant.TOTAL_SWITCH,isChecked); 47 | startNotifyService(); 48 | } 49 | }); 50 | notifySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 51 | @Override 52 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 53 | SPHelper.save(Constant.OPEN_NOTIFY,isChecked); 54 | startNotifyService(); 55 | } 56 | }); 57 | monitorClickSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 58 | @Override 59 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 60 | SPHelper.save(Constant.MONITOR_CLICK,isChecked); 61 | } 62 | }); 63 | monitorLongClickSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 64 | @Override 65 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 66 | SPHelper.save(Constant.MONITOR_LONG_CLICK,isChecked); 67 | } 68 | }); 69 | 70 | totalSwitchSwitch.setChecked(SPHelper.getBoolean(Constant.TOTAL_SWITCH,true)); 71 | notifySwitch.setChecked(SPHelper.getBoolean(Constant.OPEN_NOTIFY,true)); 72 | monitorClickSwitch.setChecked(SPHelper.getBoolean(Constant.MONITOR_CLICK,true)); 73 | monitorLongClickSwitch.setChecked(SPHelper.getBoolean(Constant.MONITOR_LONG_CLICK,true)); 74 | 75 | } 76 | 77 | private void startNotifyService() { 78 | Intent notificationIntent = new Intent(this,NotifyService.class); 79 | try { 80 | startService(notificationIntent); 81 | } catch (Throwable e) { 82 | e.printStackTrace(); 83 | } 84 | } 85 | 86 | private View.OnClickListener mOnClickListener=new View.OnClickListener() { 87 | @Override 88 | public void onClick(View v) { 89 | int id=v.getId(); 90 | switch (id){ 91 | case R.id.total_switch_rl: 92 | totalSwitchSwitch.setChecked(!totalSwitchSwitch.isChecked()); 93 | break; 94 | case R.id.notify_rl: 95 | notifySwitch.setChecked(!notifySwitch.isChecked()); 96 | break; 97 | case R.id.key_trigger_rl: 98 | monitorClickSwitch.setChecked(!monitorClickSwitch.isChecked()); 99 | break; 100 | case R.id.long_key_trigger_rl: 101 | monitorLongClickSwitch.setChecked(!monitorLongClickSwitch.isChecked()); 102 | break; 103 | case R.id.donate_rl: 104 | startActivity(new Intent(MainActivity.this,DonateActivity.class)); 105 | break; 106 | case R.id.guide_rl: 107 | startActivity(new Intent(MainActivity.this,HowToUseActivity.class)); 108 | break; 109 | } 110 | } 111 | }; 112 | 113 | @Override 114 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { 115 | return super.onKeyLongPress(keyCode, event); 116 | } 117 | 118 | @Override 119 | public boolean onKeyUp(int keyCode, KeyEvent event) { 120 | return super.onKeyUp(keyCode, event); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/NotifyService.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.app.Notification; 4 | import android.app.PendingIntent; 5 | import android.app.Service; 6 | import android.content.BroadcastReceiver; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.content.IntentFilter; 10 | import android.graphics.Bitmap; 11 | import android.graphics.BitmapFactory; 12 | import android.os.Build; 13 | import android.os.Handler; 14 | import android.os.IBinder; 15 | import android.os.Looper; 16 | import android.support.v7.app.NotificationCompat; 17 | 18 | import com.pl.universalcopy.utils.SPHelper; 19 | 20 | import static com.pl.universalcopy.Constant.UNIVERSAL_COPY_BROADCAST_XP_DELAY; 21 | 22 | 23 | /** 24 | * Created by l4656_000 on 2015/11/9. 25 | */ 26 | public class NotifyService extends Service { 27 | private static final int ONGOING_NOTIFICATION=10086; 28 | private Bitmap notifyIcon; 29 | private boolean isForegroundShow=false; 30 | private Handler handler; 31 | 32 | @Override 33 | public IBinder onBind(Intent intent) { 34 | return null ; 35 | } 36 | 37 | @Override 38 | public void onCreate() { 39 | //只有在同意使用了以后才开始service 40 | super.onCreate(); 41 | IntentFilter intentFilter=new IntentFilter(UNIVERSAL_COPY_BROADCAST_XP_DELAY); 42 | try { 43 | registerReceiver(mUniversalCopyBR,intentFilter); 44 | } catch (Throwable e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | 49 | @Override 50 | public int onStartCommand(Intent intent, int flags, int startId) { 51 | adjustService(); 52 | return START_STICKY; 53 | } 54 | 55 | @Override 56 | public void onDestroy() { 57 | try { 58 | unregisterReceiver(mUniversalCopyBR); 59 | } catch (Throwable e) { 60 | e.printStackTrace(); 61 | } 62 | super.onDestroy(); 63 | } 64 | 65 | private void adjustService() { 66 | boolean isForground = SPHelper.getBoolean(Constant.IS_UNIVERSAL_COPY_FOREGROUND, true); 67 | boolean totalSwitch = SPHelper.getBoolean(Constant.TOTAL_SWITCH, true); 68 | if (isForground && totalSwitch) { 69 | startForeground("",true); 70 | } else { 71 | stopForeground(true); 72 | isForegroundShow=false; 73 | } 74 | } 75 | 76 | private void startForeground(String msg,boolean isForce){ 77 | if (isForegroundShow){ 78 | return; 79 | } 80 | NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 81 | if (notifyIcon==null){ 82 | notifyIcon= BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher); 83 | } 84 | builder.setLargeIcon(notifyIcon); 85 | // TODO: 2016/11/15 86 | builder.setSmallIcon(R.mipmap.ic_launcher); 87 | builder.setWhen(System.currentTimeMillis()); 88 | Intent notificationIntent = new Intent(Constant.UNIVERSAL_COPY_BROADCAST_XP); 89 | PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, 0); 90 | builder.setContentIntent(pendingIntent); 91 | builder.setContentTitle(getString(R.string.copy_title)); 92 | builder.setContentText(getString(R.string.copy_msg)); 93 | builder.setPriority(NotificationCompat.PRIORITY_MIN); 94 | 95 | Notification notification; 96 | if (Build.VERSION.SDK_INT<16){ 97 | notification=builder.getNotification(); 98 | }else{ 99 | notification=builder.build(); 100 | } 101 | startForeground(ONGOING_NOTIFICATION, notification); 102 | isForegroundShow=true; 103 | } 104 | 105 | private BroadcastReceiver mUniversalCopyBR = new BroadcastReceiver() { 106 | @Override 107 | public void onReceive(Context context, Intent intent) { 108 | if (handler==null){ 109 | handler=new Handler(Looper.getMainLooper()); 110 | } 111 | handler.postDelayed(new Runnable() { 112 | @Override 113 | public void run() { 114 | boolean totalSwitch = SPHelper.getBoolean(Constant.TOTAL_SWITCH, true); 115 | if (totalSwitch) { 116 | Intent notificationIntent = new Intent(Constant.UNIVERSAL_COPY_BROADCAST_XP); 117 | sendBroadcast(notificationIntent); 118 | if (! SPHelper.getBoolean(Constant.IS_UNIVERSAL_COPY_FOREGROUND, true)){ 119 | stopSelf(); 120 | } 121 | } 122 | } 123 | },500); 124 | } 125 | }; 126 | 127 | 128 | 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/UCXPApp.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.app.Application; 4 | 5 | /** 6 | * Created by penglu on 2016/10/26. 7 | */ 8 | 9 | public class UCXPApp extends Application { 10 | private static UCXPApp instance; 11 | 12 | public static UCXPApp getInstance() { 13 | return instance; 14 | } 15 | 16 | @Override 17 | public void onCreate() { 18 | super.onCreate(); 19 | instance = this; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/UniversalCopyActiity.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | 7 | public class UniversalCopyActiity extends AppCompatActivity { 8 | 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | try { 13 | startService(new Intent(this,NotifyService.class)); 14 | } catch (Throwable e) { 15 | e.printStackTrace(); 16 | } 17 | try { 18 | sendBroadcast(new Intent(Constant.UNIVERSAL_COPY_BROADCAST_XP_DELAY)); 19 | } catch (Throwable e) { 20 | e.printStackTrace(); 21 | } 22 | finish(); 23 | return; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/WakeUpBR.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | 7 | public class WakeUpBR extends BroadcastReceiver { 8 | public static final String UNIVERSAL_COPY_WAKE_UP_ACTION="universal_copy_wake_up_action"; 9 | public WakeUpBR() { 10 | } 11 | 12 | @Override 13 | public void onReceive(Context context, Intent intent) { 14 | if (intent.getAction().equals(UNIVERSAL_COPY_WAKE_UP_ACTION)){ 15 | Intent intent1=new Intent(context, NotifyService.class); 16 | try { 17 | context.startService(intent1); 18 | } catch (Exception e) { 19 | e.printStackTrace(); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/copy/CopyActivity.java: -------------------------------------------------------------------------------- 1 | 2 | package com.pl.universalcopy.copy; 3 | 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.os.Bundle; 7 | import android.os.Vibrator; 8 | import android.support.design.widget.BottomSheetBehavior; 9 | import android.support.design.widget.BottomSheetDialog; 10 | import android.support.design.widget.FloatingActionButton; 11 | import android.support.v7.app.ActionBar; 12 | import android.support.v7.app.AppCompatActivity; 13 | import android.support.v7.widget.Toolbar; 14 | import android.util.DisplayMetrics; 15 | import android.util.TypedValue; 16 | import android.view.ActionMode; 17 | import android.view.Menu; 18 | import android.view.MenuItem; 19 | import android.view.View; 20 | import android.view.ViewGroup; 21 | import android.widget.FrameLayout; 22 | import android.widget.TextView; 23 | 24 | import com.pl.universalcopy.BaseActivity; 25 | import com.pl.universalcopy.R; 26 | import com.pl.universalcopy.utils.ClipboardUtils; 27 | import com.pl.universalcopy.utils.SPHelper; 28 | import com.pl.universalcopy.utils.StatusBarCompat; 29 | import com.pl.universalcopy.utils.ToastUtil; 30 | import com.pl.universalcopy.utils.ViewUtil; 31 | 32 | import java.util.ArrayList; 33 | import java.util.Arrays; 34 | import java.util.Comparator; 35 | import java.util.Iterator; 36 | import java.util.List; 37 | 38 | import static com.pl.universalcopy.Constant.IS_FULL_SCREEN_COPY; 39 | 40 | 41 | public class CopyActivity extends BaseActivity { 42 | private FrameLayout copyNodeViewContainer; 43 | private FloatingActionButton copyFab; 44 | private FloatingActionButton exitFab; 45 | private FloatingActionButton exitFullScreenFab; 46 | private Menu menu; 47 | private List selectedNodes; 48 | private OnCopyNodeViewClickCallback mOnCopyNodeViewClickCallback; 49 | private int actionBarHeight = 0; 50 | private BottomSheetDialog bottomSheetDialog; 51 | private boolean v = false; 52 | private boolean isFullScreen = false; 53 | 54 | private void addCopyNodeView(CopyNode var1, int var2) { 55 | (new CopyNodeView(this, var1, this.mOnCopyNodeViewClickCallback)).addToFrameLayout(this.copyNodeViewContainer, var2); 56 | } 57 | 58 | private void adjustActionBar(boolean notingSelected, boolean var2) { 59 | this.menu.setGroupVisible(R.id.copy_actions, var2); 60 | if(this.isFullScreen) { 61 | if(var2) { 62 | this.exitFab.show(); 63 | this.copyFab.show(); 64 | this.exitFullScreenFab.show(); 65 | } else { 66 | this.exitFab.show(); 67 | this.copyFab.hide(); 68 | this.exitFullScreenFab.show(); 69 | } 70 | } 71 | 72 | ActionBar var3 = this.getSupportActionBar(); 73 | if(var3 != null) { 74 | if(notingSelected) { 75 | var3.setTitle(R.string.copy_title); 76 | var3.setSubtitle(R.string.copy_subtitle); 77 | var3.setHomeAsUpIndicator(R.mipmap.ic_close_white_24dp); 78 | return; 79 | } 80 | 81 | var3.setTitle((CharSequence)null); 82 | var3.setSubtitle((CharSequence)null); 83 | var3.setHomeAsUpIndicator(R.mipmap.ic_arrow_back_white_24dp); 84 | } 85 | 86 | } 87 | 88 | private void setSelectTextToClipboard(TextView var1) { 89 | ClipboardUtils.setText(this,this.getSelectedTextViewText(var1)); 90 | ToastUtil.show("已复制"); 91 | } 92 | 93 | 94 | private String getSelectedTextViewText(TextView var1) { 95 | if(var1 == null) { 96 | return getSelectedText(); 97 | } else { 98 | CharSequence var2 = var1.getText(); 99 | if(var1.getSelectionStart() == var1.getSelectionEnd()) { 100 | return var2.toString(); 101 | } else { 102 | CharSequence var3 = var2.subSequence(var1.getSelectionStart(), var1.getSelectionEnd()); 103 | return var3 != null?var3.toString():var2.toString(); 104 | } 105 | } 106 | } 107 | 108 | private void fullScreenMode(boolean var1) { 109 | ActionBar var2 = getSupportActionBar(); 110 | this.isFullScreen = var1; 111 | if(var1) { 112 | if(var2 != null) { 113 | var2.hide(); 114 | } 115 | 116 | this.adjustActionBarWrap(); 117 | } else { 118 | if(var2 != null) { 119 | var2.show(); 120 | } 121 | 122 | this.copyFab.hide(); 123 | this.exitFab.hide(); 124 | this.exitFullScreenFab.hide(); 125 | } 126 | SPHelper.save(IS_FULL_SCREEN_COPY,var1); 127 | } 128 | 129 | private void showSelectedText() { 130 | this.v = false; 131 | this.adjustActionBar(false, false); 132 | this.bottomSheetDialog = new BottomSheetDialog(this){ 133 | @Override 134 | protected void onCreate(Bundle savedInstanceState) { 135 | super.onCreate(savedInstanceState); 136 | StatusBarCompat.setTranslucentStatus(getWindow(),true); 137 | } 138 | }; 139 | View var1 = this.getLayoutInflater().inflate(R.layout.dialog_copy_text_editor, (ViewGroup)null); 140 | FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 141 | // layoutParams.topMargin = (int) (this.actionBarHeight - ViewUtil.dp2px(44)); 142 | var1.setLayoutParams(layoutParams); 143 | TextView textView = (TextView)var1.findViewById(R.id.text); 144 | textView.setText(getSelectedText()); 145 | // textView.setText(new SpannableString(getSelectedText()), TextView.BufferType.NORMAL); 146 | // textView.setCustomSelectionActionModeCallback(new MySelectionActionModeCallback(textView)); 147 | ((FloatingActionButton)var1.findViewById(R.id.fab_copy)).setOnClickListener(new View.OnClickListener() { 148 | @Override 149 | public void onClick(View v) { 150 | setSelectTextToClipboard(null); 151 | bottomSheetDialog.dismiss(); 152 | finish(); 153 | } 154 | }); 155 | this.bottomSheetDialog.setContentView(var1); 156 | ((View)var1.getParent()).setBackgroundColor(getResources().getColor(android.R.color.transparent)); 157 | final BottomSheetBehavior var3 = BottomSheetBehavior.from((View)var1.getParent()); 158 | this.bottomSheetDialog.setOnShowListener(new DialogInterface.OnShowListener() { 159 | @Override 160 | public void onShow(DialogInterface dialog) { 161 | var3.setState(BottomSheetBehavior.STATE_EXPANDED); 162 | // var1.requestLayout(); 163 | } 164 | }); 165 | this.bottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { 166 | @Override 167 | public void onDismiss(DialogInterface dialog) { 168 | adjustActionBarWrap(); 169 | } 170 | }); 171 | this.bottomSheetDialog.show(); 172 | 173 | } 174 | 175 | private void adjustActionBarWrap() { 176 | boolean var2 = true; 177 | boolean var1; 178 | if(this.selectedNodes.size() > 0) { 179 | var1 = true; 180 | } else { 181 | var1 = false; 182 | } 183 | 184 | if(var1) { 185 | var2 = false; 186 | } 187 | 188 | this.adjustActionBar(var2, var1); 189 | } 190 | 191 | private String getSelectedText() { 192 | StringBuilder var2 = new StringBuilder(); 193 | 194 | for(int var1 = 0; var1 < this.selectedNodes.size(); ++var1) { 195 | var2.append(((CopyNodeView)this.selectedNodes.get(var1)).getText()); 196 | if(var1 + 1 < this.selectedNodes.size()) { 197 | var2.append("\n"); 198 | } 199 | } 200 | 201 | return var2.toString(); 202 | } 203 | 204 | private int getStatusBarHeight() { 205 | int var1 = this.getResources().getIdentifier("status_bar_height", "dimen", "android"); 206 | return var1 > 0?this.getResources().getDimensionPixelSize(var1):(int)Math.ceil((double)(25.0F * this.getResources().getDisplayMetrics().density)); 207 | } 208 | 209 | protected void onCreate(Bundle var1) { 210 | int var3 = 0; 211 | super.onCreate(var1); 212 | Vibrator vibrator= (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); 213 | vibrator.vibrate(10); 214 | 215 | 216 | this.setContentView(R.layout.activity_copy_overlay); 217 | Toolbar toolbar = (Toolbar)this.findViewById(R.id.toolbar); 218 | if(toolbar != null) { 219 | 220 | try { 221 | setSupportActionBar(toolbar); 222 | } catch (Throwable e) { 223 | e.printStackTrace(); 224 | } 225 | 226 | getSupportActionBar().setTitle(R.string.copy_title); 227 | getSupportActionBar().setSubtitle(R.string.copy_subtitle); 228 | getSupportActionBar().setHomeAsUpIndicator(R.mipmap.ic_close_white_24dp); 229 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 230 | 231 | 232 | } 233 | 234 | this.selectedNodes = new ArrayList(); 235 | this.mOnCopyNodeViewClickCallback = new OnCopyNodeViewClickCallback() { 236 | @Override 237 | public void onCopyNodeViewLongClick(CopyNodeView var1, boolean var2) { 238 | if (var2){ 239 | selectedNodes.add(var1); 240 | adjustActionBarWrap(); 241 | showSelectedText(); 242 | }else { 243 | selectedNodes.remove(var1); 244 | adjustActionBarWrap(); 245 | } 246 | } 247 | 248 | @Override 249 | public void onCopyNodeViewClick(CopyNodeView var1, boolean var2) { 250 | if (var2){ 251 | selectedNodes.add(var1); 252 | adjustActionBarWrap(); 253 | }else { 254 | selectedNodes.remove(var1); 255 | adjustActionBarWrap(); 256 | } 257 | } 258 | }; 259 | this.copyFab = (FloatingActionButton)this.findViewById(R.id.fab_copy_main); 260 | this.copyFab.setOnClickListener(new View.OnClickListener() { 261 | @Override 262 | public void onClick(View v) { 263 | 264 | setSelectTextToClipboard(null); 265 | finish(); 266 | } 267 | }); 268 | this.exitFab = (FloatingActionButton)this.findViewById(R.id.exit_button); 269 | this.exitFab.setOnClickListener(new View.OnClickListener() { 270 | @Override 271 | public void onClick(View v) { 272 | 273 | finish(); 274 | } 275 | }); 276 | this.exitFullScreenFab = (FloatingActionButton)this.findViewById(R.id.exit_full_screen_button); 277 | exitFullScreenFab.setOnClickListener(new View.OnClickListener() { 278 | @Override 279 | public void onClick(View v) { 280 | 281 | fullScreenMode(false); 282 | } 283 | }); 284 | 285 | // this.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 286 | 287 | DisplayMetrics displayMetrics = new DisplayMetrics(); 288 | getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 289 | 290 | int statusBarHeight = getStatusBarHeight(); 291 | int screenHeight = displayMetrics.heightPixels; 292 | this.copyNodeViewContainer = (FrameLayout)this.findViewById(R.id.overlay_root); 293 | TypedValue var8 = new TypedValue(); 294 | if(this.getTheme().resolveAttribute(android.R.attr.actionBarSize, var8, true)) { 295 | this.actionBarHeight = TypedValue.complexToDimensionPixelSize(var8.data, this.getResources().getDisplayMetrics()); 296 | } 297 | 298 | Bundle extras = getIntent().getExtras(); 299 | if (extras==null){ 300 | finish(); 301 | return; 302 | } 303 | extras.setClassLoader(CopyNode.class.getClassLoader()); 304 | 305 | String var9 = extras.getString("source_package"); 306 | screenHeight = statusBarHeight; 307 | if(var9 != null) { 308 | screenHeight = statusBarHeight; 309 | if("com.android.chrome".equals(var9)) { 310 | screenHeight = (int) (this.actionBarHeight - statusBarHeight - ViewUtil.dp2px(7)); 311 | } 312 | } 313 | 314 | ArrayList var10 = extras.getParcelableArrayList("copy_nodes"); 315 | if(var10 != null && var10.size() > 0) { 316 | CopyNode[] var11 = (CopyNode[])var10.toArray(new CopyNode[0]); 317 | Arrays.sort(var11, new CopyNodeComparator()); 318 | 319 | for(statusBarHeight = var11.length; var3 < statusBarHeight; ++var3) { 320 | this.addCopyNodeView(var11[var3], screenHeight); 321 | } 322 | } else { 323 | ToastUtil.show(R.string.error_in_copy); 324 | this.finish(); 325 | } 326 | exitFab.postDelayed(new Runnable() { 327 | @Override 328 | public void run() { 329 | fullScreenMode(SPHelper.getBoolean(IS_FULL_SCREEN_COPY,false)); 330 | } 331 | }, 10); 332 | } 333 | 334 | 335 | public boolean onCreateOptionsMenu(Menu var1) { 336 | this.getMenuInflater().inflate(R.menu.universal_copy, var1); 337 | this.menu = var1; 338 | return super.onCreateOptionsMenu(var1); 339 | } 340 | 341 | public boolean onOptionsItemSelected(MenuItem var1) { 342 | switch(var1.getItemId()) { 343 | case android.R.id.home: 344 | 345 | // TODO: 2016/11/19 346 | if(this.selectedNodes.size() <= 0) { 347 | 348 | this.finish(); 349 | return true; 350 | } 351 | 352 | Iterator var2 = this.selectedNodes.iterator(); 353 | 354 | while(var2.hasNext()) { 355 | ((CopyNodeView)var2.next()).setActiveState(false); 356 | } 357 | 358 | this.selectedNodes.clear(); 359 | this.adjustActionBarWrap(); 360 | return true; 361 | case R.id.action_full_screen: 362 | 363 | this.fullScreenMode(true); 364 | return true; 365 | case R.id.action_select_mode: 366 | 367 | showSelectedText(); 368 | return true; 369 | case R.id.action_select_all: 370 | 371 | selectAll(); 372 | return true; 373 | case R.id.action_copy: 374 | 375 | setSelectTextToClipboard((TextView)null); 376 | finish(); 377 | return true; 378 | default: 379 | return false; 380 | } 381 | } 382 | 383 | private void selectAll(){ 384 | int length=copyNodeViewContainer.getChildCount(); 385 | int nodeLength=0; 386 | for (int i = 0; i < length; i++) { 387 | View view = copyNodeViewContainer.getChildAt(i); 388 | if (view instanceof CopyNodeView) { 389 | nodeLength++; 390 | } 391 | } 392 | if (selectedNodes.size()==nodeLength && nodeLength!=0){ 393 | selectedNodes.clear(); 394 | for (int i = 0; i < length; i++) { 395 | View view = copyNodeViewContainer.getChildAt(i); 396 | if (view instanceof CopyNodeView) { 397 | ((CopyNodeView) view).setActiveState(false); 398 | } 399 | } 400 | }else { 401 | for (int i = 0; i < length; i++) { 402 | View view = copyNodeViewContainer.getChildAt(i); 403 | if (view instanceof CopyNodeView) { 404 | ((CopyNodeView) view).setActiveState(true); 405 | if (!selectedNodes.contains(view)) { 406 | selectedNodes.add((CopyNodeView) view); 407 | } 408 | } 409 | } 410 | } 411 | adjustActionBarWrap(); 412 | } 413 | 414 | public interface OnCopyNodeViewClickCallback { 415 | void onCopyNodeViewLongClick(CopyNodeView var1, boolean var2); 416 | 417 | void onCopyNodeViewClick(CopyNodeView var1, boolean var2); 418 | } 419 | 420 | public class CopyNodeComparator implements Comparator { 421 | 422 | public int compare(CopyNode var1, CopyNode var2) { 423 | long var3 = var1.caculateSize(); 424 | long var5 = var2.caculateSize(); 425 | return var3 < var5?-1:(var3 == var5?0:1); 426 | } 427 | } 428 | 429 | private class MySelectionActionModeCallback implements ActionMode.Callback { 430 | private TextView b; 431 | 432 | private MySelectionActionModeCallback(TextView var2) { 433 | this.b = var2; 434 | } 435 | 436 | public boolean onActionItemClicked(ActionMode var1, MenuItem var2) { 437 | switch(var2.getItemId()) { 438 | case R.id.fab_copy: 439 | 440 | setSelectTextToClipboard(this.b); 441 | finish(); 442 | return true; 443 | default: 444 | return false; 445 | } 446 | } 447 | 448 | public boolean onCreateActionMode(ActionMode var1, Menu var2) { 449 | return true; 450 | } 451 | 452 | public void onDestroyActionMode(ActionMode var1) { 453 | if(CopyActivity.this.bottomSheetDialog != null && !CopyActivity.this.v) { 454 | CopyActivity.this.v = true; 455 | 456 | try { 457 | CopyActivity.this.bottomSheetDialog.dismiss(); 458 | } catch (IllegalArgumentException var2) { 459 | } 460 | } 461 | 462 | CopyActivity.this.v = false; 463 | } 464 | 465 | public boolean onPrepareActionMode(ActionMode var1, Menu var2) { 466 | for(int var3 = 0; var3 < var2.size(); ++var3) { 467 | var2.getItem(var3).setVisible(false); 468 | } 469 | 470 | return false; 471 | } 472 | 473 | } 474 | } 475 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/copy/CopyNode.java: -------------------------------------------------------------------------------- 1 | 2 | package com.pl.universalcopy.copy; 3 | 4 | import android.graphics.Rect; 5 | import android.os.Parcel; 6 | import android.os.Parcelable; 7 | 8 | public class CopyNode implements Parcelable { 9 | public static Creator CREATOR = new Creator() { 10 | 11 | @Override 12 | public CopyNode createFromParcel(Parcel source) { 13 | return new CopyNode(source); 14 | } 15 | 16 | @Override 17 | public CopyNode[] newArray(int size) { 18 | return new CopyNode[size]; 19 | } 20 | }; 21 | 22 | private Rect bound; 23 | private String content; 24 | 25 | public CopyNode(Rect var1, String var2) { 26 | this.bound = var1; 27 | this.content = var2; 28 | } 29 | 30 | public CopyNode(Parcel var1) { 31 | this.bound = new Rect(var1.readInt(), var1.readInt(), var1.readInt(), var1.readInt()); 32 | this.content = var1.readString(); 33 | } 34 | 35 | public long caculateSize() { 36 | return (long)(this.bound.width() * this.bound.height()); 37 | } 38 | 39 | public Rect getBound() { 40 | return this.bound; 41 | } 42 | 43 | public String getContent() { 44 | return this.content; 45 | } 46 | 47 | public int describeContents() { 48 | return 0; 49 | } 50 | 51 | public void writeToParcel(Parcel var1, int var2) { 52 | var1.writeInt(this.bound.left); 53 | var1.writeInt(this.bound.top); 54 | var1.writeInt(this.bound.right); 55 | var1.writeInt(this.bound.bottom); 56 | var1.writeString(this.content); 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "CopyNode{" + 62 | "bound=" + bound + 63 | ", content='" + content + '\'' + 64 | '}'; 65 | } 66 | 67 | // public static byte[] parseArrayListToByte(ArrayList nodes) throws IOException { 68 | // 69 | // ByteArrayOutputStream byteArray=new ByteArrayOutputStream(); 70 | // ObjectOutputStream byteArrayOutputStream=new ObjectOutputStream(byteArray); 71 | // byteArrayOutputStream.writeInt(nodes.size()); 72 | // for (int i=0;i parseByteToArrayList(byte[] byteStream) throws IOException { 85 | // 86 | // ByteArrayInputStream byteArray=new ByteArrayInputStream(byteStream); 87 | // ObjectInputStream byteArrayOutputStream=new ObjectInputStream(byteArray); 88 | // int length = byteArrayOutputStream.readInt(); 89 | // ArrayList result=new ArrayList<>(); 90 | // for (int i=0;i 12 | * 复制剪贴工具类 13 | */ 14 | public class ClipboardUtils { 15 | 16 | private static ClipboardManager mClipboardManager; 17 | private static ClipboardManager mNewCliboardManager; 18 | 19 | 20 | private static boolean isNew() { 21 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; 22 | } 23 | 24 | private static void instance(Context context) { 25 | if (isNew()) { 26 | if (mNewCliboardManager == null) 27 | mNewCliboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); 28 | } else { 29 | if (mClipboardManager == null) 30 | mClipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); 31 | } 32 | } 33 | 34 | /** 35 | * 为剪切板设置内容 36 | * 37 | * @param context 38 | * @param text 39 | */ 40 | public static void setText(Context context, CharSequence text) { 41 | if (isNew()) { 42 | instance(context); 43 | ClipData clip = ClipData.newPlainText("simple text", text); 44 | mNewCliboardManager.setPrimaryClip(clip); 45 | } else { 46 | instance(context); 47 | mClipboardManager.setText(text); 48 | } 49 | } 50 | 51 | /** 52 | * 获取剪切板的内容 53 | * 54 | * @param context 55 | * @return 56 | */ 57 | public static CharSequence getText(Context context) { 58 | StringBuilder sb = new StringBuilder(); 59 | if (isNew()) { 60 | instance(context); 61 | if (!mNewCliboardManager.hasPrimaryClip()) { 62 | return sb.toString(); 63 | } else { 64 | ClipData clipData = (mNewCliboardManager).getPrimaryClip(); 65 | int count = clipData.getItemCount(); 66 | for (int i = 0; i < count; ++i) { 67 | ClipData.Item item = clipData.getItemAt(i); 68 | CharSequence str = item.coerceToText(context); 69 | sb.append(str); 70 | } 71 | } 72 | } else { 73 | instance(context); 74 | sb.append(mClipboardManager.getText()); 75 | } 76 | return sb.toString(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/utils/CountLinkMovementMethod.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy.utils; 2 | /* 3 | * Copyright (C) 2006 The Android Open Source Project 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import android.text.Layout; 19 | import android.text.NoCopySpan; 20 | import android.text.Selection; 21 | import android.text.Spannable; 22 | import android.text.method.MovementMethod; 23 | import android.text.method.ScrollingMovementMethod; 24 | import android.text.style.ClickableSpan; 25 | import android.text.style.URLSpan; 26 | import android.view.KeyEvent; 27 | import android.view.MotionEvent; 28 | import android.view.View; 29 | import android.widget.TextView; 30 | 31 | import com.pl.universalcopy.DonateActivity; 32 | import com.pl.universalcopy.R; 33 | 34 | 35 | /** 36 | * A movement method that traverses links in the text buffer and scrolls if necessary. 37 | * Supports clicking on links with DPad Center or Enter. 38 | */ 39 | public class CountLinkMovementMethod extends ScrollingMovementMethod { 40 | private static final int CLICK = 1; 41 | private static final int UP = 2; 42 | private static final int DOWN = 3; 43 | 44 | @Override 45 | public boolean canSelectArbitrarily() { 46 | return true; 47 | } 48 | 49 | @Override 50 | protected boolean handleMovementKey(TextView widget, Spannable buffer, int keyCode, 51 | int movementMetaState, KeyEvent event) { 52 | switch (keyCode) { 53 | case KeyEvent.KEYCODE_DPAD_CENTER: 54 | case KeyEvent.KEYCODE_ENTER: 55 | if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) { 56 | if (event.getAction() == KeyEvent.ACTION_DOWN && 57 | event.getRepeatCount() == 0 && action(CLICK, widget, buffer)) { 58 | return true; 59 | } 60 | } 61 | break; 62 | } 63 | return super.handleMovementKey(widget, buffer, keyCode, movementMetaState, event); 64 | } 65 | 66 | @Override 67 | protected boolean up(TextView widget, Spannable buffer) { 68 | if (action(UP, widget, buffer)) { 69 | return true; 70 | } 71 | 72 | return super.up(widget, buffer); 73 | } 74 | 75 | @Override 76 | protected boolean down(TextView widget, Spannable buffer) { 77 | if (action(DOWN, widget, buffer)) { 78 | return true; 79 | } 80 | 81 | return super.down(widget, buffer); 82 | } 83 | 84 | @Override 85 | protected boolean left(TextView widget, Spannable buffer) { 86 | if (action(UP, widget, buffer)) { 87 | return true; 88 | } 89 | 90 | return super.left(widget, buffer); 91 | } 92 | 93 | @Override 94 | protected boolean right(TextView widget, Spannable buffer) { 95 | if (action(DOWN, widget, buffer)) { 96 | return true; 97 | } 98 | 99 | return super.right(widget, buffer); 100 | } 101 | 102 | private boolean action(int what, TextView widget, Spannable buffer) { 103 | Layout layout = widget.getLayout(); 104 | 105 | int padding = widget.getTotalPaddingTop() + 106 | widget.getTotalPaddingBottom(); 107 | int areatop = widget.getScrollY(); 108 | int areabot = areatop + widget.getHeight() - padding; 109 | 110 | int linetop = layout.getLineForVertical(areatop); 111 | int linebot = layout.getLineForVertical(areabot); 112 | 113 | int first = layout.getLineStart(linetop); 114 | int last = layout.getLineEnd(linebot); 115 | 116 | ClickableSpan[] candidates = buffer.getSpans(first, last, ClickableSpan.class); 117 | 118 | int a = Selection.getSelectionStart(buffer); 119 | int b = Selection.getSelectionEnd(buffer); 120 | 121 | int selStart = Math.min(a, b); 122 | int selEnd = Math.max(a, b); 123 | 124 | if (selStart < 0) { 125 | if (buffer.getSpanStart(FROM_BELOW) >= 0) { 126 | selStart = selEnd = buffer.length(); 127 | } 128 | } 129 | 130 | if (selStart > last) 131 | selStart = selEnd = Integer.MAX_VALUE; 132 | if (selEnd < first) 133 | selStart = selEnd = -1; 134 | 135 | switch (what) { 136 | case CLICK: 137 | if (selStart == selEnd) { 138 | return false; 139 | } 140 | 141 | ClickableSpan[] link = buffer.getSpans(selStart, selEnd, ClickableSpan.class); 142 | 143 | if (link.length != 1) 144 | return false; 145 | 146 | link[0].onClick(widget); 147 | break; 148 | 149 | case UP: 150 | int beststart, bestend; 151 | 152 | beststart = -1; 153 | bestend = -1; 154 | 155 | for (int i = 0; i < candidates.length; i++) { 156 | int end = buffer.getSpanEnd(candidates[i]); 157 | 158 | if (end < selEnd || selStart == selEnd) { 159 | if (end > bestend) { 160 | beststart = buffer.getSpanStart(candidates[i]); 161 | bestend = end; 162 | } 163 | } 164 | } 165 | 166 | if (beststart >= 0) { 167 | Selection.setSelection(buffer, bestend, beststart); 168 | return true; 169 | } 170 | 171 | break; 172 | 173 | case DOWN: 174 | beststart = Integer.MAX_VALUE; 175 | bestend = Integer.MAX_VALUE; 176 | 177 | for (int i = 0; i < candidates.length; i++) { 178 | int start = buffer.getSpanStart(candidates[i]); 179 | 180 | if (start > selStart || selStart == selEnd) { 181 | if (start < beststart) { 182 | beststart = start; 183 | bestend = buffer.getSpanEnd(candidates[i]); 184 | } 185 | } 186 | } 187 | 188 | if (bestend < Integer.MAX_VALUE) { 189 | Selection.setSelection(buffer, beststart, bestend); 190 | return true; 191 | } 192 | 193 | break; 194 | } 195 | 196 | return false; 197 | } 198 | 199 | @Override 200 | public boolean onTouchEvent(TextView widget, Spannable buffer, 201 | MotionEvent event) { 202 | int action = event.getAction(); 203 | 204 | if (action == MotionEvent.ACTION_UP || 205 | action == MotionEvent.ACTION_DOWN) { 206 | int x = (int) event.getX(); 207 | int y = (int) event.getY(); 208 | 209 | x -= widget.getTotalPaddingLeft(); 210 | y -= widget.getTotalPaddingTop(); 211 | 212 | x += widget.getScrollX(); 213 | y += widget.getScrollY(); 214 | 215 | Layout layout = widget.getLayout(); 216 | int line = layout.getLineForVertical(y); 217 | int off = layout.getOffsetForHorizontal(line, x); 218 | 219 | ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class); 220 | 221 | if (link.length != 0) { 222 | if (action == MotionEvent.ACTION_UP) { 223 | try { 224 | link[0].onClick(widget); 225 | } catch (Exception e) { 226 | e.printStackTrace(); 227 | ToastUtil.show(R.string.not_foud_qq); 228 | } 229 | if(((URLSpan) link[0]).getURL() != null){ 230 | if(DonateActivity.zhifubao.startsWith(((URLSpan) link[0]).getURL())){ 231 | } 232 | } 233 | } else if (action == MotionEvent.ACTION_DOWN) { 234 | Selection.setSelection(buffer, 235 | buffer.getSpanStart(link[0]), 236 | buffer.getSpanEnd(link[0])); 237 | } 238 | 239 | return true; 240 | } else { 241 | Selection.removeSelection(buffer); 242 | } 243 | } 244 | 245 | return super.onTouchEvent(widget, buffer, event); 246 | } 247 | 248 | @Override 249 | public void initialize(TextView widget, Spannable text) { 250 | Selection.removeSelection(text); 251 | text.removeSpan(FROM_BELOW); 252 | } 253 | 254 | @Override 255 | public void onTakeFocus(TextView view, Spannable text, int dir) { 256 | Selection.removeSelection(text); 257 | 258 | if ((dir & View.FOCUS_BACKWARD) != 0) { 259 | text.setSpan(FROM_BELOW, 0, 0, Spannable.SPAN_POINT_POINT); 260 | } else { 261 | text.removeSpan(FROM_BELOW); 262 | } 263 | } 264 | 265 | public static MovementMethod getInstance() { 266 | if (sInstance == null) 267 | sInstance = new CountLinkMovementMethod(); 268 | 269 | return sInstance; 270 | } 271 | 272 | private static CountLinkMovementMethod sInstance; 273 | private static Object FROM_BELOW = new NoCopySpan.Concrete(); 274 | } 275 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/utils/IOUtil.java: -------------------------------------------------------------------------------- 1 | 2 | package com.pl.universalcopy.utils; 3 | 4 | import java.io.BufferedOutputStream; 5 | import java.io.ByteArrayInputStream; 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.File; 8 | import java.io.FileInputStream; 9 | import java.io.FileNotFoundException; 10 | import java.io.FileOutputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.io.ObjectInputStream; 14 | import java.io.ObjectOutputStream; 15 | import java.io.OutputStream; 16 | import java.io.OutputStreamWriter; 17 | import java.io.Serializable; 18 | import java.nio.channels.FileChannel; 19 | import java.nio.channels.FileLock; 20 | import java.util.Arrays; 21 | import java.util.LinkedList; 22 | 23 | public class IOUtil { 24 | public IOUtil() { 25 | } 26 | 27 | public static void delete(File file) { 28 | file.delete(); 29 | } 30 | 31 | public static void delete(String file) { 32 | (new File(file)).delete(); 33 | } 34 | 35 | public static void mv(String source, String target) { 36 | try { 37 | Runtime.getRuntime().exec(String.format("mv %s %s", new Object[]{source, target})); 38 | } catch (IOException var3) { 39 | var3.printStackTrace(); 40 | } 41 | 42 | } 43 | 44 | public static void mv(File source, File target) { 45 | target.deleteOnExit(); 46 | source.renameTo(target); 47 | } 48 | 49 | public static String readString(String file) throws IOException { 50 | return readString(new File(file)); 51 | } 52 | 53 | public static String readString(File file) throws IOException { 54 | FileInputStream in = new FileInputStream(file); 55 | String str = readString((InputStream)in); 56 | in.close(); 57 | return str; 58 | } 59 | 60 | public static byte[] readBytes(InputStream in) throws IOException { 61 | byte[] buf = new byte[1024]; 62 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 63 | boolean c = false; 64 | 65 | int c1; 66 | while((c1 = in.read(buf)) > 0) { 67 | out.write(buf, 0, c1); 68 | } 69 | 70 | byte[] bytes = out.toByteArray(); 71 | out.close(); 72 | return bytes; 73 | } 74 | 75 | public static byte[] readBytes(String path) throws IOException { 76 | FileInputStream in = new FileInputStream(path); 77 | byte[] bytes = readBytes((InputStream)in); 78 | in.close(); 79 | return bytes; 80 | } 81 | 82 | public static String readString(InputStream in) throws IOException { 83 | byte[] bytes = readBytes(in); 84 | return new String(bytes, "UTF-8"); 85 | } 86 | 87 | public static void writeString(OutputStream out, String str) throws IOException { 88 | out.write(str.getBytes()); 89 | } 90 | 91 | public static void appendString(OutputStream out, String str) throws IOException { 92 | out.write(str.getBytes()); 93 | } 94 | 95 | public static void appendString(File file, String str) throws IOException { 96 | FileOutputStream out = new FileOutputStream(file, true); 97 | out.write(str.getBytes()); 98 | out.close(); 99 | } 100 | 101 | public static void appendString(String file, String str) throws IOException { 102 | appendString(new File(file), str); 103 | } 104 | 105 | public static void writeString(File file, String str) throws IOException { 106 | FileOutputStream out = new FileOutputStream(file); 107 | out.write(str.getBytes()); 108 | out.close(); 109 | } 110 | 111 | public static void writeUTF8String(File file, String str) throws IOException { 112 | OutputStreamWriter outw = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); 113 | outw.write(str); 114 | outw.close(); 115 | } 116 | 117 | public static void writeUTF8String(String file, String str) throws IOException { 118 | writeUTF8String(new File(file), str); 119 | } 120 | 121 | public static void writeString(String file, String str) throws IOException { 122 | writeString(new File(file), str); 123 | } 124 | 125 | public static void copy(InputStream in, String target) throws IOException { 126 | FileOutputStream out = null; 127 | 128 | try { 129 | out = new FileOutputStream(new File(target)); 130 | byte[] buf = new byte[10240]; 131 | boolean c = false; 132 | 133 | int c1; 134 | while((c1 = in.read(buf)) > 0) { 135 | out.write(buf, 0, c1); 136 | } 137 | } finally { 138 | if(out != null) { 139 | try { 140 | out.flush(); 141 | out.close(); 142 | } catch (IOException var10) { 143 | var10.printStackTrace(); 144 | } 145 | } 146 | 147 | } 148 | } 149 | 150 | public static void copy(String source, String target) throws IOException { 151 | FileInputStream in = null; 152 | FileOutputStream out = null; 153 | 154 | try { 155 | in = new FileInputStream(new File(source)); 156 | out = new FileOutputStream(new File(target)); 157 | byte[] e = new byte[1024]; 158 | boolean c = false; 159 | 160 | int c1; 161 | while((c1 = in.read(e)) > 0) { 162 | out.write(e, 0, c1); 163 | } 164 | 165 | } finally { 166 | if(in != null) { 167 | try { 168 | in.close(); 169 | } catch (IOException var20) { 170 | var20.printStackTrace(); 171 | } 172 | } 173 | 174 | if(out != null) { 175 | try { 176 | out.flush(); 177 | out.close(); 178 | } catch (IOException var19) { 179 | var19.printStackTrace(); 180 | } 181 | } 182 | 183 | } 184 | } 185 | 186 | public static boolean copyWithFileLock(String source, String target) { 187 | FileInputStream in = null; 188 | FileOutputStream out = null; 189 | FileChannel fileChannel = null; 190 | File targetFile=new File(target); 191 | FileLock fileLock = null; 192 | boolean hasBeenLocked = false; 193 | 194 | try { 195 | in = new FileInputStream(new File(source)); 196 | out = new FileOutputStream(targetFile,true); 197 | //用源文件做锁,不然目标文件会被置空 198 | fileChannel=out.getChannel(); 199 | fileLock=fileChannel.tryLock(); 200 | if (fileLock==null){ 201 | hasBeenLocked=true; 202 | fileLock=fileChannel.lock(); 203 | } 204 | 205 | //由于是复制,所以复制一次就够了,等其他地方复制完毕,就返回 206 | if (hasBeenLocked){ 207 | return true; 208 | } 209 | 210 | out = new FileOutputStream(targetFile); 211 | byte[] e = new byte[1024]; 212 | boolean c = false; 213 | 214 | int c1; 215 | while((c1 = in.read(e)) > 0) { 216 | out.write(e, 0, c1); 217 | } 218 | 219 | out.flush(); 220 | return true; 221 | } catch (FileNotFoundException var21) { 222 | var21.printStackTrace(); 223 | return false; 224 | } catch (IOException var22) { 225 | var22.printStackTrace(); 226 | } finally { 227 | if (fileLock!=null){ 228 | try { 229 | fileLock.release(); 230 | } catch (IOException e) { 231 | e.printStackTrace(); 232 | } 233 | } 234 | if(in != null) { 235 | try { 236 | in.close(); 237 | } catch (IOException var20) { 238 | var20.printStackTrace(); 239 | } 240 | } 241 | if(out != null) { 242 | try { 243 | out.close(); 244 | } catch (IOException var19) { 245 | var19.printStackTrace(); 246 | } 247 | } 248 | 249 | 250 | } 251 | return false; 252 | } 253 | public static void serialize(Serializable obj, String file) throws FileNotFoundException, IOException { 254 | ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); 255 | 256 | try { 257 | oos.writeObject(obj); 258 | } catch (IOException var11) { 259 | var11.printStackTrace(); 260 | throw var11; 261 | } finally { 262 | try { 263 | oos.close(); 264 | } catch (IOException var10) { 265 | var10.printStackTrace(); 266 | } 267 | 268 | } 269 | 270 | } 271 | 272 | public static Object unserialize(String file) throws Exception { 273 | ObjectInputStream ois = null; 274 | 275 | try { 276 | ois = new ObjectInputStream(new FileInputStream(file)); 277 | Object var4 = ois.readObject(); 278 | return var4; 279 | } catch (Exception var12) { 280 | ; 281 | } finally { 282 | try { 283 | if(ois != null) { 284 | ois.close(); 285 | } 286 | } catch (IOException var11) { 287 | var11.printStackTrace(); 288 | } 289 | 290 | } 291 | 292 | return null; 293 | } 294 | 295 | public static Object cloneObject(Object obj){ 296 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 297 | ByteArrayInputStream in = null; 298 | 299 | ObjectInputStream ois = null; 300 | ObjectOutputStream oos = null; 301 | try { 302 | oos = new ObjectOutputStream(out); 303 | oos.writeObject(obj); 304 | 305 | in = new ByteArrayInputStream(out.toByteArray()); 306 | ois = new ObjectInputStream(in); 307 | return ois.readObject(); 308 | } catch (IOException e) { 309 | // TODO Auto-generated catch block 310 | e.printStackTrace(); 311 | } catch (ClassNotFoundException e) { 312 | // TODO Auto-generated catch block 313 | e.printStackTrace(); 314 | }finally{ 315 | try { 316 | if(oos != null) 317 | oos.close(); 318 | if(ois != null) 319 | ois.close(); 320 | if(in != null) 321 | in.close(); 322 | out.close(); 323 | } catch (IOException e) { 324 | // TODO Auto-generated catch block 325 | e.printStackTrace(); 326 | } 327 | } 328 | return null; 329 | } 330 | 331 | public static void saveToFile(InputStream in, String file) throws IOException { 332 | File outputFile=new File(file); 333 | outputFile.deleteOnExit(); 334 | outputFile.getParentFile().mkdirs(); 335 | BufferedOutputStream outputStream=new BufferedOutputStream(new FileOutputStream(outputFile)); 336 | byte[] buffer=new byte[2048]; 337 | int length=in.read(buffer); 338 | while (length!=-1){ 339 | outputStream.write(buffer,0,length); 340 | length=in.read(buffer); 341 | } 342 | outputStream.flush(); 343 | outputStream.close(); 344 | } 345 | public static void saveToFile(InputStream in, File file) throws IOException { 346 | File outputFile= file; 347 | outputFile.deleteOnExit(); 348 | outputFile.getParentFile().mkdirs(); 349 | BufferedOutputStream outputStream=new BufferedOutputStream(new FileOutputStream(outputFile)); 350 | byte[] buffer=new byte[2048]; 351 | int length=in.read(buffer); 352 | while (length!=-1){ 353 | outputStream.write(buffer,0,length); 354 | length=in.read(buffer); 355 | } 356 | outputStream.flush(); 357 | outputStream.close(); 358 | } 359 | /** 360 | * 获得指定文件的byte数组 361 | */ 362 | public static byte[] getBytes(String filePath){ 363 | byte[] buffer = null; 364 | try { 365 | File file = new File(filePath); 366 | FileInputStream fis = new FileInputStream(file); 367 | ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length()); 368 | byte[] b = new byte[(int) file.length()]; 369 | int n; 370 | while ((n = fis.read(b)) != -1) { 371 | bos.write(b, 0, n); 372 | } 373 | fis.close(); 374 | bos.close(); 375 | buffer = bos.toByteArray(); 376 | } catch (FileNotFoundException e) { 377 | e.printStackTrace(); 378 | } catch (IOException e) { 379 | e.printStackTrace(); 380 | } 381 | return buffer; 382 | } 383 | 384 | public static void deleteDirs(String themePath){ 385 | LinkedList themeLinkedList=new LinkedList(); 386 | File themeDir=new File(themePath); 387 | if (!themeDir.exists()) { 388 | return; 389 | }else if (themeDir.isDirectory()){ 390 | themeLinkedList.addAll(Arrays.asList(themeDir.listFiles())); 391 | while(!themeLinkedList.isEmpty()) 392 | deleteContent(themeLinkedList.pollLast()); 393 | }else { 394 | themeDir.delete(); 395 | } 396 | } 397 | 398 | private static void deleteContent(File file){ 399 | LinkedList themeLinkedList=new LinkedList(); 400 | if (file.isDirectory()) { 401 | themeLinkedList.addAll(Arrays.asList(file.listFiles())); 402 | while (!themeLinkedList.isEmpty()) { 403 | File subFile=themeLinkedList.pollLast(); 404 | deleteContent(subFile); 405 | } 406 | } 407 | file.delete(); 408 | } 409 | 410 | public static void copyFile(String srcPath,String desPath) throws IOException { 411 | File srcDir=new File(srcPath); 412 | File desDir=new File(desPath); 413 | if (!srcDir.exists()){ 414 | return; 415 | } 416 | if (srcDir.isDirectory()) { 417 | desDir.mkdirs(); 418 | File[] files=srcDir.listFiles(); 419 | for (int i=0;i getStringSet(String name, Set defaultValue) { 100 | SharedPreferences sp = getSP(name); 101 | return sp.getStringSet(name, defaultValue); 102 | } 103 | 104 | public static boolean contains(String name) { 105 | SharedPreferences sp = getSP(name); 106 | return sp.contains(name); 107 | } 108 | 109 | public static void remove(String name) { 110 | SharedPreferences sp = getSP(name); 111 | SharedPreferences.Editor editor = sp.edit(); 112 | editor.remove(name); 113 | editor.commit(); 114 | } 115 | 116 | public static void clear(){ 117 | SharedPreferences sp = getSP(null); 118 | if (sp == null) { 119 | } else { 120 | SharedPreferences.Editor editor = sp.edit(); 121 | editor.clear(); 122 | editor.commit(); 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/utils/StatusBarCompat.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy.utils; 2 | 3 | import android.app.Activity; 4 | import android.os.Build; 5 | import android.view.Gravity; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.view.Window; 9 | import android.view.WindowManager; 10 | import android.widget.FrameLayout; 11 | 12 | public class StatusBarCompat { 13 | 14 | public static void setupStatusBarView(Activity activity, ViewGroup decorViewGroup, boolean on, int colorRes) { 15 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 16 | Window win = activity.getWindow(); 17 | setTranslucentStatus(win, on); 18 | View mStatusBarTintView = new View(activity); 19 | int mStatusBarHeight = 0; 20 | int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android"); 21 | if (resourceId > 0) { 22 | mStatusBarHeight = activity.getResources().getDimensionPixelSize(resourceId); 23 | } 24 | FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, mStatusBarHeight); 25 | params.gravity = Gravity.TOP; 26 | mStatusBarTintView.setLayoutParams(params); 27 | mStatusBarTintView.setBackgroundResource(colorRes); 28 | mStatusBarTintView.setVisibility(View.VISIBLE); 29 | decorViewGroup.addView(mStatusBarTintView); 30 | } 31 | } 32 | 33 | public static void setTranslucentStatus(Window window, boolean on){ 34 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { 35 | WindowManager.LayoutParams winParams = window.getAttributes(); 36 | final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 37 | if (on) { 38 | winParams.flags |= bits; 39 | } else { 40 | winParams.flags &= ~bits; 41 | } 42 | window.setAttributes(winParams); 43 | } 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/utils/ToastUtil.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy.utils; 2 | 3 | import android.widget.Toast; 4 | 5 | import com.pl.universalcopy.UCXPApp; 6 | 7 | 8 | /** 9 | * Created by l4656_000 on 2015/12/27. 10 | */ 11 | public class ToastUtil { 12 | public static void show(String msg){ 13 | Toast.makeText(UCXPApp.getInstance(), msg, Toast.LENGTH_SHORT).show(); 14 | } 15 | public static void show(int rid){ 16 | Toast.makeText(UCXPApp.getInstance(), rid, Toast.LENGTH_SHORT).show(); 17 | } 18 | public static void showLong(int rid){ 19 | Toast.makeText(UCXPApp.getInstance(), rid, Toast.LENGTH_LONG).show(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/xposed/Filter.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy.xposed; 2 | 3 | import android.view.View; 4 | import android.widget.EditText; 5 | import android.widget.TextView; 6 | import java.lang.reflect.Field; 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.lang.reflect.Method; 9 | 10 | public interface Filter { 11 | 12 | boolean filter(View view); 13 | 14 | String getContent(View view); 15 | 16 | class TextViewValidFilter implements Filter { 17 | 18 | @Override public boolean filter(View view) { 19 | return (view instanceof TextView) && !(view instanceof EditText); 20 | // return (view instanceof TextView || view instanceof AppCompatTextView) && !(view instanceof Button) 21 | // && !(view instanceof EditText) 22 | // && !(view instanceof CheckedTextView) 23 | // && !(view instanceof DigitalClock) 24 | // && !(view instanceof Chronometer); 25 | } 26 | 27 | @Override public String getContent(View view) { 28 | if (view instanceof TextView) { 29 | CharSequence text = ((TextView) view).getText(); 30 | return text == null ? null : text.toString(); 31 | } 32 | return null; 33 | } 34 | } 35 | 36 | class EditTextFilter implements Filter { 37 | 38 | @Override public boolean filter(View view) { 39 | return (view instanceof EditText); 40 | // return (view instanceof TextView || view instanceof AppCompatTextView) && !(view instanceof Button) 41 | // && !(view instanceof EditText) 42 | // && !(view instanceof CheckedTextView) 43 | // && !(view instanceof DigitalClock) 44 | // && !(view instanceof Chronometer); 45 | } 46 | 47 | @Override public String getContent(View view) { 48 | if (view instanceof EditText) { 49 | CharSequence text = ((TextView) view).getText(); 50 | return text == null ? null : text.toString(); 51 | } 52 | return null; 53 | } 54 | } 55 | 56 | class WeChatCellTextViewFilter implements Filter { 57 | 58 | private static final String TAG = "WeChatCellTextViewFilter"; 59 | Class staticTextViewClass; 60 | private Method getTextMethod; 61 | 62 | WeChatCellTextViewFilter(ClassLoader classLoader) { 63 | try { 64 | staticTextViewClass = 65 | classLoader.loadClass("com.tencent.mm.ui.widget.celltextview.CellTextView"); 66 | } catch (ClassNotFoundException e) { 67 | e.printStackTrace(); 68 | } 69 | } 70 | 71 | @Override public boolean filter(View view) { 72 | if (staticTextViewClass != null) { 73 | return staticTextViewClass.isInstance(view); 74 | } 75 | return false; 76 | } 77 | 78 | @Override public String getContent(View view) { 79 | if (!staticTextViewClass.isInstance(view)) { 80 | return null; 81 | } 82 | if (staticTextViewClass != null) { 83 | try { 84 | if (getTextMethod == null) { 85 | try { 86 | getTextMethod = staticTextViewClass.getMethod("cgv"); 87 | } catch (NoSuchMethodException e) { 88 | e.printStackTrace(); 89 | Method[] methods = staticTextViewClass.getDeclaredMethods(); 90 | if (methods != null) { 91 | for (Method method : methods) { 92 | if (method.getReturnType().equals(String.class) 93 | && method.getParameterTypes().length == 0) { 94 | getTextMethod = method; 95 | } 96 | } 97 | } 98 | } 99 | } 100 | if (getTextMethod != null) { 101 | Object invoke = getTextMethod.invoke(view); 102 | if (invoke != null) { 103 | return invoke.toString(); 104 | } 105 | } 106 | } catch (InvocationTargetException e) { 107 | e.printStackTrace(); 108 | } catch (IllegalAccessException e) { 109 | e.printStackTrace(); 110 | } 111 | } 112 | return null; 113 | } 114 | } 115 | 116 | class WeChatValidFilter implements Filter { 117 | 118 | private static final String TAG = "WeChatValidFilter"; 119 | Class staticTextViewClass; 120 | 121 | WeChatValidFilter(ClassLoader classLoader) { 122 | try { 123 | staticTextViewClass = 124 | classLoader.loadClass("com.tencent.mm.kiss.widget.textview.StaticTextView"); 125 | } catch (ClassNotFoundException e) { 126 | e.printStackTrace(); 127 | } 128 | } 129 | 130 | @Override public boolean filter(View view) { 131 | if (staticTextViewClass != null) { 132 | return staticTextViewClass.isInstance(view); 133 | } 134 | return false; 135 | } 136 | 137 | @Override public String getContent(View view) { 138 | if (!staticTextViewClass.isInstance(view)) { 139 | return null; 140 | } 141 | if (staticTextViewClass != null) { 142 | try { 143 | Method getText = staticTextViewClass.getMethod("getText"); 144 | if (getText != null) { 145 | Object invoke = getText.invoke(view); 146 | if (invoke != null) { 147 | return invoke.toString(); 148 | } 149 | } 150 | } catch (NoSuchMethodException e) { 151 | e.printStackTrace(); 152 | } catch (InvocationTargetException e) { 153 | e.printStackTrace(); 154 | } catch (IllegalAccessException e) { 155 | e.printStackTrace(); 156 | } 157 | } 158 | return null; 159 | } 160 | } 161 | 162 | class WeChatValidNoMeasuredTextViewFilter extends CommonViewFilter { 163 | 164 | WeChatValidNoMeasuredTextViewFilter(ClassLoader classLoader) { 165 | super(classLoader, "com.tencent.mm.ui.base.NoMeasuredTextView", "mText"); 166 | } 167 | } 168 | 169 | class CommonViewFilter implements Filter { 170 | 171 | private static final String TAG = "CommonViewFilter"; 172 | Class staticTextViewClass; 173 | private Field getTextField; 174 | String fieldName; 175 | String className; 176 | boolean hasLoadClassInFilter = false; 177 | 178 | CommonViewFilter(ClassLoader classLoader, String className, String fieldName) { 179 | this.fieldName = fieldName; 180 | this.className = className; 181 | try { 182 | staticTextViewClass = classLoader.loadClass(className); 183 | } catch (ClassNotFoundException e) { 184 | e.printStackTrace(); 185 | } 186 | } 187 | 188 | @Override public boolean filter(View view) { 189 | if (staticTextViewClass != null) { 190 | return staticTextViewClass.isInstance(view); 191 | } else if (!hasLoadClassInFilter) { 192 | hasLoadClassInFilter = true; 193 | try { 194 | staticTextViewClass = view.getClass().getClassLoader().loadClass(className); 195 | filter(view); 196 | } catch (ClassNotFoundException e) { 197 | e.printStackTrace(); 198 | } 199 | } 200 | return false; 201 | } 202 | 203 | @Override public String getContent(View view) { 204 | if (!staticTextViewClass.isInstance(view)) { 205 | return null; 206 | } 207 | if (staticTextViewClass != null) { 208 | try { 209 | if (getTextField == null) { 210 | try { 211 | Field field = staticTextViewClass.getDeclaredField(fieldName); 212 | try { 213 | field.getType().asSubclass(CharSequence.class); 214 | getTextField = field; 215 | getTextField.setAccessible(true); 216 | } catch (Exception e) { 217 | e.printStackTrace(); 218 | throw new NoSuchFieldException(); 219 | } 220 | } catch (NoSuchFieldException e) { 221 | e.printStackTrace(); 222 | Field[] fields = staticTextViewClass.getDeclaredFields(); 223 | if (fields != null) { 224 | for (Field method : fields) { 225 | try { 226 | method.getType().asSubclass(CharSequence.class); 227 | getTextField = method; 228 | getTextField.setAccessible(true); 229 | break; 230 | } catch (Exception e1) { 231 | e1.printStackTrace(); 232 | } 233 | } 234 | } 235 | } 236 | } 237 | if (getTextField != null) { 238 | Object invoke = getTextField.get(view); 239 | if (invoke != null) { 240 | return invoke.toString(); 241 | }else { 242 | CharSequence desc= view.getContentDescription(); 243 | if (desc!=null){ 244 | return desc.toString(); 245 | } 246 | } 247 | } 248 | } catch (IllegalAccessException e) { 249 | e.printStackTrace(); 250 | } 251 | } 252 | return null; 253 | } 254 | } 255 | 256 | class QQSingleLineTextView extends CommonViewFilter { 257 | QQSingleLineTextView(ClassLoader classLoader) { 258 | super(classLoader, "com.tencent.widget.SingleLineTextView", 259 | "jdField_a_of_type_JavaLangCharSequence"); 260 | } 261 | } 262 | 263 | class QQZoneFeedForwardTextView extends CommonViewFilter { 264 | QQZoneFeedForwardTextView(ClassLoader classLoader) { 265 | super(classLoader, "com.qzone.module.feedcomponent.ui.FeedForwardView", "a"); 266 | } 267 | } 268 | 269 | class QQZonePraiseListView extends CommonViewFilter { 270 | QQZonePraiseListView(ClassLoader classLoader) { 271 | super(classLoader, "com.qzone.module.feedcomponent.ui.PraiseListView", "a"); 272 | } 273 | } 274 | } 275 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/xposed/Logger.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy.xposed; 2 | 3 | import android.util.Log; 4 | 5 | import com.pl.universalcopy.BuildConfig; 6 | 7 | import de.robv.android.xposed.XposedBridge; 8 | 9 | 10 | public class Logger { 11 | 12 | private static boolean sEnable = BuildConfig.DEBUG; 13 | private static final String TAG = "XposedBigBang"; 14 | 15 | public static void e(String tag, String msg) { 16 | if (sEnable) { 17 | Log.e(TAG + ":" + tag, msg); 18 | } 19 | } 20 | 21 | public static void d(String tag, String msg) { 22 | if (sEnable) { 23 | Log.d(TAG + ":" + tag, msg); 24 | XposedBridge.log(TAG + ":" + msg); 25 | } 26 | } 27 | 28 | public static void logClass(String tag, Class c) { 29 | if(sEnable) { 30 | d(tag, "class: " + c.getName()); 31 | if (c.getSuperclass() != null) { 32 | Log.e(TAG + ":" + tag, c.getCanonicalName()); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/xposed/XposedEnable.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy.xposed; 2 | 3 | 4 | public class XposedEnable { 5 | 6 | public static boolean isEnable() { 7 | return false; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/xposed/XposedKeyUpHandler.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy.xposed; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Vibrator; 7 | import android.view.KeyEvent; 8 | 9 | import com.pl.universalcopy.Constant; 10 | 11 | /** 12 | * Created by penglu on 2017/1/11. 13 | */ 14 | 15 | public class XposedKeyUpHandler { 16 | 17 | public static final int LONG_PRESS_DELAY = 500; 18 | private Context mContext; 19 | 20 | public XposedKeyUpHandler(Context application){ 21 | mContext=application; 22 | } 23 | 24 | private KeyEvent lastKeyEvent; 25 | public void onKeyEvent(KeyEvent keyEvent){ 26 | if (lastKeyEvent!=null){ 27 | if ((lastKeyEvent.getKeyCode()==KeyEvent.KEYCODE_VOLUME_DOWN && keyEvent.getKeyCode()==KeyEvent.KEYCODE_VOLUME_UP ) 28 | ||(keyEvent.getKeyCode()==KeyEvent.KEYCODE_VOLUME_DOWN && lastKeyEvent.getKeyCode()==KeyEvent.KEYCODE_VOLUME_UP )){ 29 | if (keyEvent.getEventTime()-lastKeyEvent.getEventTime() mFilters = new ArrayList<>(); 41 | 42 | @Override public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) 43 | throws Throwable { 44 | Log.e("shang", "xposed-packageName:" + loadPackageParam.packageName); 45 | setXpoedEnable(loadPackageParam); 46 | // if (!new File("/data/data/"+PACKAGE_NAME).exists()) 47 | // return; 48 | // wakeup(loadPackageParam); 49 | // Logger.d(TAG, loadPackageParam.packageName); 50 | 51 | XSharedPreferences appXSP; 52 | appXSP = new XSharedPreferences(PACKAGE_NAME, SP_NAME); 53 | appXSP.makeWorldReadable(); 54 | // boolean enabled =appXSP.getBoolean(IS_UNIVERSAL_COPY_ENABLE,true); 55 | // 56 | // if (!enabled){ 57 | // return; 58 | // } 59 | mFilters.add(new Filter.TextViewValidFilter()); 60 | 61 | //优化QQ 下的体验。 62 | if (loadPackageParam.packageName != null && loadPackageParam.packageName.startsWith( 63 | "com.tencent.mobileqq")) { 64 | mFilters.add(new Filter.QQSingleLineTextView(loadPackageParam.classLoader)); 65 | mFilters.add(new Filter.QQZoneFeedForwardTextView(loadPackageParam.classLoader)); 66 | mFilters.add(new Filter.QQZonePraiseListView(loadPackageParam.classLoader)); 67 | } 68 | //优化微信 下的体验。 69 | if (loadPackageParam.packageName != null && loadPackageParam.packageName.startsWith( 70 | "com.tencent.mm")) { 71 | //朋友圈内容拦截。 72 | mFilters.add(new Filter.WeChatValidFilter(loadPackageParam.classLoader)); 73 | //聊天详情中的文字点击事件优化 74 | mFilters.add(new Filter.WeChatCellTextViewFilter(loadPackageParam.classLoader)); 75 | mFilters.add(new Filter.WeChatValidNoMeasuredTextViewFilter(loadPackageParam.classLoader)); 76 | } 77 | 78 | mUniversalCopyHandler.setFilters(mFilters); 79 | // installer 不注入。 防止代码出错。进不去installer 中。 80 | if (!"de.robv.android.xposed.installer".equals(loadPackageParam.packageName) 81 | && !"com.android.systemui".equals(loadPackageParam.packageName)) { 82 | // try { 83 | // findAndHookMethod(Class.forName("android.app.ActivityThread"), "handleResumeActivity", 84 | // IBinder.class, boolean.class, boolean.class, boolean.class, int.class, String.class, 85 | // new UniversalCopyActivityThreadHook()); 86 | // } catch (Throwable e) { 87 | // e.printStackTrace(); 88 | // } 89 | // try { 90 | // findAndHookMethod(Class.forName("android.app.ActivityThread"), "handleResumeActivity", 91 | // IBinder.class, boolean.class, boolean.class, boolean.class, 92 | // new UniversalCopyActivityThreadHook()); 93 | // } catch (Throwable e) { 94 | // e.printStackTrace(); 95 | // } 96 | // try { 97 | // findAndHookMethod(Class.forName("android.app.ActivityThread"), "handleResumeActivity", 98 | // IBinder.class, boolean.class, boolean.class, new UniversalCopyActivityThreadHook()); 99 | // } catch (Throwable e) { 100 | // e.printStackTrace(); 101 | // } 102 | 103 | findAndHookMethod(Activity.class, "onStart", new UniversalCopyOnStartHook()); 104 | findAndHookMethod(Activity.class, "onStop", new UniversalCopyOnStopHook()); 105 | if (appXSP.getBoolean(MONITOR_LONG_CLICK, true)) { 106 | findAndHookMethod(Activity.class, "onKeyLongPress", int.class, KeyEvent.class, 107 | new ViewonKeyLongPressHooker()); 108 | } 109 | if (appXSP.getBoolean(MONITOR_CLICK, true)) { 110 | findAndHookMethod(Activity.class, "onKeyUp", int.class, KeyEvent.class, 111 | new ViewonKeyUpHooker()); 112 | } 113 | } 114 | } 115 | 116 | private void setXpoedEnable(XC_LoadPackage.LoadPackageParam loadPackageParam) 117 | throws ClassNotFoundException { 118 | if (loadPackageParam.packageName.equals(PACKAGE_NAME)) { 119 | findAndHookMethod( 120 | loadPackageParam.classLoader.loadClass("com.pl.universalcopy.xposed.XposedEnable"), 121 | "isEnable", new XC_MethodReplacement() { 122 | @Override protected Object replaceHookedMethod(MethodHookParam methodHookParam) 123 | throws Throwable { 124 | return true; 125 | } 126 | }); 127 | } 128 | } 129 | 130 | private Set getLauncherAsWhiteList(Context c) { 131 | HashSet packages = new HashSet<>(); 132 | PackageManager packageManager = c.getPackageManager(); 133 | final Intent intent = new Intent(Intent.ACTION_MAIN); 134 | intent.addCategory(Intent.CATEGORY_HOME); 135 | // final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0); 136 | List resolveInfo = 137 | packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); 138 | for (ResolveInfo ri : resolveInfo) { 139 | packages.add(ri.activityInfo.packageName); 140 | } 141 | return packages; 142 | } 143 | 144 | private Set getInputMethodAsWhiteList(Context context) { 145 | HashSet packages = new HashSet<>(); 146 | InputMethodManager imm = 147 | (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); 148 | List methodList = imm.getInputMethodList(); 149 | for (InputMethodInfo info : methodList) { 150 | packages.add(info.getPackageName()); 151 | } 152 | return packages; 153 | } 154 | 155 | private boolean isKeyBoardOrLauncher = false; 156 | private boolean isKeyBoardOrLauncherChecked = false; 157 | 158 | private boolean isKeyBoardOrLauncher(Context context, String packageName) { 159 | if (isKeyBoardOrLauncherChecked) { 160 | return isKeyBoardOrLauncher; 161 | } 162 | if (context == null) { 163 | isKeyBoardOrLauncher = true; 164 | isKeyBoardOrLauncherChecked = true; 165 | return true; 166 | } 167 | for (String package_process : getInputMethodAsWhiteList(context)) { 168 | if (package_process.equals(packageName)) { 169 | isKeyBoardOrLauncher = true; 170 | isKeyBoardOrLauncherChecked = true; 171 | return true; 172 | } 173 | } 174 | for (String package_process : getLauncherAsWhiteList(context)) { 175 | if (package_process.equals(packageName)) { 176 | isKeyBoardOrLauncher = true; 177 | isKeyBoardOrLauncherChecked = true; 178 | return true; 179 | } 180 | } 181 | isKeyBoardOrLauncher = false; 182 | isKeyBoardOrLauncherChecked = true; 183 | return false; 184 | } 185 | 186 | private class UniversalCopyOnStartHook extends XC_MethodHook { 187 | 188 | @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { 189 | super.beforeHookedMethod(param); 190 | Activity activity = (Activity) param.thisObject; 191 | mUniversalCopyHandler.onStart(activity); 192 | Intent intent = new Intent(WakeUpBR.UNIVERSAL_COPY_WAKE_UP_ACTION); 193 | intent.setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); 194 | try { 195 | activity.sendBroadcast(intent); 196 | } catch (Throwable e) { 197 | } 198 | } 199 | } 200 | 201 | private class UniversalCopyActivityThreadHook extends XC_MethodHook { 202 | 203 | @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { 204 | super.beforeHookedMethod(param); 205 | mUniversalCopyHandler.setActivityThreadObject(param.thisObject); 206 | } 207 | } 208 | 209 | private class UniversalCopyOnStopHook extends XC_MethodHook { 210 | 211 | @Override protected void beforeHookedMethod(MethodHookParam param) throws Throwable { 212 | super.beforeHookedMethod(param); 213 | Activity activity = (Activity) param.thisObject; 214 | mUniversalCopyHandler.onStop(activity); 215 | } 216 | } 217 | 218 | private class ViewonKeyUpHooker extends XC_MethodHook { 219 | 220 | @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { 221 | super.beforeHookedMethod(param); 222 | Activity activity = (Activity) param.thisObject; 223 | Log.e(TAG, "ViewonKeyUpHooker afterHookedMethod= " + activity); 224 | if (mXposedKeyUpHandler == null) { 225 | mXposedKeyUpHandler = new XposedKeyUpHandler(activity.getApplicationContext()); 226 | } 227 | mXposedKeyUpHandler.onKeyEvent((KeyEvent) param.args[1]); 228 | } 229 | } 230 | 231 | private class ViewonKeyLongPressHooker extends XC_MethodHook { 232 | 233 | @Override protected void afterHookedMethod(MethodHookParam param) throws Throwable { 234 | super.beforeHookedMethod(param); 235 | Activity activity = (Activity) param.thisObject; 236 | Log.e(TAG, "ViewonKeyLongPressHooker afterHookedMethod= " + activity); 237 | if (mXposedKeyUpHandler == null) { 238 | mXposedKeyUpHandler = new XposedKeyUpHandler(activity.getApplicationContext()); 239 | } 240 | mXposedKeyUpHandler.onKeyLongPress((KeyEvent) param.args[1]); 241 | } 242 | } 243 | } -------------------------------------------------------------------------------- /app/src/main/java/com/pl/universalcopy/xposed/XposedUniversalCopyHandler.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy.xposed; 2 | 3 | import android.app.Activity; 4 | import android.app.ActivityManager; 5 | import android.content.BroadcastReceiver; 6 | import android.content.ComponentName; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.content.IntentFilter; 10 | import android.graphics.Rect; 11 | import android.os.Bundle; 12 | import android.os.Handler; 13 | import android.os.Looper; 14 | import android.util.DisplayMetrics; 15 | import android.util.Log; 16 | import android.view.View; 17 | import android.view.ViewGroup; 18 | import android.view.WindowManager; 19 | import android.widget.Toast; 20 | 21 | 22 | import com.pl.universalcopy.Constant; 23 | import com.pl.universalcopy.copy.CopyNode; 24 | 25 | import java.lang.reflect.Field; 26 | import java.util.ArrayList; 27 | import java.util.Iterator; 28 | import java.util.List; 29 | import java.util.Map; 30 | import java.util.Set; 31 | 32 | import static com.pl.universalcopy.Constant.UNIVERSAL_COPY_BROADCAST_XP; 33 | 34 | /** 35 | * Created by penglu on 2017/1/4. 36 | */ 37 | 38 | public class XposedUniversalCopyHandler { 39 | public static final String TAG="UniversalCopyHandler"; 40 | 41 | 42 | List mActivities=new ArrayList<>(); 43 | IntentFilter intentFilter=new IntentFilter(UNIVERSAL_COPY_BROADCAST_XP); 44 | Handler handler; 45 | List mFilters; 46 | private Object activityThreadObject = null; 47 | 48 | public void setActivityThreadObject(Object activityThreadObject) { 49 | this.activityThreadObject = activityThreadObject; 50 | } 51 | 52 | public void setFilters(List mFilters) { 53 | this.mFilters = mFilters; 54 | } 55 | 56 | public void onStart(Activity activity){ 57 | mActivities.add(activity); 58 | try { 59 | activity.getApplication().registerReceiver(mUniversalCopyBR,intentFilter); 60 | } catch (Throwable e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | 65 | public void onStop(Activity activity){ 66 | mActivities.remove(activity); 67 | if (mActivities.size()==0){ 68 | try { 69 | activity.getApplication().unregisterReceiver(mUniversalCopyBR); 70 | } catch (Throwable e) { 71 | e.printStackTrace(); 72 | } 73 | } 74 | } 75 | 76 | private void startUniversalCopy(){ 77 | Log.e(TAG,"startUniversalCopy"); 78 | Activity topActivity=null; 79 | try { 80 | ActivityManager activityManager= (ActivityManager) mActivities.get(0).getApplication().getSystemService(Context.ACTIVITY_SERVICE); 81 | List taskInfos=activityManager.getRunningTasks(1); 82 | if (taskInfos.size()>0){ 83 | ComponentName top=taskInfos.get(0).topActivity; 84 | if (top!=null){ 85 | String name=top.getClassName(); 86 | for (Activity activity:mActivities){ 87 | if (activity.getClass().getName().equals(name) && !activity.isFinishing()){ 88 | topActivity=activity; 89 | break; 90 | } 91 | } 92 | if (topActivity==null && activityThreadObject!=null){ 93 | Class clazz = Class.forName("android.app.ActivityThread"); 94 | Field field = clazz.getDeclaredField("mActivities") ; 95 | field.setAccessible(true); 96 | Map mActivities = (Map) field.get(activityThreadObject); 97 | if (mActivities!=null) { 98 | Set set = mActivities.entrySet(); 99 | Iterator iterator = set.iterator(); 100 | Class recordClass = Class.forName("android.app.ActivityThread$ActivityClientRecord"); 101 | Field activityField = recordClass.getDeclaredField("activity"); 102 | activityField.setAccessible(true); 103 | while (iterator.hasNext()) { 104 | Activity activity = (Activity) activityField.get( 105 | ((Map.Entry) iterator.next()).getValue()); 106 | if (activity.getClass().getName().equals(name)) { 107 | topActivity = activity; 108 | break; 109 | } 110 | } 111 | } 112 | } 113 | } 114 | } 115 | } catch (Throwable e) { 116 | e.printStackTrace(); 117 | } 118 | if (topActivity==null){ 119 | if (mActivities.size()>0) { 120 | topActivity = mActivities.get(mActivities.size() - 1); 121 | if (topActivity.isFinishing()){ 122 | mActivities.remove(topActivity); 123 | topActivity=null; 124 | } 125 | } 126 | } 127 | UniversalCopy(topActivity); 128 | } 129 | 130 | private int retryTimes=0; 131 | private void UniversalCopy(final Activity activity) { 132 | if (activity==null){ 133 | return; 134 | } 135 | boolean isSuccess=false; 136 | label37: { 137 | View decirView =activity.getWindow().getDecorView(); 138 | if(this.retryTimes < 10) { 139 | String packageName; 140 | packageName = activity.getPackageName(); 141 | 142 | if(decirView == null || packageName != null && packageName.contains("com.android.systemui")) { 143 | ++this.retryTimes; 144 | this.handler.postDelayed(new Runnable() { 145 | @Override 146 | public void run() { 147 | UniversalCopy(activity); 148 | } 149 | }, 100); 150 | return; 151 | } 152 | 153 | WindowManager var5 = (WindowManager)activity.getSystemService(Context.WINDOW_SERVICE); 154 | 155 | DisplayMetrics displayMetrics = new DisplayMetrics(); 156 | var5.getDefaultDisplay().getMetrics(displayMetrics); 157 | int var1 = displayMetrics.heightPixels; 158 | int var2 = displayMetrics.widthPixels; 159 | ArrayList nodeList = traverseNode(decirView, var2, var1); 160 | for (CopyNode node:nodeList) { 161 | Log.e(TAG, "traverseNode result= " + node); 162 | } 163 | if(nodeList.size() > 0) { 164 | // Intent intent = new Intent(activity, CopyActivity.class); 165 | Intent intent = new Intent(); 166 | intent.setComponent(new ComponentName(Constant.PACKAGE_NAME,"com.pl.universalcopy.copy.CopyActivity")); 167 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 168 | Bundle bundle=new Bundle(); 169 | bundle.setClassLoader(CopyNode.class.getClassLoader()); 170 | bundle.putString("source_package", packageName); 171 | bundle.putParcelableArrayList("copy_nodes", nodeList); 172 | intent.putExtras(bundle); 173 | try { 174 | activity.startActivity(intent); 175 | } catch (Throwable e) { 176 | e.printStackTrace(); 177 | } 178 | isSuccess = true; 179 | break label37; 180 | } 181 | 182 | // ae.a(this.getApplication(), "APP_DATA", "UC_MODE_FAILED", packageName); 183 | } 184 | 185 | isSuccess = false; 186 | } 187 | 188 | if(!isSuccess) { 189 | try { 190 | Toast.makeText(activity, "无法启动全局复制,可能当前应用做了防Xposed注入" , Toast.LENGTH_SHORT).show(); 191 | } catch (Throwable e) { 192 | e.printStackTrace(); 193 | } 194 | } 195 | this.retryTimes = 0; 196 | } 197 | 198 | private ArrayList traverseNode(View nodeInfo, int screenWidth, int scerrnHeight) { 199 | ArrayList nodeList = new ArrayList(); 200 | if(nodeInfo != null ) { 201 | if (!nodeInfo.isShown()){ 202 | return nodeList; 203 | } 204 | if (nodeInfo instanceof ViewGroup){ 205 | ViewGroup viewGroup = (ViewGroup) nodeInfo; 206 | for(int var4 = 0; var4 < viewGroup.getChildCount(); ++var4) { 207 | nodeList.addAll(this.traverseNode(viewGroup.getChildAt(var4), screenWidth, scerrnHeight)); 208 | } 209 | } 210 | if(nodeInfo.getClass().getName() != null && nodeInfo.getClass().getName().equals("android.webkit.WebView")) { 211 | return nodeList; 212 | } else { 213 | String content = null; 214 | String description = content; 215 | if(nodeInfo.getContentDescription() != null) { 216 | description = content; 217 | if(!"".equals(nodeInfo.getContentDescription())) { 218 | description = nodeInfo.getContentDescription().toString(); 219 | } 220 | } 221 | 222 | content = description; 223 | String text=getTextInFilters(nodeInfo,mFilters); 224 | if(text != null) { 225 | content = description; 226 | if(!"".equals(text)) { 227 | content = text.toString(); 228 | } 229 | } 230 | 231 | if(content != null) { 232 | Rect var8 = new Rect(); 233 | nodeInfo.getGlobalVisibleRect(var8); 234 | if(checkBound(var8, screenWidth, scerrnHeight)) { 235 | nodeList.add(new CopyNode(var8, content)); 236 | } 237 | } 238 | 239 | return nodeList; 240 | } 241 | } else { 242 | return nodeList; 243 | } 244 | } 245 | 246 | private String getTextInFilters(View v,List filters){ 247 | for (Filter filter:filters){ 248 | if (filter.filter(v)){ 249 | return filter.getContent(v); 250 | } 251 | } 252 | return null; 253 | } 254 | 255 | private boolean checkBound(Rect var1, int var2, int var3) { 256 | return var1.bottom >= 0 && var1.right >= 0 && var1.top <= var3 && var1.left <= var2; 257 | } 258 | 259 | 260 | private BroadcastReceiver mUniversalCopyBR = new BroadcastReceiver() { 261 | @Override 262 | public void onReceive(Context context, Intent intent) { 263 | if (handler==null){ 264 | handler=new Handler(Looper.getMainLooper()); 265 | } 266 | handler.post(new Runnable() { 267 | @Override 268 | public void run() { 269 | startUniversalCopy(); 270 | } 271 | }); 272 | } 273 | }; 274 | 275 | 276 | } 277 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/notify_copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/drawable-xhdpi/notify_copy.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/borders.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/button_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/universal_copy_node_bg_n.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_copy_overlay.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 16 | 27 | 39 | 40 | 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_donate.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 22 | 23 | 27 | 32 | 33 | 44 | 45 | 46 | 56 | 62 | 63 | 72 | 73 | 79 | 80 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_how_to_use.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 25 | 26 | 30 | 31 | 35 | 36 | 41 | 42 | 43 | 47 | 48 | 49 | 53 | 57 | 58 | 59 | 60 | 61 | 65 | 66 | 67 | 71 | 72 | 76 | 77 | 78 | 79 | 80 | 86 | 87 | 97 | 98 | 102 | 103 | 106 | 107 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 22 | 23 | 28 | 29 | 33 | 34 | 37 | 38 | 39 | 43 | 44 | 49 | 50 | 54 | 55 | 58 | 59 | 60 | 64 | 65 | 70 | 71 | 75 | 76 | 79 | 80 | 81 | 85 | 86 | 91 | 92 | 96 | 97 | 100 | 101 | 102 | 106 | 107 | 112 | 113 | 118 | 119 | 120 | 121 | 126 | 127 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_copy_text_editor.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 32 | 33 | 34 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/menu/universal_copy.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | 15 | 16 | 17 | 21 | 22 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_arrow_back_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xhdpi/ic_arrow_back_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_close_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xhdpi/ic_close_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_edit_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xhdpi/ic_edit_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_float_copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xhdpi/ic_float_copy.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_fullscreen_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xhdpi/ic_fullscreen_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/universal_copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xhdpi/universal_copy.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/universal_select_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xhdpi/universal_select_all.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/raw/alipay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/raw/alipay.jpg -------------------------------------------------------------------------------- /app/src/main/res/raw/wechat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/app/src/main/res/raw/wechat.jpg -------------------------------------------------------------------------------- /app/src/main/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values-v19/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | @dimen/margin_four 4 | @dimen/height_normal 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values-v19/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #000000 4 | #FFFFFFFF 5 | @color/white 6 | #212121 7 | #727272 8 | #dddddd 9 | #cdcdcd 10 | #E64A19 11 | #88E64A19 12 | #80FFFFFF 13 | 14 | #00000000 15 | #FF03A9F4 16 | #FF0288D1 17 | @color/primary 18 | @color/primary_dark 19 | #bc1e1e1e 20 | #cee9e9e9 21 | #40000000 22 | #aa000000 23 | #00000000 24 | 25 | #3d85c0 26 | 27 | #dc404040 28 | 29 | //bigbangBackgroundColor 30 | #000000 31 | #dcedc8 32 | #b2ebf2 33 | #f8bbd0 34 | #c5cae9 35 | #d0d9ff 36 | #b2dfdb 37 | #ffccbc 38 | #e1bee7 39 | #d7ccc8 40 | #cfd8dc 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #03A9F4 5 | #0288D1 6 | #B3E5FC 7 | #009688 8 | #FF78909C 9 | #3F51B5 10 | #FF78909C 11 | 12 | #3303A9F4 13 | #9003A9F4 14 | #9078909C 15 | #009688 16 | #3300E5FF 17 | #9000E5FF 18 | 19 | #00796B 20 | 21 | 22 | #50808080 23 | #40000000 24 | #20000000 25 | 26 | #ccd4d4d4 27 | #ccb9b9b9 28 | #33d4d4d4 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 80dp 4 | 50dp 5 | 150dp 6 | 7 | 16dp 8 | 16dp 9 | 88dp 10 | 11 | 0dp 12 | 8dp 13 | 42dp 14 | 15 | 16 | 1dp 17 | 1.5dp 18 | 2dp 19 | 3dp 20 | 25dp 21 | 30dp 22 | 40dp 23 | 40dp 24 | 48dp 25 | 26 | 5dp 27 | 8dp 28 | 3dp 29 | 10dp 30 | 20dp 31 | 30dp 32 | 33 | 33sp 34 | 24sp 35 | 19sp 36 | 16sp 37 | 14sp 38 | 12sp 39 | 10sp 40 | 41 | 42 | 8dp 43 | 16dp 44 | 24dp 45 | 32dp 46 | 47 | 24dp 48 | 32dp 49 | 48dp 50 | 56dp 51 | 72dp 52 | 53 | 54 | 0dp 55 | @dimen/margin_triple 56 | @dimen/height_normal 57 | 60dp 58 | @dimen/margin_normal 59 | @dimen/margin_normal 60 | @dimen/margin_double 61 | 20dp 62 | @dimen/margin_four 63 | @dimen/margin_normal 64 | 4dp 65 | 2dp 66 | 67 | 4dp 68 | 2dp 69 | 32dp 70 | 148dp 71 | 72 | 5dp 73 | 8dp 74 | 1dp 75 | 76 | 77 | 150dp 78 | 79 | 10dp 80 | 81 | @dimen/height_small_32 82 | @dimen/height_normal 83 | 84 | 85 | @dimen/margin_double 86 | @dimen/margin_normal 87 | 88 | @dimen/height_small_32 89 | @dimen/height_small 90 | @dimen/margin_normal 91 | 92 | @dimen/height_title 93 | 94 | 220dp 95 | 96 | 97 | @dimen/margin_double 98 | @dimen/margin_double 99 | 100 | 101 | @dimen/height_normal 102 | 103 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 全局复制XP 3 | 4 | 5 | 全局\n复制 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 | 未找到QQ 33 | 我的支付宝二维码 34 | 我的微信二维码 35 | 有您的支持,我们会越做越好的 36 | 二维码已保存到本地相册 37 | 点击二维码保存到相册 38 | 39 | 为什么全局复制在有些页面没有用 40 | \t\t\t\t全局复制的原理是去抓取当前页面中的文字信息,以下情况可能会导致全局复制抓不到文字:\n\t\t\t\t 41 | 1.如果应用中的文字不是使用标准文字组件,则无法抓取文字,比如浏览器和微信QQ的消息界面等,此时可以考虑使用普通复制。\n\t\t\t\t 42 | 2.一些看似是文字的内容,其实是当成图片绘制的,所以也抓不到文字信息,比如锤子桌面、iReader等。 43 | 44 | 45 | 46 | 软件功能介绍 47 | \t\t\t\t 48 | 所谓全局复制,就是在一些本来不能复制的页面也能够复制,增大了复制功能的适用范围,比如在系统设置页面也可以复制,本应用需要xposed框架支持。\n\t\t\t\t 49 | 如果你还需要对复制到的词语进行处理,比如分词、快速编辑、搜索、翻译等,可以下载“全能分词”或者“锤子Bigbang"应用,该应用不但包含本应用的功能,还有更多新玩法。 50 | 51 | 52 | 关于多种触发方式的设置 53 | \t\t\t\t我们提供了通知栏、组合音量键、长按返回键,三种触发全局复制的方式。\n\t\t\t\t 54 | 你可以根据自己的需要进行自由选择,个人建议是使用组合音量键触发,因为有些应用对返回键做了特殊处理,导致我们无法获取,比如微信和QQ。\n\t\t\t\t 55 | 修改设置以后,最好重启生效,否则可能会造成一些副作用。 56 | 57 | 58 | 59 | 如何通过外部应用触发功能 60 | 如果你对我们提供的这几种触发方法仍然不满意,或者你使用了第三方的自定义开关(比如悬浮菜单),可以将我们的开关集成进去,方法如下:\n 61 | 包名:\n\tcom.pl.universalcopy\n\n 62 | 类名:\n\tcom.pl.universalcopy.UniversalCopyActiity\n\n 63 | 64 | 提示:本页面可以通过全局复制来复制包名和类名。 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 31 | 32 | 35 | 36 | 46 | 47 | 57 | 58 | 59 | 65 | 66 | 74 | 75 | 76 | 77 | 80 | 81 | 91 | 100 | 101 | 106 | 107 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /app/src/test/java/com/pl/universalcopy/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.pl.universalcopy; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /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 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:3.1.2' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | google() 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | -------------------------------------------------------------------------------- /gif/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/penglu20/UniversalCopy_xposed/35fbb2c2876ef31526fe952462a59049023394c1/gif/demo.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 | org.gradle.jvmargs=-Xmx1024m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------