├── .gitignore ├── .project ├── .settings └── org.eclipse.m2e.core.prefs ├── LICENSE ├── README.md ├── UtilSet ├── .checkstyle ├── .gitignore ├── LICENSE ├── pom.xml ├── project.properties ├── src │ └── com │ │ └── navercorp │ │ └── utilset │ │ ├── audio │ │ └── VolumeUtils.java │ │ ├── cipher │ │ ├── AesCipher.java │ │ ├── CipherMode.java │ │ ├── CipherObject.java │ │ ├── CipherObjectFactory.java │ │ └── CipherUtils.java │ │ ├── device │ │ ├── DeviceType.java │ │ ├── DeviceTypeDetector.java │ │ ├── DeviceUtils.java │ │ ├── LauncherInfo.java │ │ ├── LauncherType.java │ │ ├── LauncherTypeDetector.java │ │ └── PhoneNumberUtils.java │ │ ├── input │ │ ├── KeyboardUtils.java │ │ └── SoftwareKeyDetector.java │ │ ├── network │ │ └── NetworkMonitor.java │ │ ├── storage │ │ └── DiskUtils.java │ │ ├── string │ │ ├── CompressUtils.java │ │ └── StringCompressor.java │ │ ├── system │ │ ├── ProcessorUtils.java │ │ ├── RootChecker.java │ │ └── SystemUtils.java │ │ └── ui │ │ ├── ActivityUtils.java │ │ ├── PixelUtils.java │ │ └── ScreenUtils.java └── test │ └── com │ └── navercorp │ └── utilset │ ├── audio │ └── VolumeUtilsTest.java │ ├── cipher │ ├── CipherObjectFactoryTest.java │ └── CipherUtilsTest.java │ ├── storage │ └── DiskUtilsTest.java │ ├── string │ └── CompressUtilsTest.java │ ├── system │ └── SystemUtilsTest.java │ └── ui │ ├── ActivityUtilsTest.java │ ├── PixelUtilsTest.java │ └── ScreenUtilsTest.java ├── UtilSetInstrumentationTest ├── .checkstyle ├── .classpath ├── .gitignore ├── .project ├── AndroidManifest.xml ├── LICENSE ├── ic_launcher-web.png ├── lib │ └── utilset-0.0.1-SNAPSHOT.jar ├── libs │ ├── android-support-v4.jar │ └── robotium-solo-4.3.jar ├── lint.xml ├── pom.xml ├── proguard-project.txt ├── project.properties ├── repo │ └── utilset-0.0.1-SNAPSHOT.jar ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── menu │ │ └── main.xml │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── description.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── navercorp │ └── utilsettest │ ├── introduction │ └── Introduction.java │ └── test │ ├── CipherUtilsTestCase.java │ ├── KeyboardUtilsTestCase.java │ ├── NetworkListenerTestCase.java │ ├── ScreenUtilsTestCase.java │ ├── StringUtilsTestCase.java │ └── VolumeUpDownTestCase.java ├── UtilSetSampleApp ├── .checkstyle ├── .classpath ├── .gitignore ├── .project ├── AndroidManifest.xml ├── LICENSE ├── ic_launcher-web.png ├── lib │ └── utilset-0.0.1-SNAPSHOT.jar ├── libs │ ├── android-support-v4.jar │ └── robotium-solo-4.3.jar ├── lint.xml ├── pom.xml ├── proguard-project.txt ├── project.properties ├── repo │ └── utilset-0.0.1-SNAPSHOT.jar ├── res │ ├── drawable-hdpi │ │ ├── close_button.png │ │ ├── ic_launcher.png │ │ ├── progress_bg_holo_dark.9.png │ │ ├── progress_horizontal_holo_dark.xml │ │ ├── progress_primary_holo_dark.9.png │ │ ├── progress_secondary_holo_dark.9.png │ │ └── rounded_background.xml │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── layout │ │ ├── acitivty_volumeutils.xml │ │ ├── activity_activityutils.xml │ │ ├── activity_cipher.xml │ │ ├── activity_deviceutils.xml │ │ ├── activity_diskutils.xml │ │ ├── activity_keyboardutils.xml │ │ ├── activity_main.xml │ │ ├── activity_network_listener.xml │ │ ├── activity_networkutils.xml │ │ ├── activity_stringutils.xml │ │ ├── activity_systemutils.xml │ │ ├── dialog_introduction.xml │ │ ├── fragment_keep_screen_on.xml │ │ └── fragment_reset_screen_on.xml │ ├── menu │ │ └── main.xml │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── navercorp │ └── utilsettest │ ├── ButtonColor.java │ ├── ButtonColorList.java │ ├── MainActivity.java │ ├── audio │ └── VolumeUtilsTestActivity.java │ ├── cipher │ └── CipherTestActivity.java │ ├── device │ └── DeviceUtilsTestActivity.java │ ├── dialog │ ├── IntroductionDialogController.java │ ├── IntroductionDialogFactory.java │ └── IntroductionDialogFragment.java │ ├── input │ └── KeyboardUtilsTestActivity.java │ ├── network │ ├── NetworkListenerTestActivity.java │ └── NetworkMonitorTestActivity.java │ ├── storage │ └── DiskUtilsTestAcitivity.java │ ├── string │ └── StringUtilsTestActivity.java │ ├── system │ └── SystemUtilsTestActivity.java │ └── ui │ ├── ActivityUtilsClearScreenOnFragment.java │ ├── ActivityUtilsConstants.java │ ├── ActivityUtilsKeepScreenOnFragment.java │ ├── ActivityUtilsPagerAdapter.java │ └── ActivityUtilsTestActivity.java ├── pom.xml └── repo └── utilset-0.0.1-SNAPSHOT.jar /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | gen 3 | target 4 | .settings 5 | .claspath 6 | .project 7 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | utilset-parent 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License, Version 2.0 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 13 | 14 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 15 | 16 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 17 | 18 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 19 | 20 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 21 | 22 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 23 | 24 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 25 | 26 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 27 | 28 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 29 | 30 | 2. Grant of Copyright License. 31 | 32 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 33 | 34 | 3. Grant of Patent License. 35 | 36 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 37 | 38 | 4. Redistribution. 39 | 40 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 41 | 42 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 43 | You must cause any modified files to carry prominent notices stating that You changed the files; and 44 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 45 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 46 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 47 | 48 | 5. Submission of Contributions. 49 | 50 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 51 | 52 | 6. Trademarks. 53 | 54 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 55 | 56 | 7. Disclaimer of Warranty. 57 | 58 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 59 | 60 | 8. Limitation of Liability. 61 | 62 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 63 | 64 | 9. Accepting Warranty or Additional Liability. 65 | 66 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 67 | 68 | END OF TERMS AND CONDITIONS 69 | 70 | APPENDIX: How to apply the Apache License to your work 71 | 72 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. 73 | 74 | Copyright [yyyy] [name of copyright owner] 75 | 76 | Licensed under the Apache License, Version 2.0 (the "License"); 77 | you may not use this file except in compliance with the License. 78 | You may obtain a copy of the License at 79 | 80 | http://www.apache.org/licenses/LICENSE-2.0 81 | 82 | Unless required by applicable law or agreed to in writing, software 83 | distributed under the License is distributed on an "AS IS" BASIS, 84 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 85 | See the License for the specific language governing permissions and 86 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Utilset 2 | 3 | ### Introduction 4 |   Utilset is collections of useful functions to save your valuable time. 5 | Because there are a ton of different ways to implement a method,
6 | we often spend our valuable time to search and test those ways. 7 | Some may work, but some may not work.
8 |   As such, we collected, tested and refined methods so as to prevent seeking code snippet.
9 | 10 | ------- 11 | ### Overview 12 | Utilset includes: 13 | 14 | * DeviceUtils 15 | + determines whether the device is mobile phone or not 16 | + determines if the phone has SMS capability 17 | + etc... 18 | 19 | * ActivityUtils 20 | + checks if a user specified package is installed 21 | + gets information of base activity package name and class name 22 | 23 | * NetworkUtils 24 | + provides listeners which notify when network state changes, , receives a call, or a connection is made 25 | + checks if WiFi is enabled and if WiFi is connected 26 | + checks if Mobile Network (3G/4G) is connected 27 | + obtains IP Address in either v4 or v6 form 28 | + etc... 29 | 30 | * DiskUtils 31 | + obtains external storage path for caching 32 | + obtains external storage path for temporary files 33 | + obtains MicroSD Card path 34 | 35 | * KeyboardUtils 36 | + shows, hides, and toggles Software keyboards 37 | + checks if a device has software menu/home/back button 38 | 39 | * CipherUtils 40 | + provides simple AES based cryptographic methods 41 | 42 | * StringUtils 43 | + provides string compression/decompression methods 44 | 45 | * SystemUtils 46 | + checks if a device is rooted 47 | + counts the number of processors(more specifically the number of cores) 48 | 49 | 50 | ------- 51 | ### Download 52 |   The latest version can be downloaded in jar and referenced as a library. 53 | Link is here http://repo.nhncorp.com/maven2/com/navercorp/utilset/utilset/1.0/utilset-1.0.jar 54 | Just add downloaded jar file into libs folder in your android project. 55 | 56 | or 57 | 58 | You can also configure pom.xml if using Maven : 59 | ```xml 60 | 61 | 62 | com.navercorp 63 | utilset 64 | 1.0.2 65 | 66 | ``` 67 | 68 | ------- 69 | ### Usage 70 | Please, refer sample project 71 | 72 | ------- 73 | ### How to run sample project 74 | (1) Download Utilset Maven Project from https://github.com/nhnopensource/android-utilset/releases/tag/v1.0.2
75 | (2) Import downloaded project as Maven project in Eclipse (Maven plug-in must be installed to run utilset test project)
76 | (3) Right click on utilset-parent in Package Explorer
77 | (4) Select Run As and then Maven Build
78 | (5) If you run utilset-parent for the first time, then Run Configuration will appear
79 | (6) Type clean install to the Goal tab
80 | (7) Click run button on the bottom
81 | 82 | ------- 83 | ## License 84 | 85 | Copyright 2013 Navercorp 86 | 87 | Licensed under the Apache License, Version 2.0 (the "License"); 88 | you may not use this file except in compliance with the License. 89 | You may obtain a copy of the License at 90 | 91 | http://www.apache.org/licenses/LICENSE-2.0 92 | 93 | Unless required by applicable law or agreed to in writing, software 94 | distributed under the License is distributed on an "AS IS" BASIS, 95 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 96 | See the License for the specific language governing permissions and 97 | limitations under the License. -------------------------------------------------------------------------------- /UtilSet/.checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /UtilSet/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /.classpath 3 | /.project 4 | /target 5 | /target 6 | /target 7 | -------------------------------------------------------------------------------- /UtilSet/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License, Version 2.0 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 13 | 14 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 15 | 16 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 17 | 18 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 19 | 20 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 21 | 22 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 23 | 24 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 25 | 26 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 27 | 28 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 29 | 30 | 2. Grant of Copyright License. 31 | 32 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 33 | 34 | 3. Grant of Patent License. 35 | 36 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 37 | 38 | 4. Redistribution. 39 | 40 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 41 | 42 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 43 | You must cause any modified files to carry prominent notices stating that You changed the files; and 44 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 45 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 46 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 47 | 48 | 5. Submission of Contributions. 49 | 50 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 51 | 52 | 6. Trademarks. 53 | 54 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 55 | 56 | 7. Disclaimer of Warranty. 57 | 58 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 59 | 60 | 8. Limitation of Liability. 61 | 62 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 63 | 64 | 9. Accepting Warranty or Additional Liability. 65 | 66 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 67 | 68 | END OF TERMS AND CONDITIONS 69 | 70 | APPENDIX: How to apply the Apache License to your work 71 | 72 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. 73 | 74 | Copyright [yyyy] [name of copyright owner] 75 | 76 | Licensed under the Apache License, Version 2.0 (the "License"); 77 | you may not use this file except in compliance with the License. 78 | You may obtain a copy of the License at 79 | 80 | http://www.apache.org/licenses/LICENSE-2.0 81 | 82 | Unless required by applicable law or agreed to in writing, software 83 | distributed under the License is distributed on an "AS IS" BASIS, 84 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 85 | See the License for the specific language governing permissions and 86 | limitations under the License. -------------------------------------------------------------------------------- /UtilSet/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.navercorp 6 | utilset-parent 7 | 1.0.3-SNAPSHOT 8 | 9 | 10 | utilset 11 | jar 12 | UtilSet 13 | 14 | 15 | UTF-8 16 | 4.1.1.4 17 | 17 18 | r7 19 | 1.6 20 | 21 | 22 | 23 | 24 | com.google.android 25 | android 26 | provided 27 | 28 | 29 | 30 | com.google.android 31 | annotations 32 | 33 | 34 | 35 | com.google.android 36 | support-v4 37 | 38 | 39 | 40 | junit 41 | junit 42 | 43 | 44 | 45 | org.robolectric 46 | robolectric 47 | 48 | 49 | 50 | org.hamcrest 51 | hamcrest-all 52 | provided 53 | 54 | 55 | 56 | 57 | 58 | 59 | maven-compiler-plugin 60 | 3.1 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /UtilSet/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/audio/VolumeUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.audio; 2 | 3 | import android.content.Context; 4 | import android.media.AudioManager; 5 | 6 | /** 7 | * Controls Media Volume 8 | * 9 | * @author jaemin.woo 10 | * 11 | */ 12 | public class VolumeUtils { 13 | private VolumeUtils() {} 14 | 15 | /** 16 | * Returns current media volume 17 | * @param context 18 | * @return current volume 19 | */ 20 | public static int getCurrentVolume(Context context) { 21 | AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 22 | return mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 23 | } 24 | 25 | /** 26 | * Sets media volume.
27 | * When setting the value of parameter 'volume' greater than the maximum value of the media volume will not either cause error or throw exception but maximize the media volume.
28 | * Setting the value of volume lower than 0 will minimize the media volume. 29 | * 30 | * @param context Context 31 | * @param volume volume to be changed 32 | */ 33 | public static void setVolume(Context context, int volume) { 34 | adjustMediaVolume(context, volume, 0); 35 | } 36 | 37 | /** 38 | * Sets media volume and displays volume level.
39 | * When setting the value of parameter 'volume' greater than the maximum value of the media volume will not either cause error or throw exception but maximize the media volume.
40 | * Setting the value of volume lower than 0 will minimize the media volume. 41 | * 42 | * @param context Context 43 | * @param volume volume to be changed 44 | */ 45 | public static void setVolumeWithLevel(Context context, int volume) { 46 | adjustMediaVolume(context, volume, AudioManager.FLAG_SHOW_UI); 47 | } 48 | 49 | /** 50 | * Increases media volume 51 | * 52 | * @param context 53 | */ 54 | public static void increaseVolume(Context context) { 55 | adjustMediaVolume(context, getCurrentVolume(context) + 1, 0); 56 | } 57 | 58 | /** 59 | * Increases media volume and displays volume level 60 | * 61 | * @param context 62 | */ 63 | public static void increaseVolumeWithLevel(Context context) { 64 | adjustMediaVolume(context, getCurrentVolume(context) + 1, AudioManager.FLAG_SHOW_UI); 65 | } 66 | 67 | /** 68 | * Decreases media volume 69 | * 70 | * @param context 71 | */ 72 | public static void decreaseVolume(Context context) { 73 | adjustMediaVolume(context, getCurrentVolume(context) - 1, 0); 74 | } 75 | 76 | /** 77 | * Decreases media volume and displays volume level 78 | * 79 | * @param context 80 | */ 81 | public static void decreaseVolumeWithLevel(Context context) { 82 | adjustMediaVolume(context, getCurrentVolume(context) - 1, AudioManager.FLAG_SHOW_UI); 83 | } 84 | 85 | /** Returns maximum volume the media volume can have 86 | * 87 | * @param context Context 88 | * @return Maximum volume 89 | */ 90 | public static int getMaximumVolume(Context context) { 91 | return ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE)).getStreamMaxVolume(AudioManager.STREAM_MUSIC); 92 | } 93 | 94 | /** Returns minimum volume the media volume can have 95 | * 96 | * @param context Context 97 | * @return Minimum volume 98 | */ 99 | public static int getMinimumVolume(Context context) { 100 | return 0; 101 | } 102 | 103 | private static void adjustMediaVolume(Context context, int volume, int flag) { 104 | final int MAX_VOLUME = getMaximumVolume(context); 105 | final int MIN_VOLUME = 0; 106 | 107 | if( volume < MIN_VOLUME ) { 108 | volume = MIN_VOLUME; 109 | } else if( volume > MAX_VOLUME ) { 110 | volume = MAX_VOLUME; 111 | } 112 | 113 | AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 114 | if (audioManager != null) { 115 | audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, flag); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/cipher/AesCipher.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.cipher; 2 | 3 | import java.security.InvalidKeyException; 4 | import java.security.NoSuchAlgorithmException; 5 | import java.security.NoSuchProviderException; 6 | import java.security.SecureRandom; 7 | 8 | import javax.crypto.BadPaddingException; 9 | import javax.crypto.Cipher; 10 | import javax.crypto.IllegalBlockSizeException; 11 | import javax.crypto.KeyGenerator; 12 | import javax.crypto.NoSuchPaddingException; 13 | import javax.crypto.SecretKey; 14 | import javax.crypto.spec.SecretKeySpec; 15 | 16 | import android.util.Log; 17 | 18 | /** 19 | * @author jaemin.woo 20 | * 21 | */ 22 | public class AesCipher implements CipherObject { 23 | private static final String TAG = AesCipher.class.getSimpleName(); 24 | private final static int JELLY_BEAN_MR1 = 17; 25 | 26 | @Override 27 | public String encrypt(String seed, String plaintext) { 28 | byte[] rawKey = getRawKey(seed.getBytes()); 29 | byte[] result = encrypt(rawKey, plaintext.getBytes()); 30 | return toHex(result); 31 | } 32 | 33 | @Override 34 | public String decrypt(String seed, String ciphertext) { 35 | byte[] rawKey = getRawKey(seed.getBytes()); 36 | byte[] enc = toByte(ciphertext); 37 | byte[] result = decrypt(rawKey, enc); 38 | return new String(result); 39 | 40 | } 41 | 42 | private static void handleGettingAesFailure() { 43 | Log.d(TAG, "Getting AES provider has failed but this can't be happened"); 44 | } 45 | 46 | private static byte[] getRawKey(byte[] seed) { 47 | KeyGenerator kgen = null; 48 | 49 | try { 50 | kgen = KeyGenerator.getInstance("AES"); 51 | SecureRandom sr = null; 52 | if (android.os.Build.VERSION.SDK_INT >= JELLY_BEAN_MR1) { 53 | sr = SecureRandom.getInstance("SHA1PRNG", "Crypto"); 54 | } else { 55 | sr = SecureRandom.getInstance("SHA1PRNG"); 56 | } 57 | if (sr == null) { 58 | Log.d(TAG, "Failed to get SecureRandom Crypto Algorithm"); 59 | return null; 60 | } 61 | sr.setSeed(seed); 62 | kgen.init(128, sr); // 192 and 256 bits may not be available 63 | } catch (NoSuchAlgorithmException e) { 64 | // Impossible 65 | handleGettingAesFailure(); 66 | } catch (NoSuchProviderException e) { 67 | // Android whose version is equal or above than JELLY_BEAN_MR1 provides Crypto provider 68 | // If it doesn't, this method can work as it is supposed to do 69 | throw new RuntimeException(e); 70 | } 71 | 72 | if (kgen != null) { 73 | SecretKey skey = kgen.generateKey(); 74 | return skey.getEncoded(); 75 | } else { 76 | return null; 77 | } 78 | } 79 | 80 | private byte[] encrypt(byte[] raw, byte[] clear) { 81 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); 82 | Cipher cipher; 83 | byte [] encrypted = null; 84 | try { 85 | cipher = Cipher.getInstance("AES"); 86 | cipher.init(Cipher.ENCRYPT_MODE, skeySpec); 87 | encrypted = cipher.doFinal(clear); 88 | } catch (NoSuchAlgorithmException e) { 89 | // Android provides AES Encryption by default 90 | handleGettingAesFailure(); 91 | } 92 | // Exceptions under here occurs because of programming error 93 | catch (NoSuchPaddingException e) { 94 | throw new RuntimeException(e); 95 | } catch (InvalidKeyException e) { 96 | throw new RuntimeException(e); 97 | } catch (IllegalBlockSizeException e) { 98 | throw new RuntimeException(e); 99 | } catch (BadPaddingException e) { 100 | throw new RuntimeException(e); 101 | } 102 | 103 | return encrypted; 104 | } 105 | 106 | private byte[] decrypt(byte[] raw, byte[] encrypted) { 107 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); 108 | Cipher cipher; 109 | byte [] decrypted = null; 110 | try { 111 | cipher = Cipher.getInstance("AES"); 112 | cipher.init(Cipher.DECRYPT_MODE, skeySpec); 113 | decrypted = cipher.doFinal(encrypted); 114 | } catch (NoSuchAlgorithmException e) { 115 | // Can't be happened 116 | handleGettingAesFailure(); 117 | } 118 | // Exceptions under here occurs because of programming error 119 | catch (NoSuchPaddingException e) { 120 | throw new RuntimeException(e); 121 | } catch (InvalidKeyException e) { 122 | throw new RuntimeException(e); 123 | } catch (IllegalBlockSizeException e) { 124 | throw new RuntimeException(e); 125 | } catch (BadPaddingException e) { 126 | throw new RuntimeException(e); 127 | } 128 | 129 | return decrypted; 130 | } 131 | 132 | private byte[] toByte(String hexString) { 133 | int len = hexString.length() / 2; 134 | byte[] result = new byte[len]; 135 | for (int i = 0; i < len; i++) { 136 | result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), 16).byteValue(); 137 | } 138 | return result; 139 | } 140 | 141 | private String toHex(byte[] buf) { 142 | if (buf == null) { 143 | return ""; 144 | } 145 | StringBuffer result = new StringBuffer(2 * buf.length); 146 | for (int i = 0; i < buf.length; i++) { 147 | appendHex(result, buf[i]); 148 | } 149 | return result.toString(); 150 | } 151 | 152 | private final static String HEX = "0123456789ABCDEF"; 153 | 154 | private static void appendHex(StringBuffer sb, byte bt) { 155 | sb.append(HEX.charAt((bt >> 4) & 0x0f)).append(HEX.charAt(bt & 0x0f)); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/cipher/CipherMode.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.cipher; 2 | 3 | /** 4 | * Cipher mode to be used for encryption
5 | * Currently, default cipher algorithm, AES, is solely provided 6 | * 7 | * @author jaemin.woo 8 | */ 9 | public enum CipherMode { 10 | AES, 11 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/cipher/CipherObject.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.cipher; 2 | 3 | 4 | /** 5 | * @author jaemin.woo 6 | */ 7 | interface CipherObject { 8 | 9 | public String encrypt(String seed, String plainText); 10 | 11 | 12 | public String decrypt(String seed, String cipherText); 13 | } 14 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/cipher/CipherObjectFactory.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.cipher; 2 | 3 | /** 4 | * @author jaemin.woo 5 | */ 6 | class CipherObjectFactory { 7 | private CipherObjectFactory() {} 8 | 9 | public static CipherObject getInstance(CipherMode mode) { 10 | if (CipherMode.AES == mode) { 11 | return new AesCipher(); 12 | } 13 | return new AesCipher(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/cipher/CipherUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.cipher; 2 | 3 | 4 | /** 5 | * Provides basic encryption and decryption methods
6 | * Default cipher algorithm is AES and currently algorithms other than AES are not provided 7 | * 8 | * @author jaemin.woo 9 | */ 10 | public class CipherUtils { 11 | CipherMode cipherMode; 12 | CipherObject cipherObject; 13 | 14 | public CipherUtils() { 15 | this(CipherMode.AES); 16 | } 17 | 18 | public CipherUtils(CipherMode cipherMode) { 19 | this.cipherMode = cipherMode; 20 | cipherObject = CipherObjectFactory.getInstance(this.cipherMode); 21 | } 22 | 23 | /** 24 | * 25 | * @param seed Seed string which is used for encryption and decryption 26 | * @param plainText String to be encrypted 27 | * @return encrypted text 28 | */ 29 | public String encrypt(String seed, String plainText) { 30 | return cipherObject.encrypt(seed, plainText); 31 | } 32 | 33 | /** 34 | * 35 | * @param seed Seed string which is used for encryption and decryption 36 | * @param cipherText String encrypted by encrypt method 37 | * @return plain text 38 | */ 39 | public String decrypt(String seed, String cipherText) { 40 | return cipherObject.decrypt(seed, cipherText); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/device/DeviceType.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.device; 2 | 3 | /** 4 | * There are two types of android device, tablet and handset
5 | * In the near future, new type of devices such as glasses, watch and wearable stuff can be come up
6 | * 7 | */ 8 | public enum DeviceType { 9 | Tablet, Handset 10 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/device/DeviceTypeDetector.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.device; 2 | /* 3 | * DeviceInfoHelper.java 4 | * 5 | * Copyright 2011 NHN Corp. All rights Reserved. 6 | * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 7 | */ 8 | 9 | import android.app.Activity; 10 | import android.content.Context; 11 | import android.content.res.Configuration; 12 | import android.util.DisplayMetrics; 13 | 14 | class DeviceTypeDetector { 15 | private static final int SCREENLAYOUT_SIZE_XLARGE = 4; 16 | private static final int DENSITY_TV = 213; 17 | private static final int DENSITY_XHIGH = 320; 18 | 19 | /** 20 | * Checks if the device is a tablet or a phone 21 | * 22 | * @param activityContext The Activity Context. 23 | * @return Returns true if the device is a Tablet 24 | */ 25 | public DeviceType getDeviceType(Context activityContext) { 26 | // Verifies if the Generalized Size of the device is XLARGE to be 27 | // considered a Tablet 28 | boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == SCREENLAYOUT_SIZE_XLARGE); 29 | 30 | // If XLarge, checks if the Generalized Density is at least MDPI 31 | // (160dpi) 32 | if (xlarge) { 33 | DisplayMetrics metrics = new DisplayMetrics(); 34 | Activity activity = (Activity)activityContext; 35 | activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); 36 | 37 | // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160, 38 | // DENSITY_TV=213, DENSITY_XHIGH=320 39 | if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT 40 | || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH 41 | || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM 42 | || metrics.densityDpi == DENSITY_TV 43 | || metrics.densityDpi == DENSITY_XHIGH) { 44 | 45 | // this is a tablet! 46 | return DeviceType.Tablet; 47 | } 48 | } 49 | 50 | // this is not a tablet! 51 | return DeviceType.Handset; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/device/DeviceUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.device; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * 7 | * @author jaemin.woo 8 | * 9 | */ 10 | public class DeviceUtils { 11 | private static DeviceTypeDetector deviceTypeDetector; 12 | private static PhoneNumberUtils phoneNumberUtils; 13 | 14 | static { 15 | phoneNumberUtils = new PhoneNumberUtils(); 16 | deviceTypeDetector = new DeviceTypeDetector(); 17 | } 18 | 19 | /** 20 | * Gives type information of user device.
21 | * 22 | * According to the Google API guide, 23 | * devices whose screen size is less than 7 inches will be classified as a handset.
24 | * For example, Huge looking mobile phones like Samsung galaxy Note III will be sorted as a handset by this rule.
25 | * Among the rest, devices with 7 inch screen and LDPI will be classified as a handset too.
26 | * All other devices with 7 or larger screen will be classified as a tablet. 27 | * 28 | * @param context 29 | * Context derived from Activity. ApplicationContext can not be 30 | * used to take advantage of this function. 31 | * 32 | * @return DeviceType.Tablet if the screen size is equal to or larger than 33 | * XLarge, which is defined as display size from 7 to 10 inches;
34 | * DeviceType.Handset if the screen size is smaller than XLarge 35 | */ 36 | public static DeviceType getDeviceType(Context context) { 37 | return deviceTypeDetector.getDeviceType(context); 38 | } 39 | 40 | /** 41 | * Returns launcher type. 42 | * 43 | * @param context 44 | * Context to provide package information 45 | * @return LauncherType 46 | */ 47 | public static LauncherType getLauncherType(Context context) { 48 | return LauncherTypeDetector.getType(context); 49 | } 50 | 51 | /** 52 | * Determines if user device has capability of SMS.

53 | * 54 | * Requires READ_PHONE_STATE Permission must be set to use this function 55 | * @param context 56 | * Context to derive device information 57 | * @return true if user device has SMS capability; false otherwise 58 | */ 59 | public static boolean hasSmsCapability(Context context) { 60 | return phoneNumberUtils.isAbleToReceiveSms(context); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/device/LauncherInfo.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.device; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.pm.PackageManager; 6 | import android.content.pm.ResolveInfo; 7 | 8 | class LauncherInfo { 9 | public static String getName(Context context) { 10 | PackageManager pm = context.getPackageManager(); 11 | final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 12 | mainIntent.addCategory(Intent.CATEGORY_HOME); 13 | ResolveInfo resolveInfo = pm.resolveActivity(mainIntent, PackageManager.MATCH_DEFAULT_ONLY); 14 | if (resolveInfo.activityInfo.applicationInfo.className == null) { 15 | return "ANDROID"; 16 | } 17 | return resolveInfo.activityInfo.applicationInfo.packageName + resolveInfo.activityInfo.applicationInfo.className; 18 | } 19 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/device/LauncherType.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.device; 2 | 3 | public enum LauncherType { 4 | /** Samsung Default Home */ 5 | SAMSUNG_SMALL("com.sec.android.app.twlauncher.LauncherApplication", 140), 6 | 7 | /** Samsung Large Text */ 8 | SMASUNG_LARGE("com.sec.android.app.seniorlauncher.LauncherApplication", 140), 9 | 10 | /** Galaxy S3/S4 */ 11 | SMASUNG_GALAXY3_4("com.sec.android.app.launchercom.android.launcher2.LauncherApplication", 200), 12 | 13 | /** ICS Default Launcher */ 14 | ICS_JELLY_BEAN_DEFAULT("com.android.launcher2.LauncherApplication", 150), 15 | 16 | /** Gingerbread Default Launcher */ 17 | GINGERBREAD_DEFAULT("com.android.launcher2.LauncherApplication", 125), 18 | 19 | /** GO Launcher */ 20 | GO("com.jiubang.ggheart.launcher.GOLauncherApp", 115), 21 | 22 | /** Go Launcher */ 23 | GO_EX("com.gau.go.launcherex", 115), 24 | 25 | /** Nova Launcher */ 26 | NOVA("com.teslacoilsw.launcher.NovaApplication", 105), 27 | 28 | /** Apex Launcher */ 29 | APEX("com.anddoes.launcher.LauncherApplication", 105), 30 | 31 | /** LG Default Launcher */ 32 | LG_DEFUALT("com.lge.launcher.LauncherApplication", 95), 33 | 34 | /** If Launcher is not defined */ 35 | ANDROID("android", 130); 36 | 37 | String packageName; 38 | float paddingDp; 39 | 40 | private LauncherType(String packageName, float paddingDp) { 41 | this.packageName = packageName; 42 | this.paddingDp = paddingDp; 43 | } 44 | 45 | public float getPaddingDp() { 46 | return paddingDp; 47 | } 48 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/device/LauncherTypeDetector.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.device; 2 | import java.util.ArrayList; 3 | import java.util.List; 4 | 5 | import android.content.Context; 6 | import android.os.Build; 7 | 8 | /** 9 | * @author jaemin.woo 10 | */ 11 | class LauncherTypeDetector { 12 | private static List EXCEPT_DEVICES = new ArrayList(); 13 | 14 | static { 15 | // Galaxy S 16 | EXCEPT_DEVICES.add("SHW-M180S"); 17 | } 18 | 19 | private static boolean containExceptDevices() { 20 | String device = android.os.Build.DEVICE; 21 | return EXCEPT_DEVICES.contains(device); 22 | } 23 | 24 | public static LauncherType getType(Context context) { 25 | String packageName = LauncherInfo.getName(context); 26 | 27 | if (packageName.length() == 0) { 28 | return LauncherType.ANDROID; 29 | } 30 | 31 | if (containExceptDevices()) { 32 | return LauncherType.ANDROID; 33 | } 34 | 35 | for (LauncherType type : LauncherType.values()) { 36 | if (packageName.contains(type.packageName)) { 37 | if (type == LauncherType.ICS_JELLY_BEAN_DEFAULT 38 | && !(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)) { 39 | return LauncherType.GINGERBREAD_DEFAULT; 40 | } 41 | return type; 42 | } 43 | } 44 | return LauncherType.ANDROID; 45 | } 46 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/device/PhoneNumberUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.device; 2 | 3 | import android.content.Context; 4 | import android.telephony.TelephonyManager; 5 | 6 | /** 7 | * 8 | * @author jaemin.woo 9 | * 10 | */ 11 | class PhoneNumberUtils { 12 | public String getMobilePhoneNumber(Context context) { 13 | TelephonyManager telManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 14 | return telManager.getLine1Number(); 15 | } 16 | 17 | public boolean isAbleToReceiveSms(Context context) { 18 | String phoneNumber = getMobilePhoneNumber(context); 19 | 20 | if (phoneNumber == null) 21 | return false; 22 | 23 | if (phoneNumber.length() != 0) 24 | return true; 25 | 26 | return false; 27 | } 28 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/input/KeyboardUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.input; 2 | 3 | import java.util.Timer; 4 | import java.util.TimerTask; 5 | 6 | import android.content.Context; 7 | import android.view.View; 8 | import android.view.inputmethod.InputMethodManager; 9 | 10 | /** 11 | * 12 | * @author jaemin.woo 13 | * 14 | */ 15 | public class KeyboardUtils { 16 | private static SoftwareKeyDetector deviceKeyboardDetector; 17 | 18 | static { 19 | deviceKeyboardDetector = new SoftwareKeyDetector(); 20 | } 21 | 22 | /** 23 | * Shows keypad 24 | * 25 | * @param context 26 | * @param view View to have keypad control 27 | */ 28 | public static void showSoftKeyboard(Context context, View view) { 29 | InputMethodManager imm = (InputMethodManager) context 30 | .getSystemService(Context.INPUT_METHOD_SERVICE); 31 | imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); 32 | } 33 | 34 | /** 35 | * Hides keypad 36 | * 37 | * @param context 38 | * @param view View holding keypad control 39 | */ 40 | public static void hideSoftKeyboard(Context context, View view) { 41 | InputMethodManager imm = (InputMethodManager) context 42 | .getSystemService(Context.INPUT_METHOD_SERVICE); 43 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 44 | } 45 | 46 | /** 47 | * Toggles keypad 48 | * 49 | * @param context 50 | */ 51 | public static void toggleKeyPad(Context context) { 52 | InputMethodManager imm = (InputMethodManager) context 53 | .getSystemService(Context.INPUT_METHOD_SERVICE); 54 | if (imm != null) { 55 | imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); 56 | } 57 | } 58 | 59 | /** 60 | * Delayed version of {@link #hideSoftKeyboard(Context, View) 61 | * hideSoftKeyboard} method 62 | * 63 | * @param context 64 | * @param view View holding keypad control 65 | */ 66 | public static void delayedHideSoftKeyboard(final Context context, 67 | final View view, int delay) { 68 | TimerTask task = new TimerTask() { 69 | @Override 70 | public void run() { 71 | hideSoftKeyboard(context, view); 72 | } 73 | }; 74 | 75 | Timer timer = new Timer(); 76 | timer.schedule(task, delay); 77 | } 78 | 79 | /** 80 | * Delayed version of {@link #showSoftKeyboard(Context, View) 81 | * showSoftKeyboard} method 82 | * 83 | * @param context 84 | * @param view View to have keypad control 85 | */ 86 | public static void delayedShowSoftKeyboard(final Context context, 87 | final View view, int delay) { 88 | TimerTask task = new TimerTask() { 89 | @Override 90 | public void run() { 91 | showSoftKeyboard(context, view); 92 | } 93 | }; 94 | 95 | Timer timer = new Timer(); 96 | timer.schedule(task, delay); 97 | } 98 | 99 | /** 100 | * Determines if the device has software keys. 101 | * 102 | * @return true if device has software keys; false otherwise 103 | */ 104 | public static boolean hasSoftwareKeys(Context context) { 105 | return deviceKeyboardDetector.hasSoftwareKeys(context); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/input/SoftwareKeyDetector.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.input; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import android.annotation.TargetApi; 6 | import android.content.Context; 7 | import android.os.Build; 8 | import android.os.IBinder; 9 | import android.view.KeyCharacterMap; 10 | import android.view.KeyEvent; 11 | import android.view.ViewConfiguration; 12 | 13 | /** 14 | * 15 | * @author jaemin.woo 16 | * 17 | */ 18 | class SoftwareKeyDetector { 19 | @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) 20 | public boolean hasSoftwareKeys(Context context) { 21 | int sdkVersion = Build.VERSION.SDK_INT; 22 | 23 | // Gingerbread and below are considered to have physical buttons. 24 | if (sdkVersion <= Build.VERSION_CODES.GINGERBREAD_MR1) 25 | return false; 26 | 27 | // Honeycomb is dedicated to the tablets having no physical buttons. 28 | if (sdkVersion >= Build.VERSION_CODES.GINGERBREAD_MR1 && sdkVersion <= Build.VERSION_CODES.HONEYCOMB_MR2) 29 | return true; 30 | 31 | // ICS and above provide convenient function able to determine if the 32 | // device has 33 | // physical buttons or not. 34 | // This function is not available below ICS 35 | 36 | boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey(); 37 | boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK); 38 | 39 | return !hasMenuKey && !hasBackKey; 40 | } 41 | 42 | private boolean softkeyNavigationCalled; 43 | private boolean softkeyNavigationBar; 44 | private Object lock = new Object(); 45 | 46 | public boolean getHasSoftkeyNavigationBar() { 47 | // Prevent reflection from being called indefinitely 48 | if (softkeyNavigationCalled) { 49 | return softkeyNavigationBar; 50 | } 51 | 52 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { 53 | return false; 54 | } 55 | 56 | try { 57 | Class serviceManagerClass = Class.forName("android.os.ServiceManager"); 58 | Method getService = serviceManagerClass.getDeclaredMethod("getService", String.class); 59 | Object ws = getService.invoke(null, "window"); 60 | Class wmClassStub = Class.forName("android.view.IWindowManager$Stub"); 61 | Method asInterface = wmClassStub.getDeclaredMethod("asInterface", IBinder.class); 62 | Object iWindowManager = asInterface.invoke(null, (IBinder)ws); 63 | Method declaredMethod = iWindowManager.getClass().getDeclaredMethod("hasNavigationBar"); 64 | 65 | synchronized (lock) { 66 | softkeyNavigationBar = (Boolean) declaredMethod.invoke(iWindowManager); 67 | } 68 | } 69 | catch (Exception e) { 70 | // If this method does not exist, then it may be thought that the device does not have one 71 | softkeyNavigationCalled = false; 72 | } 73 | 74 | synchronized (lock) { 75 | softkeyNavigationCalled = true; 76 | } 77 | 78 | return softkeyNavigationBar; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/storage/DiskUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.storage; 2 | 3 | import java.io.File; 4 | 5 | import android.content.Context; 6 | import android.os.Environment; 7 | 8 | /** 9 | * Cautious!
10 | * External disk do not necessarily mean that it is a SD Card.
11 | * 12 | * Any large size of space can be external disk.
13 | * As such, do not make assumptions that you are working on SDCard.
14 | * 15 | * getMicroSDPath method that finds MicroSDCard path if it exists has been removed since it depends on /system/etc/vold.fstab file.
16 | * Because that file was removed as of JELLY_BEAN_MR2, this function could not work as solid as it should do.
17 | * For that reason, this method is excluded. 18 | * 19 | * @author jaemin.woo 20 | */ 21 | public final class DiskUtils { 22 | private static final String DATA_FOLDER = "/Android/data"; 23 | protected static final String TEMPORARY_FOLDER = "/temp"; 24 | protected static final String CACHE_FOLDER = "/cache"; 25 | 26 | /** 27 | * Checks if External storage is mounted 28 | * @return true if mounted; false otherwise 29 | */ 30 | public static boolean isExternalStorageMounted() { 31 | return Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); 32 | } 33 | 34 | /** 35 | * Returns directory name to save cache data in the external storage

36 | * 37 | * This method always returns path of external storage even if it does not exist.
38 | * As such, make sure to call isExternalStorageMounted method as state-testing method and then call this function only if state-testing method returns true. 39 | * 40 | * @param context Context to get external storage information 41 | * @return String containing cache directory name 42 | */ 43 | public static String getExternalDirPath(Context context) { 44 | return Environment.getExternalStorageDirectory().getAbsolutePath() + DATA_FOLDER + File.separator + context.getPackageName() + CACHE_FOLDER; 45 | } 46 | 47 | /** 48 | * Returns directory name to save temporary files in the external storage for temporary

49 | * 50 | * This method always returns path of external storage even if it does not exist.
51 | * As such, make sure to call isExternalStorageMounted method as state-testing method and then call this function only if state-testing method returns true. 52 | * 53 | * @param context Context to get external storage information 54 | * @return String containing temporary directory name 55 | */ 56 | public static String getExternalTemporaryDirPath(Context context) { 57 | return Environment.getExternalStorageDirectory().getAbsolutePath() + DATA_FOLDER + File.separator + context.getPackageName() + TEMPORARY_FOLDER; 58 | } 59 | 60 | 61 | /** 62 | * Returns root directory of the external storage.

63 | * 64 | * This method always returns path of external storage even if it does not exist.
65 | * As such, make sure to call isExternalStorageMounted method as state-testing method and then call this function only if state-testing method returns true. 66 | * 67 | * @param context Context to get external storage information 68 | * @return String containing external root directory name 69 | */ 70 | public static String getExternalContextRootDir(Context context) { 71 | return Environment.getExternalStorageDirectory().getAbsolutePath() + DATA_FOLDER + File.separator + context.getPackageName(); 72 | } 73 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/string/CompressUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.string; 2 | 3 | 4 | /** 5 | * StringUtils provides string related function
6 | * By using compressString and deompressString, string long and has repeated part can be shrunk 7 | * 8 | * @author jaemin.woo 9 | */ 10 | public class CompressUtils { 11 | private static StringCompressor stringCompressor; 12 | 13 | static { 14 | stringCompressor = new StringCompressor(); 15 | } 16 | 17 | public static String compressString(String stringToBeCompressed) { 18 | return stringCompressor.compress(stringToBeCompressed); 19 | } 20 | 21 | public static String decompressString(String stringToBeDecompressed) { 22 | return stringCompressor.decompress(stringToBeDecompressed); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/string/StringCompressor.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.string; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.ByteArrayInputStream; 5 | import java.io.ByteArrayOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.InputStreamReader; 9 | import java.io.UnsupportedEncodingException; 10 | import java.net.URLDecoder; 11 | import java.util.zip.GZIPInputStream; 12 | import java.util.zip.GZIPOutputStream; 13 | 14 | import android.net.Uri; 15 | import android.util.Base64; 16 | import android.util.Log; 17 | 18 | /** 19 | * It is easy to be confused by the result that the compressed string is not shorter than original one.
20 | * When string to be compressed neither lengthy nor repeated at all, then that is not the case for this method to be utilized. 21 | * Long repeated string is where this method really shines.

22 | * Look at these examples.
23 | * A long repeated string 'aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbcccccccccc' will be compressed into 'H4slAAAAAAAAAEtMxAKSslBkOAAA0lkFljMAAAA=' which is shorter than original one. 24 | * In contrast, A short but not repeated string 'abcdefghijklmnopqrstuvwxyz' will be compressed into 'H4slAAAAAAAAAEtMSk5JTUvPyMzKzsnNyy8oLCouKS0rr6isAgC9UCdMGgAAAA==' which is longer than original string. 25 | * 26 | * @author jaemin.woo 27 | * 28 | */ 29 | public class StringCompressor { 30 | private static final int BUFFER_SIZE = 2 * 1024; 31 | 32 | public String compress(String str) { 33 | if (str == null || str.length() == 0) { 34 | return str; 35 | } 36 | 37 | String compressBase64EncodeStr = null; 38 | InputStream is = null; 39 | ByteArrayOutputStream baos = null; 40 | GZIPOutputStream gzos = null; 41 | 42 | try { 43 | is = new ByteArrayInputStream(str.getBytes("UTF-8")); 44 | baos = new ByteArrayOutputStream(); 45 | gzos = new GZIPOutputStream(baos); 46 | byte buffer[] = new byte[BUFFER_SIZE]; 47 | int count = -1; 48 | while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) { 49 | gzos.write(buffer, 0, count); 50 | } 51 | gzos.finish(); 52 | compressBase64EncodeStr = new String(Base64.encode( 53 | baos.toByteArray(), Base64.DEFAULT)); 54 | } catch (UnsupportedEncodingException e1) { 55 | // This can't be happened 56 | throw new RuntimeException("This would never be happened"); 57 | } catch (IOException e) { 58 | throw new RuntimeException(String.format("Exception occured while compressing String \"%s\"", str)); 59 | } finally { 60 | if (is != null) { 61 | try { 62 | is.close(); 63 | } catch (IOException e) { 64 | throw new RuntimeException("Exception occured while closing InputStream"); 65 | } 66 | } 67 | 68 | if (gzos != null) { 69 | try { 70 | gzos.close(); 71 | } catch (IOException e) { 72 | throw new RuntimeException("Exception occured while closing GZIPOutputStream"); 73 | } 74 | } 75 | } 76 | 77 | return compressBase64EncodeStr; 78 | } 79 | 80 | private static String urlDecode(String src) { 81 | String dst = null; 82 | try { 83 | dst = URLDecoder.decode(src, "UTF-8"); 84 | } catch (UnsupportedEncodingException e) { 85 | Log.e("UtilSet", 86 | "An UnsupportedEncodingException occured in " 87 | + StringCompressor.class 88 | + ".urlDecode. However, it does not terminate application and continues decode with default encoding character set."); 89 | dst = Uri.decode(src); 90 | } 91 | 92 | return dst; 93 | } 94 | 95 | public String decompress(String str) { 96 | if (str == null || str.length() == 0) { 97 | return str; 98 | } 99 | 100 | String decompressStr = null; 101 | InputStream is = null; 102 | GZIPInputStream gzis = null; 103 | ByteArrayOutputStream baos = null; 104 | 105 | try { 106 | is = new ByteArrayInputStream(Base64.decode(urlDecode(str) 107 | .getBytes(), Base64.DEFAULT)); 108 | gzis = new GZIPInputStream(is); 109 | baos = new ByteArrayOutputStream(); 110 | 111 | byte buffer[] = new byte[BUFFER_SIZE]; 112 | int count = -1; 113 | while ((count = gzis.read(buffer, 0, BUFFER_SIZE)) != -1) { 114 | baos.write(buffer, 0, count); 115 | } 116 | 117 | decompressStr = new String(baos.toByteArray(), "UTF-8"); 118 | } catch (IOException e) { 119 | throw new RuntimeException(String.format("Exception occured while decompressing string \"%s\"")); 120 | } 121 | finally { 122 | if (baos != null) { 123 | try { 124 | baos.close(); 125 | } catch (IOException e) { 126 | throw new RuntimeException("Exception occured while closing ByteArrayOutputStream"); 127 | } 128 | } 129 | 130 | if (gzis != null) { 131 | try { 132 | gzis.close(); 133 | } catch (IOException e) { 134 | throw new RuntimeException("Exception occured while closing GZIPInputStream"); 135 | } 136 | } 137 | } 138 | 139 | return decompressStr; 140 | } 141 | 142 | public InputStream decompress(InputStream is) { 143 | if (is == null) { 144 | return is; 145 | } 146 | 147 | InputStream retIs = null; 148 | ByteArrayInputStream bais = null; 149 | GZIPInputStream gzis = null; 150 | ByteArrayOutputStream baos = null; 151 | 152 | try { 153 | bais = new ByteArrayInputStream(Base64.decode( 154 | convertStreamToByteArray(is), Base64.DEFAULT)); 155 | gzis = new GZIPInputStream(bais); 156 | baos = new ByteArrayOutputStream(); 157 | 158 | byte buffer[] = new byte[BUFFER_SIZE]; 159 | int count = -1; 160 | while ((count = gzis.read(buffer, 0, BUFFER_SIZE)) != -1) { 161 | baos.write(buffer, 0, count); 162 | } 163 | 164 | retIs = new ByteArrayInputStream(baos.toByteArray()); 165 | } catch (IOException e) { 166 | throw new RuntimeException("Exception occured while decompressing InputStream"); 167 | } finally { 168 | if (baos != null) { 169 | try { 170 | baos.close(); 171 | } catch (IOException e) { 172 | throw new RuntimeException("Exception occured while closing ByteArrayOutputStream"); 173 | } 174 | } 175 | 176 | if (gzis != null) { 177 | try { 178 | gzis.close(); 179 | } catch (IOException e) { 180 | throw new RuntimeException("Exception occured while closing GZIPInputStream"); 181 | } 182 | } 183 | } 184 | 185 | return retIs; 186 | } 187 | 188 | private byte[] convertStreamToByteArray(InputStream is) throws IOException { 189 | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); 190 | StringBuilder sb = new StringBuilder(); 191 | String line = null; 192 | 193 | try { 194 | while ((line = reader.readLine()) != null) { 195 | sb.append(line); 196 | } 197 | } catch (IOException e) { 198 | // Just bypasses exception so that the caller can handle finalization works or propagate exception 199 | throw e; 200 | } finally { 201 | try { 202 | is.close(); 203 | } catch (IOException e) { 204 | // This barely happens. 205 | // Just bypasses exception so that the caller can handle finalization works or propagate exception 206 | throw e; 207 | } 208 | } 209 | 210 | return sb.toString().getBytes(); 211 | } 212 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/system/ProcessorUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.system; 2 | 3 | import java.io.File; 4 | import java.io.FileFilter; 5 | import java.util.regex.Pattern; 6 | 7 | import android.util.Log; 8 | 9 | class ProcessorUtils { 10 | /** 11 | http://stackoverflow.com/questions/7962155/how-can-you-detect-a-dual-core-cpu-on-an-android-device-from-code 12 | * Gets the number of cores available in this device, across all processors. 13 | * Requires: Ability to peruse the file system at "/sys/devices/system/cpu" 14 | * @return The number of cores, or Runtime.getRuntime().availableProcessors() if failed to get result 15 | */ 16 | public static int getNumCores() { 17 | //Private Class to display only CPU devices in the directory listing 18 | class CpuFilter implements FileFilter { 19 | 20 | @Override 21 | public boolean accept(File pathname) { 22 | //Check if filename is "cpu", followed by a single digit number 23 | if(Pattern.matches("cpu[0-9]", pathname.getName())) { 24 | return true; 25 | } 26 | 27 | return false; 28 | } 29 | } 30 | 31 | try { 32 | //Get directory containing CPU info 33 | File dir = new File("/sys/devices/system/cpu/"); 34 | 35 | //Filter to only list the devices we care about 36 | File[] files = dir.listFiles(new CpuFilter()); 37 | 38 | if (files == null) 39 | return Runtime.getRuntime().availableProcessors(); 40 | 41 | //Return the number of cores (virtual CPU devices) 42 | return files.length; 43 | } catch(Exception e) { 44 | // The number of cores can vary with JVM status 45 | return Runtime.getRuntime().availableProcessors(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/system/RootChecker.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.system; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | 8 | import android.util.Log; 9 | 10 | class RootChecker { 11 | private static final String TAG = "RootChecker"; 12 | private static final String[] PLACES = { "/sbin/", "/system/bin/", 13 | "/system/xbin/", "/data/local/xbin/", "/data/local/bin/", 14 | "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/" }; 15 | 16 | private static final String ROOT_CHECKING_BINARY_NAME = "su"; 17 | 18 | public boolean isRootAvailable() { 19 | for (String where : PLACES) { 20 | if (hasFile(where + ROOT_CHECKING_BINARY_NAME)) { 21 | Log.d(TAG, where + ROOT_CHECKING_BINARY_NAME + " was found!"); 22 | return true; 23 | } 24 | } 25 | Log.d(TAG, ROOT_CHECKING_BINARY_NAME + " was not found!"); 26 | return false; 27 | } 28 | 29 | private boolean hasFile(String fullPath) { 30 | try { 31 | File file = new File(fullPath); 32 | return file.exists(); 33 | } catch (Exception e) { 34 | Log.e(TAG, "An error occured while checking " + fullPath, e); 35 | return false; 36 | } 37 | } 38 | 39 | 40 | // Refer : http://lsit81.tistory.com/entry/Android-%EB%A3%A8%ED%8C%85-%EC%97%AC%EB%B6%80-%ED%99%95%EC%9D%B8%ED%95%98%EA%B8%B0 41 | public boolean checkRootingDevice() { 42 | boolean isRootingFlag = false; 43 | BufferedReader reader = null; 44 | try { 45 | Process process = Runtime.getRuntime().exec("find / -name su"); 46 | 47 | reader = new BufferedReader(new InputStreamReader( 48 | process.getInputStream())); 49 | 50 | String result = reader.readLine(); 51 | if (result == null) { 52 | Log.d(TAG, "Failed to execute find command to check if a file which is evidence of root exists"); 53 | throw new RuntimeException("Unable to check if device is rooted"); 54 | } 55 | 56 | if (result.contains("/su") == true) { 57 | isRootingFlag = true; 58 | } 59 | 60 | } catch (Exception e) { 61 | isRootingFlag = false; 62 | } finally { 63 | if (reader != null) { 64 | try { 65 | reader.close(); 66 | } catch (IOException e) { 67 | Log.d(TAG, "Error occured while closing input stream"); 68 | } 69 | } 70 | } 71 | 72 | if (!isRootingFlag) { 73 | isRootingFlag = checkRootingFiles(PLACES); 74 | } 75 | 76 | return isRootingFlag; 77 | } 78 | 79 | private boolean checkRootingFiles(String[] filePaths) { 80 | boolean result = false; 81 | File file; 82 | 83 | for (String path : filePaths) { 84 | file = new File(path + "su"); 85 | 86 | if (file != null && file.exists() && file.isFile()) { 87 | result = true; 88 | break; 89 | } else { 90 | result = false; 91 | } 92 | } 93 | 94 | return result; 95 | } 96 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/system/SystemUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.system; 2 | 3 | 4 | /** 5 | * 6 | * @author jaemin.woo 7 | * 8 | */ 9 | public class SystemUtils { 10 | private static RootChecker rootChecker; 11 | 12 | static { 13 | rootChecker = new RootChecker(); 14 | } 15 | 16 | /** 17 | * Returns boolean that indicates whether current device is rooted or not. 18 | * 19 | *

This method is not guaranteed to cover all the root methods. 20 | * It takes simple approach; 21 | * It tries to finds 'su' command and then executes. 22 | * If 'su' command is not found or unable to execute then an exception will be thrown. 23 | * This indicates that device is rooted. 24 | * Because this is well known way to check root, Root tools today may not be detected by this method. 25 | * For more detailed implementation, refer to 'RootTools' library. 26 | * 27 | * @return true if the device is rooted; false otherwise 28 | * @throws RuntimeException if root check fails 29 | */ 30 | public static boolean isRooted() { 31 | return rootChecker.checkRootingDevice(); 32 | } 33 | 34 | /** 35 | * Returns the number of cores of device.
36 | * Until JELLY_BEAN_MR1, It is possible for processors to be off-line for power saving purpose and those off-line CPUs may not be counted.
37 | * Use this method if Runtime.availableProcessors() seems not to return exact core numbers. 38 | * 39 | * @return the number of cores 40 | */ 41 | public static int getProcessorNumbers() { 42 | return ProcessorUtils.getNumCores(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/ui/ActivityUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.ui; 2 | 3 | import java.util.List; 4 | 5 | import android.app.ActivityManager; 6 | import android.app.ActivityManager.RunningAppProcessInfo; 7 | import android.app.ActivityManager.RunningTaskInfo; 8 | import android.content.ComponentName; 9 | import android.content.Context; 10 | import android.content.Intent; 11 | import android.content.pm.PackageManager; 12 | import android.content.pm.ResolveInfo; 13 | 14 | /** 15 | * 16 | * @author jaemin.woo 17 | * 18 | */ 19 | public class ActivityUtils { 20 | /** Checks if a package is installed. 21 | * 22 | * @param context Context to be used to verify the existence of the package. 23 | * @param packageName Package name to be searched. 24 | * @return true if the package is discovered; false otherwise 25 | */ 26 | public static boolean isPackageInstalled(Context context, String packageName) { 27 | try { 28 | context.getPackageManager().getApplicationInfo(packageName, 0); 29 | return true; 30 | } catch (Exception e) { 31 | return false; 32 | } 33 | } 34 | 35 | /** Returns Package name of base activity.

36 | * Requires GET_TASK permission 37 | * @param context Context to get base activity information 38 | * @return String containing base package name 39 | */ 40 | public static String getBaseActivityPackageName(Context context) { 41 | ComponentName activity = getBaseActivity(context); 42 | if (activity == null) { 43 | return null; 44 | } 45 | return activity.getPackageName(); 46 | } 47 | 48 | /** 49 | * Returns Class name of base activity 50 | * @param context Context to provide activity information 51 | * @return String representing class name of base activity 52 | */ 53 | public static String getBaseActivityClassName(Context context) { 54 | ComponentName activity = getBaseActivity(context); 55 | if (activity == null) { 56 | return null; 57 | } 58 | return activity.getClassName(); 59 | } 60 | 61 | /** 62 | * Returns Package name of top activity 63 | * @param context Context to provide activity information 64 | * @return String representing package name of top activity 65 | */ 66 | public static String getTopActivityPackageName(Context context) { 67 | ComponentName activity = getTopActivity(context); 68 | if (activity == null) { 69 | return null; 70 | } 71 | return activity.getPackageName(); 72 | } 73 | 74 | /** 75 | * Returns Class name of top activity 76 | * @param context Context to provide activity information 77 | * @return String representing class name of top activity 78 | */ 79 | public static String getTopActivityClassName(Context context) { 80 | ComponentName activity = getTopActivity(context); 81 | if (activity == null) { 82 | return null; 83 | } 84 | return activity.getClassName(); 85 | } 86 | 87 | 88 | 89 | /** 90 | * Determines if this application is top activity 91 | * @param context Context to be examined 92 | * @return true if this application is a top activity; false otherwise 93 | */ 94 | public static boolean isTopApplication(Context context) { 95 | ComponentName activity = getTopActivity(context); 96 | if (activity == null) { 97 | return false; 98 | } 99 | return activity.getPackageName().equals(context.getApplicationInfo().packageName); 100 | } 101 | 102 | 103 | /** 104 | * Checks if this application is foreground 105 | * 106 | * @param context Context to be examined 107 | * @return true if this application is running on the top; false otherwise 108 | */ 109 | public static boolean isContextForeground(Context context) { 110 | 111 | ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 112 | List appProcesses = activityManager.getRunningAppProcesses(); 113 | int pid = getPid(); 114 | for (RunningAppProcessInfo appProcess : appProcesses) { 115 | if (appProcess.pid == pid) { 116 | return appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND; 117 | } 118 | } 119 | return false; 120 | } 121 | 122 | private static int getPid() { 123 | return android.os.Process.myPid(); 124 | } 125 | 126 | private static ComponentName getTopActivity(Context context) { 127 | ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); 128 | if (am == null) { 129 | return null; 130 | } 131 | List info = am.getRunningTasks(1); 132 | if (info == null) { 133 | return null; 134 | } 135 | ComponentName activity = info.get(0).topActivity; 136 | return activity; 137 | } 138 | 139 | private static ComponentName getBaseActivity(Context context) { 140 | ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); 141 | if (am == null) { 142 | return null; 143 | } 144 | List info = am.getRunningTasks(1); 145 | if (info == null) { 146 | return null; 147 | } 148 | ComponentName activity = info.get(0).baseActivity; 149 | return activity; 150 | } 151 | 152 | public static boolean isIntentAvailable(Context context, Intent intent) { 153 | PackageManager packageManager = context.getPackageManager(); 154 | List resolves = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); 155 | boolean isIntentAvailable = resolves.size() > 0; 156 | return isIntentAvailable; 157 | } 158 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/ui/PixelUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DisplayUtil.java 3 | * 4 | * Copyright 2011 NHN Corp. All rights Reserved. 5 | * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 6 | */ 7 | package com.navercorp.utilset.ui; 8 | 9 | import android.content.Context; 10 | 11 | /** 12 | * 13 | * @author jaemin.woo 14 | * 15 | */ 16 | public class PixelUtils { 17 | private static final float ROUND_FACTOR = 0.5f; 18 | /** 19 | * Converts Pixel to DP
20 | * @param pixel Pixel 21 | * @return DP 22 | * @see http://developer.android.com/guide/practices/screens_support.html#dips-pels 23 | */ 24 | public static int getDpFromPixel(Context context, int pixel) { 25 | float scale = context.getResources().getDisplayMetrics().density; // get display density 26 | 27 | return (int)(pixel / scale); 28 | } 29 | 30 | /** 31 | * Converts DP to Pixel
32 | * 33 | * @param dp DP 34 | * @return Pixel 35 | * @see http://developer.android.com/guide/practices/screens_support.html#dips-pels 36 | */ 37 | public static int getPixelFromDp(Context context, int dp) { 38 | // Get the screen's density scale 39 | float scale = context.getResources().getDisplayMetrics().density; 40 | 41 | // Convert the dps to pixels, based on density scale 42 | // because dp*scale is cast as an integer value, this will cause the result to be truncated. 43 | // Therefore, Adding ROUND_FACTOR helps the result to have properly rounded integer value. 44 | return (int)(dp * scale + ROUND_FACTOR); 45 | } 46 | } -------------------------------------------------------------------------------- /UtilSet/src/com/navercorp/utilset/ui/ScreenUtils.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.ui; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.provider.Settings; 6 | import android.view.WindowManager; 7 | 8 | /** 9 | * 10 | * @author jaemin.woo 11 | * 12 | */ 13 | public class ScreenUtils { 14 | 15 | /** 16 | * @param activity 17 | * @param dim 0.004f is the least brightness to work. if it is set below 0.004f, it won't work. 18 | */ 19 | public static void setScreenBrightness(Activity activity, float dim) { 20 | WindowManager.LayoutParams lp=activity.getWindow().getAttributes(); 21 | lp.screenBrightness = dim; 22 | activity.getWindow().setAttributes(lp); 23 | } 24 | 25 | /** 26 | * @param context 27 | * @param millis Time for screen to turn off. Setting this value to -1 will prohibit screen from turning off 28 | * 29 | */ 30 | public static void setScreenOffTimeout(Context context, int millis) { 31 | Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, millis); 32 | } 33 | 34 | /** 35 | * Prevents screen from being turned off. 36 | * 37 | * @param activity 38 | */ 39 | public static void setScreenOn(Activity activity) { 40 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 41 | } 42 | 43 | /** 44 | * Let screen to be turned off 45 | * 46 | * @param activity 47 | */ 48 | public static void clearScreenOn(Activity activity) { 49 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /UtilSet/test/com/navercorp/utilset/audio/VolumeUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.audio; 2 | 3 | import static org.hamcrest.Matchers.*; 4 | import static org.hamcrest.MatcherAssert.*; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.robolectric.Robolectric; 10 | import org.robolectric.RobolectricTestRunner; 11 | import org.robolectric.annotation.Config; 12 | import org.robolectric.shadows.ShadowLog; 13 | 14 | import android.content.Context; 15 | 16 | /** 17 | * @author sanghyuk.jung 18 | * 19 | */ 20 | @RunWith(RobolectricTestRunner.class) 21 | @Config(manifest=Config.NONE) 22 | public class VolumeUtilsTest { 23 | private Context context; 24 | 25 | @Before 26 | public void setUp() { 27 | ShadowLog.stream = System.out; 28 | this.context = Robolectric.application; 29 | } 30 | 31 | @Test 32 | public void shouldSetVolume(){ 33 | VolumeUtils.setVolume(context, 3); 34 | int volume = VolumeUtils.getCurrentVolume(context); 35 | assertThat(volume, is(3)); 36 | } 37 | 38 | @Test 39 | public void shouldIncreaseVolume(){ 40 | VolumeUtils.setVolume(context, 3); 41 | VolumeUtils.increaseVolume(context); 42 | int volume = VolumeUtils.getCurrentVolume(context); 43 | assertThat(volume, is(4)); 44 | } 45 | 46 | @Test 47 | public void shouldIncreaseVolumeWithLevel(){ 48 | VolumeUtils.setVolumeWithLevel(context, 3); 49 | VolumeUtils.increaseVolumeWithLevel(context); 50 | int volume = VolumeUtils.getCurrentVolume(context); 51 | assertThat(volume, is(4)); 52 | } 53 | 54 | @Test 55 | public void shouldDecreaseVolume(){ 56 | VolumeUtils.setVolume(context, 3); 57 | VolumeUtils.decreaseVolume(context); 58 | int volume = VolumeUtils.getCurrentVolume(context); 59 | assertThat(volume, is(2)); 60 | } 61 | 62 | @Test 63 | public void shouldDecreaseVolumeWithLevel(){ 64 | VolumeUtils.setVolumeWithLevel(context, 3); 65 | VolumeUtils.decreaseVolumeWithLevel(context); 66 | int volume = VolumeUtils.getCurrentVolume(context); 67 | assertThat(volume, is(2)); 68 | } 69 | 70 | @Test 71 | public void shouldGetMaxiumVolume(){ 72 | int maxVolume = VolumeUtils.getMaximumVolume(context); 73 | int maxVolumeInRobolectric = 15; 74 | assertThat(maxVolume, is(maxVolumeInRobolectric)); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /UtilSet/test/com/navercorp/utilset/cipher/CipherObjectFactoryTest.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.cipher; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.robolectric.RobolectricTestRunner; 9 | import org.robolectric.annotation.Config; 10 | 11 | @RunWith(RobolectricTestRunner.class) 12 | @Config(manifest=Config.NONE) 13 | public class CipherObjectFactoryTest { 14 | 15 | @Before 16 | public void setUp() { 17 | } 18 | 19 | @Test 20 | public void testCipherObjectFactory() { 21 | CipherObject co = CipherObjectFactory.getInstance(CipherMode.AES); 22 | assertNotNull(co); 23 | assertTrue(co instanceof AesCipher); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /UtilSet/test/com/navercorp/utilset/cipher/CipherUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.cipher; 2 | 3 | import static org.hamcrest.Matchers.*; 4 | import static org.junit.Assert.*; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.robolectric.RobolectricTestRunner; 10 | import org.robolectric.annotation.Config; 11 | import org.robolectric.shadows.ShadowLog; 12 | 13 | import com.navercorp.utilset.cipher.CipherMode; 14 | import com.navercorp.utilset.cipher.CipherUtils; 15 | 16 | /** 17 | * @author jaemin.woo 18 | * 19 | */ 20 | @RunWith(RobolectricTestRunner.class) 21 | @Config(manifest=Config.NONE) 22 | public class CipherUtilsTest { 23 | private static String SEED = "SEED"; 24 | private static String PLAIN_TEXT = "PLAIN_TEXT"; 25 | 26 | @Before 27 | public void setUp() { 28 | ShadowLog.stream = System.out; 29 | } 30 | 31 | private String encrypt(String seed, String plainText) { 32 | CipherUtils cipherUtils = new CipherUtils(CipherMode.AES); 33 | return cipherUtils.encrypt(seed, plainText); 34 | } 35 | 36 | @Test 37 | public void shouldEncryptPlainTextWithAESCipher() { 38 | String encrypted = encrypt(SEED, PLAIN_TEXT); 39 | assertThat(encrypted, is(not(PLAIN_TEXT))); 40 | } 41 | 42 | private String decrypt(String seed, String cipherText) { 43 | CipherUtils cipherUtils = new CipherUtils(CipherMode.AES); 44 | return cipherUtils.decrypt(seed, cipherText); 45 | } 46 | 47 | @Test 48 | public void shouldDecryptCipherTextWithAESCipher() { 49 | String encrypted = encrypt(SEED, PLAIN_TEXT); 50 | String decrypted = decrypt(SEED, encrypted); 51 | assertEquals(PLAIN_TEXT, decrypted); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /UtilSet/test/com/navercorp/utilset/storage/DiskUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.storage; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.robolectric.Robolectric; 9 | import org.robolectric.RobolectricTestRunner; 10 | import org.robolectric.annotation.Config; 11 | import org.robolectric.shadows.ShadowLog; 12 | 13 | import android.content.Context; 14 | 15 | /** 16 | * 17 | * @author jaemin.woo 18 | * 19 | */ 20 | @RunWith(RobolectricTestRunner.class) 21 | @Config(manifest=Config.NONE) 22 | public class DiskUtilsTest { 23 | private Context context; 24 | 25 | @Before 26 | public void setUp() { 27 | ShadowLog.stream = System.out; 28 | this.context = Robolectric.application; 29 | } 30 | 31 | @Test 32 | public void shouldReturnExternalDirectoryPath() { 33 | String root = DiskUtils.getExternalContextRootDir(context); 34 | assertNotNull(root); 35 | } 36 | 37 | @Test 38 | public void shouldReturnExternalContextRootDirectory() { 39 | String root = DiskUtils.getExternalContextRootDir(context); 40 | 41 | String path = DiskUtils.getExternalDirPath(context); 42 | assertNotNull(path); 43 | 44 | assertEquals(root + DiskUtils.CACHE_FOLDER, path); 45 | } 46 | 47 | @Test 48 | public void shouldReturnExternalTemporaryDirectoryPath() { 49 | String root = DiskUtils.getExternalContextRootDir(context); 50 | 51 | String path = DiskUtils.getExternalTemporaryDirPath(context); 52 | assertNotNull(path); 53 | 54 | assertEquals(root + DiskUtils.TEMPORARY_FOLDER, path); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /UtilSet/test/com/navercorp/utilset/string/CompressUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.string; 2 | 3 | import static org.hamcrest.MatcherAssert.assertThat; 4 | import static org.hamcrest.Matchers.is; 5 | import static org.hamcrest.Matchers.lessThan; 6 | import static org.hamcrest.Matchers.not; 7 | 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.robolectric.RobolectricTestRunner; 12 | import org.robolectric.annotation.Config; 13 | import org.robolectric.shadows.ShadowLog; 14 | 15 | /** 16 | * @author jaemin.woo 17 | * 18 | */ 19 | @RunWith(RobolectricTestRunner.class) 20 | @Config(manifest=Config.NONE) 21 | public class CompressUtilsTest { 22 | private static String LONG_LONG_STRING = "qwertyuiopassdfghjklxcvbnm!@#$%^&*()"; 23 | private static String STRING_TO_BE_COMPRESSED_EFFECTIVELY = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; 24 | 25 | @Before 26 | public void setUp() { 27 | ShadowLog.stream = System.out; 28 | } 29 | 30 | @Test 31 | public void shouldCompressString() { 32 | String compressed = CompressUtils.compressString(LONG_LONG_STRING); 33 | assertThat(compressed, is(not(LONG_LONG_STRING))); 34 | } 35 | 36 | @Test 37 | public void shouldRestoreCompressedStringToOriginalString() { 38 | String compressed = CompressUtils.compressString(LONG_LONG_STRING); 39 | assertThat(compressed, is(not(LONG_LONG_STRING))); 40 | 41 | String restored = CompressUtils.decompressString(compressed); 42 | assertThat(restored, is(not(compressed))); 43 | assertThat(restored, is(LONG_LONG_STRING)); 44 | } 45 | 46 | @Test 47 | public void shouldCompressShorterThanOriginalStringAsItHasDumbSoLongContents() { 48 | String compressed = CompressUtils.compressString(STRING_TO_BE_COMPRESSED_EFFECTIVELY); 49 | assertThat(compressed.length(), is(lessThan(STRING_TO_BE_COMPRESSED_EFFECTIVELY.length()))); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /UtilSet/test/com/navercorp/utilset/system/SystemUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.system; 2 | 3 | import static org.hamcrest.MatcherAssert.*; 4 | import static org.hamcrest.Matchers.*; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.robolectric.RobolectricTestRunner; 10 | import org.robolectric.annotation.Config; 11 | import org.robolectric.shadows.ShadowLog; 12 | 13 | /** 14 | * 15 | * @author jaemin.woo 16 | * 17 | */ 18 | @RunWith(RobolectricTestRunner.class) 19 | @Config(manifest = Config.NONE) 20 | public class SystemUtilsTest { 21 | @Before 22 | public void setUp() { 23 | ShadowLog.stream = System.out; 24 | } 25 | 26 | @Test 27 | public void shouldReturnAtLeastOneAsProcessorNumbers() { 28 | assertThat(SystemUtils.getProcessorNumbers(), is(greaterThanOrEqualTo(1))); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /UtilSet/test/com/navercorp/utilset/ui/ActivityUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.ui; 2 | 3 | import static org.hamcrest.CoreMatchers.*; 4 | import static org.junit.Assert.*; 5 | 6 | import java.util.Arrays; 7 | 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.robolectric.Robolectric; 12 | import org.robolectric.RobolectricTestRunner; 13 | import org.robolectric.annotation.Config; 14 | import org.robolectric.res.builder.RobolectricPackageManager; 15 | import org.robolectric.shadows.ShadowActivityManager; 16 | import org.robolectric.shadows.ShadowLog; 17 | import org.robolectric.shadows.ShadowWindow; 18 | import org.robolectric.util.ActivityController; 19 | 20 | import android.app.Activity; 21 | import android.app.ActivityManager; 22 | import android.app.ActivityManager.RunningAppProcessInfo; 23 | import android.app.ActivityManager.RunningTaskInfo; 24 | import android.content.ComponentName; 25 | import android.content.Context; 26 | import android.content.pm.PackageInfo; 27 | import android.view.WindowManager; 28 | 29 | /** 30 | * 31 | * @author jaemin.woo 32 | * @author sanghyuk.jung 33 | */ 34 | @RunWith(RobolectricTestRunner.class) 35 | @Config(manifest = Config.NONE) 36 | public class ActivityUtilsTest { 37 | private Context context; 38 | private static final String NOT_INSTALLED_PACKAGE = "seventh.son.of.a.seventh.son"; 39 | private static final String INSTALLED_PACKAGE = "com.navercorp.utilset"; 40 | private static final String TEST_ACTIVITY = "TestActivity"; 41 | 42 | @Before 43 | public void setUp() { 44 | ShadowLog.stream = System.out; 45 | this.context = Robolectric.application; 46 | } 47 | 48 | @Test 49 | public void shouldBeFalseForNotInstalledPackage() { 50 | boolean installed = ActivityUtils.isPackageInstalled(context, NOT_INSTALLED_PACKAGE); 51 | assertThat(installed, is(false)); 52 | } 53 | 54 | @Test 55 | public void shouldBeTrueForInstalledPackage() { 56 | addInstalledPackage(INSTALLED_PACKAGE); 57 | boolean installed = ActivityUtils.isPackageInstalled(context, INSTALLED_PACKAGE); 58 | assertThat(installed, is(true)); 59 | } 60 | 61 | @Test 62 | public void shouldAddKeepScreenOnFlag() { 63 | TestActivity activity = createActivity(TestActivity.class); 64 | ScreenUtils.setScreenOn(activity); 65 | boolean flag = getFlag(activity, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 66 | assertThat(flag, is(true)); 67 | } 68 | 69 | @Test 70 | public void shouldClearKeepScreenOnFlag() { 71 | TestActivity activity = createActivity(TestActivity.class); 72 | ScreenUtils.clearScreenOn(activity); 73 | boolean flag = getFlag(activity, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 74 | assertThat(flag, is(false)); 75 | } 76 | 77 | @Test 78 | public void shouldGetBaseActivityPackageName() { 79 | createRunningTaskInfo().baseActivity = new ComponentName(INSTALLED_PACKAGE, ""); 80 | String packageName = ActivityUtils.getBaseActivityPackageName(context); 81 | assertThat(packageName, is(INSTALLED_PACKAGE)); 82 | } 83 | 84 | @Test 85 | public void shouldGetBaseActivityClassName() { 86 | createRunningTaskInfo().baseActivity = new ComponentName(INSTALLED_PACKAGE, TEST_ACTIVITY); 87 | String className = ActivityUtils.getBaseActivityClassName(context); 88 | assertThat(className, is(TEST_ACTIVITY)); 89 | } 90 | 91 | @Test 92 | public void shouldGetTopActivityPackageName() { 93 | createRunningTaskInfo().topActivity = new ComponentName(INSTALLED_PACKAGE, ""); 94 | String packageName = ActivityUtils.getTopActivityPackageName(context); 95 | assertThat(packageName, is(INSTALLED_PACKAGE)); 96 | } 97 | 98 | @Test 99 | public void shouldGetTopActivityClassName() { 100 | createRunningTaskInfo().topActivity = new ComponentName(INSTALLED_PACKAGE, TEST_ACTIVITY); 101 | String className = ActivityUtils.getTopActivityClassName(context); 102 | assertThat(className, is(TEST_ACTIVITY)); 103 | } 104 | 105 | @Test 106 | public void shouldBeFalseWhenThisApplicationIsNotTop() { 107 | createRunningTaskInfo().topActivity = new ComponentName(INSTALLED_PACKAGE, TEST_ACTIVITY); 108 | boolean top = ActivityUtils.isTopApplication(context); 109 | assertThat(top, is(false)); 110 | } 111 | 112 | @Test 113 | public void shouldBeTrueWhenThisContextIsForeground(){ 114 | // android.os.Process.myPid() returns 0 in Robolectric 115 | createRunningAppProcessInfo(0); 116 | boolean foreground = ActivityUtils.isContextForeground(context); 117 | assertThat(foreground, is(true)); 118 | } 119 | 120 | @Test 121 | public void shouldBeFalseWhenThisContextIsNotForeground(){ 122 | // android.os.Process.myPid() returns 0 in Robolectric 123 | createRunningAppProcessInfo(3); 124 | boolean foreground = ActivityUtils.isContextForeground(context); 125 | assertThat(foreground, is(false)); 126 | } 127 | 128 | private void addInstalledPackage(String packageName) { 129 | RobolectricPackageManager pm = Robolectric.packageManager; 130 | PackageInfo packInfo = new PackageInfo(); 131 | packInfo.packageName = packageName; 132 | pm.addPackage(packInfo); 133 | } 134 | 135 | private RunningTaskInfo createRunningTaskInfo() { 136 | ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 137 | ShadowActivityManager shadowAm = Robolectric.shadowOf(am); 138 | RunningTaskInfo info = new RunningTaskInfo(); 139 | shadowAm.setTasks(Arrays.asList(info)); 140 | return info; 141 | } 142 | 143 | private T createActivity(Class activityClass) { 144 | ActivityController controller = Robolectric.buildActivity(activityClass); 145 | controller.create(); 146 | return controller.get(); 147 | } 148 | 149 | private boolean getFlag(TestActivity activity, int flagToMatch) { 150 | ShadowWindow window = Robolectric.shadowOf(activity.getWindow()); 151 | return window.getFlag(flagToMatch); 152 | } 153 | 154 | private void createRunningAppProcessInfo(int pid) { 155 | ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 156 | ShadowActivityManager shadowAm = Robolectric.shadowOf(am); 157 | 158 | RunningAppProcessInfo proc = new RunningAppProcessInfo(); 159 | proc.importance = RunningAppProcessInfo.IMPORTANCE_FOREGROUND; 160 | proc.pid = pid; 161 | shadowAm.setProcesses(Arrays.asList(proc)); 162 | } 163 | 164 | static class TestActivity extends Activity { 165 | } 166 | } -------------------------------------------------------------------------------- /UtilSet/test/com/navercorp/utilset/ui/PixelUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.ui; 2 | 3 | import static org.hamcrest.CoreMatchers.*; 4 | import static org.junit.Assert.*; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.robolectric.Robolectric; 10 | import org.robolectric.RobolectricTestRunner; 11 | import org.robolectric.annotation.Config; 12 | import org.robolectric.shadows.ShadowLog; 13 | 14 | import android.content.Context; 15 | 16 | /** 17 | * 18 | * @author sanghyuk.jung 19 | */ 20 | @RunWith(RobolectricTestRunner.class) 21 | @Config(manifest = Config.NONE) 22 | public class PixelUtilsTest { 23 | private Context context; 24 | 25 | @Before 26 | public void setUp() { 27 | ShadowLog.stream = System.out; 28 | this.context = Robolectric.application; 29 | } 30 | 31 | @Test 32 | public void shouldGetDpFromPixel(){ 33 | Robolectric.setDisplayMetricsDensity(1.5f); 34 | int dp = PixelUtils.getDpFromPixel(context, 50); 35 | assertThat(dp, is(33)); 36 | } 37 | 38 | @Test 39 | public void shouldPixelDpFromDp(){ 40 | Robolectric.setDisplayMetricsDensity(1.5f); 41 | int pixel = PixelUtils.getPixelFromDp(context, 33); 42 | assertThat(pixel, is(50)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /UtilSet/test/com/navercorp/utilset/ui/ScreenUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilset.ui; 2 | 3 | import static org.hamcrest.CoreMatchers.*; 4 | import static org.junit.Assert.*; 5 | 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.robolectric.Robolectric; 10 | import org.robolectric.RobolectricTestRunner; 11 | import org.robolectric.annotation.Config; 12 | import org.robolectric.shadows.ShadowLog; 13 | import org.robolectric.util.ActivityController; 14 | 15 | import android.app.Activity; 16 | import android.content.Context; 17 | import android.provider.Settings; 18 | import android.provider.Settings.SettingNotFoundException; 19 | import android.view.WindowManager.LayoutParams; 20 | 21 | 22 | /** 23 | * @author sanghyuk.jung 24 | * 25 | */ 26 | @RunWith(RobolectricTestRunner.class) 27 | @Config(manifest = Config.NONE) 28 | public class ScreenUtilsTest { 29 | private Context context; 30 | 31 | @Before 32 | public void setUp() { 33 | ShadowLog.stream = System.out; 34 | this.context = Robolectric.application; 35 | } 36 | @Test 37 | public void shouldChangeScreenBrightness() { 38 | TestActivity activity = createActivity(TestActivity.class); 39 | float brightness = 0.5f; 40 | ScreenUtils.setScreenBrightness(activity, brightness); 41 | 42 | LayoutParams lp = activity.getWindow().getAttributes(); 43 | 44 | assertThat(lp.screenBrightness, is(brightness)); 45 | } 46 | 47 | @Test 48 | public void shouldSetScreenOfTimeout() throws SettingNotFoundException { 49 | int timeout = 15000; 50 | ScreenUtils.setScreenOffTimeout(context, timeout); 51 | 52 | int timeoutFromSettings = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT); 53 | 54 | assertThat(timeoutFromSettings, is(timeout)); 55 | } 56 | 57 | private T createActivity(Class activityClass) { 58 | ActivityController controller = Robolectric.buildActivity(activityClass); 59 | controller.create(); 60 | return controller.get(); 61 | } 62 | 63 | static class TestActivity extends Activity { 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/.checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AndroidUtilSetInstrumentationTest 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.m2e.core.maven2Nature 36 | com.android.ide.eclipse.adt.AndroidNature 37 | org.eclipse.jdt.core.javanature 38 | 39 | 40 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 21 | 22 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetInstrumentationTest/ic_launcher-web.png -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/lib/utilset-0.0.1-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetInstrumentationTest/lib/utilset-0.0.1-SNAPSHOT.jar -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetInstrumentationTest/libs/android-support-v4.jar -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/libs/robotium-solo-4.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetInstrumentationTest/libs/robotium-solo-4.3.jar -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.navercorp 5 | utilset-parent 6 | 1.0.3-SNAPSHOT 7 | 8 | 9 | utilset-instrumentation 10 | apk 11 | UtilSet - Instrumentation 12 | 13 | 14 | 15 | com.navercorp 16 | utilset 17 | provided 18 | 19 | 20 | 21 | com.google.android 22 | android 23 | provided 24 | 25 | 26 | com.google.android 27 | android-test 28 | provided 29 | 30 | 31 | com.google.android 32 | annotations 33 | provided 34 | 35 | 36 | 37 | com.google.android 38 | support-v4 39 | provided 40 | 41 | 42 | 43 | com.navercorp 44 | utilset-sample 45 | ${project.version} 46 | apk 47 | 48 | 49 | com.navercorp 50 | utilset-sample 51 | ${project.version} 52 | provided 53 | jar 54 | 55 | 56 | com.jayway.android.robotium 57 | robotium-solo 58 | 4.0 59 | 60 | 61 | 62 | junit 63 | junit 64 | provided 65 | 66 | 67 | 68 | org.hamcrest 69 | hamcrest-all 70 | 71 | 72 | 73 | org.robolectric 74 | robolectric 75 | 76 | 77 | 78 | 79 | ${project.artifactId} 80 | 81 | 82 | com.jayway.maven.plugins.android.generation2 83 | android-maven-plugin 84 | 85 | 86 | false 87 | true 88 | 89 | 90 | true 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/repo/utilset-0.0.1-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetInstrumentationTest/repo/utilset-0.0.1-SNAPSHOT.jar -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetInstrumentationTest/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetInstrumentationTest/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetInstrumentationTest/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetInstrumentationTest/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/menu/main.xml: -------------------------------------------------------------------------------- 1 |

2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/values/description.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | This test simulates Media Volume Control. 5 | 6 | 7 | 8 | This test simulates simple AES based encryption and decryption. 9 | 10 | 11 | 12 | This test simulates simple AES based encryption and decryption. 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AndroidUtilSetTest 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/src/com/navercorp/utilsettest/introduction/Introduction.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilsettest.introduction; 2 | 3 | import android.support.v4.app.FragmentActivity; 4 | 5 | import com.navercorp.utilsettest.dialog.IntroductionDialogController; 6 | import com.navercorp.utilsettest.dialog.IntroductionDialogFactory; 7 | 8 | public enum Introduction { 9 | CipherUtilsTestCase_testCipher() { 10 | @Override 11 | public String getIntroduction() { 12 | return "CipherUtils provides simple AES encryption.\n" + 13 | "So this test shows the ciphertext by applying AES encryption utility function on user entered plaintext." + 14 | "Short after the encryption, you can verify the encrypted string can be restored to the exactly same string as the original one by decryption utility function."; 15 | } 16 | }, 17 | 18 | VolumeUpDownTestCase_testVolumeUpAndDown() { 19 | @Override 20 | public String getIntroduction() { 21 | return "This method manipulates media volume.\n" + 22 | "Three times of volume up and then the same number of volume down will be done."; 23 | } 24 | }, 25 | 26 | KeyboardUtilsTestCase_testKeyboard() { 27 | @Override 28 | public String getIntroduction() { 29 | return "This method shows a software keyboard being shown, hid, and toggled.\n" + 30 | "\n\n*** Should you not see the keyboard appear, when this being run on emulator, uncheck Hardware keyboard present option on your emulator property in AVD Manager. " + 31 | "This will make it work ***"; 32 | }// 33 | }, 34 | 35 | NetworkListenerTestCase_showIntroductionDialog() { 36 | @Override 37 | public String getIntroduction() { 38 | return "When network state changes, for example, from 3G/4G to WiFi or in the opposite case, INetworkStateChangedListener will be notified if registered.\n" + 39 | "This shows network state change by turning on and off the WiFi Adapter.\n" + 40 | "If USIM is not inserted or no Access Point is near, this test shows nothing more than changing WiFi state."; 41 | } 42 | }, 43 | 44 | ScreenUtilsTestCase_testSetBrightness() { 45 | @Override 46 | public String getIntroduction() { 47 | return "This test makes screen the darkest and then the brightest\n"; 48 | } 49 | 50 | }, 51 | 52 | StringUtils_testHighCompressionRatio() { 53 | @Override 54 | public String getIntroduction() { 55 | return "This test simulates string compression util.\n" + 56 | "This is good example of how efficiently recurring characters can be compressed, " + 57 | "this is not usual case though.\n" + 58 | "Following this test, an inefficient test will be executed.\n"; 59 | } 60 | }, 61 | 62 | StringUtils_testLowCompressionRatio() { 63 | @Override 64 | public String getIntroduction() { 65 | return "Followed by efficient test previously done, " + 66 | "this test demonstrates how disordered characters serverely affects on compression ratio"; 67 | } 68 | } 69 | ; 70 | 71 | abstract public String getIntroduction(); 72 | 73 | static public void showIntroductionDialog(FragmentActivity fa, Introduction introduction, int time) { 74 | IntroductionDialogController idc = IntroductionDialogFactory.getInstance(fa, introduction.getIntroduction(), time); 75 | 76 | try { 77 | Thread.sleep(500); 78 | idc.show(); 79 | Thread.sleep(500); 80 | } catch (InterruptedException e) { 81 | e.printStackTrace(); 82 | } 83 | } 84 | 85 | static public void showIntroductionDialog(FragmentActivity fa, Introduction introduction) { 86 | showIntroductionDialog(fa, introduction, DEFAULT_TIME); 87 | } 88 | 89 | private static int DEFAULT_TIME = 5000; 90 | } 91 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/src/com/navercorp/utilsettest/test/CipherUtilsTestCase.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilsettest.test; 2 | 3 | import android.support.v4.app.FragmentActivity; 4 | import android.test.ActivityInstrumentationTestCase2; 5 | 6 | import com.jayway.android.robotium.solo.Solo; 7 | import com.navercorp.utilsettest.cipher.CipherTestActivity; 8 | import com.navercorp.utilsettest.introduction.Introduction; 9 | 10 | public class CipherUtilsTestCase extends 11 | ActivityInstrumentationTestCase2 { 12 | private Solo solo; 13 | private String seed = "do re mi pa"; // "do re mi pa so la ti do"; 14 | private String plainText = "so la ti do"; 15 | private FragmentActivity activity; 16 | 17 | public CipherUtilsTestCase() { 18 | // TODO Auto-generated constructor stub 19 | super(CipherTestActivity.class); 20 | } 21 | 22 | @Override 23 | protected void setUp() throws Exception { 24 | // TODO Auto-generated method stub 25 | super.setUp(); 26 | 27 | activity = getActivity(); 28 | solo = new Solo(getInstrumentation(), activity); 29 | } 30 | 31 | public void tearDown() throws Exception 32 | { 33 | solo.finishOpenedActivities(); 34 | } 35 | 36 | public void testCipher() { 37 | solo.waitForActivity(activity.getClass().getSimpleName()); 38 | 39 | Introduction.showIntroductionDialog(activity, Introduction.CipherUtilsTestCase_testCipher); 40 | 41 | int size = seed.length(); 42 | for (int i=0;i { 12 | private Solo solo; 13 | FragmentActivity activity; 14 | 15 | public KeyboardUtilsTestCase() { 16 | super(KeyboardUtilsTestActivity.class); 17 | } 18 | 19 | @Override 20 | protected void setUp() throws Exception { 21 | // TODO Auto-generated method stub 22 | super.setUp(); 23 | 24 | activity = getActivity(); 25 | 26 | solo = new Solo(getInstrumentation(), activity); 27 | } 28 | 29 | @SmallTest 30 | public void testKeyboard() { 31 | solo.waitForActivity(activity.getClass().getSimpleName()); 32 | 33 | Introduction.showIntroductionDialog(activity, Introduction.KeyboardUtilsTestCase_testKeyboard); 34 | 35 | try { 36 | solo.clickOnButton("Show"); 37 | Thread.sleep(500); 38 | solo.clickOnButton("Hide"); 39 | Thread.sleep(500); 40 | solo.clickOnButton("Toggle"); 41 | Thread.sleep(500); 42 | solo.clickOnButton("Toggle"); 43 | Thread.sleep(500); 44 | } catch (InterruptedException e) { 45 | // TODO Auto-generated catch block 46 | e.printStackTrace(); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/src/com/navercorp/utilsettest/test/NetworkListenerTestCase.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilsettest.test; 2 | 3 | import android.support.v4.app.FragmentActivity; 4 | import android.test.ActivityInstrumentationTestCase2; 5 | 6 | import com.jayway.android.robotium.solo.Solo; 7 | import com.navercorp.utilsettest.R; 8 | import com.navercorp.utilsettest.introduction.Introduction; 9 | import com.navercorp.utilsettest.network.NetworkListenerTestActivity; 10 | 11 | public class NetworkListenerTestCase extends ActivityInstrumentationTestCase2 { 12 | private Solo solo; 13 | private FragmentActivity activity; 14 | 15 | public NetworkListenerTestCase() { 16 | super(NetworkListenerTestActivity.class); 17 | } 18 | 19 | @Override 20 | protected void setUp() throws Exception { 21 | // TODO Auto-generated method stub 22 | super.setUp(); 23 | 24 | activity = getActivity(); 25 | solo = new Solo(getInstrumentation(), activity); 26 | 27 | } 28 | 29 | public void tearDown() throws Exception 30 | { 31 | solo.finishOpenedActivities(); 32 | } 33 | 34 | public void testNetworkListener() { 35 | solo.waitForActivity(activity.getClass().getSimpleName()); 36 | 37 | Introduction.showIntroductionDialog(activity, Introduction.NetworkListenerTestCase_showIntroductionDialog); 38 | 39 | solo.waitForDialogToClose(10000); 40 | 41 | solo.sleep(500); 42 | solo.clickOnView(solo.getView(R.id.network_listener_test_toggle_wifi)); 43 | solo.sleep(5000); 44 | solo.clickOnView(solo.getView(R.id.network_listener_test_toggle_wifi)); 45 | solo.sleep(5000); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/src/com/navercorp/utilsettest/test/ScreenUtilsTestCase.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilsettest.test; 2 | 3 | import java.util.concurrent.CountDownLatch; 4 | 5 | import android.os.Handler; 6 | import android.support.v4.app.FragmentActivity; 7 | import android.test.ActivityInstrumentationTestCase2; 8 | 9 | import com.jayway.android.robotium.solo.Solo; 10 | import com.navercorp.utilset.ui.ScreenUtils; 11 | import com.navercorp.utilsettest.MainActivity; 12 | import com.navercorp.utilsettest.introduction.Introduction; 13 | 14 | public class ScreenUtilsTestCase extends 15 | ActivityInstrumentationTestCase2 { 16 | private Solo solo; 17 | private FragmentActivity activity; 18 | 19 | public ScreenUtilsTestCase() { 20 | super(MainActivity.class); 21 | } 22 | 23 | @Override 24 | protected void setUp() throws Exception { 25 | super.setUp(); 26 | 27 | activity = getActivity(); 28 | 29 | solo = new Solo(getInstrumentation(), activity); 30 | } 31 | 32 | public void tearDown() throws Exception 33 | { 34 | solo.finishOpenedActivities(); 35 | } 36 | 37 | private Handler handler = new Handler(); 38 | 39 | public void testSetBrightness() { 40 | solo.waitForActivity(activity.getClass().getSimpleName()); 41 | 42 | Introduction.showIntroductionDialog(activity, Introduction.ScreenUtilsTestCase_testSetBrightness, 2500); 43 | 44 | final CountDownLatch latchForDimness = new CountDownLatch(1); 45 | final CountDownLatch latchForBrightness = new CountDownLatch(1); 46 | 47 | solo.waitForDialogToClose(5000); 48 | 49 | handler.postDelayed(new Runnable() { 50 | @Override 51 | public void run() { 52 | ScreenUtils.setScreenBrightness(activity, 0.04f); 53 | latchForDimness.countDown(); 54 | } 55 | }, 500); 56 | 57 | try { 58 | latchForDimness.await(); 59 | Thread.sleep(1000); 60 | } catch (InterruptedException e) { 61 | e.printStackTrace(); 62 | } 63 | 64 | handler.post(new Runnable() { 65 | @Override 66 | public void run() { 67 | ScreenUtils.setScreenBrightness(activity, 1.0f); 68 | latchForBrightness.countDown(); 69 | } 70 | }); 71 | 72 | try { 73 | latchForBrightness.await(); 74 | Thread.sleep(1000); 75 | } catch (InterruptedException e) { 76 | e.printStackTrace(); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /UtilSetInstrumentationTest/src/com/navercorp/utilsettest/test/StringUtilsTestCase.java: -------------------------------------------------------------------------------- 1 | package com.navercorp.utilsettest.test; 2 | 3 | import java.util.concurrent.ExecutionException; 4 | 5 | import android.os.AsyncTask; 6 | import android.support.v4.app.FragmentActivity; 7 | import android.test.ActivityInstrumentationTestCase2; 8 | 9 | import com.jayway.android.robotium.solo.Solo; 10 | import com.navercorp.utilsettest.introduction.Introduction; 11 | import com.navercorp.utilsettest.string.StringUtilsTestActivity; 12 | 13 | public class StringUtilsTestCase extends 14 | ActivityInstrumentationTestCase2 { 15 | private Solo solo; 16 | private FragmentActivity activity; 17 | private static String highCompressionRatioString = "aaaaaaaaaaaa"; 18 | private static String lowCompressionRatioString = "abcdefghijkl"; 19 | 20 | public StringUtilsTestCase() { 21 | // TODO Auto-generated constructor stub 22 | super(StringUtilsTestActivity.class); 23 | } 24 | 25 | @Override 26 | protected void setUp() throws Exception { 27 | // TODO Auto-generated method stub 28 | super.setUp(); 29 | 30 | activity = getActivity(); 31 | solo = new Solo(getInstrumentation(), activity); 32 | } 33 | 34 | public void tearDown() throws Exception 35 | { 36 | solo.finishOpenedActivities(); 37 | } 38 | 39 | private AsyncTask task = new AsyncTask() { 40 | @Override 41 | protected Void doInBackground(String... params) { 42 | String string = params[0]; 43 | int length = string.length(); 44 | for (int i=0;i { 14 | private Solo solo; 15 | private FragmentActivity activity; 16 | private Button volumeUpButton; 17 | private Button volumeDownButton; 18 | 19 | public VolumeUpDownTestCase() { 20 | super(VolumeUtilsTestActivity.class); 21 | } 22 | 23 | @Override 24 | protected void setUp() throws Exception { 25 | // TODO Auto-generated method stub 26 | super.setUp(); 27 | activity = getActivity(); 28 | solo = new Solo(getInstrumentation(), activity); 29 | volumeUpButton = (Button) activity.findViewById(R.id.volumeUpButton); 30 | volumeDownButton = (Button) activity.findViewById(R.id.volumeDownButton); 31 | } 32 | 33 | public void tearDown() throws Exception 34 | { 35 | solo.finishOpenedActivities(); 36 | } 37 | 38 | public void testVolumeUpAndDown() { 39 | solo.waitForActivity(activity.getClass().getSimpleName()); 40 | 41 | Introduction.showIntroductionDialog(activity, Introduction.VolumeUpDownTestCase_testVolumeUpAndDown, 2500); 42 | 43 | solo.clickOnView(volumeUpButton); 44 | solo.sleep(500); 45 | solo.clickOnView(volumeUpButton); 46 | solo.sleep(500); 47 | solo.clickOnView(volumeUpButton); 48 | solo.sleep(500); 49 | solo.clickOnView(volumeDownButton); 50 | solo.sleep(500); 51 | solo.clickOnView(volumeDownButton); 52 | solo.sleep(500); 53 | solo.clickOnView(volumeDownButton); 54 | solo.sleep(500); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /UtilSetSampleApp/.checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /UtilSetSampleApp/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /UtilSetSampleApp/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /target 3 | -------------------------------------------------------------------------------- /UtilSetSampleApp/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AndroidUtilSetSampleApp 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.m2e.core.maven2Nature 36 | com.android.ide.eclipse.adt.AndroidNature 37 | org.eclipse.jdt.core.javanature 38 | 39 | 40 | -------------------------------------------------------------------------------- /UtilSetSampleApp/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /UtilSetSampleApp/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/ic_launcher-web.png -------------------------------------------------------------------------------- /UtilSetSampleApp/lib/utilset-0.0.1-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/lib/utilset-0.0.1-SNAPSHOT.jar -------------------------------------------------------------------------------- /UtilSetSampleApp/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/libs/android-support-v4.jar -------------------------------------------------------------------------------- /UtilSetSampleApp/libs/robotium-solo-4.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/libs/robotium-solo-4.3.jar -------------------------------------------------------------------------------- /UtilSetSampleApp/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /UtilSetSampleApp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.navercorp 6 | utilset-parent 7 | 1.0.3-SNAPSHOT 8 | 9 | 10 | utilset-sample 11 | apk 12 | UtilSet - Sample 13 | 14 | 15 | development 16 | 17 | 18 | 19 | 20 | com.navercorp 21 | utilset 22 | 23 | 24 | 25 | com.google.android 26 | support-v4 27 | 28 | 29 | 30 | com.google.android 31 | android 32 | provided 33 | 34 | 35 | 36 | com.google.android 37 | android-test 38 | provided 39 | 40 | 41 | 42 | junit 43 | junit 44 | 45 | 46 | 47 | com.google.android 48 | annotations 49 | provided 50 | 51 | 52 | 53 | 54 | ${project.artifactId} 55 | 56 | 57 | 58 | com.jayway.maven.plugins.android.generation2 59 | android-maven-plugin 60 | true 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | manifestUpdate 69 | process-resources 70 | 71 | manifest-update 72 | 73 | 74 | 75 | alignApk 76 | package 77 | 78 | zipalign 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /UtilSetSampleApp/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /UtilSetSampleApp/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | -------------------------------------------------------------------------------- /UtilSetSampleApp/repo/utilset-0.0.1-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/repo/utilset-0.0.1-SNAPSHOT.jar -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-hdpi/close_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/res/drawable-hdpi/close_button.png -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-hdpi/progress_bg_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/res/drawable-hdpi/progress_bg_holo_dark.9.png -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-hdpi/progress_horizontal_holo_dark.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-hdpi/progress_primary_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/res/drawable-hdpi/progress_primary_holo_dark.9.png -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-hdpi/progress_secondary_holo_dark.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/res/drawable-hdpi/progress_secondary_holo_dark.9.png -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-hdpi/rounded_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /UtilSetSampleApp/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naver/android-utilset/4af5f821466bc5bec4ea221ca6d87e0ac9b87e0b/UtilSetSampleApp/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /UtilSetSampleApp/res/layout/acitivty_volumeutils.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 11 | 12 | 17 | 18 | 24 | 25 | 29 | 30 |