├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── assets
│ │ │ ├── readme.css
│ │ │ ├── wrmndfzzy.css
│ │ │ ├── wrmndfzzy.md
│ │ │ ├── readme.md
│ │ │ ├── atomizeLicense.html
│ │ │ └── licenses.html
│ │ ├── res
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_atom.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── wrmndfzzy.png
│ │ │ │ ├── atom_watermark.png
│ │ │ │ ├── intro_slide_1_icon.png
│ │ │ │ ├── intro_slide_2_icon.png
│ │ │ │ ├── intro_slide_3_icon.png
│ │ │ │ ├── intro_slide_4_icon.png
│ │ │ │ └── intro_slide_5_icon.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── layout
│ │ │ │ ├── about_list_item.xml
│ │ │ │ ├── activity_license.xml
│ │ │ │ ├── activity_about.xml
│ │ │ │ ├── intro_permissions_dialog.xml
│ │ │ │ ├── aboutwrmndfzzy_dialog.xml
│ │ │ │ ├── app_license_dialog.xml
│ │ │ │ ├── aboutapp_dialog.xml
│ │ │ │ ├── filename_dialog.xml
│ │ │ │ ├── intro_slide1.xml
│ │ │ │ ├── intro_slide2.xml
│ │ │ │ ├── intro_slide3.xml
│ │ │ │ ├── intro_slide5.xml
│ │ │ │ ├── intro_slide4.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── menu
│ │ │ │ └── menu_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── wrmndfzzy
│ │ │ │ └── atomize
│ │ │ │ ├── LicenseActivity.java
│ │ │ │ ├── intro
│ │ │ │ ├── IntroSlideFragment.java
│ │ │ │ └── IntroActivity.java
│ │ │ │ ├── AboutActivity.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── wrmndfzzy
│ │ │ └── atomize
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── wrmndfzzy
│ │ └── atomize
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── pngquant-android
├── build.gradle
└── pngquant-android-release.aar
├── .gitignore
├── .gitmodules
├── TODO.md
├── README.md
├── gradle.properties
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':pngquant-android'
2 |
--------------------------------------------------------------------------------
/app/src/main/assets/readme.css:
--------------------------------------------------------------------------------
1 | html{
2 | padding:10px;
3 | background:#212121;
4 | color:#FFFFFF;
5 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/pngquant-android/build.gradle:
--------------------------------------------------------------------------------
1 | configurations.maybeCreate("default")
2 | artifacts.add("default", file('pngquant-android-release.aar'))
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_atom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_atom.png
--------------------------------------------------------------------------------
/pngquant-android/pngquant-android-release.aar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/pngquant-android/pngquant-android-release.aar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/wrmndfzzy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/app/src/main/res/drawable-xxxhdpi/wrmndfzzy.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/atom_watermark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/app/src/main/res/drawable-xxxhdpi/atom_watermark.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/intro_slide_1_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/app/src/main/res/drawable-xxxhdpi/intro_slide_1_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/intro_slide_2_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/app/src/main/res/drawable-xxxhdpi/intro_slide_2_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/intro_slide_3_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/app/src/main/res/drawable-xxxhdpi/intro_slide_3_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/intro_slide_4_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/app/src/main/res/drawable-xxxhdpi/intro_slide_4_icon.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/intro_slide_5_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wrmndfzzy/Atomize/HEAD/app/src/main/res/drawable-xxxhdpi/intro_slide_5_icon.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # IntelliJ IDEA
2 | .idea
3 | *.iml
4 | classes
5 |
6 | # Gradle
7 | .gradle
8 | build
9 | local.properties
10 |
11 | *~
12 | ndk.bin
13 | android-ndk-r10e/
14 |
--------------------------------------------------------------------------------
/app/src/main/assets/wrmndfzzy.css:
--------------------------------------------------------------------------------
1 | html{
2 | padding:10px;
3 | background:#212121;
4 | color:#FFFFFF;
5 | text-align:center;
6 | word-wrap: break-word;
7 | }
8 |
9 | a{
10 | color: #ff6a00;
11 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
36 | Atomize is released under the GPL Version 2. All copies and derivatives 37 | of this OpenSource software must retain this license file and the 38 | copylefts listed above. 39 | 40 | GNU GENERAL PUBLIC LICENSE 41 | Version 2, June 1991 42 | 43 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., http://fsf.org 44 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 45 | Everyone is permitted to copy and distribute verbatim copies 46 | of this license document, but changing it is not allowed. 47 | 48 | Preamble 49 | 50 | The licenses for most software are designed to take away your 51 | freedom to share and change it. By contrast, the GNU General Public 52 | License is intended to guarantee your freedom to share and change free 53 | software--to make sure the software is free for all its users. This 54 | General Public License applies to most of the Free Software 55 | Foundation's software and to any other program whose authors commit to 56 | using it. (Some other Free Software Foundation software is covered by 57 | the GNU Lesser General Public License instead.) You can apply it to 58 | your programs, too. 59 | 60 | When we speak of free software, we are referring to freedom, not 61 | price. Our General Public Licenses are designed to make sure that you 62 | have the freedom to distribute copies of free software (and charge for 63 | this service if you wish), that you receive source code or can get it 64 | if you want it, that you can change the software or use pieces of it 65 | in new free programs; and that you know you can do these things. 66 | 67 | To protect your rights, we need to make restrictions that forbid 68 | anyone to deny you these rights or to ask you to surrender the rights. 69 | These restrictions translate to certain responsibilities for you if you 70 | distribute copies of the software, or if you modify it. 71 | 72 | For example, if you distribute copies of such a program, whether 73 | gratis or for a fee, you must give the recipients all the rights that 74 | you have. You must make sure that they, too, receive or can get the 75 | source code. And you must show them these terms so they know their 76 | rights. 77 | 78 | We protect your rights with two steps: (1) copyright the software, and 79 | (2) offer you this license which gives you legal permission to copy, 80 | distribute and/or modify the software. 81 | 82 | Also, for each author's protection and ours, we want to make certain 83 | that everyone understands that there is no warranty for this free 84 | software. If the software is modified by someone else and passed on, we 85 | want its recipients to know that what they have is not the original, so 86 | that any problems introduced by others will not reflect on the original 87 | authors' reputations. 88 | 89 | Finally, any free program is threatened constantly by software 90 | patents. We wish to avoid the danger that redistributors of a free 91 | program will individually obtain patent licenses, in effect making the 92 | program proprietary. To prevent this, we have made it clear that any 93 | patent must be licensed for everyone's free use or not licensed at all. 94 | 95 | The precise terms and conditions for copying, distribution and 96 | modification follow. 97 | 98 | GNU GENERAL PUBLIC LICENSE 99 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 100 | 101 | 0. This License applies to any program or other work which contains 102 | a notice placed by the copyright holder saying it may be distributed 103 | under the terms of this General Public License. The "Program", below, 104 | refers to any such program or work, and a "work based on the Program" 105 | means either the Program or any derivative work under copyright law: 106 | that is to say, a work containing the Program or a portion of it, 107 | either verbatim or with modifications and/or translated into another 108 | language. (Hereinafter, translation is included without limitation in 109 | the term "modification".) Each licensee is addressed as "you". 110 | 111 | Activities other than copying, distribution and modification are not 112 | covered by this License; they are outside its scope. The act of 113 | running the Program is not restricted, and the output from the Program 114 | is covered only if its contents constitute a work based on the 115 | Program (independent of having been made by running the Program). 116 | Whether that is true depends on what the Program does. 117 | 118 | 1. You may copy and distribute verbatim copies of the Program's 119 | source code as you receive it, in any medium, provided that you 120 | conspicuously and appropriately publish on each copy an appropriate 121 | copyright notice and disclaimer of warranty; keep intact all the 122 | notices that refer to this License and to the absence of any warranty; 123 | and give any other recipients of the Program a copy of this License 124 | along with the Program. 125 | 126 | You may charge a fee for the physical act of transferring a copy, and 127 | you may at your option offer warranty protection in exchange for a fee. 128 | 129 | 2. You may modify your copy or copies of the Program or any portion 130 | of it, thus forming a work based on the Program, and copy and 131 | distribute such modifications or work under the terms of Section 1 132 | above, provided that you also meet all of these conditions: 133 | 134 | a) You must cause the modified files to carry prominent notices 135 | stating that you changed the files and the date of any change. 136 | 137 | b) You must cause any work that you distribute or publish, that in 138 | whole or in part contains or is derived from the Program or any 139 | part thereof, to be licensed as a whole at no charge to all third 140 | parties under the terms of this License. 141 | 142 | c) If the modified program normally reads commands interactively 143 | when run, you must cause it, when started running for such 144 | interactive use in the most ordinary way, to print or display an 145 | announcement including an appropriate copyright notice and a 146 | notice that there is no warranty (or else, saying that you provide 147 | a warranty) and that users may redistribute the program under 148 | these conditions, and telling the user how to view a copy of this 149 | License. (Exception: if the Program itself is interactive but 150 | does not normally print such an announcement, your work based on 151 | the Program is not required to print an announcement.) 152 | 153 | These requirements apply to the modified work as a whole. If 154 | identifiable sections of that work are not derived from the Program, 155 | and can be reasonably considered independent and separate works in 156 | themselves, then this License, and its terms, do not apply to those 157 | sections when you distribute them as separate works. But when you 158 | distribute the same sections as part of a whole which is a work based 159 | on the Program, the distribution of the whole must be on the terms of 160 | this License, whose permissions for other licensees extend to the 161 | entire whole, and thus to each and every part regardless of who wrote it. 162 | 163 | Thus, it is not the intent of this section to claim rights or contest 164 | your rights to work written entirely by you; rather, the intent is to 165 | exercise the right to control the distribution of derivative or 166 | collective works based on the Program. 167 | 168 | In addition, mere aggregation of another work not based on the Program 169 | with the Program (or with a work based on the Program) on a volume of 170 | a storage or distribution medium does not bring the other work under 171 | the scope of this License. 172 | 173 | 3. You may copy and distribute the Program (or a work based on it, 174 | under Section 2) in object code or executable form under the terms of 175 | Sections 1 and 2 above provided that you also do one of the following: 176 | 177 | a) Accompany it with the complete corresponding machine-readable 178 | source code, which must be distributed under the terms of Sections 179 | 1 and 2 above on a medium customarily used for software interchange; or, 180 | 181 | b) Accompany it with a written offer, valid for at least three 182 | years, to give any third party, for a charge no more than your 183 | cost of physically performing source distribution, a complete 184 | machine-readable copy of the corresponding source code, to be 185 | distributed under the terms of Sections 1 and 2 above on a medium 186 | customarily used for software interchange; or, 187 | 188 | c) Accompany it with the information you received as to the offer 189 | to distribute corresponding source code. (This alternative is 190 | allowed only for noncommercial distribution and only if you 191 | received the program in object code or executable form with such 192 | an offer, in accord with Subsection b above.) 193 | 194 | The source code for a work means the preferred form of the work for 195 | making modifications to it. For an executable work, complete source 196 | code means all the source code for all modules it contains, plus any 197 | associated interface definition files, plus the scripts used to 198 | control compilation and installation of the executable. However, as a 199 | special exception, the source code distributed need not include 200 | anything that is normally distributed (in either source or binary 201 | form) with the major components (compiler, kernel, and so on) of the 202 | operating system on which the executable runs, unless that component 203 | itself accompanies the executable. 204 | 205 | If distribution of executable or object code is made by offering 206 | access to copy from a designated place, then offering equivalent 207 | access to copy the source code from the same place counts as 208 | distribution of the source code, even though third parties are not 209 | compelled to copy the source along with the object code. 210 | 211 | 4. You may not copy, modify, sublicense, or distribute the Program 212 | except as expressly provided under this License. Any attempt 213 | otherwise to copy, modify, sublicense or distribute the Program is 214 | void, and will automatically terminate your rights under this License. 215 | However, parties who have received copies, or rights, from you under 216 | this License will not have their licenses terminated so long as such 217 | parties remain in full compliance. 218 | 219 | 5. You are not required to accept this License, since you have not 220 | signed it. However, nothing else grants you permission to modify or 221 | distribute the Program or its derivative works. These actions are 222 | prohibited by law if you do not accept this License. Therefore, by 223 | modifying or distributing the Program (or any work based on the 224 | Program), you indicate your acceptance of this License to do so, and 225 | all its terms and conditions for copying, distributing or modifying 226 | the Program or works based on it. 227 | 228 | 6. Each time you redistribute the Program (or any work based on the 229 | Program), the recipient automatically receives a license from the 230 | original licensor to copy, distribute or modify the Program subject to 231 | these terms and conditions. You may not impose any further 232 | restrictions on the recipients' exercise of the rights granted herein. 233 | You are not responsible for enforcing compliance by third parties to 234 | this License. 235 | 236 | 7. If, as a consequence of a court judgment or allegation of patent 237 | infringement or for any other reason (not limited to patent issues), 238 | conditions are imposed on you (whether by court order, agreement or 239 | otherwise) that contradict the conditions of this License, they do not 240 | excuse you from the conditions of this License. If you cannot 241 | distribute so as to satisfy simultaneously your obligations under this 242 | License and any other pertinent obligations, then as a consequence you 243 | may not distribute the Program at all. For example, if a patent 244 | license would not permit royalty-free redistribution of the Program by 245 | all those who receive copies directly or indirectly through you, then 246 | the only way you could satisfy both it and this License would be to 247 | refrain entirely from distribution of the Program. 248 | 249 | If any portion of this section is held invalid or unenforceable under 250 | any particular circumstance, the balance of the section is intended to 251 | apply and the section as a whole is intended to apply in other 252 | circumstances. 253 | 254 | It is not the purpose of this section to induce you to infringe any 255 | patents or other property right claims or to contest validity of any 256 | such claims; this section has the sole purpose of protecting the 257 | integrity of the free software distribution system, which is 258 | implemented by public license practices. Many people have made 259 | generous contributions to the wide range of software distributed 260 | through that system in reliance on consistent application of that 261 | system; it is up to the author/donor to decide if he or she is willing 262 | to distribute software through any other system and a licensee cannot 263 | impose that choice. 264 | 265 | This section is intended to make thoroughly clear what is believed to 266 | be a consequence of the rest of this License. 267 | 268 | 8. If the distribution and/or use of the Program is restricted in 269 | certain countries either by patents or by copyrighted interfaces, the 270 | original copyright holder who places the Program under this License 271 | may add an explicit geographical distribution limitation excluding 272 | those countries, so that distribution is permitted only in or among 273 | countries not thus excluded. In such case, this License incorporates 274 | the limitation as if written in the body of this License. 275 | 276 | 9. The Free Software Foundation may publish revised and/or new versions 277 | of the General Public License from time to time. Such new versions will 278 | be similar in spirit to the present version, but may differ in detail to 279 | address new problems or concerns. 280 | 281 | Each version is given a distinguishing version number. If the Program 282 | specifies a version number of this License which applies to it and "any 283 | later version", you have the option of following the terms and conditions 284 | either of that version or of any later version published by the Free 285 | Software Foundation. If the Program does not specify a version number of 286 | this License, you may choose any version ever published by the Free Software 287 | Foundation. 288 | 289 | 10. If you wish to incorporate parts of the Program into other free 290 | programs whose distribution conditions are different, write to the author 291 | to ask for permission. For software which is copyrighted by the Free 292 | Software Foundation, write to the Free Software Foundation; we sometimes 293 | make exceptions for this. Our decision will be guided by the two goals 294 | of preserving the free status of all derivatives of our free software and 295 | of promoting the sharing and reuse of software generally. 296 | 297 | NO WARRANTY 298 | 299 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 300 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 301 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 302 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 303 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 304 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 305 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 306 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 307 | REPAIR OR CORRECTION. 308 | 309 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 310 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 311 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 312 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 313 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 314 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 315 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 316 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 317 | POSSIBILITY OF SUCH DAMAGES. 318 | 319 | END OF TERMS AND CONDITIONS 320 |321 | 322 | 323 | -------------------------------------------------------------------------------- /app/src/main/java/com/wrmndfzzy/atomize/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.wrmndfzzy.atomize; 2 | 3 | import android.Manifest; 4 | import android.app.Activity; 5 | import android.app.Dialog; 6 | import android.content.ContentUris; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.content.SharedPreferences; 10 | import android.content.pm.PackageManager; 11 | import android.database.Cursor; 12 | import android.graphics.Bitmap; 13 | import android.net.Uri; 14 | import android.os.AsyncTask; 15 | import android.os.Environment; 16 | import android.preference.PreferenceManager; 17 | import android.provider.DocumentsContract; 18 | import android.provider.MediaStore; 19 | import android.support.annotation.NonNull; 20 | import android.support.v4.app.ActivityCompat; 21 | import android.support.v4.content.ContextCompat; 22 | import android.support.v7.app.AppCompatActivity; 23 | import android.os.Bundle; 24 | import android.util.Log; 25 | import android.view.Menu; 26 | import android.view.MenuItem; 27 | import android.view.View; 28 | import android.view.Window; 29 | import android.webkit.MimeTypeMap; 30 | import android.widget.Button; 31 | import android.widget.EditText; 32 | import android.widget.ImageView; 33 | import android.widget.ProgressBar; 34 | import android.widget.Switch; 35 | import android.widget.TextView; 36 | import android.support.design.widget.Snackbar; 37 | 38 | import java.io.File; 39 | import java.io.IOException; 40 | 41 | import com.wrmndfzzy.pngquant.LibPngQuant; 42 | 43 | public class MainActivity extends AppCompatActivity { 44 | 45 | private TextView imgPath; 46 | private ImageView preView; 47 | private static final int SELECT_PICTURE = 1; 48 | private static String selectedImagePath; 49 | private static String gone = "image does not exist"; 50 | private boolean imgSelected = false; 51 | static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1; 52 | static final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 2; 53 | File extFolder = new File(Environment.getExternalStorageDirectory() + "/Atomize"); 54 | 55 | private Switch deleteSwitch; 56 | 57 | private Button atomButton; 58 | 59 | File input; 60 | File output; 61 | private EditText fnEdit; 62 | public String imageName; 63 | 64 | private ProgressBar quantProgress; 65 | 66 | private String wrongFileType="wrongfiletype"; 67 | 68 | Button fnDialogCancel; 69 | Button fnDialogConfirm; 70 | 71 | public static Activity mA; 72 | 73 | public static Activity getInstance(){ 74 | return mA; 75 | } 76 | 77 | @Override 78 | protected void onCreate(Bundle savedInstanceState) { 79 | super.onCreate(savedInstanceState); 80 | 81 | mA = this; 82 | 83 | Thread t = new Thread(new Runnable() { 84 | @Override 85 | public void run() { 86 | // Initialize SharedPreferences 87 | SharedPreferences getPrefs = PreferenceManager 88 | .getDefaultSharedPreferences(getBaseContext()); 89 | // Create a new boolean and preference and set it to true 90 | boolean isFirstStart = getPrefs.getBoolean("firstStart", true); 91 | // If the activity has never started before... 92 | if (isFirstStart) { 93 | // Launch app intro 94 | Intent i = new Intent(MainActivity.this, com.wrmndfzzy.atomize.intro.IntroActivity.class); 95 | startActivity(i); 96 | } 97 | } 98 | }); 99 | // Start the thread 100 | t.start(); 101 | 102 | setContentView(R.layout.activity_main); 103 | 104 | imgPath = (TextView) findViewById(R.id.imgPath); 105 | final Button select = (Button) findViewById(R.id.select); 106 | preView = (ImageView) findViewById(R.id.imgPreview); 107 | 108 | 109 | deleteSwitch = (Switch) findViewById(R.id.deleteSwitch); 110 | 111 | atomButton = (Button) findViewById(R.id.atomize); 112 | 113 | quantProgress = (ProgressBar) findViewById(R.id.progBar); 114 | 115 | select.setOnClickListener(new View.OnClickListener() { 116 | @Override 117 | public void onClick(View v) { 118 | try { 119 | if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) 120 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); 121 | 122 | if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) 123 | ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); 124 | } 125 | catch (Exception e) { 126 | e.printStackTrace(); 127 | } 128 | 129 | Intent intent = new Intent(); 130 | intent.setType("image/png"); 131 | intent.setAction(Intent.ACTION_GET_CONTENT); 132 | startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE); 133 | } 134 | }); 135 | } 136 | 137 | @Override 138 | public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { 139 | switch (requestCode) { 140 | case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: { 141 | // If request is cancelled, the result arrays are empty. 142 | if (grantResults.length <= 0 143 | && grantResults[0] != PackageManager.PERMISSION_GRANTED) { 144 | // permission denied, boo! Disable the 145 | // functionality that depends on this permission. 146 | Snackbar.make(findViewById(android.R.id.content), "Read permissions are required to run this app.", Snackbar.LENGTH_LONG).show(); 147 | /*Intent homeIntent = new Intent(Intent.ACTION_MAIN); 148 | homeIntent.addCategory( Intent.CATEGORY_HOME ); 149 | homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 150 | startActivity(homeIntent); 151 | MainActivity.this.finish();*/ 152 | } 153 | else{ 154 | Snackbar.make(findViewById(android.R.id.content), "Read permissions granted!", Snackbar.LENGTH_LONG).show(); 155 | } 156 | break; 157 | } 158 | 159 | case MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: { 160 | // If request is cancelled, the result arrays are empty. 161 | if (grantResults.length <= 0 162 | && grantResults[0] != PackageManager.PERMISSION_GRANTED) { 163 | // permission denied, boo! Disable the 164 | // functionality that depends on this permission. 165 | Snackbar.make(findViewById(android.R.id.content), "Write permissions are required to run this app.", Snackbar.LENGTH_LONG).show(); 166 | /*Intent homeIntent = new Intent(Intent.ACTION_MAIN); 167 | homeIntent.addCategory( Intent.CATEGORY_HOME ); 168 | homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 169 | startActivity(homeIntent); 170 | MainActivity.this.finish();*/ 171 | } 172 | else{ 173 | Snackbar.make(findViewById(android.R.id.content), "Write permissions granted!", Snackbar.LENGTH_LONG).show(); 174 | } 175 | break; 176 | } 177 | } 178 | } 179 | 180 | //Thanks: http://codetheory.in/android-pick-select-image-from-gallery-with-intents/ 181 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 182 | String invSel = "Invalid selection."; 183 | String invFile = "Invalid file type."; 184 | super.onActivityResult(requestCode, resultCode, data); 185 | if (resultCode == RESULT_OK) { 186 | if (requestCode == SELECT_PICTURE) { 187 | Uri selectedImageUri = data.getData(); 188 | selectedImagePath = getPath(this, selectedImageUri); 189 | if (selectedImagePath != null) { 190 | String imageType = handleImageType(selectedImagePath); 191 | String selectedImageLocation = "Selected Image Path: " + selectedImagePath; 192 | if (imageType.equals(gone)) { 193 | Snackbar.make(findViewById(android.R.id.content), "Selected image has either been\n" + 194 | "deleted or already Atomized.", Snackbar.LENGTH_LONG).show(); 195 | imgPath.setText(invSel); 196 | preView.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.atom_watermark)); 197 | imgSelected = false; 198 | } else if (imageType.equals(wrongFileType)) { 199 | Snackbar.make(findViewById(android.R.id.content), "Please select a valid PNG file.", Snackbar.LENGTH_LONG).show(); 200 | imgPath.setText(invFile); 201 | preView.setImageDrawable(ContextCompat.getDrawable(MainActivity.this, R.drawable.atom_watermark)); 202 | imgSelected = false; 203 | } else { 204 | imgSelected = true; 205 | try { 206 | Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImageUri); 207 | Log.d("imgSelected", String.valueOf(bitmap)); 208 | preView.setImageBitmap(bitmap); 209 | imgPath.setText(selectedImageLocation); 210 | } catch (IOException e) { 211 | e.printStackTrace(); 212 | } 213 | } 214 | } 215 | else { 216 | Snackbar.make(findViewById(android.R.id.content), "Invalid File Path.", Snackbar.LENGTH_LONG).show(); 217 | } 218 | } 219 | } 220 | } 221 | 222 | // listen for atomize once picture is chosen 223 | public void atomize(View v) { 224 | if(imgSelected){ 225 | if(!extFolder.exists() && !extFolder.isDirectory()){ 226 | try{ 227 | if(!extFolder.mkdirs()) 228 | Log.e("extFolder", "directory cannot be create"); 229 | } 230 | catch(Exception e){ 231 | //fileProbDialog(); 232 | } 233 | } 234 | input = new File(selectedImagePath); 235 | fileNameDialog(); 236 | } 237 | else{ 238 | Snackbar.make(findViewById(android.R.id.content), "Please select an image.", Snackbar.LENGTH_SHORT).show(); 239 | } 240 | } 241 | 242 | public void execQuantTask(){ 243 | output = new File(extFolder + "/" + imageName); 244 | new AsyncTask