From 10a85472dd2aba849b9291d6b13a19a7bb0f3a2f Mon Sep 17 00:00:00 2001 From: pierx Date: Sat, 9 Mar 2019 19:52:45 +0800 Subject: [PATCH] Initial commit --- .gitignore | 13 ++ .idea/codeStyles/Project.xml | 29 +++ .idea/gradle.xml | 15 ++ .../markdown-navigator/profiles_settings.xml | 3 + .idea/misc.xml | 14 ++ .idea/runConfigurations.xml | 12 ++ README.md | 13 ++ app/.gitignore | 1 + app/build.gradle | 18 ++ app/proguard-rules.pro | 21 +++ app/src/main/AndroidManifest.xml | 21 +++ .../java/com/convert/spr/MainActivity.java | 141 ++++++++++++++ app/src/main/res/drawable/sample.bmp | Bin 0 -> 567 bytes app/src/main/res/drawable/sample_two.bmp | Bin 0 -> 472 bytes app/src/main/res/layout/activity_main.xml | 19 ++ app/src/main/res/values/strings.xml | 4 + build.gradle | 27 +++ gradle.properties | 19 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 ++++++++++++++++++ gradlew.bat | 84 +++++++++ settings.gradle | 1 + 23 files changed, 633 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/markdown-navigator/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 README.md create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/convert/spr/MainActivity.java create mode 100644 app/src/main/res/drawable/sample.bmp create mode 100644 app/src/main/res/drawable/sample_two.bmp create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b75303 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..2996d53 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml new file mode 100644 index 0000000..57927c5 --- /dev/null +++ b/.idea/markdown-navigator/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..29bb4c5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..687456f --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# SPR Converter + +How to convert Samsung .spr/.bmp to .png + +Instruction +1. Place all the .spr files inside the src/main/res/drawable folder inside the project +2. Replace all the .spr extension to .bmp (Tip: Use BulkRenameUtility software and use extension) +3. Build the app with Android Studio or Gradle cli +4. Install the app apk on Samsung devices +5. Press Convert now and check out the result on convert folder on storage + +Credits to dgadelha @xda +https://forum.xda-developers.com/showpost.php?p=77683386&postcount=105 \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..dfb01e3 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,18 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.convert.spr" + minSdkVersion 24 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..8c15fc9 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/convert/spr/MainActivity.java b/app/src/main/java/com/convert/spr/MainActivity.java new file mode 100644 index 0000000..d007c15 --- /dev/null +++ b/app/src/main/java/com/convert/spr/MainActivity.java @@ -0,0 +1,141 @@ +package com.convert.spr; + +import android.Manifest; +import android.app.Activity; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.os.Environment; +import android.util.Log; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.Toast; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; + +public class MainActivity extends Activity { + Button button; + ImageView image; + + public static Bitmap drawableToBitmap(Drawable drawable) { + Bitmap bitmap; + + if (drawable instanceof BitmapDrawable) { + BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; + if (bitmapDrawable.getBitmap() != null) { + return bitmapDrawable.getBitmap(); + } + } + + if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { + bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel + } else { + bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + } + + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + drawable.draw(canvas); + return bitmap; + } + + /* + * Bitmap.CompressFormat can be PNG,JPEG or WEBP. + * + * quality goes from 1 to 100. (Percentage). + * + * dir you can get from many places like Environment.getExternalStorageDirectory() or mContext.getFilesDir() + * depending on where you want to save the image. + */ + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + addListenerOnButton(); + } + + public void saveBitmapToFile(File dir, String fileName, Bitmap bm, + Bitmap.CompressFormat format, int quality) { + if (bm == null) { + Log.e("spr", "bm is null"); + return; + } + File imageFile = new File(dir, fileName); + + FileOutputStream fos = null; + try { + fos = new FileOutputStream(imageFile); + + bm.compress(format, quality, fos); + + fos.close(); + + } catch (IOException e) { + Log.e("app", e.getMessage()); + if (fos != null) { + try { + fos.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } + } + + public void addListenerOnButton() { + + image = findViewById(R.id.imageView1); + button = findViewById(R.id.btnChangeImage); + button.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View arg0) { + /* Loop through all drawables to convert them */ + final R.drawable drawableResources = new R.drawable(); + final Class c = R.drawable.class; + final Field[] fields = c.getDeclaredFields(); + + for (Field field : fields) { + Log.i("spr", "Dumping: " + field); + final int resourceId; + try { + resourceId = field.getInt(drawableResources); + } catch (Exception e) { + continue; + } + /* make use of resourceId for accessing Drawables here */ + @SuppressWarnings("deprecation") Drawable d = getResources().getDrawable(resourceId); + image.setImageDrawable(d); + Bitmap bm = drawableToBitmap(d); + // Bitmap bm = BitmapFactory.decodeResource(image.getResources(), resourceId); + String name = image.getResources().getResourceEntryName(resourceId); + + + File dir = new File(Environment.getExternalStorageDirectory() + File.separator + "convert"); + + boolean doSave = true; + if (!dir.exists()) { + doSave = dir.mkdirs(); + } + + if (doSave) { + saveBitmapToFile(dir, name + ".png", bm, Bitmap.CompressFormat.PNG, 100); + Toast.makeText(MainActivity.this, "Done. \nCheck out the convert folder on storage", Toast.LENGTH_SHORT).show(); + } else { + Log.e("app", "Couldn't create target directory."); + } + } + } + + }); + } +} diff --git a/app/src/main/res/drawable/sample.bmp b/app/src/main/res/drawable/sample.bmp new file mode 100644 index 0000000000000000000000000000000000000000..85d83bbda9559cc28d9dd5e41c7c2adc7770b815 GIT binary patch literal 567 zcmaivK`2B~6o&tMdz5LC($vJpC<{rw1vX5^v9gm{OO%B@Ha2f#H_ArJN)yRqR#Fy2 zY1E`hDY3C*uVi6^{~T|gX*N!sd%n*7&%OUC&dwnW!w~?B%w=XHTmz<4faZTuD44?L ze2dt10q&YjgDSxXJU*D+PA--(^`3>7p$UUPavcVetwP*WWHp_pLK~a;f|p^!+FSGs zoh4qK_d^o6Ib=sQ2^?HftmAu`7;aw?Sm*vL(jVn<0BS+2S5pds)HWi!sh1(D)XGtB zKvRK%x};L~_}eF5tX&uHY5Qg7f))NK6LP0!1(MGJU(9U9Je?c%!8bJju(x{!Ko!Z2R9|W|}$|i-N zDeP24Ec^jBfLcDKq!t3pH;zI zt8jdIufTWP;KMdl&tD}F9E~sVbqRd?0j^iT4`o<|_bGv+18@f<e{w?2MLx8O%x3Vvb+ lzIO?#(TZe6lzy=39;cegGBwXWsw- literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..96cb260 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,19 @@ + + + + + +