├── .github ├── HELP_zh_CN.md ├── PlayStore_Post.png └── screenshot.png ├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── dictionaries │ └── fytho.xml └── vcs.xml ├── HELP.md ├── LICENSE ├── PRIVACY-POLICY.md ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── moe │ │ └── feng │ │ └── nevo │ │ └── decorators │ │ └── enscreenshot │ │ ├── BarcodeListAdapter.java │ │ ├── Constants.java │ │ ├── DecoratorApplication.java │ │ ├── PermissionRequestActivity.java │ │ ├── PreferencesActivity.java │ │ ├── PreviewActivity.java │ │ ├── PreviewSettingsActivity.java │ │ ├── ScreenshotDecorator.java │ │ ├── ScreenshotDecoratorSettingsReceiver.java │ │ ├── ScreenshotPreferences.java │ │ ├── SupportUsDialog.java │ │ ├── ViewBarcodeActivity.java │ │ ├── service │ │ └── PreviewService.java │ │ ├── utils │ │ ├── DeviceInfoPrinter.java │ │ ├── Executors.java │ │ ├── FileUtils.java │ │ ├── FormatUtils.java │ │ ├── IntentUtils.java │ │ ├── MyFirebaseHelper.java │ │ ├── PendingIntentCompat.java │ │ ├── PermissionUtils.java │ │ ├── ResourcesUtils.java │ │ ├── ScreenUtils.java │ │ ├── Singleton.java │ │ └── SingletonImpl.java │ │ └── widget │ │ ├── DividerItemDecoration.java │ │ ├── HtmlTextView.java │ │ ├── PreviewActionForegroundDrawable.java │ │ ├── RoundRectFrameLayout.java │ │ └── SwitchBar.java │ └── res │ ├── drawable-xxxhdpi │ └── ic_launcher_foreground.png │ ├── drawable │ ├── ic_assistant_white_24dp.xml │ ├── ic_delete_black_24dp.xml │ ├── ic_delete_white_24dp.xml │ ├── ic_edit_white_24dp.xml │ ├── ic_keyboard_arrow_up_white_24dp.xml │ ├── ic_open_in_browser_white_24dp.xml │ ├── ic_share_white_24dp.xml │ ├── ic_thumb_up_color_control_normal_24dp.xml │ ├── material_button_flat_with_border.xml │ └── material_button_flat_with_border_background.xml │ ├── layout │ ├── activity_preview_settings.xml │ ├── dialog_layout_edit_text.xml │ ├── dialog_layout_view_barcode.xml │ ├── item_barcode.xml │ ├── layout_preview.xml │ ├── preference_right_icon.xml │ ├── preview_window_content.xml │ └── switch_bar_content.xml │ ├── menu │ └── menu_preferences.xml │ ├── mipmap-anydpi-v26 │ └── ic_launcher.xml │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-v27 │ └── styles.xml │ ├── values-zh-rCN │ └── strings.xml │ ├── values-zh-rTW │ └── strings.xml │ ├── values │ ├── arrays.xml │ ├── attrs.xml │ ├── colors.xml │ ├── colors_material.xml │ ├── dimens.xml │ ├── hardcode_strings.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ ├── file_provider.xml │ └── preferences.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/HELP_zh_CN.md: -------------------------------------------------------------------------------- 1 | 增强截图通知 - 帮助 2 | ==== 3 | 4 | ![](./PlayStore_Post.png) 5 | 6 | 这里我只展示常见问题。如果你遇到了一些 Bugs,请在这个仓库中[创建一个 Issue](https://github.com/fython/EnhancedScreenshotNotification/issues/new)。 7 | 8 | ## Q: 如何使用这个应用? 9 | 10 | 1. 这个应用仅支持 Android 7.0 或更高版本。 11 | 2. 安装 [女娲石(Nevolution)应用](https://play.google.com/store/apps/details?id=com.oasisfeng.nevo)。增强截图通知仅仅是女娲石的插件。 12 | 3. 安装增强截图通知。你可以从 GitHub Releases 或者 Google Play 中获得预编译包。如果你拥有开发环境,可以自行编译。 13 | 4. 打开 Nevolution 并为 “系统界面(System UI)” 激活这个应用插件。如果你的 Android 系统截图通知不是由这些包发出,请告诉我来增加支持: 14 | - `com.android.systemui` (AOSP 原生和大部分系统) 15 | - `com.oneplus.screenshot` (一加系统) 16 | - `com.samsung.android.app.smartcapture` (三星系统) 17 | 5. 为了得到你最新的截图位置,允许增强截图通知的存储权限,否则大部分功能无法工作。 18 | 6. 现在增强截图通知应该可以运作了。你可以在设置中设置你的偏好。 19 | 20 | ## Q: 哪里可以捐赠作者呢? 21 | 22 | 如果你认为我的应用十分有用而且你乐意帮助我,你可以通过支付宝捐赠我: `fythonx#gmail.com` (将 `#` 换成 `@`) 23 | 24 | Paypal 也是可以接受的,但它扣取大量的手续费所以更推荐支付宝。Paypal: [paypal.me/fython](https://paypal.me/fython) 25 | 26 | ## Q: 为什么我给予了增强截图通知存储权限,但它还是不能为截图通知提供“编辑”操作? 27 | 28 | 首先,阅读第一个关于如何正确安装的问题。 29 | 30 | 检查你的系统默认截图目录是否为 `<内部储存空间/外部储存空间>/Pictures/Screenshots`。如果不是,在设置中修改为正确的路径。 31 | 32 | ## Q: 我能直接用指定应用编辑截图而不用每次都选择吗? 33 | 34 | 可以,去增强截图通知设置然后设定你偏好的编辑器。 35 | 36 | ## Q: 我能自定义截图声音吗? 37 | 38 | 不能,它的声音是系统指定的。 39 | 40 | ## Q: 如何使用悬浮预览? 41 | 42 | 首先,**保证你的 Android 系统是 8.0 或者更高版本**。它依赖了 Android 8.0 的新特性——画中画接口。 43 | 44 | 启用设置然后选择是否要自动显示悬浮预览窗来取代通知,通知不会自动隐藏但它的优先级会被设置为最低。 45 | 46 | # 对于开发者 47 | 48 | ## Q: 我能在这个项目上贡献吗? 49 | 50 | 当然可以,我很乐意和其它开发者一起工作。 51 | 52 | 如果你修复了一些 Bugs,放轻松然后直接发送 Pull Request。 53 | 54 | 如果你想添加或者改变一些特性,请在发送 Pull Request 前创建一个 Issue 或者联系我进行讨论。 55 | -------------------------------------------------------------------------------- /.github/PlayStore_Post.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/EnhancedScreenshotNotification/098a74405080b9ed6b1efc3218b4f9baee543015/.github/PlayStore_Post.png -------------------------------------------------------------------------------- /.github/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/EnhancedScreenshotNotification/098a74405080b9ed6b1efc3218b4f9baee543015/.github/screenshot.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/assetWizardSettings.xml 9 | /.idea/gradle.xml 10 | /.idea/misc.xml 11 | /.idea/runConfigurations.xml 12 | .DS_Store 13 | /build 14 | /captures 15 | .externalNativeBuild 16 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 37 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/dictionaries/fytho.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | arisu 5 | enscreenshot 6 | feng 7 | firebase 8 | nevo 9 | nevolution 10 | noti 11 | oasisfeng 12 | oneplus 13 | systemui 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /HELP.md: -------------------------------------------------------------------------------- 1 | Enhanced Screenshot Notification - Help 2 | ==== 3 | 4 | ![](.github/PlayStore_Post.png) 5 | 6 | Here I only show frequent asked questions. If you are meeting some bugs, please [create an issue](https://github.com/fython/EnhancedScreenshotNotification/issues/new) in this repository. 7 | 8 | Needs other languages? [简体中文 (zh-CN)](./.github/HELP_zh_CN.md) 9 | 10 | ## Q: How to use this app? 11 | 12 | 0. This app supports only Android 7.0+ currently. 13 | 1. Install [Nevolution app](https://play.google.com/store/apps/details?id=com.oasisfeng.nevo). This app is just a decorator plug-in. 14 | 2. Install this app. You can get prebuilt package from GitHub Releases and Google Play. If you have development environment, you can compile your own package. 15 | 3. Open Nevolution and activate this app for "System UI". If your Android ROM's screenshot notification isn't sent from these packages, please tell me for adding support: 16 | - `com.android.systemui` (AOSP and most ROMs) 17 | - `com.oneplus.screenshot` (OnePlus ROM) 18 | - `com.samsung.android.app.smartcapture` (Samsung ROM) 19 | 4. Grant storage permission for Enhanced Screenshots Notification in order that it can get your latest screenshot's path. If you don't do that, most functions cannot work. 20 | 5. Enhanced Screenshots Notification should be working now. You can set up your preferences in ESN's settings. 21 | 22 | ## Q: Where can I donate author? 23 | 24 | If you think my app is very useful and you're glad to help me, you can donate me via Alipay (支付宝): `fythonx#gmail.com` (Replace `#` with `@`) 25 | 26 | Paypal is also acceptable but it will deduct a lot of fees so I recommend to use Alipay instead. Paypal: [paypal.me/fython](https://paypal.me/fython) 27 | 28 | ## Q: I granted storage permission for ENS, but it still doesn't provide **Edit** action for screenshot notification. Why? 29 | 30 | Firstly, read the first question that about how to install properly. 31 | 32 | Check if your ROM's default screenshot path is `/Pictures/Screenshots`. If not, change ENS settings to correct path. 33 | 34 | ## Q: Can I directly edit screenshot by specified app instead of choosing editors every time? 35 | 36 | Yes. Go to ENS Settings and set your preferred editor. 37 | 38 | ## Q: Can I customize screenshot sound? 39 | 40 | No. Its sound is specified by system. 41 | 42 | ## Q: How to use floating preview? 43 | 44 | First, **ensure your Android version is 8.0+**. It depends PiP API which is supported only in Android 8.0+. 45 | 46 | Enable settings and choose if show floating preview automatically instead of notifcation. Notification will not dismiss completely, but its priority is set to minimum level. 47 | 48 | # For developers 49 | 50 | ## Q: Can I contribute on this project? 51 | 52 | Of course. I am glad to work with other developers together. 53 | 54 | If you fix some bugs, relax and send a pull request directly. 55 | 56 | If you want to add / change some features, please create an issue / contact me for a discussion before sending PRs. 57 | -------------------------------------------------------------------------------- /PRIVACY-POLICY.md: -------------------------------------------------------------------------------- 1 | # Privacy policy 2 | 3 | Enhanced Screenshot Notification will use following permissions: 4 | 5 | - **Internet:** Produce barcode links preview; collect crash report to developers; get the latest discussion link. 6 | - **Storage:** Get information from the latest screenshot; delete screenshot; share screenshot by users\' action. 7 | 8 | All source code except Google API keys is open-sourced. If you are suspicious of the pre-compiled version, you can 9 | self-check the code and compile your own package. (You can also try to use F-Droid compiled package.) 10 | 11 | ------ 12 | 13 | # 隐私政策 14 | 15 | 增强截图通知会使用以下权限: 16 | 17 | - **网络:** 产生条码链接预览;收集崩溃报告给开发者;获取最新讨论链接。 18 | - **存储:** 获得最新截图的信息;删除截图;根据用户操作分享截图。 19 | 20 | 除 Google API 密钥外所有源码均已开源。如果你对预编译版本存疑,你可以自查代码并编译自己的包。(你还可以尝试 F-Droid 编译的包) 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Enhanced Screenshot Notification (Nevolution Decorator) 2 | ==== 3 | 4 | Download prebuilt package from [Github releases](https://github.com/fython/EnhancedScreenshotNotification/releases) | [Google Play](https://play.google.com/store/apps/details?id=moe.feng.nevo.decorators.enscreenshot) 5 | 6 | [Help Documentation English (en)](./HELP.md) | [简体中文 (zh-CN)](./.github/HELP_zh_CN.md) 7 | 8 | # Introduction 9 | 10 | Enhance screenshot notification then you can start to edit screenshot quickly. 11 | 12 | ![Screenshot](.github/screenshot.png) 13 | 14 | > "Edit action" feature is implemented in Android P & some third-party ROMs. 15 | 16 | Other features: 17 | 18 | - Preview the latest screenshot in floating window 19 | - Set preferred editor app 20 | - Show total screenshots count 21 | - Show new screenshot's details 22 | - Hide icon from launcher 23 | - Recognize barcode in screenshot 24 | 25 | # Requirements 26 | 27 | ## For users 28 | 29 | - Android 7.0+ 30 | - A normal Android ROM 31 | - [Nevolution app](https://play.google.com/store/apps/details?id=com.oasisfeng.nevo) installed. 32 | - Grant this app to read external storage for accessing latest screenshot. 33 | 34 | ## For developers 35 | 36 | - Android SDK 28 37 | - Android Studio 3.2+ 38 | - Gradle 4.8 39 | 40 | # TO-DO 41 | 42 | - [x] "Edit" action 43 | - [x] Dismiss evolved notification after clicking "Delete" action 44 | - [x] Customizable "Share" & "Edit" action 45 | - [x] Multi-language (Chinese supported) 46 | - [x] Multi-format of "Edit in..." action text 47 | - [x] Settings interface 48 | - [x] PiP Screenshot preview (Toggle size, dismiss, delete) 49 | - [x] Support Android P 50 | - [ ] Keep previous screenshot notification and organize them 51 | - [ ] Support older Android version 52 | - [x] Stable behavior when other notifications are posted from System UI 53 | - [x] Barcode detection 54 | - [x] Material Design 2 55 | - [x] Better screenshot preview experience 56 | 57 | # Contact me 58 | 59 | Telegram: [@fython](https://t.me/fython) 60 | 61 | # License 62 | 63 | ![GPL v3](https://www.gnu.org/graphics/gplv3-127x51.png) 64 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /release 3 | google-services.json -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | defaultConfig { 6 | applicationId "moe.feng.nevo.decorators.enscreenshot" 7 | // Enable Java 8 runtime (streams, optional, etc.) 8 | minSdkVersion 24 9 | targetSdkVersion 28 10 | versionCode 11 11 | versionName "2.0" 12 | 13 | resConfigs "en", "zh_CN", "zh_TW" 14 | 15 | // Please DO NOT change this string. Thanks! 16 | buildConfigField "String", "ALIPAY_SUPPORT_URL", "\"https://qr.alipay.com/fkx04860gv3hon55av00874\"" 17 | 18 | // Always show for test 19 | buildConfigField "boolean", "SHOW_ALIPAY_ALWAYS", "true" 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled true 25 | shrinkResources true 26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | 30 | // Multi product flavors 31 | flavorDimensions "channel" 32 | productFlavors { 33 | playStore { 34 | dimension "channel" 35 | ext { 36 | showAlipayAlways = false 37 | } 38 | } 39 | other { 40 | dimension "channel" 41 | ext { 42 | showAlipayAlways = true 43 | } 44 | } 45 | } 46 | 47 | // Enable Java 8 language features 48 | compileOptions { 49 | sourceCompatibility JavaVersion.VERSION_1_8 50 | targetCompatibility JavaVersion.VERSION_1_8 51 | } 52 | 53 | applicationVariants.all { variant -> 54 | def flavor = variant.productFlavors[0] 55 | // Apply build config field from flavor.ext 56 | variant.buildConfigField "boolean", "SHOW_ALIPAY_ALWAYS", "${flavor.ext.showAlipayAlways}" 57 | } 58 | } 59 | 60 | dependencies { 61 | implementation 'com.oasisfeng.nevo:sdk:1.1.1' 62 | final androidxVersion = '1.0.0' 63 | implementation "androidx.annotation:annotation:$androidxVersion" 64 | implementation "androidx.core:core:$androidxVersion" 65 | implementation "androidx.recyclerview:recyclerview:$androidxVersion" 66 | implementation 'net.grandcentrix.tray:tray:0.12.0' 67 | implementation 'com.google.firebase:firebase-core:16.0.4' 68 | implementation 'com.google.firebase:firebase-ml-vision:17.0.1' 69 | } 70 | 71 | apply plugin: 'com.google.gms.google-services' -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | -dontobfuscate 2 | -keepattributes SourceFile,LineNumberTable 3 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 18 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 43 | 44 | 45 | 46 | 47 | 48 | 54 | 55 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 74 | 75 | 76 | 77 | 78 | 79 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 94 | 95 | 98 | 99 | 100 | 101 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/BarcodeListAdapter.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.Button; 10 | import android.widget.TextView; 11 | import androidx.annotation.NonNull; 12 | import androidx.annotation.StringRes; 13 | import androidx.recyclerview.widget.DiffUtil; 14 | import androidx.recyclerview.widget.ListAdapter; 15 | import androidx.recyclerview.widget.RecyclerView; 16 | import com.google.android.gms.vision.barcode.Barcode; 17 | import moe.feng.nevo.decorators.enscreenshot.utils.IntentUtils; 18 | 19 | public class BarcodeListAdapter extends ListAdapter { 20 | 21 | BarcodeListAdapter() { 22 | super(new DiffCallback()); 23 | } 24 | 25 | @NonNull 26 | @Override 27 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 28 | return new ViewHolder(LayoutInflater.from(parent.getContext()) 29 | .inflate(R.layout.item_barcode, parent, false)); 30 | } 31 | 32 | @Override 33 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) { 34 | holder.onBind(getItem(position)); 35 | } 36 | 37 | class ViewHolder extends RecyclerView.ViewHolder { 38 | 39 | private final Context mContext; 40 | 41 | private final TextView mText1, mText2; 42 | private final Button mButton1, mCopyButton; 43 | 44 | private Barcode mData; 45 | 46 | ViewHolder(@NonNull View itemView) { 47 | super(itemView); 48 | mContext = itemView.getContext(); 49 | mText1 = itemView.findViewById(android.R.id.text1); 50 | mText2 = itemView.findViewById(android.R.id.text2); 51 | mButton1 = itemView.findViewById(android.R.id.button1); 52 | mCopyButton = itemView.findViewById(android.R.id.copy); 53 | } 54 | 55 | void onBind(Barcode data) { 56 | mData = data; 57 | 58 | mText1.setText(data.rawValue); 59 | mText2.setText(mText2.getResources().getStringArray(R.array.barcode_types)[data.valueFormat]); 60 | 61 | switch (data.valueFormat) { 62 | case Barcode.URL: { 63 | onUrlItemBind(); 64 | break; 65 | } 66 | case Barcode.PHONE: { 67 | onPhoneItemBind(); 68 | break; 69 | } 70 | case Barcode.CONTACT_INFO: { 71 | onContactInfoItemBind(); 72 | break; 73 | } 74 | default: { 75 | onNormalItemBind(); 76 | } 77 | } 78 | } 79 | 80 | private void onContactInfoItemBind() { 81 | bindButton1(R.string.action_add_to_contacts, v -> mContext.startActivity( 82 | IntentUtils.createAddContactFromBarcode(mData) 83 | )); 84 | bindCopyButton(android.R.string.copy); 85 | } 86 | 87 | private void onPhoneItemBind() { 88 | bindButton1(R.string.action_call, v -> mContext.startActivity( 89 | IntentUtils.createDialIntent(Uri.parse(mData.rawValue)) 90 | )); 91 | bindCopyButton(android.R.string.copy); 92 | } 93 | 94 | private void onUrlItemBind() { 95 | bindButton1(R.string.action_open_link, v -> mContext.startActivity(Intent.createChooser( 96 | IntentUtils.createViewIntent(Uri.parse(mData.rawValue)), 97 | mContext.getString(R.string.action_open_link) 98 | ))); 99 | bindCopyButton(android.R.string.copyUrl); 100 | } 101 | 102 | private void onNormalItemBind() { 103 | hideButton1(); 104 | bindCopyButton(android.R.string.copy); 105 | } 106 | 107 | private void hideButton1() { 108 | mButton1.setVisibility(View.GONE); 109 | } 110 | 111 | private void bindButton1(@StringRes int textRes, @NonNull View.OnClickListener listener) { 112 | mButton1.setVisibility(View.VISIBLE); 113 | mButton1.setText(textRes); 114 | mButton1.setOnClickListener(listener); 115 | } 116 | 117 | private void bindCopyButton(@StringRes int textRes) { 118 | mCopyButton.setText(textRes); 119 | mCopyButton.setOnClickListener(v -> mContext.sendBroadcast(IntentUtils.createCopyIntent(mData.rawValue))); 120 | } 121 | 122 | } 123 | 124 | private static class DiffCallback extends DiffUtil.ItemCallback { 125 | 126 | @Override 127 | public boolean areItemsTheSame(@NonNull Barcode oldItem, @NonNull Barcode newItem) { 128 | return oldItem.rawValue.equals(newItem.rawValue); 129 | } 130 | 131 | @Override 132 | public boolean areContentsTheSame(@NonNull Barcode oldItem, @NonNull Barcode newItem) { 133 | return areItemsTheSame(oldItem, newItem); 134 | } 135 | 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/Constants.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | public final class Constants { 4 | 5 | private Constants() {} 6 | 7 | public static final String CHANNEL_ID_SCREENSHOT = "screenshot"; 8 | public static final String CHANNEL_ID_PREVIEWED_SCREENSHOT = "previewed"; 9 | public static final String CHANNEL_ID_OTHER = "other"; 10 | public static final String CHANNEL_ID_PERMISSION = "permission"; 11 | public static final String CHANNEL_ID_ASSISTANT = "assistant"; 12 | public static final String CHANNEL_ID_PREVIEW_SERVICE = "preview"; 13 | 14 | public static final int NOTIFICATION_ID_REQUEST_PERMISSION = 10; 15 | public static final int NOTIFICATION_ID_BARCODE = 11; 16 | public static final int NOTIFICATION_ID_PREVIEW_SERVICE = 12; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/DecoratorApplication.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | import android.app.Application; 4 | import android.content.res.Configuration; 5 | import com.google.firebase.FirebaseApp; 6 | import com.google.firebase.FirebaseOptions; 7 | import moe.feng.nevo.decorators.enscreenshot.utils.FormatUtils; 8 | 9 | public final class DecoratorApplication extends Application { 10 | 11 | public static FirebaseApp getFirebaseApp() { 12 | return FirebaseApp.getInstance(FIREBASE_NAME); 13 | } 14 | 15 | public static final String FILE_PROVIDER_AUTHORITY = BuildConfig.APPLICATION_ID + ".provider.files"; 16 | 17 | public static final String FIREBASE_NAME = "[ESN]"; 18 | 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | 23 | final FirebaseOptions firebaseOptions = new FirebaseOptions.Builder() 24 | .setApplicationId(BuildConfig.APPLICATION_ID) 25 | .setApiKey(getString(R.string.google_api_key)) 26 | .setProjectId(getString(R.string.project_id)) 27 | .build(); 28 | FirebaseApp.initializeApp(this, firebaseOptions, FIREBASE_NAME); 29 | } 30 | 31 | @Override 32 | public void onConfigurationChanged(Configuration newConfig) { 33 | super.onConfigurationChanged(newConfig); 34 | final ScreenshotPreferences preferences = new ScreenshotPreferences(this); 35 | preferences.setEditActionTextFormat(FormatUtils.getEditActionTextFormats(newConfig.getLocales()).second.get(1)); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/PermissionRequestActivity.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.pm.PackageManager; 7 | import android.os.Bundle; 8 | import android.util.Log; 9 | import android.util.SparseArray; 10 | 11 | import java.util.Arrays; 12 | import java.util.Optional; 13 | 14 | import androidx.annotation.NonNull; 15 | import androidx.annotation.Nullable; 16 | 17 | public final class PermissionRequestActivity extends Activity { 18 | 19 | public static final String TAG = "PermissionRequest"; 20 | 21 | public static final String EXTRA_PERMISSION_TYPE = 22 | BuildConfig.APPLICATION_ID + ".extra.PERMISSION_TYPE"; 23 | 24 | public static final int TYPE_STORAGE = 1; 25 | 26 | private static final int REQUEST_CODE_PERMISSION = 1000; 27 | 28 | private static final SparseArray PERMISSIONS_MAP = new SparseArray<>(); 29 | 30 | static { 31 | PERMISSIONS_MAP.append(TYPE_STORAGE, new String[] { 32 | Manifest.permission.READ_EXTERNAL_STORAGE, 33 | Manifest.permission.WRITE_EXTERNAL_STORAGE 34 | }); 35 | } 36 | 37 | @Override 38 | protected void onCreate(@Nullable Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | 41 | final int type = Optional.ofNullable(getIntent()) 42 | .map(intent -> intent.getIntExtra(EXTRA_PERMISSION_TYPE, 0)) 43 | .orElse(0); 44 | if (type <= 0) { 45 | Log.wtf(TAG, "Request type should be a positive number."); 46 | finish(); 47 | return; 48 | } 49 | 50 | requestPermissions(PERMISSIONS_MAP.get(type), REQUEST_CODE_PERMISSION); 51 | } 52 | 53 | @Override 54 | public void onRequestPermissionsResult( 55 | int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 56 | if (Arrays.stream(grantResults).allMatch(i -> i == PackageManager.PERMISSION_GRANTED)) { 57 | setResult(RESULT_OK); 58 | } else { 59 | setResult(RESULT_CANCELED); 60 | } 61 | finish(); 62 | } 63 | 64 | public static boolean checkIfPermissionTypeGranted(@NonNull Context context, int type) { 65 | for (String permission : PERMISSIONS_MAP.get(type)) { 66 | if (context.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { 67 | return false; 68 | } 69 | } 70 | return true; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/PreviewActivity.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | import android.app.Activity; 4 | import android.app.PendingIntent; 5 | import android.app.PictureInPictureParams; 6 | import android.app.RemoteAction; 7 | import android.content.BroadcastReceiver; 8 | import android.content.Context; 9 | import android.content.Intent; 10 | import android.content.IntentFilter; 11 | import android.content.res.Configuration; 12 | import android.graphics.BitmapFactory; 13 | import android.graphics.drawable.Icon; 14 | import android.net.Uri; 15 | import android.os.Build; 16 | import android.os.Bundle; 17 | import android.util.Log; 18 | import android.util.Rational; 19 | import android.widget.ImageView; 20 | import androidx.annotation.Nullable; 21 | import androidx.annotation.RequiresApi; 22 | import moe.feng.nevo.decorators.enscreenshot.utils.Executors; 23 | import moe.feng.nevo.decorators.enscreenshot.utils.ScreenUtils; 24 | 25 | import java.io.FileNotFoundException; 26 | import java.io.InputStream; 27 | import java.util.ArrayList; 28 | import java.util.List; 29 | import java.util.concurrent.CompletableFuture; 30 | 31 | @RequiresApi(Build.VERSION_CODES.O) 32 | public class PreviewActivity extends Activity { 33 | 34 | public static final String EXTRA_SHARE_INTENT = BuildConfig.APPLICATION_ID + ".extra.SHARE_INTENT"; 35 | public static final String EXTRA_DELETE_INTENT = BuildConfig.APPLICATION_ID + ".extra.DELETE_INTENT"; 36 | public static final String EXTRA_EDIT_INTENT = BuildConfig.APPLICATION_ID + ".extra.EDIT_INTENT"; 37 | public static final String EXTRA_NOTIFICATION_KEY = BuildConfig.APPLICATION_ID + ".extra.NOTIFICATION_KEY"; 38 | 39 | public static final String ACTION_SHARE = BuildConfig.APPLICATION_ID + ".action.PREVIEW_ACTION_SHARE"; 40 | public static final String ACTION_DELETE = BuildConfig.APPLICATION_ID + ".action.PREVIEW_ACTION_DELETE"; 41 | public static final String ACTION_EDIT = BuildConfig.APPLICATION_ID + ".action.PREVIEW_ACTION_EDIT"; 42 | 43 | private static final String TAG = "PreviewActivity"; 44 | 45 | private PictureInPictureParams mPIPParams; 46 | 47 | private ImageView mImageView; 48 | 49 | private Uri mImageUri; 50 | private PendingIntent mShareIntent, mDeleteIntent, mEditIntent; 51 | private String mNotificationKey; 52 | 53 | private CompletableFuture mImageLoadFuture; 54 | 55 | private final RemoteActionReceiver mRemoteActionReceiver = new RemoteActionReceiver(); 56 | 57 | @Override 58 | protected void onCreate(Bundle savedInstanceState) { 59 | super.onCreate(savedInstanceState); 60 | 61 | final Intent intent = getIntent(); 62 | if (intent == null || intent.getData() == null) { 63 | Log.e(TAG, "Intent is null."); 64 | if (!isFinishing()) { 65 | finish(); 66 | } 67 | return; 68 | } 69 | mImageUri = intent.getData(); 70 | mShareIntent = intent.getParcelableExtra(EXTRA_SHARE_INTENT); 71 | mDeleteIntent = intent.getParcelableExtra(EXTRA_DELETE_INTENT); 72 | mEditIntent = intent.getParcelableExtra(EXTRA_EDIT_INTENT); 73 | mNotificationKey = intent.getStringExtra(EXTRA_NOTIFICATION_KEY); 74 | 75 | setContentView(R.layout.layout_preview); 76 | 77 | mImageView = findViewById(R.id.image_view); 78 | 79 | if (mPIPParams == null) { 80 | updatePictureInPictureParams(); 81 | } 82 | 83 | if (!isInPictureInPictureMode()) { 84 | enterPictureInPictureMode(mPIPParams); 85 | } 86 | 87 | loadImage(); 88 | 89 | final IntentFilter intentFilter = new IntentFilter(); 90 | intentFilter.addAction(ACTION_SHARE); 91 | intentFilter.addAction(ACTION_DELETE); 92 | intentFilter.addAction(ACTION_EDIT); 93 | registerReceiver(mRemoteActionReceiver, intentFilter); 94 | } 95 | 96 | private void loadImage() { 97 | mImageView.setImageBitmap(null); 98 | 99 | InputStream input = null; 100 | if (mImageUri.toString().startsWith("content://")) { 101 | try { 102 | input = getContentResolver().openInputStream(mImageUri); 103 | } catch (FileNotFoundException e) { 104 | e.printStackTrace(); 105 | } 106 | } else { 107 | throw new IllegalArgumentException("Unsupported uri: " + mImageUri); 108 | } 109 | 110 | if (input == null) { 111 | Log.e(TAG, "Cannot open input stream for " + mImageUri); 112 | if (!isFinishing()) { 113 | finish(); 114 | } 115 | return; 116 | } 117 | 118 | final InputStream is = input; 119 | if (mImageLoadFuture != null) { 120 | try { 121 | mImageLoadFuture.cancel(true); 122 | } catch (Exception ignored) { 123 | 124 | } 125 | } 126 | mImageLoadFuture = CompletableFuture.supplyAsync(() -> BitmapFactory.decodeStream(is)) 127 | .whenCompleteAsync((bitmap, err) -> { 128 | if (err != null) { 129 | err.printStackTrace(); 130 | if (!isFinishing()) { 131 | finish(); 132 | } 133 | return; 134 | } 135 | updatePictureInPictureParams(new Rational(bitmap.getWidth(), bitmap.getHeight())); 136 | mImageView.setImageBitmap(bitmap); 137 | }, Executors.mainThread()); 138 | } 139 | 140 | @Override 141 | protected void onDestroy() { 142 | Log.d(TAG, "PreviewActivity: onDestroy"); 143 | super.onDestroy(); 144 | if (mImageLoadFuture != null) { 145 | mImageLoadFuture.cancel(true); 146 | } 147 | sendBroadcast(new Intent(ScreenshotDecorator.ACTION_CANCEL_NOTIFICATION) 148 | .putExtra("key", mNotificationKey)); 149 | try { 150 | unregisterReceiver(mRemoteActionReceiver); 151 | } catch (Exception ignored) { 152 | 153 | } 154 | } 155 | 156 | @Override 157 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) { 158 | if (!isInPictureInPictureMode) { 159 | final Intent intent = new Intent(Intent.ACTION_VIEW); 160 | intent.setDataAndType(mImageUri, "image/*"); 161 | startActivity(intent); 162 | if (!isFinishing()) { 163 | finish(); 164 | } 165 | } 166 | } 167 | 168 | private void updatePictureInPictureParams() { 169 | updatePictureInPictureParams(null); 170 | } 171 | 172 | private synchronized void updatePictureInPictureParams(@Nullable Rational aspect) { 173 | if (aspect == null) { 174 | aspect = ScreenUtils.getDefaultDisplayRational(this); 175 | } 176 | 177 | final List remoteActions = new ArrayList<>(); 178 | 179 | if (mShareIntent != null) { 180 | final RemoteAction shareAction = new RemoteAction( 181 | Icon.createWithResource(this, R.drawable.ic_share_white_24dp), 182 | getString(R.string.action_share_screenshot), 183 | getString(R.string.action_share_screenshot), 184 | PendingIntent.getBroadcast(this, 0, 185 | new Intent(ACTION_SHARE), PendingIntent.FLAG_UPDATE_CURRENT) 186 | ); 187 | remoteActions.add(shareAction); 188 | } 189 | 190 | if (mDeleteIntent != null) { 191 | final RemoteAction deleteAction = new RemoteAction( 192 | Icon.createWithResource(this, R.drawable.ic_delete_white_24dp), 193 | getString(R.string.action_delete_screenshot), 194 | getString(R.string.action_delete_screenshot), 195 | PendingIntent.getBroadcast(this, 0, 196 | new Intent(ACTION_DELETE), PendingIntent.FLAG_UPDATE_CURRENT) 197 | ); 198 | remoteActions.add(deleteAction); 199 | } 200 | 201 | if (mEditIntent != null) { 202 | final RemoteAction editAction = new RemoteAction( 203 | Icon.createWithResource(this, R.drawable.ic_edit_white_24dp), 204 | getString(R.string.action_edit), 205 | getString(R.string.action_edit), 206 | PendingIntent.getBroadcast(this, 0, 207 | new Intent(ACTION_EDIT), PendingIntent.FLAG_UPDATE_CURRENT) 208 | ); 209 | remoteActions.add(editAction); 210 | } 211 | 212 | mPIPParams = new PictureInPictureParams.Builder() 213 | .setAspectRatio(aspect) 214 | .setActions(remoteActions) 215 | .build(); 216 | 217 | if (isInPictureInPictureMode()) { 218 | setPictureInPictureParams(mPIPParams); 219 | } 220 | } 221 | 222 | private final class RemoteActionReceiver extends BroadcastReceiver { 223 | 224 | private static final String TAG = "RemoteActionReceiver"; 225 | 226 | @Override 227 | public void onReceive(Context context, Intent intent) { 228 | if (intent == null || intent.getAction() == null) { 229 | Log.e(TAG, "onReceive intent should not be null and contain an action."); 230 | return; 231 | } 232 | 233 | switch (intent.getAction()) { 234 | case ACTION_SHARE: { 235 | try { 236 | mShareIntent.send(); 237 | if (!isFinishing()) { 238 | finish(); 239 | } 240 | } catch (PendingIntent.CanceledException e) { 241 | e.printStackTrace(); 242 | } 243 | break; 244 | } 245 | case ACTION_DELETE: { 246 | try { 247 | mDeleteIntent.send(); 248 | if (!isFinishing()) { 249 | finish(); 250 | } 251 | } catch (PendingIntent.CanceledException e) { 252 | e.printStackTrace(); 253 | } 254 | break; 255 | } 256 | case ACTION_EDIT: { 257 | try { 258 | mEditIntent.send(); 259 | if (!isFinishing()) { 260 | finish(); 261 | } 262 | } catch (PendingIntent.CanceledException e) { 263 | e.printStackTrace(); 264 | } 265 | break; 266 | } 267 | } 268 | } 269 | 270 | } 271 | 272 | } 273 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/PreviewSettingsActivity.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.content.Intent; 6 | import android.content.pm.PackageManager; 7 | import android.os.Build; 8 | import android.os.Bundle; 9 | import android.view.MenuItem; 10 | import android.widget.LinearLayout; 11 | import android.widget.RadioButton; 12 | import androidx.annotation.NonNull; 13 | import androidx.annotation.Nullable; 14 | import moe.feng.nevo.decorators.enscreenshot.utils.PermissionUtils; 15 | import moe.feng.nevo.decorators.enscreenshot.widget.SwitchBar; 16 | 17 | import java.util.Objects; 18 | 19 | import static moe.feng.nevo.decorators.enscreenshot.ScreenshotPreferences.PREVIEW_TYPE_ARISU; 20 | import static moe.feng.nevo.decorators.enscreenshot.ScreenshotPreferences.PREVIEW_TYPE_NONE; 21 | import static moe.feng.nevo.decorators.enscreenshot.ScreenshotPreferences.PREVIEW_TYPE_PIP; 22 | 23 | public class PreviewSettingsActivity extends Activity implements SwitchBar.OnCheckedChangeListener { 24 | 25 | private static final int REQUEST_CODE_OVERLAY_PERMISSION = 1; 26 | 27 | private ScreenshotPreferences mPreferences; 28 | 29 | private SwitchBar mSwitchBar; 30 | private RadioButton mArisuRadio, mPiPRadio; 31 | private LinearLayout mArisuLayout, mPiPLayout; 32 | 33 | @Override 34 | protected void onCreate(@Nullable Bundle savedInstanceState) { 35 | mPreferences = new ScreenshotPreferences(this); 36 | 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.activity_preview_settings); 39 | 40 | Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true); 41 | 42 | mSwitchBar = findViewById(R.id.switch_bar); 43 | mArisuRadio = findViewById(R.id.radio_button_arisu_mode); 44 | mPiPRadio = findViewById(R.id.radio_button_pip_mode); 45 | mArisuLayout = findViewById(R.id.choice_arisu_mode); 46 | mPiPLayout = findViewById(R.id.choice_pip_mode); 47 | 48 | mSwitchBar.setOnCheckedChangeListener(this); 49 | mArisuLayout.setOnClickListener(v -> { 50 | if (!PermissionUtils.canDrawOverlays(this)) { 51 | PermissionUtils.requestOverlayPermission(this, REQUEST_CODE_OVERLAY_PERMISSION); 52 | return; 53 | } 54 | mArisuRadio.setChecked(true); 55 | mPiPRadio.setChecked(false); 56 | mPreferences.setPreviewType(PREVIEW_TYPE_ARISU); 57 | }); 58 | mPiPLayout.setOnClickListener(v -> { 59 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || 60 | !getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) { 61 | new AlertDialog.Builder(this) 62 | .setMessage(R.string.pref_preview_in_floating_window_summary_unsupported) 63 | .setNegativeButton(android.R.string.ok, null) 64 | .show(); 65 | return; 66 | } 67 | mArisuRadio.setChecked(false); 68 | mPiPRadio.setChecked(true); 69 | mPreferences.setPreviewType(PREVIEW_TYPE_PIP); 70 | }); 71 | 72 | if (savedInstanceState == null) { 73 | mSwitchBar.setChecked(mPreferences.getPreviewType() != PREVIEW_TYPE_NONE); 74 | } 75 | 76 | mArisuRadio.setChecked(mPreferences.getPreviewType() == PREVIEW_TYPE_ARISU); 77 | mPiPRadio.setChecked(mPreferences.getPreviewType() == PREVIEW_TYPE_PIP); 78 | 79 | setChoicesEnabled(mSwitchBar.isChecked()); 80 | } 81 | 82 | private void setChoicesEnabled(boolean enabled) { 83 | mArisuLayout.setEnabled(enabled); 84 | mPiPLayout.setEnabled(enabled); 85 | } 86 | 87 | @Override 88 | public void onBackPressed() { 89 | if (mSwitchBar.isChecked() && mPreferences.getPreviewType() == PREVIEW_TYPE_NONE) { 90 | new AlertDialog.Builder(this) 91 | .setMessage(R.string.pref_preview_type_dialog_not_save) 92 | .setPositiveButton(android.R.string.yes, (dialog, which) -> super.onBackPressed()) 93 | .setNegativeButton(android.R.string.no, null) 94 | .show(); 95 | return; 96 | } 97 | super.onBackPressed(); 98 | } 99 | 100 | @Override 101 | public boolean onOptionsItemSelected(MenuItem item) { 102 | if (item.getItemId() == android.R.id.home) { 103 | onBackPressed(); 104 | return true; 105 | } 106 | return super.onOptionsItemSelected(item); 107 | } 108 | 109 | @Override 110 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 111 | if (REQUEST_CODE_OVERLAY_PERMISSION == requestCode && RESULT_OK == resultCode) { 112 | if (PermissionUtils.canDrawOverlays(this)) { 113 | mArisuLayout.performClick(); 114 | } 115 | } 116 | } 117 | 118 | @Override 119 | public void onCheckedChanged(@NonNull SwitchBar view, boolean isChecked) { 120 | if (isChecked) { 121 | if (mPreferences.getPreviewType() == PREVIEW_TYPE_NONE) { 122 | mPiPRadio.setChecked(false); 123 | mArisuRadio.setChecked(false); 124 | } 125 | setChoicesEnabled(true); 126 | } else { 127 | mPiPRadio.setChecked(false); 128 | mArisuRadio.setChecked(false); 129 | mSwitchBar.setChecked(false); 130 | setChoicesEnabled(false); 131 | mPreferences.setPreviewType(PREVIEW_TYPE_NONE); 132 | } 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/ScreenshotDecoratorSettingsReceiver.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import androidx.annotation.NonNull; 7 | import androidx.annotation.Nullable; 8 | import moe.feng.nevo.decorators.enscreenshot.utils.IntentUtils; 9 | 10 | public class ScreenshotDecoratorSettingsReceiver extends BroadcastReceiver { 11 | 12 | @Override 13 | public void onReceive(@NonNull Context context, @Nullable Intent intent) { 14 | context.startActivity(new Intent(context, PreferencesActivity.class) 15 | .setAction(Intent.ACTION_APPLICATION_PREFERENCES) 16 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 17 | IntentUtils.closeSystemDialogs(context); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/ScreenshotPreferences.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | import android.content.ComponentName; 4 | import android.content.Context; 5 | import android.content.pm.PackageManager; 6 | import android.graphics.drawable.Drawable; 7 | import android.os.Environment; 8 | import android.os.LocaleList; 9 | import android.text.TextUtils; 10 | 11 | import androidx.annotation.IntDef; 12 | import moe.feng.nevo.decorators.enscreenshot.utils.FormatUtils; 13 | import net.grandcentrix.tray.TrayPreferences; 14 | 15 | import java.io.File; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.util.Objects; 19 | import java.util.Optional; 20 | 21 | import androidx.annotation.NonNull; 22 | import androidx.annotation.Nullable; 23 | 24 | public final class ScreenshotPreferences { 25 | 26 | public static final int SHARE_EVOLVE_TYPE_NONE = 0; 27 | public static final int SHARE_EVOLVE_TYPE_DISMISS_AFTER_SHARING = 1; 28 | public static final int SHARE_EVOLVE_TYPE_DELETE_SCREENSHOT = 2; 29 | 30 | @IntDef({ SHARE_EVOLVE_TYPE_NONE, 31 | SHARE_EVOLVE_TYPE_DISMISS_AFTER_SHARING, SHARE_EVOLVE_TYPE_DELETE_SCREENSHOT }) 32 | @Retention(RetentionPolicy.SOURCE) 33 | public @interface ShareEvolveType {} 34 | 35 | public static final int PREVIEW_TYPE_NONE = 0; 36 | public static final int PREVIEW_TYPE_PIP = 1; 37 | public static final int PREVIEW_TYPE_ARISU = 2; 38 | 39 | @IntDef({ PREVIEW_TYPE_NONE, PREVIEW_TYPE_PIP, PREVIEW_TYPE_ARISU }) 40 | @Retention(RetentionPolicy.SOURCE) 41 | public @interface PreviewType {} 42 | 43 | private static final String PREF_NAME = "screenshot"; 44 | 45 | private static final String KEY_SCREENSHOT_PATH = "screenshot_path"; 46 | private static final String KEY_PREFERRED_EDITOR_COMPONENT = "preferred_component"; 47 | private static final String KEY_SHARE_EVOLVE_TYPE = "share_evolve_type"; 48 | private static final String KEY_EDIT_ACTION_TEXT_FORMAT = "edit_action_text_format"; 49 | private static final String KEY_SHOW_SCREENSHOTS_COUNT = "show_screenshots_count"; 50 | private static final String KEY_SHOW_SCREENSHOT_DETAILS = "show_screenshot_details"; 51 | private static final String KEY_PREVIEW_FLOATING_WINDOW_TYPE = "preview_floating_window_type"; 52 | private static final String KEY_REPLACE_NOTIFICATION_WITH_PREVIEW = "replace_notification_with_preview"; 53 | private static final String KEY_DETECT_BARCODE = "detect_barcode"; 54 | 55 | private static final File DEFAULT_SCREENSHOT_PATH = 56 | new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), 57 | "Screenshots"); 58 | 59 | private static final ComponentName LAUNCH_COMPONENT_NAME = 60 | ComponentName.createRelative(BuildConfig.APPLICATION_ID, ".LaunchActivity"); 61 | 62 | private final TrayPreferences mPreferences; 63 | private final PackageManager mPackageManager; 64 | 65 | public ScreenshotPreferences(@NonNull Context context) { 66 | mPreferences = new TrayPreferences(context, PREF_NAME, 1); 67 | mPackageManager = context.getPackageManager(); 68 | } 69 | 70 | @NonNull 71 | public String getScreenshotPath() { 72 | return Optional.ofNullable(mPreferences.getString(KEY_SCREENSHOT_PATH, null)) 73 | .orElse(DEFAULT_SCREENSHOT_PATH.getAbsolutePath()); 74 | } 75 | 76 | public Optional getPreferredEditorComponentName() { 77 | final String value = mPreferences.getString(KEY_PREFERRED_EDITOR_COMPONENT, null); 78 | if (TextUtils.isEmpty(value)) { 79 | return Optional.empty(); 80 | } 81 | return Optional.ofNullable(ComponentName.unflattenFromString(value)); 82 | } 83 | 84 | public boolean isPreferredEditorAvailable() { 85 | final Optional cn = getPreferredEditorComponentName(); 86 | if (cn.isPresent()) { 87 | try { 88 | if (Objects.equals( 89 | mPackageManager.getPackageInfo( 90 | cn.get().getPackageName(), 0).packageName, 91 | cn.get().getPackageName())) { 92 | return true; 93 | } 94 | } catch (PackageManager.NameNotFoundException ignored) { 95 | 96 | } 97 | } 98 | return false; 99 | } 100 | 101 | public Optional getPreferredEditorTitle() { 102 | final Optional cn = getPreferredEditorComponentName(); 103 | if (cn.isPresent()) { 104 | try { 105 | return Optional.of( 106 | mPackageManager.getActivityInfo(cn.get(), PackageManager.GET_META_DATA) 107 | .loadLabel(mPackageManager)); 108 | } catch (PackageManager.NameNotFoundException ignored) { 109 | 110 | } 111 | } 112 | return Optional.empty(); 113 | } 114 | 115 | public Optional getPreferredEditorIcon() { 116 | final Optional cn = getPreferredEditorComponentName(); 117 | if (cn.isPresent()) { 118 | try { 119 | return Optional.of( 120 | mPackageManager.getActivityInfo(cn.get(), PackageManager.GET_META_DATA) 121 | .loadUnbadgedIcon(mPackageManager)); 122 | } catch (PackageManager.NameNotFoundException ignored) { 123 | 124 | } 125 | } 126 | return Optional.empty(); 127 | } 128 | 129 | public boolean isHideLauncherIcon() { 130 | return mPackageManager.getComponentEnabledSetting(LAUNCH_COMPONENT_NAME) 131 | == PackageManager.COMPONENT_ENABLED_STATE_DISABLED; 132 | } 133 | 134 | @ShareEvolveType 135 | public int getShareEvolveType() { 136 | return mPreferences.getInt(KEY_SHARE_EVOLVE_TYPE, SHARE_EVOLVE_TYPE_NONE); 137 | } 138 | 139 | @NonNull 140 | public String getEditActionTextFormat() { 141 | return Optional.ofNullable(mPreferences.getString(KEY_EDIT_ACTION_TEXT_FORMAT, null)) 142 | .orElseGet(() -> FormatUtils.getEditActionTextFormats(LocaleList.getDefault()).second.get(1)); 143 | } 144 | 145 | public boolean isShowScreenshotsCount() { 146 | return mPreferences.getBoolean(KEY_SHOW_SCREENSHOTS_COUNT, false); 147 | } 148 | 149 | public boolean isShowScreenshotDetails() { 150 | return mPreferences.getBoolean(KEY_SHOW_SCREENSHOT_DETAILS, false); 151 | } 152 | 153 | @PreviewType 154 | public int getPreviewType() { 155 | return mPreferences.getInt(KEY_PREVIEW_FLOATING_WINDOW_TYPE, PREVIEW_TYPE_NONE); 156 | } 157 | 158 | public boolean isReplaceNotificationWithPreview() { 159 | return mPreferences.getBoolean(KEY_REPLACE_NOTIFICATION_WITH_PREVIEW, false); 160 | } 161 | 162 | public boolean shouldDetectBarcode() { 163 | return mPreferences.getBoolean(KEY_DETECT_BARCODE, false); 164 | } 165 | 166 | public void setScreenshotPath(@Nullable String screenshotPath) { 167 | if (screenshotPath == null) { 168 | mPreferences.remove(KEY_SCREENSHOT_PATH); 169 | } else { 170 | mPreferences.put(KEY_SCREENSHOT_PATH, screenshotPath); 171 | } 172 | } 173 | 174 | public void setPreferredEditorComponentName(@Nullable ComponentName componentName) { 175 | if (componentName == null) { 176 | mPreferences.remove(KEY_PREFERRED_EDITOR_COMPONENT); 177 | } else { 178 | mPreferences.put(KEY_PREFERRED_EDITOR_COMPONENT, componentName.flattenToString()); 179 | } 180 | } 181 | 182 | public void setHideLauncherIcon(boolean shouldHide) { 183 | mPackageManager.setComponentEnabledSetting( 184 | LAUNCH_COMPONENT_NAME, 185 | shouldHide ? 186 | PackageManager.COMPONENT_ENABLED_STATE_DISABLED 187 | : PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 188 | PackageManager.DONT_KILL_APP); 189 | } 190 | 191 | public void setShareEvolveType(@ShareEvolveType int type) { 192 | mPreferences.put(KEY_SHARE_EVOLVE_TYPE, type); 193 | } 194 | 195 | public void setEditActionTextFormat(@NonNull String format) { 196 | mPreferences.put(KEY_EDIT_ACTION_TEXT_FORMAT, format); 197 | } 198 | 199 | public void setShowScreenshotsCount(boolean bool) { 200 | mPreferences.put(KEY_SHOW_SCREENSHOTS_COUNT, bool); 201 | } 202 | 203 | public void setShowScreenshotDetails(boolean bool) { 204 | mPreferences.put(KEY_SHOW_SCREENSHOT_DETAILS, bool); 205 | } 206 | 207 | public void setPreviewType(@PreviewType int type) { 208 | mPreferences.put(KEY_PREVIEW_FLOATING_WINDOW_TYPE, type); 209 | } 210 | 211 | public void setReplaceNotificationWithPreview(boolean bool) { 212 | mPreferences.put(KEY_REPLACE_NOTIFICATION_WITH_PREVIEW, bool); 213 | } 214 | 215 | public void setDetectBarcode(boolean bool) { 216 | mPreferences.put(KEY_DETECT_BARCODE, bool); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/SupportUsDialog.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | import android.app.AlertDialog; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.pm.PackageInfo; 7 | import android.content.pm.PackageManager; 8 | import android.net.Uri; 9 | import android.util.Log; 10 | import androidx.annotation.NonNull; 11 | import androidx.core.text.HtmlCompat; 12 | import moe.feng.nevo.decorators.enscreenshot.utils.IntentUtils; 13 | 14 | public final class SupportUsDialog { 15 | 16 | private static final String ALIPAY_PACKAGE_NAME = "com.eg.android.AlipayGphone"; 17 | 18 | private static final String TAG = "SupportUsDialog"; 19 | 20 | public static boolean hasInstalledAlipayClient(@NonNull Context context) { 21 | final PackageManager pm = context.getPackageManager(); 22 | try { 23 | final PackageInfo info = pm.getPackageInfo(ALIPAY_PACKAGE_NAME, PackageManager.MATCH_DISABLED_COMPONENTS); 24 | return info != null; 25 | } catch (PackageManager.NameNotFoundException e) { 26 | return false; 27 | } 28 | } 29 | 30 | public static void start(@NonNull Context context) { 31 | if (BuildConfig.DEBUG) { 32 | Log.i(TAG, "BuildConfig.SHOW_ALIPAY_ALWAYS: " + BuildConfig.SHOW_ALIPAY_ALWAYS); 33 | Log.i(TAG, "hasInstalledAlipayClient: " + hasInstalledAlipayClient(context)); 34 | } 35 | final boolean shouldShowAlipay = BuildConfig.SHOW_ALIPAY_ALWAYS || hasInstalledAlipayClient(context); 36 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); 37 | builder.setTitle(R.string.support_us_dialog_title); 38 | builder.setMessage(HtmlCompat.fromHtml(context.getString(shouldShowAlipay ? 39 | R.string.support_us_dialog_message : R.string.support_us_dialog_message_play_store), 0)); 40 | builder.setPositiveButton(R.string.rate_us, (dialog, which) -> { 41 | context.startActivity(IntentUtils.createViewIntent( 42 | Uri.parse("https://play.google.com/store/apps/details?id=moe.feng.nevo.decorators.enscreenshot") 43 | ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 44 | }); 45 | builder.setNegativeButton(android.R.string.cancel, null); 46 | if (shouldShowAlipay) { 47 | builder.setNeutralButton(R.string.donate, (dialog, which) -> startAlipayDonateDialog(context)); 48 | } 49 | builder.show(); 50 | } 51 | 52 | public static void startAlipayDonateDialog(@NonNull Context context) { 53 | new AlertDialog.Builder(context) 54 | .setTitle(R.string.alipay_dialog_title) 55 | .setMessage(R.string.alipay_dialog_message) 56 | .setPositiveButton(R.string.alipay_installed_button, (dialog, which) -> { 57 | context.startActivity(IntentUtils.createViewIntent( 58 | Uri.parse(BuildConfig.ALIPAY_SUPPORT_URL) 59 | ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 60 | }) 61 | .setNegativeButton(android.R.string.cancel, null) 62 | .show(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/ViewBarcodeActivity.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot; 2 | 3 | import android.app.Activity; 4 | import android.app.AlertDialog; 5 | import android.app.Dialog; 6 | import android.app.DialogFragment; 7 | import android.content.DialogInterface; 8 | import android.content.Intent; 9 | import android.os.Bundle; 10 | import android.util.Log; 11 | import androidx.annotation.NonNull; 12 | import androidx.annotation.Nullable; 13 | import androidx.recyclerview.widget.RecyclerView; 14 | import com.google.android.gms.vision.barcode.Barcode; 15 | import moe.feng.nevo.decorators.enscreenshot.widget.DividerItemDecoration; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import java.util.Objects; 20 | 21 | public class ViewBarcodeActivity extends Activity { 22 | 23 | public static final String ACTION = "moe.feng.intent.action.VIEW_BARCODE"; 24 | 25 | public static final String EXTRA_BARCODE = "moe.feng.intent.extra.BARCODE"; 26 | 27 | private static final String TAG = ViewBarcodeActivity.class.getSimpleName(); 28 | 29 | @Override 30 | protected void onCreate(@Nullable Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | 33 | final Intent intent = getIntent(); 34 | if (intent == null || !ACTION.equals(intent.getAction()) || !intent.hasExtra(EXTRA_BARCODE)) { 35 | Log.e(TAG, "Received Intent is not valid."); 36 | finish(); 37 | return; 38 | } 39 | 40 | List barcodeList = intent.getParcelableArrayListExtra(EXTRA_BARCODE); 41 | if (barcodeList.isEmpty()) { 42 | Log.e(TAG, "No Barcode"); 43 | finish(); 44 | return; 45 | } 46 | 47 | if (savedInstanceState == null) { 48 | ViewBarcodeDialog.newInstance(barcodeList) 49 | .show(getFragmentManager(), ViewBarcodeDialog.class.getSimpleName()); 50 | } 51 | } 52 | 53 | public static class ViewBarcodeDialog extends DialogFragment { 54 | 55 | public static ViewBarcodeDialog newInstance(@NonNull List data) { 56 | final Bundle args = new Bundle(); 57 | args.putParcelableArrayList(EXTRA_BARCODE, (ArrayList) data); 58 | final ViewBarcodeDialog dialog = new ViewBarcodeDialog(); 59 | dialog.setArguments(args); 60 | return dialog; 61 | } 62 | 63 | private final BarcodeListAdapter mAdapter = new BarcodeListAdapter(); 64 | 65 | private DividerItemDecoration mDividerDecoration; 66 | 67 | private List mData; 68 | 69 | @Override 70 | public void onCreate(Bundle savedInstanceState) { 71 | super.onCreate(savedInstanceState); 72 | 73 | mData = Objects.requireNonNull(getArguments()).getParcelableArrayList(EXTRA_BARCODE); 74 | mData.add(mData.get(0)); 75 | } 76 | 77 | @Override 78 | public Dialog onCreateDialog(Bundle savedInstanceState) { 79 | final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); 80 | builder.setTitle(R.string.action_view_barcode); 81 | builder.setView(R.layout.dialog_layout_view_barcode); 82 | builder.setNegativeButton(android.R.string.cancel, null); 83 | final AlertDialog dialog = builder.create(); 84 | dialog.setOnShowListener(this::onShow); 85 | return dialog; 86 | } 87 | 88 | public void onShow(DialogInterface dialogInterface) { 89 | final AlertDialog dialog = (AlertDialog) dialogInterface; 90 | final RecyclerView listView = dialog.findViewById(android.R.id.list); 91 | listView.setAdapter(mAdapter); 92 | if (mDividerDecoration == null) { 93 | mDividerDecoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL); 94 | mDividerDecoration.setDoNotDrawForLastItem(true); 95 | } 96 | listView.addItemDecoration(mDividerDecoration); 97 | mAdapter.submitList(mData); 98 | } 99 | 100 | @Override 101 | public void onDismiss(DialogInterface dialog) { 102 | super.onDismiss(dialog); 103 | getActivity().finish(); 104 | } 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/DeviceInfoPrinter.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import android.content.Context; 4 | import android.os.Build; 5 | import android.os.LocaleList; 6 | import android.util.DisplayMetrics; 7 | import androidx.annotation.NonNull; 8 | 9 | public final class DeviceInfoPrinter { 10 | 11 | private static final String FORMAT = "" + 12 | "Manufacturer: " + Build.MANUFACTURER + "\n" + 13 | "Model: " + Build.MODEL + "\n" + 14 | "Android Version: " + Build.VERSION.RELEASE + " (" + Build.VERSION.SDK_INT + ")\n" + 15 | "Screen resolution: " + "{screenWidth}*{screenHeight}" + "\n" + 16 | "Language: " + LocaleList.getDefault().toString() + "\n" + 17 | ""; 18 | 19 | public static final String DIVIDER = "---- Device information can help us easier to improve app ----\n"; 20 | 21 | private DeviceInfoPrinter() { 22 | throw new InstantiationError(); 23 | } 24 | 25 | @NonNull 26 | public static String print(@NonNull Context context) { 27 | final DisplayMetrics realDm = ScreenUtils.getDefaultDisplayRealMetrics(context); 28 | 29 | final String result = FORMAT.replace("{screenWidth}", String.valueOf(realDm.widthPixels)) 30 | .replace("{screenHeight}", String.valueOf(realDm.heightPixels)); 31 | 32 | return result; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/Executors.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import android.os.Build; 4 | import android.os.Handler; 5 | import android.os.Looper; 6 | 7 | import java.util.concurrent.Executor; 8 | 9 | import android.os.Message; 10 | import androidx.annotation.NonNull; 11 | 12 | public final class Executors { 13 | 14 | private static final Executor MAIN_THREAD_EXECUTOR = new AsyncLooperExecutor(Looper.getMainLooper()); 15 | 16 | @NonNull 17 | public static Executor mainThread() { 18 | return MAIN_THREAD_EXECUTOR; 19 | } 20 | 21 | private Executors() { 22 | throw new InstantiationError("Cannot instantiate class Executors"); 23 | } 24 | 25 | private static final class AsyncLooperExecutor implements Executor { 26 | 27 | private final Handler mHandler; 28 | 29 | AsyncLooperExecutor(@NonNull Looper looper) { 30 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 31 | mHandler = Handler.createAsync(looper); 32 | } else { 33 | mHandler = new Handler(looper); 34 | } 35 | } 36 | 37 | @Override 38 | public void execute(@NonNull Runnable command) { 39 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { 40 | mHandler.post(command); 41 | } else { 42 | Message message = Message.obtain(mHandler, command); 43 | message.setAsynchronous(true); 44 | mHandler.sendMessage(message); 45 | } 46 | } 47 | 48 | } 49 | 50 | public static class HandlerExecutor implements Executor { 51 | 52 | private final Handler mHandler; 53 | 54 | public HandlerExecutor(@NonNull Handler handler) { 55 | mHandler = handler; 56 | } 57 | 58 | @Override 59 | public void execute(@NonNull Runnable command) { 60 | mHandler.post(command); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.net.Uri; 7 | import android.provider.MediaStore; 8 | import android.util.Log; 9 | import android.webkit.MimeTypeMap; 10 | import androidx.annotation.NonNull; 11 | import androidx.annotation.Nullable; 12 | 13 | import java.io.File; 14 | import java.io.FileInputStream; 15 | import java.io.FileOutputStream; 16 | import java.io.IOException; 17 | import java.nio.channels.FileChannel; 18 | import java.util.Optional; 19 | 20 | public final class FileUtils { 21 | 22 | private static final MimeTypeMap sMimeTypeMap = MimeTypeMap.getSingleton(); 23 | 24 | private FileUtils() { 25 | throw new InstantiationError("Cannot instantiate class FileUtils"); 26 | } 27 | 28 | public static boolean ensureDirectory(@NonNull File dir) { 29 | if (dir.isFile() && !dir.delete()) { 30 | return false; 31 | } else if (dir.isDirectory()) { 32 | return true; 33 | } 34 | return dir.mkdirs(); 35 | } 36 | 37 | public static boolean moveFile(@NonNull File source, @NonNull File target) { 38 | try { 39 | if (source.renameTo(target)) { 40 | return true; 41 | } 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | } 45 | 46 | if (!target.exists()) { 47 | try { 48 | target.createNewFile(); 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | try (FileChannel outputChannel = new FileOutputStream(target).getChannel(); 54 | FileChannel inputChannel = new FileInputStream(source).getChannel()) { 55 | inputChannel.transferTo(0, inputChannel.size(), outputChannel); 56 | } catch (IOException ignored) { 57 | return false; 58 | } 59 | if (!source.delete()) { 60 | Log.d("FileUtils", "source failed to delete"); 61 | } 62 | return true; 63 | } 64 | 65 | @Nullable 66 | public static String getMimeTypeFromFile(@NonNull File file) { 67 | return sMimeTypeMap.getMimeTypeFromExtension(getExtensionFromFileName(file.getName())); 68 | } 69 | 70 | @Nullable 71 | public static String getMimeTypeFromFileName(@NonNull String file) { 72 | return sMimeTypeMap.getMimeTypeFromExtension(getExtensionFromFileName(file)); 73 | } 74 | 75 | @Nullable 76 | public static String getExtensionFromFileName(@NonNull String name) { 77 | if (name.contains(".")) { 78 | return name.substring(name.lastIndexOf(".") + 1); 79 | } 80 | return null; 81 | } 82 | 83 | @Nullable 84 | public static Uri getImageContentUri(@NonNull Context context, @NonNull File imageFile) { 85 | String filePath = imageFile.getAbsolutePath(); 86 | try (Cursor cursor = context.getContentResolver().query( 87 | MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 88 | new String[] { MediaStore.Images.Media._ID }, 89 | MediaStore.Images.Media.DATA + "=? ", 90 | new String[] { filePath }, null)) { 91 | if (cursor != null && cursor.moveToFirst()) { 92 | int id = cursor.getInt(cursor 93 | .getColumnIndex(MediaStore.MediaColumns._ID)); 94 | Uri baseUri = Uri.parse("content://media/external/images/media"); 95 | return Uri.withAppendedPath(baseUri, "" + id); 96 | } else { 97 | if (imageFile.exists()) { 98 | ContentValues values = new ContentValues(); 99 | values.put(MediaStore.Images.Media.DATA, filePath); 100 | return context.getContentResolver().insert( 101 | MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 102 | } else { 103 | return null; 104 | } 105 | } 106 | } 107 | } 108 | 109 | @Nullable 110 | public static File backupScreenshot(@NonNull Context context, @NonNull File file) { 111 | final File screenshotDir = new File(context.getCacheDir(), "screenshot"); 112 | final File backupFile = new File(screenshotDir, file.getName()); 113 | 114 | // Clear old files 115 | for (File oldFile : Optional.ofNullable(screenshotDir.listFiles()).orElse(new File[0])) { 116 | if (!oldFile.delete()) { 117 | Log.d("FileUtils", "Failed to delete " + oldFile.getAbsolutePath()); 118 | } 119 | } 120 | 121 | // Start backup for sharing 122 | if (backupFile.exists() && !backupFile.delete()) { 123 | return null; 124 | } else if (!FileUtils.ensureDirectory(screenshotDir)) { 125 | return null; 126 | } else if (FileUtils.moveFile(file, backupFile)) { 127 | return backupFile; 128 | } else { 129 | return null; 130 | } 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/FormatUtils.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import android.os.LocaleList; 4 | import android.util.Pair; 5 | import androidx.annotation.NonNull; 6 | 7 | import java.util.*; 8 | 9 | public final class FormatUtils { 10 | 11 | private static final Map> sEditActionTextFormats = new HashMap<>(); 12 | 13 | static { 14 | sEditActionTextFormats.put( 15 | Locale.ENGLISH, 16 | Arrays.asList("Edit", "Edit in %s", "%s") 17 | ); 18 | sEditActionTextFormats.put( 19 | Locale.SIMPLIFIED_CHINESE, 20 | Arrays.asList("编辑", "在%s编辑", "在 %s 编辑", "%s") 21 | ); 22 | sEditActionTextFormats.put( 23 | Locale.TRADITIONAL_CHINESE, 24 | Arrays.asList("編輯", "在%s編輯", "在 %s 編輯", "%s") 25 | ); 26 | } 27 | 28 | @NonNull 29 | private static Locale chooseAvailableLocale(@NonNull Locale locale) { 30 | if (sEditActionTextFormats.containsKey(locale)) { 31 | return locale; 32 | } 33 | for (Locale loc : sEditActionTextFormats.keySet()) { 34 | if (loc.getLanguage().equals(locale.getLanguage())) { 35 | return loc; 36 | } 37 | } 38 | return Locale.ENGLISH; 39 | } 40 | 41 | @NonNull 42 | private static Locale chooseAvailableLocale(@NonNull LocaleList localeList) { 43 | for (int i = 0; i < localeList.size(); i++) { 44 | final Locale locale = localeList.get(i); 45 | if (sEditActionTextFormats.containsKey(locale)) { 46 | return locale; 47 | } 48 | for (Locale loc : sEditActionTextFormats.keySet()) { 49 | if (loc.getLanguage().equals(locale.getLanguage())) { 50 | return loc; 51 | } 52 | } 53 | } 54 | return Locale.ENGLISH; 55 | } 56 | 57 | @NonNull 58 | public static List getEditActionTextFormats(@NonNull Locale locale) { 59 | return Collections.unmodifiableList(sEditActionTextFormats.get(chooseAvailableLocale(locale))); 60 | } 61 | 62 | @NonNull 63 | public static Pair> getEditActionTextFormats(@NonNull LocaleList localeList) { 64 | final Locale actualLocale = chooseAvailableLocale(localeList); 65 | final List formats = Collections.unmodifiableList(sEditActionTextFormats.get(actualLocale)); 66 | return Pair.create(actualLocale, formats); 67 | } 68 | 69 | @NonNull 70 | public static String safeGetEditActionTextFormat(@NonNull Locale locale, int index) { 71 | final List formats = getEditActionTextFormats(locale); 72 | if (index >= formats.size()) { 73 | return formats.get(1); 74 | } else { 75 | return formats.get(index); 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/IntentUtils.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import android.content.ActivityNotFoundException; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | 8 | import android.provider.ContactsContract; 9 | import android.widget.Toast; 10 | import androidx.annotation.NonNull; 11 | import com.google.android.gms.vision.barcode.Barcode; 12 | import moe.feng.nevo.decorators.enscreenshot.R; 13 | import moe.feng.nevo.decorators.enscreenshot.ScreenshotDecorator; 14 | 15 | public final class IntentUtils { 16 | 17 | private IntentUtils() { 18 | throw new InstantiationError(); 19 | } 20 | 21 | public static void viewAppInMarket(@NonNull Context context, @NonNull String packageName) { 22 | try { 23 | context.startActivity( 24 | new Intent(Intent.ACTION_VIEW, Uri.parse( 25 | "market://details?id=" + packageName))); 26 | } catch (android.content.ActivityNotFoundException ignored) { 27 | try { 28 | context.startActivity( 29 | new Intent(Intent.ACTION_VIEW, Uri.parse( 30 | "https://play.google.com/store/apps/details?id=" + packageName))); 31 | } catch (ActivityNotFoundException e) { 32 | try { 33 | Toast.makeText(context, R.string.toast_activity_not_found, Toast.LENGTH_LONG).show(); 34 | } catch (Exception ignore) { 35 | 36 | } 37 | } 38 | } 39 | } 40 | 41 | public static Intent createViewIntent(@NonNull Uri uri) { 42 | return new Intent(Intent.ACTION_VIEW, uri); 43 | } 44 | 45 | public static Intent createDialIntent(@NonNull Uri uri) { 46 | return new Intent(Intent.ACTION_DIAL, uri); 47 | } 48 | 49 | public static Intent createMailSendToIntent(@NonNull String address, String subject, String text) { 50 | final Intent intent = new Intent(Intent.ACTION_SENDTO); 51 | intent.setData(Uri.parse("mailto:" + address)); 52 | intent.putExtra(Intent.EXTRA_EMAIL, address); 53 | intent.putExtra(Intent.EXTRA_SUBJECT, subject); 54 | intent.putExtra(Intent.EXTRA_TEXT, text); 55 | return intent; 56 | } 57 | 58 | public static void closeSystemDialogs(@NonNull Context context) { 59 | Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 60 | context.sendBroadcast(intent); 61 | } 62 | 63 | public static Intent createCopyIntent(@NonNull String text) { 64 | final Intent copyIntent = new Intent(); 65 | copyIntent.setComponent(ScreenshotDecorator.CopyUrlReceiver.COMPONENT_NAME); 66 | copyIntent.putExtra("data", text); 67 | return copyIntent; 68 | } 69 | 70 | public static Intent createAddContactFromBarcode(@NonNull Barcode barcode) { 71 | if (Barcode.CONTACT_INFO != barcode.valueFormat || barcode.contactInfo == null) { 72 | throw new IllegalArgumentException("The expected value format of Barcode is Barcode.CONTACT_INFO."); 73 | } 74 | final Barcode.ContactInfo src = barcode.contactInfo; 75 | final Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION); 76 | intent.setType(ContactsContract.RawContacts.CONTENT_TYPE); 77 | 78 | if (src.name != null) { 79 | final Barcode.PersonName name = src.name; 80 | if (name.formattedName != null) { 81 | intent.putExtra(ContactsContract.Intents.Insert.NAME, name.formattedName); 82 | } 83 | } 84 | 85 | if (src.emails != null && src.emails.length > 0) { 86 | intent.putExtra(ContactsContract.Intents.Insert.EMAIL, src.emails[0].address); 87 | int firstType = convertEmailTypeBarcodeToContract(src.emails[0].type); 88 | if (firstType != -1) { 89 | intent.putExtra(ContactsContract.Intents.Insert.EMAIL_TYPE, firstType); 90 | } 91 | if (src.emails.length > 1) { 92 | intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_EMAIL, src.emails[1].address); 93 | int secondType = convertEmailTypeBarcodeToContract(src.emails[1].type); 94 | if (secondType != -1) { 95 | intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_EMAIL_TYPE, secondType); 96 | } 97 | if (src.emails.length > 2) { 98 | intent.putExtra(ContactsContract.Intents.Insert.TERTIARY_EMAIL, src.emails[2].address); 99 | int thirdType = convertEmailTypeBarcodeToContract(src.emails[2].type); 100 | if (thirdType != -1) { 101 | intent.putExtra(ContactsContract.Intents.Insert.TERTIARY_EMAIL_TYPE, thirdType); 102 | } 103 | } 104 | } 105 | } 106 | 107 | if (src.phones != null && src.phones.length > 0) { 108 | intent.putExtra(ContactsContract.Intents.Insert.PHONE, src.phones[0].number); 109 | int firstType = convertPhoneTypeBarcodeToContract(src.phones[0].type); 110 | if (firstType != -1) { 111 | intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, firstType); 112 | } 113 | if (src.phones.length > 1) { 114 | intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE, src.phones[1].number); 115 | int secondType = convertPhoneTypeBarcodeToContract(src.phones[1].type); 116 | if (secondType != -1) { 117 | intent.putExtra(ContactsContract.Intents.Insert.SECONDARY_PHONE_TYPE, secondType); 118 | } 119 | if (src.phones.length > 2) { 120 | intent.putExtra(ContactsContract.Intents.Insert.TERTIARY_PHONE, src.phones[2].number); 121 | int thirdType = convertPhoneTypeBarcodeToContract(src.phones[2].type); 122 | if (thirdType != -1) { 123 | intent.putExtra(ContactsContract.Intents.Insert.TERTIARY_PHONE_TYPE, thirdType); 124 | } 125 | } 126 | } 127 | } 128 | 129 | return intent; 130 | } 131 | 132 | private static int convertEmailTypeBarcodeToContract(int barcodeEmailType) { 133 | switch (barcodeEmailType) { 134 | case Barcode.Email.WORK: { 135 | return ContactsContract.CommonDataKinds.Email.TYPE_WORK; 136 | } 137 | case Barcode.Email.HOME: { 138 | return ContactsContract.CommonDataKinds.Email.TYPE_HOME; 139 | } 140 | } 141 | return -1; 142 | } 143 | 144 | private static int convertPhoneTypeBarcodeToContract(int barcodePhoneType) { 145 | switch (barcodePhoneType) { 146 | case Barcode.Phone.WORK: { 147 | return ContactsContract.CommonDataKinds.Phone.TYPE_WORK; 148 | } 149 | case Barcode.Phone.HOME: { 150 | return ContactsContract.CommonDataKinds.Phone.TYPE_HOME; 151 | } 152 | case Barcode.Phone.MOBILE: { 153 | return ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE; 154 | } 155 | case Barcode.Phone.FAX: { 156 | return ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK; 157 | } 158 | } 159 | return -1; 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/MyFirebaseHelper.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import com.google.android.gms.vision.barcode.Barcode; 4 | import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | public final class MyFirebaseHelper { 9 | 10 | private MyFirebaseHelper() {} 11 | 12 | private static final Field sField_FirebaseVisionBarcode_barcode; 13 | 14 | static { 15 | Field _barcode = null; 16 | for (Field field : FirebaseVisionBarcode.class.getDeclaredFields()) { 17 | if (field.getType().isAssignableFrom(Barcode.class)) { 18 | field.setAccessible(true); 19 | _barcode = field; 20 | break; 21 | } 22 | } 23 | if (_barcode == null) { 24 | throw new NullPointerException("Cannot find Barcode field of FirebaseVisionBarcode"); 25 | } 26 | sField_FirebaseVisionBarcode_barcode = _barcode; 27 | } 28 | 29 | public static Barcode getBarcode(FirebaseVisionBarcode firebaseBarcode) { 30 | try { 31 | return (Barcode) sField_FirebaseVisionBarcode_barcode.get(firebaseBarcode); 32 | } catch (IllegalAccessException e) { 33 | throw new RuntimeException(e); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/PendingIntentCompat.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import android.app.PendingIntent; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.os.Build; 7 | import androidx.annotation.NonNull; 8 | 9 | public final class PendingIntentCompat { 10 | 11 | private PendingIntentCompat() {} 12 | 13 | public static PendingIntent getForegroundService(@NonNull Context context, int requestCode, @NonNull Intent serviceIntent, int flag) { 14 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 15 | return PendingIntent.getForegroundService(context, requestCode, serviceIntent, flag); 16 | } else { 17 | return PendingIntent.getService(context, requestCode, serviceIntent, flag); 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/PermissionUtils.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import android.app.Activity; 4 | import android.app.AppOpsManager; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | import android.os.Build; 9 | import androidx.annotation.NonNull; 10 | 11 | public final class PermissionUtils { 12 | 13 | private PermissionUtils() {} 14 | 15 | /** 16 | * Check if application can draw over other apps 17 | * @param context Context 18 | * @return Boolean 19 | */ 20 | public static boolean canDrawOverlays(@NonNull Context context) { 21 | final int sdkInt = Build.VERSION.SDK_INT; 22 | if (sdkInt >= Build.VERSION_CODES.M) { 23 | if (sdkInt == Build.VERSION_CODES.O) { 24 | // Sometimes Settings.canDrawOverlays returns false after allowing permission. 25 | // Google Issue Tracker: https://issuetracker.google.com/issues/66072795 26 | AppOpsManager appOpsMgr = context.getSystemService(AppOpsManager.class); 27 | if (appOpsMgr != null) { 28 | int mode = appOpsMgr.checkOpNoThrow( 29 | "android:system_alert_window", 30 | android.os.Process.myUid(), 31 | context.getPackageName() 32 | ); 33 | return mode == AppOpsManager.MODE_ALLOWED || mode == AppOpsManager.MODE_IGNORED; 34 | } else { 35 | return false; 36 | } 37 | } 38 | // Default 39 | return android.provider.Settings.canDrawOverlays(context); 40 | } 41 | return true; // This fallback may returns a incorrect result. 42 | } 43 | 44 | /** 45 | * Request overlay permission to draw over other apps 46 | * @param activity Current activity 47 | * @param requestCode Request code 48 | */ 49 | public static void requestOverlayPermission(@NonNull Activity activity, int requestCode) { 50 | Intent intent = new Intent( 51 | android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION, 52 | Uri.parse("package:" + activity.getPackageName())); 53 | activity.startActivityForResult(intent, requestCode); 54 | // TODO Support third-party customize ROM? 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/ResourcesUtils.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import android.content.Context; 4 | import android.util.TypedValue; 5 | import androidx.annotation.AttrRes; 6 | import androidx.annotation.ColorInt; 7 | import androidx.annotation.NonNull; 8 | 9 | import java.util.Objects; 10 | 11 | public final class ResourcesUtils { 12 | 13 | private ResourcesUtils() {} 14 | 15 | public static TypedValue resolveAttribute(@NonNull Context context, @AttrRes int attrId) { 16 | final TypedValue value = new TypedValue(); 17 | if (context.getTheme().resolveAttribute(attrId, value, true)) { 18 | return value; 19 | } else { 20 | return null; 21 | } 22 | } 23 | 24 | @ColorInt 25 | public static int resolveColorAttr(@NonNull Context context, @AttrRes int attrId) { 26 | return Objects.requireNonNull(resolveAttribute(context, attrId)).data; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/ScreenUtils.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import android.content.Context; 4 | import android.util.DisplayMetrics; 5 | import android.util.Rational; 6 | import android.view.WindowManager; 7 | import androidx.annotation.NonNull; 8 | 9 | import java.util.Objects; 10 | 11 | public final class ScreenUtils { 12 | 13 | private static Rational sDefaultDisplayRational = null; 14 | 15 | private ScreenUtils() { 16 | throw new InstantiationError(); 17 | } 18 | 19 | @NonNull 20 | public static DisplayMetrics getDefaultDisplayRealMetrics(@NonNull Context context) { 21 | final DisplayMetrics dm = new DisplayMetrics(); 22 | final WindowManager wm = Objects.requireNonNull(context.getSystemService(WindowManager.class)); 23 | wm.getDefaultDisplay().getRealMetrics(dm); 24 | 25 | return dm; 26 | } 27 | 28 | @NonNull 29 | public static Rational getDefaultDisplayRational(@NonNull Context context) { 30 | if (sDefaultDisplayRational == null) { 31 | synchronized (ScreenUtils.class) { 32 | if (sDefaultDisplayRational == null) { 33 | final DisplayMetrics dm = getDefaultDisplayRealMetrics(context); 34 | 35 | sDefaultDisplayRational = new Rational(dm.widthPixels, dm.heightPixels); 36 | } 37 | } 38 | } 39 | 40 | return sDefaultDisplayRational; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/Singleton.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import androidx.annotation.NonNull; 4 | 5 | import java.util.Objects; 6 | import java.util.concurrent.Callable; 7 | 8 | public interface Singleton { 9 | 10 | static Singleton by(@NonNull Callable callable) { 11 | return new SingletonImpl<>(Objects.requireNonNull(callable)); 12 | } 13 | 14 | T get(); 15 | 16 | boolean isInitialized(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/utils/SingletonImpl.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.utils; 2 | 3 | import androidx.annotation.NonNull; 4 | 5 | import java.util.Objects; 6 | import java.util.concurrent.Callable; 7 | 8 | class SingletonImpl implements Singleton { 9 | 10 | private final Callable callable; 11 | 12 | private final Object lock = new Object(); 13 | 14 | private volatile T value; 15 | 16 | SingletonImpl(@NonNull Callable callable) { 17 | this.callable = callable; 18 | } 19 | 20 | @NonNull 21 | @Override 22 | public T get() { 23 | if (isInitialized()) { 24 | synchronized (lock) { 25 | if (isInitialized()) { 26 | try { 27 | value = Objects.requireNonNull(callable.call()); 28 | } catch (Exception e) { 29 | throw new RuntimeException(e); 30 | } 31 | } 32 | } 33 | } 34 | return value; 35 | } 36 | 37 | @Override 38 | public boolean isInitialized() { 39 | return value == null; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/widget/DividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package moe.feng.nevo.decorators.enscreenshot.widget; 19 | 20 | import android.content.Context; 21 | import android.content.res.TypedArray; 22 | import android.graphics.Canvas; 23 | import android.graphics.Rect; 24 | import android.graphics.drawable.Drawable; 25 | import android.util.Log; 26 | import android.view.View; 27 | import android.widget.LinearLayout; 28 | 29 | import androidx.annotation.NonNull; 30 | import androidx.recyclerview.widget.LinearLayoutManager; 31 | import androidx.recyclerview.widget.RecyclerView; 32 | 33 | /** 34 | * DividerItemDecoration is a {@link RecyclerView.ItemDecoration} that can be used as a divider 35 | * between items of a {@link LinearLayoutManager}. It supports both {@link #HORIZONTAL} and 36 | * {@link #VERTICAL} orientations. 37 | * 38 | *
 39 |  *     mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
 40 |  *             mLayoutManager.getOrientation());
 41 |  *     recyclerView.addItemDecoration(mDividerItemDecoration);
 42 |  * 
43 | */ 44 | public class DividerItemDecoration extends RecyclerView.ItemDecoration { 45 | public static final int HORIZONTAL = LinearLayout.HORIZONTAL; 46 | public static final int VERTICAL = LinearLayout.VERTICAL; 47 | 48 | private static final String TAG = "DividerItem"; 49 | private static final int[] ATTRS = new int[]{ android.R.attr.listDivider }; 50 | 51 | private Drawable mDivider; 52 | 53 | /** 54 | * Current orientation. Either {@link #HORIZONTAL} or {@link #VERTICAL}. 55 | */ 56 | private int mOrientation; 57 | 58 | private boolean doNotDrawForLastItem = false; 59 | 60 | private final Rect mBounds = new Rect(); 61 | 62 | /** 63 | * Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a 64 | * {@link LinearLayoutManager}. 65 | * 66 | * @param context Current context, it will be used to access resources. 67 | * @param orientation Divider orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}. 68 | */ 69 | public DividerItemDecoration(Context context, int orientation) { 70 | final TypedArray a = context.obtainStyledAttributes(ATTRS); 71 | mDivider = a.getDrawable(0); 72 | if (mDivider == null) { 73 | Log.w(TAG, "@android:attr/listDivider was not set in the theme used for this " 74 | + "DividerItemDecoration. Please set that attribute all call setDrawable()"); 75 | } 76 | a.recycle(); 77 | setOrientation(orientation); 78 | } 79 | 80 | /** 81 | * Sets the orientation for this divider. This should be called if 82 | * {@link RecyclerView.LayoutManager} changes orientation. 83 | * 84 | * @param orientation {@link #HORIZONTAL} or {@link #VERTICAL} 85 | */ 86 | public void setOrientation(int orientation) { 87 | if (orientation != HORIZONTAL && orientation != VERTICAL) { 88 | throw new IllegalArgumentException( 89 | "Invalid orientation. It should be either HORIZONTAL or VERTICAL"); 90 | } 91 | mOrientation = orientation; 92 | } 93 | 94 | /** 95 | * Sets the {@link Drawable} for this divider. 96 | * 97 | * @param drawable Drawable that should be used as a divider. 98 | */ 99 | public void setDrawable(@NonNull Drawable drawable) { 100 | if (drawable == null) { 101 | throw new IllegalArgumentException("Drawable cannot be null."); 102 | } 103 | mDivider = drawable; 104 | } 105 | 106 | public void setDoNotDrawForLastItem(boolean doNotDrawForLastItem) { 107 | this.doNotDrawForLastItem = doNotDrawForLastItem; 108 | } 109 | 110 | @Override 111 | public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { 112 | if (parent.getLayoutManager() == null || mDivider == null) { 113 | return; 114 | } 115 | if (mOrientation == VERTICAL) { 116 | drawVertical(c, parent); 117 | } else { 118 | drawHorizontal(c, parent); 119 | } 120 | } 121 | 122 | private void drawVertical(Canvas canvas, RecyclerView parent) { 123 | canvas.save(); 124 | final int left; 125 | final int right; 126 | if (parent.getClipToPadding()) { 127 | left = parent.getPaddingLeft(); 128 | right = parent.getWidth() - parent.getPaddingRight(); 129 | canvas.clipRect(left, parent.getPaddingTop(), right, 130 | parent.getHeight() - parent.getPaddingBottom()); 131 | } else { 132 | left = 0; 133 | right = parent.getWidth(); 134 | } 135 | 136 | final int childCount = parent.getChildCount() - (doNotDrawForLastItem ? 1 : 0); 137 | for (int i = 0; i < childCount; i++) { 138 | final View child = parent.getChildAt(i); 139 | parent.getDecoratedBoundsWithMargins(child, mBounds); 140 | final int bottom = mBounds.bottom + Math.round(child.getTranslationY()); 141 | final int top = bottom - mDivider.getIntrinsicHeight(); 142 | mDivider.setBounds(left, top, right, bottom); 143 | mDivider.draw(canvas); 144 | } 145 | canvas.restore(); 146 | } 147 | 148 | private void drawHorizontal(Canvas canvas, RecyclerView parent) { 149 | canvas.save(); 150 | final int top; 151 | final int bottom; 152 | if (parent.getClipToPadding()) { 153 | top = parent.getPaddingTop(); 154 | bottom = parent.getHeight() - parent.getPaddingBottom(); 155 | canvas.clipRect(parent.getPaddingLeft(), top, 156 | parent.getWidth() - parent.getPaddingRight(), bottom); 157 | } else { 158 | top = 0; 159 | bottom = parent.getHeight(); 160 | } 161 | 162 | final int childCount = parent.getChildCount() - (doNotDrawForLastItem ? 1 : 0); 163 | for (int i = 0; i < childCount; i++) { 164 | final View child = parent.getChildAt(i); 165 | parent.getLayoutManager().getDecoratedBoundsWithMargins(child, mBounds); 166 | final int right = mBounds.right + Math.round(child.getTranslationX()); 167 | final int left = right - mDivider.getIntrinsicWidth(); 168 | mDivider.setBounds(left, top, right, bottom); 169 | mDivider.draw(canvas); 170 | } 171 | canvas.restore(); 172 | } 173 | 174 | @Override 175 | public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, 176 | @NonNull RecyclerView.State state) { 177 | if (mDivider == null) { 178 | outRect.set(0, 0, 0, 0); 179 | return; 180 | } 181 | if (mOrientation == VERTICAL) { 182 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 183 | } else { 184 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/widget/HtmlTextView.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.util.AttributeSet; 6 | import android.widget.TextView; 7 | import androidx.annotation.Nullable; 8 | import androidx.core.text.HtmlCompat; 9 | 10 | public class HtmlTextView extends TextView { 11 | 12 | public HtmlTextView(Context context) { 13 | this(context, null); 14 | } 15 | 16 | public HtmlTextView(Context context, @Nullable AttributeSet attrs) { 17 | super(context, attrs); 18 | init(context, attrs); 19 | } 20 | 21 | public HtmlTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 22 | super(context, attrs, defStyleAttr); 23 | init(context, attrs); 24 | } 25 | 26 | public HtmlTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 27 | super(context, attrs, defStyleAttr, defStyleRes); 28 | init(context, attrs); 29 | } 30 | 31 | private void init(Context context, @Nullable AttributeSet attrs) { 32 | if (attrs != null) { 33 | final TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.text }); 34 | String text = a.getString(0); 35 | if (text != null) { 36 | setText(HtmlCompat.fromHtml(text, 0)); 37 | } 38 | a.recycle(); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/widget/PreviewActionForegroundDrawable.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.*; 5 | import android.graphics.drawable.Drawable; 6 | import androidx.annotation.NonNull; 7 | import androidx.annotation.Nullable; 8 | import moe.feng.nevo.decorators.enscreenshot.R; 9 | 10 | import static java.lang.Math.pow; 11 | import static java.lang.Math.sqrt; 12 | 13 | public class PreviewActionForegroundDrawable extends Drawable { 14 | 15 | private final Paint mBackgroundPaint; 16 | private final Paint mIconArcPaint; 17 | 18 | private final int mIconSize; 19 | private final int mIconMinMargin; 20 | private final int mIconArcRadiusOffset; 21 | 22 | private Drawable mIconDrawable, mArrowDrawable; 23 | 24 | private int mBackgroundColor; 25 | 26 | private float mProgress = 0f; 27 | 28 | public PreviewActionForegroundDrawable(@NonNull Context context) { 29 | mBackgroundColor = context.getColor(R.color.material_blue_500); 30 | 31 | mBackgroundPaint = new Paint(); 32 | mBackgroundPaint.setColor(mBackgroundColor); 33 | mBackgroundPaint.setStyle(Paint.Style.FILL); 34 | mBackgroundPaint.setAntiAlias(true); 35 | 36 | mIconArcPaint = new Paint(); 37 | mIconArcPaint.setColor(Color.WHITE); 38 | mIconArcPaint.setStyle(Paint.Style.STROKE); 39 | mIconArcPaint.setStrokeWidth(context.getResources().getDimension(R.dimen.view_icon_arc_stroke_width)); 40 | mIconArcPaint.setAntiAlias(true); 41 | 42 | mIconDrawable = context.getDrawable(R.drawable.ic_open_in_browser_white_24dp); 43 | mArrowDrawable = context.getDrawable(R.drawable.ic_keyboard_arrow_up_white_24dp); 44 | mIconSize = context.getResources().getDimensionPixelSize(R.dimen.view_icon_size); 45 | mIconMinMargin = context.getResources().getDimensionPixelSize(R.dimen.view_icon_min_margin); 46 | mIconArcRadiusOffset = context.getResources().getDimensionPixelSize(R.dimen.view_icon_arc_radius_offset); 47 | } 48 | 49 | public void setProgress(float progress) { 50 | if (progress < 0 || progress > 1) { 51 | throw new IllegalArgumentException("Progress should be set between 0 and 1."); 52 | } 53 | mProgress = progress; 54 | invalidateSelf(); 55 | } 56 | 57 | public float getProgress() { 58 | return mProgress; 59 | } 60 | 61 | @Override 62 | public void draw(@NonNull Canvas canvas) { 63 | // Calculate properties 64 | final Rect bounds = getBounds(); 65 | final double maxRadius = sqrt(pow(bounds.width() / 2, 2) + pow(bounds.height(), 2)); 66 | final double currentRadius = maxRadius * mProgress; 67 | final int iconBottom = bounds.bottom - (int) Math.max(mIconMinMargin, (currentRadius - mIconSize) / 2); 68 | final Rect iconBounds = new Rect( 69 | bounds.centerX() - mIconSize / 2, iconBottom - mIconSize, 70 | bounds.centerX() + mIconSize / 2, iconBottom 71 | ); 72 | mIconDrawable.setBounds(iconBounds); 73 | final int arrowBottom = (int) (bounds.bottom - currentRadius - mIconMinMargin / 2); 74 | mArrowDrawable.setBounds( 75 | bounds.centerX() - mIconSize / 2, arrowBottom - mIconSize, 76 | bounds.centerX() + mIconSize / 2, arrowBottom 77 | ); 78 | final float mArcProgress = Math.max(mProgress - 0.2f, 0f) / 0.8f; 79 | final Path path = new Path(); 80 | path.addCircle(bounds.centerX(), bounds.bottom, (float) currentRadius, Path.Direction.CCW); 81 | 82 | // Draw shadow 83 | canvas.drawColor(Color.argb((int) (255 * Math.min(0.7f, mProgress * 0.7f)), 0, 0, 0)); 84 | 85 | // Save and clip 86 | canvas.save(); 87 | canvas.clipPath(path); 88 | 89 | // Draw round background and icon 90 | canvas.drawColor(mBackgroundColor); 91 | mIconDrawable.draw(canvas); 92 | canvas.drawArc( 93 | iconBounds.left - mIconArcRadiusOffset, iconBounds.top - mIconArcRadiusOffset, 94 | iconBounds.right + mIconArcRadiusOffset, iconBounds.bottom + mIconArcRadiusOffset, 95 | -90 + 180 * mArcProgress, 360 * mArcProgress, false, mIconArcPaint 96 | ); 97 | 98 | // Restore 99 | canvas.restore(); 100 | 101 | // Draw arrow outside 102 | mArrowDrawable.setAlpha((int) (255 * Math.min(1f, mProgress / 0.1f))); 103 | mArrowDrawable.draw(canvas); 104 | } 105 | 106 | @Override 107 | public void setAlpha(int alpha) { 108 | mBackgroundPaint.setAlpha(alpha); 109 | invalidateSelf(); 110 | } 111 | 112 | @Override 113 | public void setColorFilter(@Nullable ColorFilter colorFilter) { 114 | mBackgroundPaint.setColorFilter(colorFilter); 115 | invalidateSelf(); 116 | } 117 | 118 | @Override 119 | public int getOpacity() { 120 | return PixelFormat.TRANSPARENT; 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/widget/RoundRectFrameLayout.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.Outline; 5 | import android.graphics.Rect; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.view.ViewOutlineProvider; 9 | import android.widget.FrameLayout; 10 | import androidx.annotation.Nullable; 11 | import moe.feng.nevo.decorators.enscreenshot.R; 12 | 13 | public class RoundRectFrameLayout extends FrameLayout { 14 | 15 | public RoundRectFrameLayout(Context context) { 16 | super(context); 17 | init(); 18 | } 19 | 20 | public RoundRectFrameLayout(Context context, @Nullable AttributeSet attrs) { 21 | super(context, attrs); 22 | init(); 23 | } 24 | 25 | public RoundRectFrameLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 26 | super(context, attrs, defStyleAttr); 27 | init(); 28 | } 29 | 30 | public RoundRectFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 31 | super(context, attrs, defStyleAttr, defStyleRes); 32 | init(); 33 | } 34 | 35 | private void init() { 36 | setClipToOutline(true); 37 | setOutlineProvider(new RoundRectOutlineProvider( 38 | getResources().getDimension(R.dimen.floating_window_corner_radius))); 39 | } 40 | 41 | @Override 42 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 43 | super.onSizeChanged(w, h, oldw, oldh); 44 | invalidateOutline(); 45 | } 46 | 47 | private static class RoundRectOutlineProvider extends ViewOutlineProvider { 48 | 49 | private final float mCornerRadius; 50 | 51 | RoundRectOutlineProvider(float cornerRadius) { 52 | mCornerRadius = cornerRadius; 53 | } 54 | 55 | @Override 56 | public void getOutline(View view, Outline outline) { 57 | final Rect clipPath = new Rect(); 58 | view.getLocalVisibleRect(clipPath); 59 | outline.setRoundRect(clipPath, mCornerRadius); 60 | } 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/moe/feng/nevo/decorators/enscreenshot/widget/SwitchBar.java: -------------------------------------------------------------------------------- 1 | package moe.feng.nevo.decorators.enscreenshot.widget; 2 | 3 | import android.content.Context; 4 | import android.os.Looper; 5 | import android.os.Parcel; 6 | import android.os.Parcelable; 7 | import android.util.AttributeSet; 8 | import android.view.LayoutInflater; 9 | import android.widget.*; 10 | import androidx.annotation.NonNull; 11 | import androidx.annotation.Nullable; 12 | import moe.feng.nevo.decorators.enscreenshot.R; 13 | import moe.feng.nevo.decorators.enscreenshot.utils.ResourcesUtils; 14 | 15 | public class SwitchBar extends LinearLayout implements Checkable { 16 | 17 | private final TextView mTextView; 18 | private final Switch mSwitch; 19 | 20 | private int mDisabledBackgroundColor, mEnabledBackgroundColor; 21 | private CharSequence mDisabledText, mEnabledText; 22 | 23 | private boolean isChecked = false; 24 | 25 | private boolean isBroadcasting = false; 26 | 27 | @Nullable 28 | private OnCheckedChangeListener mListener = null; 29 | 30 | public SwitchBar(Context context) { 31 | this(context, null); 32 | } 33 | 34 | public SwitchBar(Context context, @Nullable AttributeSet attrs) { 35 | this(context, attrs, R.attr.switchBarStyle); 36 | } 37 | 38 | public SwitchBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 39 | this(context, attrs, defStyleAttr, R.style.Widget_Material_SwitchBar); 40 | } 41 | 42 | public SwitchBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 43 | super(context, attrs, defStyleAttr, defStyleRes); 44 | 45 | LayoutInflater.from(context).inflate(R.layout.switch_bar_content, this, true); 46 | mTextView = findViewById(android.R.id.text1); 47 | mSwitch = findViewById(android.R.id.checkbox); 48 | 49 | mDisabledBackgroundColor = context.getColor(R.color.material_grey_600); 50 | mEnabledBackgroundColor = ResourcesUtils.resolveColorAttr(context, android.R.attr.colorAccent); 51 | 52 | mDisabledText = context.getString(R.string.switch_bar_disabled); 53 | mEnabledText = context.getString(R.string.switch_bar_enabled); 54 | 55 | setOnClickListener(v -> toggle()); 56 | 57 | updateViewStates(); 58 | } 59 | 60 | @Override 61 | public void setChecked(boolean checked) { 62 | if (!Looper.getMainLooper().isCurrentThread()) { 63 | throw new IllegalStateException("You should call setChecked on main thread."); 64 | } 65 | this.isChecked = checked; 66 | if (!isBroadcasting) { 67 | isBroadcasting = true; 68 | if (mListener != null) { 69 | mListener.onCheckedChanged(this, isChecked); 70 | } 71 | isBroadcasting = false; 72 | } 73 | updateViewStates(); 74 | } 75 | 76 | @Override 77 | public boolean isChecked() { 78 | return isChecked; 79 | } 80 | 81 | @Override 82 | public void toggle() { 83 | setChecked(!isChecked); 84 | } 85 | 86 | public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener) { 87 | mListener = listener; 88 | } 89 | 90 | private void updateViewStates() { 91 | mTextView.setText(isChecked ? mEnabledText : mDisabledText); 92 | setBackgroundColor(isChecked ? mEnabledBackgroundColor : mDisabledBackgroundColor); 93 | mSwitch.setChecked(isChecked); 94 | } 95 | 96 | @Override 97 | protected void onRestoreInstanceState(Parcelable state) { 98 | if (state instanceof State) { 99 | final State typedState = (State) state; 100 | super.onRestoreInstanceState(typedState.getSuperState()); 101 | setChecked(typedState.isChecked); 102 | } else { 103 | super.onRestoreInstanceState(state); 104 | } 105 | } 106 | 107 | @Nullable 108 | @Override 109 | protected Parcelable onSaveInstanceState() { 110 | final State outState = new State(super.onSaveInstanceState()); 111 | outState.isChecked = isChecked; 112 | return outState; 113 | } 114 | 115 | private static class State extends BaseSavedState { 116 | 117 | boolean isChecked; 118 | 119 | State(Parcelable superState) { 120 | super(superState); 121 | } 122 | 123 | private State(Parcel source) { 124 | super(source); 125 | isChecked = source.readByte() != 0; 126 | } 127 | 128 | @Override 129 | public void writeToParcel(Parcel out, int flags) { 130 | super.writeToParcel(out, flags); 131 | out.writeByte(isChecked ? (byte) 1 : (byte) 0); 132 | } 133 | 134 | public static final Creator CREATOR = new Creator() { 135 | 136 | @Override 137 | public State createFromParcel(Parcel source) { 138 | return new State(source); 139 | } 140 | 141 | @Override 142 | public State[] newArray(int size) { 143 | return new State[size]; 144 | } 145 | 146 | }; 147 | 148 | } 149 | 150 | public interface OnCheckedChangeListener { 151 | 152 | void onCheckedChanged(@NonNull SwitchBar view, boolean isChecked); 153 | 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fython/EnhancedScreenshotNotification/098a74405080b9ed6b1efc3218b4f9baee543015/app/src/main/res/drawable-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_assistant_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_delete_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_delete_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_edit_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_keyboard_arrow_up_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_open_in_browser_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_share_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_thumb_up_color_control_normal_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/material_button_flat_with_border.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/material_button_flat_with_border_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_preview_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | 17 | 18 | 21 | 22 | 29 | 30 | 34 | 35 | 43 | 44 | 49 | 50 | 57 | 58 | 59 | 60 | 61 | 62 | 67 | 68 | 75 | 76 | 80 | 81 | 89 | 90 | 95 | 96 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_layout_edit_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_layout_view_barcode.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_barcode.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 21 | 22 | 30 | 31 | 36 | 37 |