diff --git a/README.md b/README.md index bdc018c..8574f88 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,9 @@ -![Photto Image Cache](/phottov4.jpg) # Photto -Photto is a Image Upload, Image Caching, Picture Display, Photo Collage and Image Zoom Library for Android Projects. +Photto is a Image Upload, Image Caching and Picture Display Library for Android Projects. -- Project by [@serifgungor](https://github.com/serifgungor) and Generated in 26.07.2019. Last revision at 07.09.2019 +- Project by [@serifgungor](https://github.com/serifgungor) and Generated in 26.07.2019. Last revision at 04.08.2019 # Installation -[![](https://jitpack.io/v/gungoronline/Photto.svg)](https://jitpack.io/#gungoronline/Photto) - Gradle ```groovy allprojects { @@ -16,7 +13,7 @@ allprojects { } } dependencies { - implementation 'com.github.gungoronline:Photto:0.5.0' + implementation 'com.github.gungoronline:Photto:0.2.0' } ``` or Maven @@ -24,16 +21,14 @@ or Maven com.github.gungoronline Photto - 0.5.0 + 0.2.0 ``` # How to use ? -## PhottoBuilder (Class) -![Photto Image View](/from_image.jpg) - +## PhottoBuilder class ### FROM URI ```groovy new Photto.PhottoBuilder( @@ -122,10 +117,7 @@ new Photto.PhottoBuilder( ).build(); ``` -## UploadBuilder (Class) -![Photto Image Upload](/ftp_upload.jpg) - -[Video on YouTube - Photto ImageUpload](https://youtu.be/6BrEVHpUv1s) +## UploadBuilder The easiest way, upload your images to the web server ! @@ -164,23 +156,6 @@ if($_POST){ } ?> ``` --- C#(ASP.net) Not tested yet -```groovy -public Image Base64ToImage(string base64String) - { - // Convert base 64 string to byte[] - byte[] imageBytes = Convert.FromBase64String(base64String); - // Convert byte[] to Image - using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) - { - Image image = Image.FromStream(ms, true); - return image; - } - } - string value = Request.Form["imgBase64"]; - Image img = Base64ToImage(value); - img.Save(path); -``` ### UPLOAD FROM IMAGEVIEW WITH RESIZED (Version: 0.3.0) - 600x600 (Upload Test Result: 00.04.68sec upload time) @@ -197,87 +172,21 @@ HashMap hm = new HashMap(); new Photto.UploadBuilder("https://siteurl.com/test.php",hm,0,imageView).upload(); ``` -## PhotoView (View Class) - -![Photto Image Zoom](/imageview_zoom.jpg) - -### ZoomTouchView (Added This Version: 0.4.0) -ImageView supported Double-Touch to Zoom and Pinch to Zoom ! - -```groovy - -``` - -## BitmapBuilder (Class) - -### Bitmap Type 1 -![Photto Image Upload](/bitmapbuilder.png) -```groovy -File[] files = new File[]{new File("/storage/emulated/0/tr.jpg")}; -Bitmap b = new Photto.BitmapBuilder(getApplicationContext(),files,"@serifgungor", BitmapType.TYPE_1).build(); -iv.setImageBitmap(b); -``` - -### Bitmap Type 2 -![Photto Image Upload](/bitmapbuilder2.png) -```groovy -File[] files = new File[]{new File("/storage/emulated/0/photo1.jpg"),new File("/storage/emulated/0/photo2.jpg")}; -Bitmap b = new Photto.BitmapBuilder(getApplicationContext(),files,"", BitmapType.TYPE_2).build(); -iv.setImageBitmap(b); -``` - -### Bitmap Type 3 -![Photto Image Upload](/bitmapbuilder3.png) -```groovy -File[] files = new File[]{new File("/storage/emulated/0/picture1.jpg"),new File("/storage/emulated/0/picture2.jpg")}; -Bitmap b = new Photto.BitmapBuilder(getApplicationContext(),files,"", BitmapType.TYPE_3).build(); -iv.setImageBitmap(b); -``` -### Bitmap Type 4 -![Photto Image Upload](/bitmapbuilder4.png) -```groovy -File[] files = new File[]{new File("/storage/emulated/0/picture1.jpg")}; -Bitmap b = new Photto.BitmapBuilder(getApplicationContext(),files,"", BitmapType.TYPE_4).build(); -iv.setImageBitmap(b); -``` -### Bitmap Type 5 -![Photto Image Upload](/bitmapbuilder5.png) -```groovy -File[] files = new File[]{ - new File("/storage/emulated/0/picture1.jpg"), - new File("/storage/emulated/0/picture2.jpg"), - new File("/storage/emulated/0/picture3.jpg"), - new File("/storage/emulated/0/picture4.jpg") -}; -Bitmap b = new Photto.BitmapBuilder(getApplicationContext(),files,"", BitmapType.TYPE_5).build(); -iv.setImageBitmap(b); -``` - # Change Logs ## 26.07.2019 - Version 0.1.0 has launched. (PhottoBuilder class created.FROM URL, FROM URI, FROM BASE64 STRING, FROM ASSETS FOLDER, FROM DRAWABLE added) ## 27.07.2019 - Version 0.2.0 has launched. (FROM FILE, FROM URL WITH IMAGE LOAD LISTENER added) -## 04.08.2019 +## 03.08.2019 (Now Adding) - Version 0.3.0 has launched. (UploadBuilder class created. You can upload the imageView content to the Web site) -## 07.09.2019 -- Version 0.4.0 has launched. (ZoomTouchView added. ImageView Supported Pinch Zoom and Double-Touch Zoom) -## 01.08.2020 -- Version 0.5.0 has launched. -- The new version comes with the BitmapBuilder class. BitmapBuilder Type1, Type2 and Type3 is OK ! (27.02.2020) -- BitmapBuilder Type4 and Type5 is OK ! (02.03.2020) -# Maybe later... (0.6.0) +# Maybe later... (0.4.0) - You got a new idea? Send a message to: contact@serifgungor.com Helpers -------- - Java Thread, AsyncTask classes used. - Java HttpUrlConnection/HttpsUrlConnection classes used. -- chrisbanes / PhotoView Library License -------- diff --git a/app/build.gradle b/app/build.gradle index caa3105..18186fc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,31 +1,31 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 29 - buildToolsVersion "29.0.1" - defaultConfig { - applicationId "com.gungoronline.photto" - minSdkVersion 15 - targetSdkVersion 29 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - multiDexEnabled true - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation project(path: ':photto') -} +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.1" + defaultConfig { + applicationId "com.gungoronline.photto" + minSdkVersion 15 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + multiDexEnabled true + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + implementation project(path: ':photto') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 6e7ffa9..f1b4245 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,21 +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 +# 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/androidTest/java/com/gungoronline/photto/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/gungoronline/photto/ExampleInstrumentedTest.java index 55ffeaf..eb3e6bf 100644 --- a/app/src/androidTest/java/com/gungoronline/photto/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/gungoronline/photto/ExampleInstrumentedTest.java @@ -1,27 +1,27 @@ -package com.gungoronline.photto; - -import android.content.Context; - -import androidx.test.InstrumentationRegistry; -import androidx.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.gungoronline.photto", appContext.getPackageName()); - } -} +package com.gungoronline.photto; + +import android.content.Context; + +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.gungoronline.photto", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9ddeded..b8cd948 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,21 +1,21 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/gungoronline/photto/MainActivity.java b/app/src/main/java/com/gungoronline/photto/MainActivity.java index 68c0c46..2bc5419 100644 --- a/app/src/main/java/com/gungoronline/photto/MainActivity.java +++ b/app/src/main/java/com/gungoronline/photto/MainActivity.java @@ -1,27 +1,27 @@ -package com.gungoronline.photto; - -import androidx.appcompat.app.AppCompatActivity; - -import android.graphics.Bitmap; -import android.os.Bundle; -import android.widget.ImageView; - -import com.gungoronline.photto.Model.BitmapType; -import com.gungoronline.photto.Model.Photto; - -import java.io.File; - -public class MainActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - File[] files = new File[]{new File("/storage/emulated/0/picture1.jpg"),new File("/storage/emulated/0/picture2.jpg")}; - Bitmap b = new Photto.BitmapBuilder(getApplicationContext(),files,"", BitmapType.TYPE_3).build(); - ImageView iv = new ImageView(getApplicationContext()); - iv.setImageBitmap(b); - - setContentView(iv);//R.layout.activity_main - } -} +package com.gungoronline.photto; + +import androidx.appcompat.app.AppCompatActivity; + +import android.graphics.Bitmap; +import android.os.Bundle; +import android.widget.ImageView; + +import com.gungoronline.photto.Model.BitmapType; +import com.gungoronline.photto.Model.Photto; + +import java.io.File; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + File[] files = new File[]{new File("/storage/emulated/0/picture1.jpg"),new File("/storage/emulated/0/picture2.jpg")}; + Bitmap b = new Photto.BitmapBuilder(getApplicationContext(),files,"", BitmapType.TYPE_3).build(); + ImageView iv = new ImageView(getApplicationContext()); + iv.setImageBitmap(b); + + setContentView(iv);//R.layout.activity_main + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml index 971add5..1f6bb29 100644 --- a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -1,34 +1,34 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml index eed7a42..0d025f9 100644 --- a/app/src/main/res/drawable/ic_launcher_background.xml +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -1,170 +1,170 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml index a26f6fb..eca70cf 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -1,5 +1,5 @@ - - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml index a26f6fb..eca70cf 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -1,5 +1,5 @@ - - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 6b3f6ab..69b2233 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,6 +1,6 @@ - - - #008577 - #00574B - #D81B60 - + + + #008577 + #00574B + #D81B60 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bb674f0..ef28426 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - - Photto - + + Photto + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 6f19b47..5885930 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,11 +1,11 @@ - - - - - - + + + + + + diff --git a/app/src/test/java/com/gungoronline/photto/ExampleUnitTest.java b/app/src/test/java/com/gungoronline/photto/ExampleUnitTest.java index 4cf8b5a..2b77a86 100644 --- a/app/src/test/java/com/gungoronline/photto/ExampleUnitTest.java +++ b/app/src/test/java/com/gungoronline/photto/ExampleUnitTest.java @@ -1,17 +1,17 @@ -package com.gungoronline.photto; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } +package com.gungoronline.photto; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 23ee0b6..640a976 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jul 25 23:17:54 EET 2019 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +#Thu Jul 25 23:17:54 EET 2019 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/photto/build.gradle b/photto/build.gradle index f66e29a..eb16cb7 100644 --- a/photto/build.gradle +++ b/photto/build.gradle @@ -1,30 +1,30 @@ -apply plugin: 'com.android.library' - - -android { - compileSdkVersion 29 - buildToolsVersion "29.0.1" - - - defaultConfig { - minSdkVersion 15 - targetSdkVersion 29 - versionCode 1 - versionName "1.0" - multiDexEnabled true - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - - -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.0.2' -} +apply plugin: 'com.android.library' + + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.1" + + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + multiDexEnabled true + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.0.2' +} diff --git a/photto/proguard-rules.pro b/photto/proguard-rules.pro index 6e7ffa9..f1b4245 100644 --- a/photto/proguard-rules.pro +++ b/photto/proguard-rules.pro @@ -1,21 +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 +# 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/photto/src/androidTest/java/com/gungoronline/photto/ExampleInstrumentedTest.java b/photto/src/androidTest/java/com/gungoronline/photto/ExampleInstrumentedTest.java index e14d22c..c883fa6 100644 --- a/photto/src/androidTest/java/com/gungoronline/photto/ExampleInstrumentedTest.java +++ b/photto/src/androidTest/java/com/gungoronline/photto/ExampleInstrumentedTest.java @@ -1,27 +1,27 @@ -package com.gungoronline.photto; - -import android.content.Context; - -import androidx.test.InstrumentationRegistry; -import androidx.test.runner.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("com.gungoronline.photto.test", appContext.getPackageName()); - } -} +package com.gungoronline.photto; + +import android.content.Context; + +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.gungoronline.photto.test", appContext.getPackageName()); + } +} diff --git a/photto/src/main/AndroidManifest.xml b/photto/src/main/AndroidManifest.xml index 6b46185..bc61c94 100644 --- a/photto/src/main/AndroidManifest.xml +++ b/photto/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ - - - - - - + + + + + + diff --git a/photto/src/main/java/com/gungoronline/photto/Helper/HttpUtility.java b/photto/src/main/java/com/gungoronline/photto/Helper/HttpUtility.java index c23f343..caeb704 100644 --- a/photto/src/main/java/com/gungoronline/photto/Helper/HttpUtility.java +++ b/photto/src/main/java/com/gungoronline/photto/Helper/HttpUtility.java @@ -1,96 +1,96 @@ -package com.gungoronline.photto.Helper; - -import java.io.*; -import java.net.*; -import java.util.HashMap; -import java.util.Map; -import javax.net.ssl.HttpsURLConnection; -import static java.net.HttpURLConnection.HTTP_OK; - -public class HttpUtility { - - public static final int METHOD_GET = 0; // METHOD GET - public static final int METHOD_POST = 1; // METHOD POST - - // Callback interface - public interface Callback { - // abstract methods - public void OnSuccess(String response); - public void OnError(int status_code, String message); - } - // static method - public static void newRequest(final String web_url, final int method, final HashMap < String, String > params, final Callback callback) { - - // thread for handling async task - new Thread(new Runnable() { - @Override - public void run() { - try { - String url = web_url; - // write GET params,append with url - if (method == METHOD_GET && params != null) { - for (Map.Entry < String, String > item: params.entrySet()) { - String key = URLEncoder.encode(item.getKey(), "UTF-8"); - String value = URLEncoder.encode(item.getValue(), "UTF-8"); - if (!url.contains("?")) { - url += "?" + key + "=" + value; - } else { - url += "&" + key + "=" + value; - } - } - } - - HttpsURLConnection urlConnection = (HttpsURLConnection) new URL(url).openConnection(); - urlConnection.setUseCaches(false); - urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // handle url encoded form data - urlConnection.setRequestProperty("charset", "utf-8"); - if (method == METHOD_GET) { - urlConnection.setRequestMethod("GET"); - } else if (method == METHOD_POST) { - urlConnection.setDoOutput(true); // write POST params - urlConnection.setRequestMethod("POST"); - } - - //write POST data - if (method == METHOD_POST && params != null) { - StringBuilder postData = new StringBuilder(); - for (Map.Entry < String, String > item: params.entrySet()) { - if (postData.length() != 0) postData.append('&'); - postData.append(URLEncoder.encode(item.getKey(), "UTF-8")); - postData.append('='); - postData.append(URLEncoder.encode(String.valueOf(item.getValue()), "UTF-8")); - } - byte[] postDataBytes = postData.toString().getBytes("UTF-8"); - urlConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); - urlConnection.getOutputStream().write(postDataBytes); - - } - // server response code - int responseCode = urlConnection.getResponseCode(); - if (responseCode == HTTP_OK && callback != null) { - BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); - StringBuilder response = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - response.append(line); - } - // callback success - callback.OnSuccess(response.toString()); - reader.close(); // close BufferReader - } else if (callback != null) { - // callback error - callback.OnError(responseCode, urlConnection.getResponseMessage()); - } - - urlConnection.disconnect(); // disconnect connection - } catch (IOException e) { - e.printStackTrace(); - if (callback != null) { - // callback error - callback.OnError(500, e.getLocalizedMessage()); - } - } - } - }).start(); // start thread - } +package com.gungoronline.photto.Helper; + +import java.io.*; +import java.net.*; +import java.util.HashMap; +import java.util.Map; +import javax.net.ssl.HttpsURLConnection; +import static java.net.HttpURLConnection.HTTP_OK; + +public class HttpUtility { + + public static final int METHOD_GET = 0; // METHOD GET + public static final int METHOD_POST = 1; // METHOD POST + + // Callback interface + public interface Callback { + // abstract methods + public void OnSuccess(String response); + public void OnError(int status_code, String message); + } + // static method + public static void newRequest(final String web_url, final int method, final HashMap < String, String > params, final Callback callback) { + + // thread for handling async task + new Thread(new Runnable() { + @Override + public void run() { + try { + String url = web_url; + // write GET params,append with url + if (method == METHOD_GET && params != null) { + for (Map.Entry < String, String > item: params.entrySet()) { + String key = URLEncoder.encode(item.getKey(), "UTF-8"); + String value = URLEncoder.encode(item.getValue(), "UTF-8"); + if (!url.contains("?")) { + url += "?" + key + "=" + value; + } else { + url += "&" + key + "=" + value; + } + } + } + + HttpsURLConnection urlConnection = (HttpsURLConnection) new URL(url).openConnection(); + urlConnection.setUseCaches(false); + urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // handle url encoded form data + urlConnection.setRequestProperty("charset", "utf-8"); + if (method == METHOD_GET) { + urlConnection.setRequestMethod("GET"); + } else if (method == METHOD_POST) { + urlConnection.setDoOutput(true); // write POST params + urlConnection.setRequestMethod("POST"); + } + + //write POST data + if (method == METHOD_POST && params != null) { + StringBuilder postData = new StringBuilder(); + for (Map.Entry < String, String > item: params.entrySet()) { + if (postData.length() != 0) postData.append('&'); + postData.append(URLEncoder.encode(item.getKey(), "UTF-8")); + postData.append('='); + postData.append(URLEncoder.encode(String.valueOf(item.getValue()), "UTF-8")); + } + byte[] postDataBytes = postData.toString().getBytes("UTF-8"); + urlConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); + urlConnection.getOutputStream().write(postDataBytes); + + } + // server response code + int responseCode = urlConnection.getResponseCode(); + if (responseCode == HTTP_OK && callback != null) { + BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); + StringBuilder response = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + response.append(line); + } + // callback success + callback.OnSuccess(response.toString()); + reader.close(); // close BufferReader + } else if (callback != null) { + // callback error + callback.OnError(responseCode, urlConnection.getResponseMessage()); + } + + urlConnection.disconnect(); // disconnect connection + } catch (IOException e) { + e.printStackTrace(); + if (callback != null) { + // callback error + callback.OnError(500, e.getLocalizedMessage()); + } + } + } + }).start(); // start thread + } } \ No newline at end of file diff --git a/photto/src/main/java/com/gungoronline/photto/Helper/ImageLibrary.java b/photto/src/main/java/com/gungoronline/photto/Helper/ImageLibrary.java index 15dce9e..587aa49 100644 --- a/photto/src/main/java/com/gungoronline/photto/Helper/ImageLibrary.java +++ b/photto/src/main/java/com/gungoronline/photto/Helper/ImageLibrary.java @@ -1,132 +1,132 @@ -package com.gungoronline.photto.Helper; - -import android.content.Context; -import android.content.ContextWrapper; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; - -public class ImageLibrary { - - public Bitmap getBitmapFromURL(String strURL) { - try { - URL url = new URL(strURL); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoInput(true); - connection.connect(); - InputStream input = connection.getInputStream(); - Bitmap myBitmap = BitmapFactory.decodeStream(input); - return myBitmap; - } catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - public Bitmap loadImageFromStorage(String path,String fileName){ - Bitmap b = null; - try { - File f=new File(path, fileName); - b = BitmapFactory.decodeStream(new FileInputStream(f)); - } - catch (FileNotFoundException e) - { - e.printStackTrace(); - } - return b; - } - public Bitmap loadImageFromFile(File f){ - Bitmap b = null; - try { - b = BitmapFactory.decodeStream(new FileInputStream(f)); - } - catch (FileNotFoundException e) - { - e.printStackTrace(); - } - return b; - } - - public boolean isImageInStorage(String path,String fileName){ - boolean b = false; - try { - File f=new File(path, fileName); - b = f.exists(); - } - catch (Exception e) - { - b = false; - } - return b; - } - - public String saveImageToInternalStorage(Bitmap bitmapImage,String fileName,Context context){ - ContextWrapper cw = new ContextWrapper(context); - // path to /data/data/yourapp/app_data/imageDir - File directory = cw.getDir("imageDir", Context.MODE_PRIVATE); - // Create imageDir - File mypath=new File(directory,fileName); - - FileOutputStream fos = null; - try { - fos = new FileOutputStream(mypath); - // Use the compress method on the BitMap object to write image to the OutputStream - bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - fos.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return directory.getAbsolutePath(); - } - - public String readInputStreamToStringXml(String strURL) { - String result = null; - InputStream is = null; - - try { - URL url = new URL(strURL); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setDoInput(true); - connection.connect(); - - StringBuffer sb = new StringBuffer(); - is = new BufferedInputStream(connection.getInputStream()); - BufferedReader br = new BufferedReader(new InputStreamReader(is)); - String inputLine = ""; - while ((inputLine = br.readLine()) != null) { - sb.append(inputLine); - } - result = sb.toString(); - } - catch (Exception e) { - result = null; - } - finally { - if (is != null) { - try { - is.close(); - } - catch (IOException e) { - } - } - } - - return result; - } +package com.gungoronline.photto.Helper; + +import android.content.Context; +import android.content.ContextWrapper; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +public class ImageLibrary { + + public Bitmap getBitmapFromURL(String strURL) { + try { + URL url = new URL(strURL); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.connect(); + InputStream input = connection.getInputStream(); + Bitmap myBitmap = BitmapFactory.decodeStream(input); + return myBitmap; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + public Bitmap loadImageFromStorage(String path,String fileName){ + Bitmap b = null; + try { + File f=new File(path, fileName); + b = BitmapFactory.decodeStream(new FileInputStream(f)); + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + } + return b; + } + public Bitmap loadImageFromFile(File f){ + Bitmap b = null; + try { + b = BitmapFactory.decodeStream(new FileInputStream(f)); + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + } + return b; + } + + public boolean isImageInStorage(String path,String fileName){ + boolean b = false; + try { + File f=new File(path, fileName); + b = f.exists(); + } + catch (Exception e) + { + b = false; + } + return b; + } + + public String saveImageToInternalStorage(Bitmap bitmapImage,String fileName,Context context){ + ContextWrapper cw = new ContextWrapper(context); + // path to /data/data/yourapp/app_data/imageDir + File directory = cw.getDir("imageDir", Context.MODE_PRIVATE); + // Create imageDir + File mypath=new File(directory,fileName); + + FileOutputStream fos = null; + try { + fos = new FileOutputStream(mypath); + // Use the compress method on the BitMap object to write image to the OutputStream + bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return directory.getAbsolutePath(); + } + + public String readInputStreamToStringXml(String strURL) { + String result = null; + InputStream is = null; + + try { + URL url = new URL(strURL); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.connect(); + + StringBuffer sb = new StringBuffer(); + is = new BufferedInputStream(connection.getInputStream()); + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String inputLine = ""; + while ((inputLine = br.readLine()) != null) { + sb.append(inputLine); + } + result = sb.toString(); + } + catch (Exception e) { + result = null; + } + finally { + if (is != null) { + try { + is.close(); + } + catch (IOException e) { + } + } + } + + return result; + } } \ No newline at end of file diff --git a/photto/src/main/java/com/gungoronline/photto/Model/BitmapType.java b/photto/src/main/java/com/gungoronline/photto/Model/BitmapType.java index 4b03525..83a8b0a 100644 --- a/photto/src/main/java/com/gungoronline/photto/Model/BitmapType.java +++ b/photto/src/main/java/com/gungoronline/photto/Model/BitmapType.java @@ -1,9 +1,9 @@ -package com.gungoronline.photto.Model; - -public class BitmapType { - public static int TYPE_1 = 1; - public static int TYPE_2 = 2; - public static int TYPE_3 = 3; - public static int TYPE_4 = 4; - public static int TYPE_5 = 5; -} +package com.gungoronline.photto.Model; + +public class BitmapType { + public static int TYPE_1 = 1; + public static int TYPE_2 = 2; + public static int TYPE_3 = 3; + public static int TYPE_4 = 4; + public static int TYPE_5 = 5; +} diff --git a/photto/src/main/java/com/gungoronline/photto/Model/Photto.java b/photto/src/main/java/com/gungoronline/photto/Model/Photto.java index 6583d15..8546f97 100644 --- a/photto/src/main/java/com/gungoronline/photto/Model/Photto.java +++ b/photto/src/main/java/com/gungoronline/photto/Model/Photto.java @@ -1,636 +1,636 @@ -package com.gungoronline.photto.Model; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Matrix; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.Rect; -import android.graphics.RectF; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.media.ThumbnailUtils; -import android.net.ConnectivityManager; -import android.net.Uri; -import android.os.AsyncTask; -import android.util.Base64; -import android.util.Log; -import android.widget.ImageView; - -import androidx.annotation.Nullable; - -import com.gungoronline.photto.Helper.HttpUtility; -import com.gungoronline.photto.Helper.ImageLibrary; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.InputStream; -import java.util.HashMap; - -public class Photto { - private Context context; - private String url; - private String uniqueName; - private ImageView into; - private Uri uri; - private int drawableResourceId; - private InputStream inputStream; - private byte[] decodedString; - private File file; - - private String uploadDecodedString; - private String uploadUrl; - private HashMap uploadParams; - private ImageView uploadImageView; - private int imageResize; - - - private Bitmap bitmap; - - public Photto(BitmapBuilder bitmapBuilder){ - this.bitmap = bitmap; - this.context = bitmapBuilder.context; - } - - public Photto(UploadBuilder uploadBuilder){ - this.uploadUrl = uploadBuilder.uploadUrl; - this.uploadImageView = uploadBuilder.uploadImageView; - this.uploadDecodedString = uploadBuilder.uploadDecodedString; - this.uploadParams = uploadBuilder.uploadParams; - this.imageResize = uploadBuilder.imageResize; - } - - public Photto(PhottoBuilder phottoBuilder) { - this.context = phottoBuilder.context; - this.url = phottoBuilder.url; - this.uniqueName = phottoBuilder.uniqueName; - this.into = phottoBuilder.into; - this.uri = phottoBuilder.uri; - this.drawableResourceId = phottoBuilder.drawableResourceId; - this.inputStream = phottoBuilder.inputStream; - this.decodedString = phottoBuilder.decodedString; - this.file = phottoBuilder.file; - } - - public File getFile() { - return file; - } - - public Uri getUri() { - return uri; - } - - public int getDrawableResourceId() { - return drawableResourceId; - } - - public byte[] getDecodedString() { - return decodedString; - } - - public Context getContext() { - return context; - } - - public String getUrl() { - return url; - } - - public String getUniqueName() { - return uniqueName; - } - - public InputStream getInputStream() { - return inputStream; - } - - public static class UploadBuilder{ - private ImageView uploadImageView; - private HashMap uploadParams; - private String uploadUrl; - private String uploadDecodedString; - private int imageResize; - - Photto photto; - private boolean networkConnection() { - ConnectivityManager conMgr = (ConnectivityManager) uploadImageView.getContext().getSystemService(Context.CONNECTIVITY_SERVICE); - if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) { - return true; - } else { - return false; - } - } - - public UploadBuilder(){ - } - public UploadBuilder(String uploadUrl,HashMap hashMap,ImageView imageView){ - this.uploadImageView = imageView; - this.uploadUrl = uploadUrl; - this.uploadParams = hashMap; - } - public UploadBuilder(String uploadUrl,HashMap hashMap,int imageResize,ImageView imageView){ - this.uploadImageView = imageView; - this.uploadUrl = uploadUrl; - this.uploadParams = hashMap; - this.imageResize = imageResize; - } - - - - public UploadBuilder hashMap(HashMap hashMap) { - this.uploadParams = hashMap; - return this; - } - public UploadBuilder uploadUrl(String uploadUrl) { - this.uploadUrl = uploadUrl; - return this; - } - public UploadBuilder imageView(ImageView imageView) { - this.uploadImageView = imageView; - return this; - } - public UploadBuilder imageResize(int imageResize){ - this.imageResize = imageResize; - return this; - } - - - private Bitmap getResizedBitmap(Bitmap bitmapOrg,int resize) { - Paint paint = new Paint(); - paint.setFilterBitmap(true); - int targetWidth = bitmapOrg.getWidth() / resize; - int targetHeight = bitmapOrg.getHeight() / resize; - Bitmap bmp = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888); - RectF rectf = new RectF(0, 0, targetWidth, targetHeight); - Canvas c = new Canvas(bmp); - Path path = new Path(); - path.addRect(rectf, Path.Direction.CW); - c.clipPath(path); - c.drawBitmap( bitmapOrg, new Rect(0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight()), - new Rect(0, 0, targetWidth, targetHeight), paint); - Matrix matrix = new Matrix(); - matrix.postScale(1f, 1f); - Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, targetWidth, targetHeight, matrix, true); - return resizedBitmap; - } - - - public Photto upload() { - photto = new Photto(this); - - - - Bitmap bitmap = ((BitmapDrawable) this.uploadImageView.getDrawable()).getBitmap(); - - - if(imageResize!=0){ - bitmap = getResizedBitmap(bitmap,imageResize); - } - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); - byte[] imageInByte = baos.toByteArray(); - - // send params with Hash Map - HashMap params = this.uploadParams; - params.put("imgBase64",Base64.encodeToString(imageInByte, 0)); - String url = this.uploadUrl; - - // static class "HttpUtility" with static method "newRequest(url,method,callback)" - HttpUtility.newRequest(url,HttpUtility.METHOD_POST,params, new HttpUtility.Callback() { - @Override - public void OnSuccess(String response) { - // on success - Log.d("UploadBuilder","Server OnSuccess response="+response); - } - @Override - public void OnError(int status_code, String message) { - // on error - Log.d("UploadBuilder","Server OnError status_code="+status_code+" message="+message); - } - }); - - - return photto; - } - - } - - public static class BitmapBuilder{ - private Context context; - Photto photto; - ImageLibrary il; - private int type; - private String message; - private File[] files; - - public Bitmap storiesCanvas_type1(String text,Bitmap image){ - Bitmap bm1 = null; - Bitmap newBitmap = null; - - //FOR FULL QUALITY - ByteArrayOutputStream out = new ByteArrayOutputStream(); - image.compress(Bitmap.CompressFormat.PNG, 100, out); - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = false; - Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()),null,options); - - - bm1 = Bitmap.createScaledBitmap(decoded, 740, 1600, false); - Bitmap.Config config = bm1.getConfig(); - if (config == null) { - config = Bitmap.Config.ARGB_8888; - } - - - newBitmap = Bitmap.createBitmap(1080, 1920, config); - Canvas newCanvas = new Canvas(newBitmap); - - - Paint paintText = new Paint(); - paintText.setColor(Color.BLACK); - paintText.setTextSize(80); - paintText.setTextAlign(Paint.Align.RIGHT); - paintText.setStyle(Paint.Style.FILL); - - Rect rectText = new Rect(); - paintText.getTextBounds(text, 0, text.length(), rectText); - newCanvas.translate(800, 50); - - newCanvas.drawColor(Color.WHITE); - newCanvas.rotate(90); - newCanvas.drawText(text,0,text.length(),1000, -110, paintText); - - newCanvas.save(); - newCanvas.rotate(-90); - newCanvas.translate(-800,50); - newCanvas.drawBitmap(bm1, 50, 50, null); - return newBitmap; - } - - public Bitmap storiesCanvas_type2(Bitmap image1,Bitmap image2){ - - Bitmap bm1 = null; - Bitmap bm2 = null; - Bitmap newBitmap = null; - - bm1 = Bitmap.createScaledBitmap(image1, 904, 764, false); - bm2 = Bitmap.createScaledBitmap(image2, 904, 764, false); - - - Bitmap.Config config = bm1.getConfig(); - if (config == null) { - config = Bitmap.Config.ARGB_8888; - } - - newBitmap = Bitmap.createBitmap(1080, 1920, config); - Canvas newCanvas = new Canvas(newBitmap); - - newCanvas.drawColor(Color.WHITE); - newCanvas.rotate(90); - - newCanvas.save(); - newCanvas.rotate(-90); - newCanvas.translate(40,50); - newCanvas.drawBitmap(bm1, 50, 100, null); - newCanvas.drawBitmap(bm2, 50, 950, null); - return newBitmap; - } - public Bitmap storiesCanvas_type3(Bitmap image1,Bitmap image2){ - - Bitmap bm1 = null; - Bitmap bm2 = null; - Bitmap newBitmap = null; - - bm1 = Bitmap.createScaledBitmap(image1, 904, 992, false); - bm2 = Bitmap.createScaledBitmap(image2, 904, 592, false); - - - Bitmap.Config config = bm1.getConfig(); - if (config == null) { - config = Bitmap.Config.ARGB_8888; - } - - newBitmap = Bitmap.createBitmap(1080, 1920, config); - Canvas newCanvas = new Canvas(newBitmap); - - newCanvas.drawColor(Color.WHITE); - newCanvas.rotate(90); - - newCanvas.save(); - newCanvas.rotate(-90); - newCanvas.translate(40,50); - newCanvas.drawBitmap(bm1, 50, 100, null); - newCanvas.drawBitmap(bm2, 50, 1150, null); - return newBitmap; - } - public Bitmap storiesCanvas_type4(Bitmap image1){ - - Bitmap bm1 = null; - Bitmap newBitmap = null; - - bm1 = Bitmap.createScaledBitmap(image1, 1080, 900, false); - - - Bitmap.Config config = bm1.getConfig(); - if (config == null) { - config = Bitmap.Config.ARGB_8888; - } - - newBitmap = Bitmap.createBitmap(1080, 1920, config); - Canvas newCanvas = new Canvas(newBitmap); - - newCanvas.drawColor(Color.WHITE); - newCanvas.rotate(90); - - newCanvas.save(); - newCanvas.rotate(-90); - newCanvas.translate(0,50); - newCanvas.drawBitmap(bm1, 0, 444, null); - return newBitmap; - } - - public Bitmap storiesCanvas_type5(Bitmap image1,Bitmap image2,Bitmap image3,Bitmap image4){ - - Bitmap bm1 = null; - Bitmap bm2 = null; - Bitmap bm3 = null; - Bitmap bm4 = null; - Bitmap newBitmap = null; - - bm1 = Bitmap.createScaledBitmap(image1, 520, 490, false); - bm2 = Bitmap.createScaledBitmap(image2, 520, 490, false); - bm3 = Bitmap.createScaledBitmap(image3, 520, 490, false); - bm4 = Bitmap.createScaledBitmap(image4, 520, 490, false); - - - Bitmap.Config config = bm1.getConfig(); - if (config == null) { - config = Bitmap.Config.ARGB_8888; - } - - newBitmap = Bitmap.createBitmap(1080, 1920, config); - Canvas newCanvas = new Canvas(newBitmap); - - newCanvas.drawColor(Color.WHITE); - newCanvas.rotate(90); - - newCanvas.save(); - newCanvas.rotate(-90); - newCanvas.translate(0,50); - newCanvas.drawBitmap(bm1, 0, 344, null); - newCanvas.drawBitmap(bm2, 600, 344, null); - newCanvas.drawBitmap(bm3, 0, 944, null); - newCanvas.drawBitmap(bm4, 600, 944, null); - return newBitmap; - } - public BitmapBuilder(Context context, File[] files,String message,int bitmapType) { - this.context = context; - this.files = files; - il = new ImageLibrary(); - this.type = bitmapType; - this.message = message; - } - - public BitmapBuilder context(Context context) { - this.context = context; - il = new ImageLibrary(); - return this; - } - public Bitmap build() { - photto = new Photto(this); - - Bitmap b=null; - if(this.type == BitmapType.TYPE_1){ - b = storiesCanvas_type1(message,il.loadImageFromFile(files[0])); - }else if(this.type == BitmapType.TYPE_2){ - b = storiesCanvas_type2(il.loadImageFromFile(files[0]),il.loadImageFromFile(files[1])); - }else if(this.type == BitmapType.TYPE_3){ - b = storiesCanvas_type3(il.loadImageFromFile(files[0]),il.loadImageFromFile(files[1])); - }else if(this.type == BitmapType.TYPE_4){ - b = storiesCanvas_type4(il.loadImageFromFile(files[0])); - }else if(this.type == BitmapType.TYPE_5){ - b = storiesCanvas_type5(il.loadImageFromFile(files[0]),il.loadImageFromFile(files[1]),il.loadImageFromFile(files[2]),il.loadImageFromFile(files[3])); - } - - - return b; - } - } - - public static class PhottoBuilder { - private Context context; - private String url; - private String uniqueName; - private ImageView into; - private Uri uri; - private int drawableResourceId; - private InputStream inputStream; - private byte[] decodedString; - private File file; - - Photto photto; - ImageLibrary il; - - public interface ImageLoadListener { - public void onImageLoaded(); - - public void onError(int errorCode); - - public void onImageLoading(); - } - - private ImageLoadListener imageLoadListener; - - public boolean networkConnection() { - ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) { - return true; - } else { - return false; - } - } - - - private String reverseString(String str) { - String reverse = ""; - for (int i = str.length() - 1; i >= 0; i--) { - reverse = reverse + str.charAt(i); - } - return reverse; - } - - public PhottoBuilder(Context context, String url, ImageView into) { - this.context = context; - this.url = url; - if (!url.isEmpty()) { - String str = reverseString(url.replaceAll("[^a-zA-Z0-9]", "")); - this.uniqueName = str.substring(60); - } else { - imageLoadListener.onError(2); - } - this.into = into; - } - - public PhottoBuilder(Context context, String url, ImageLoadListener imageLoadListener, ImageView into) { - this.context = context; - this.url = url; - if (!url.isEmpty()) { - String str = reverseString(url.replaceAll("[^a-zA-Z0-9]", "")); - this.uniqueName = str.substring(60); - } else { - imageLoadListener.onError(2); - } - this.into = into; - this.imageLoadListener = imageLoadListener; - } - - - public PhottoBuilder(Context context, Uri uri, ImageView into) { - this.context = context; - this.uri = uri; - this.into = into; - } - - public PhottoBuilder(Context context, File file, ImageView into) { - this.context = context; - this.file = file; - this.into = into; - } - - public PhottoBuilder(Context context, int drawableResourceId, ImageView into) { - this.context = context; - this.drawableResourceId = drawableResourceId; - this.into = into; - } - - public PhottoBuilder(Context context, InputStream inputStream, ImageView into) { - this.context = context; - this.inputStream = inputStream; - this.into = into; - } - - public PhottoBuilder(Context context, String base64Str, @Nullable byte[] decodedString, ImageView into) { - this.decodedString = Base64.decode(base64Str, Base64.DEFAULT); - this.context = context; - this.inputStream = inputStream; - this.into = into; - } - - - public PhottoBuilder context(Context context) { - this.context = context; - return this; - } - - public PhottoBuilder url(String url) { - this.url = url; - return this; - } - - public PhottoBuilder uri(Uri uri) { - this.uri = uri; - return this; - } - - public PhottoBuilder decodedString(byte[] array) { - this.decodedString = array; - return this; - } - - public PhottoBuilder inputStream(InputStream inputStream) { - this.inputStream = inputStream; - return this; - } - - public PhottoBuilder drawableResourceId(int drawableResourceId) { - this.drawableResourceId = drawableResourceId; - return this; - } - - - public PhottoBuilder into(ImageView into) { - this.into = into; - return this; - } - - public Photto build() { - photto = new Photto(this); - il = new ImageLibrary(); - - new AsyncTask() { - @Override - protected void onPreExecute() { - super.onPreExecute(); - } - - @Override - protected void onPostExecute(Void aVoid) { - super.onPostExecute(aVoid); - if (photto.getUri() != null) { - into.setImageURI(photto.uri); - } else if (photto.getUrl() != null) { - if (!photto.getUrl().isEmpty()) { - if (networkConnection()) { - if (imageLoadListener != null) { - into.setImageBitmap(il.loadImageFromStorage("/data/data/" + context.getPackageName() + "/app_imageDir", uniqueName + ".jpg")); - imageLoadListener.onImageLoaded(); - } - } else { - Bitmap bp = il.loadImageFromStorage("/data/data/" + context.getPackageName() + "/app_imageDir", uniqueName + ".jpg"); - if (bp != null) { - into.setImageBitmap(bp); - } - } - } - - } else if (photto.getDrawableResourceId() != 0) { - into.setImageResource(photto.drawableResourceId); - } else if (photto.getInputStream() != null) { - into.setImageDrawable(Drawable.createFromStream(inputStream, null)); - } else if (photto.getDecodedString() != null) { - Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); - into.setImageBitmap(bitmap); - } else if (photto.getFile() != null) { - into.setImageBitmap(BitmapFactory.decodeFile(photto.getFile().getAbsolutePath())); - } - - } - - @Override - protected Void doInBackground(Void... voids) { - if (photto.getUrl() != null) { - - if (!photto.getUrl().isEmpty()) { - if (networkConnection()) { - if (il.isImageInStorage("/data/data/" + context.getPackageName() + "/app_imageDir", uniqueName + ".jpg") == false) { - Bitmap bitmap = il.getBitmapFromURL(url); - il.saveImageToInternalStorage(bitmap, uniqueName + ".jpg", context.getApplicationContext()); - } - if (imageLoadListener != null) { - imageLoadListener.onImageLoading(); - } - } else { - Bitmap bp = il.loadImageFromStorage("/data/data/" + context.getPackageName() + "/app_imageDir", uniqueName + ".jpg"); - if (bp != null) { - imageLoadListener.onError(3); - } else { - imageLoadListener.onError(1); - } - } - } - } - return null; - } - }.execute(); - - - return photto; - } - } - +package com.gungoronline.photto.Model; + +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.media.ThumbnailUtils; +import android.net.ConnectivityManager; +import android.net.Uri; +import android.os.AsyncTask; +import android.util.Base64; +import android.util.Log; +import android.widget.ImageView; + +import androidx.annotation.Nullable; + +import com.gungoronline.photto.Helper.HttpUtility; +import com.gungoronline.photto.Helper.ImageLibrary; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStream; +import java.util.HashMap; + +public class Photto { + private Context context; + private String url; + private String uniqueName; + private ImageView into; + private Uri uri; + private int drawableResourceId; + private InputStream inputStream; + private byte[] decodedString; + private File file; + + private String uploadDecodedString; + private String uploadUrl; + private HashMap uploadParams; + private ImageView uploadImageView; + private int imageResize; + + + private Bitmap bitmap; + + public Photto(BitmapBuilder bitmapBuilder){ + this.bitmap = bitmap; + this.context = bitmapBuilder.context; + } + + public Photto(UploadBuilder uploadBuilder){ + this.uploadUrl = uploadBuilder.uploadUrl; + this.uploadImageView = uploadBuilder.uploadImageView; + this.uploadDecodedString = uploadBuilder.uploadDecodedString; + this.uploadParams = uploadBuilder.uploadParams; + this.imageResize = uploadBuilder.imageResize; + } + + public Photto(PhottoBuilder phottoBuilder) { + this.context = phottoBuilder.context; + this.url = phottoBuilder.url; + this.uniqueName = phottoBuilder.uniqueName; + this.into = phottoBuilder.into; + this.uri = phottoBuilder.uri; + this.drawableResourceId = phottoBuilder.drawableResourceId; + this.inputStream = phottoBuilder.inputStream; + this.decodedString = phottoBuilder.decodedString; + this.file = phottoBuilder.file; + } + + public File getFile() { + return file; + } + + public Uri getUri() { + return uri; + } + + public int getDrawableResourceId() { + return drawableResourceId; + } + + public byte[] getDecodedString() { + return decodedString; + } + + public Context getContext() { + return context; + } + + public String getUrl() { + return url; + } + + public String getUniqueName() { + return uniqueName; + } + + public InputStream getInputStream() { + return inputStream; + } + + public static class UploadBuilder{ + private ImageView uploadImageView; + private HashMap uploadParams; + private String uploadUrl; + private String uploadDecodedString; + private int imageResize; + + Photto photto; + private boolean networkConnection() { + ConnectivityManager conMgr = (ConnectivityManager) uploadImageView.getContext().getSystemService(Context.CONNECTIVITY_SERVICE); + if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) { + return true; + } else { + return false; + } + } + + public UploadBuilder(){ + } + public UploadBuilder(String uploadUrl,HashMap hashMap,ImageView imageView){ + this.uploadImageView = imageView; + this.uploadUrl = uploadUrl; + this.uploadParams = hashMap; + } + public UploadBuilder(String uploadUrl,HashMap hashMap,int imageResize,ImageView imageView){ + this.uploadImageView = imageView; + this.uploadUrl = uploadUrl; + this.uploadParams = hashMap; + this.imageResize = imageResize; + } + + + + public UploadBuilder hashMap(HashMap hashMap) { + this.uploadParams = hashMap; + return this; + } + public UploadBuilder uploadUrl(String uploadUrl) { + this.uploadUrl = uploadUrl; + return this; + } + public UploadBuilder imageView(ImageView imageView) { + this.uploadImageView = imageView; + return this; + } + public UploadBuilder imageResize(int imageResize){ + this.imageResize = imageResize; + return this; + } + + + private Bitmap getResizedBitmap(Bitmap bitmapOrg,int resize) { + Paint paint = new Paint(); + paint.setFilterBitmap(true); + int targetWidth = bitmapOrg.getWidth() / resize; + int targetHeight = bitmapOrg.getHeight() / resize; + Bitmap bmp = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888); + RectF rectf = new RectF(0, 0, targetWidth, targetHeight); + Canvas c = new Canvas(bmp); + Path path = new Path(); + path.addRect(rectf, Path.Direction.CW); + c.clipPath(path); + c.drawBitmap( bitmapOrg, new Rect(0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight()), + new Rect(0, 0, targetWidth, targetHeight), paint); + Matrix matrix = new Matrix(); + matrix.postScale(1f, 1f); + Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, targetWidth, targetHeight, matrix, true); + return resizedBitmap; + } + + + public Photto upload() { + photto = new Photto(this); + + + + Bitmap bitmap = ((BitmapDrawable) this.uploadImageView.getDrawable()).getBitmap(); + + + if(imageResize!=0){ + bitmap = getResizedBitmap(bitmap,imageResize); + } + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); + byte[] imageInByte = baos.toByteArray(); + + // send params with Hash Map + HashMap params = this.uploadParams; + params.put("imgBase64",Base64.encodeToString(imageInByte, 0)); + String url = this.uploadUrl; + + // static class "HttpUtility" with static method "newRequest(url,method,callback)" + HttpUtility.newRequest(url,HttpUtility.METHOD_POST,params, new HttpUtility.Callback() { + @Override + public void OnSuccess(String response) { + // on success + Log.d("UploadBuilder","Server OnSuccess response="+response); + } + @Override + public void OnError(int status_code, String message) { + // on error + Log.d("UploadBuilder","Server OnError status_code="+status_code+" message="+message); + } + }); + + + return photto; + } + + } + + public static class BitmapBuilder{ + private Context context; + Photto photto; + ImageLibrary il; + private int type; + private String message; + private File[] files; + + public Bitmap storiesCanvas_type1(String text,Bitmap image){ + Bitmap bm1 = null; + Bitmap newBitmap = null; + + //FOR FULL QUALITY + ByteArrayOutputStream out = new ByteArrayOutputStream(); + image.compress(Bitmap.CompressFormat.PNG, 100, out); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = false; + Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()),null,options); + + + bm1 = Bitmap.createScaledBitmap(decoded, 740, 1600, false); + Bitmap.Config config = bm1.getConfig(); + if (config == null) { + config = Bitmap.Config.ARGB_8888; + } + + + newBitmap = Bitmap.createBitmap(1080, 1920, config); + Canvas newCanvas = new Canvas(newBitmap); + + + Paint paintText = new Paint(); + paintText.setColor(Color.BLACK); + paintText.setTextSize(80); + paintText.setTextAlign(Paint.Align.RIGHT); + paintText.setStyle(Paint.Style.FILL); + + Rect rectText = new Rect(); + paintText.getTextBounds(text, 0, text.length(), rectText); + newCanvas.translate(800, 50); + + newCanvas.drawColor(Color.WHITE); + newCanvas.rotate(90); + newCanvas.drawText(text,0,text.length(),1000, -110, paintText); + + newCanvas.save(); + newCanvas.rotate(-90); + newCanvas.translate(-800,50); + newCanvas.drawBitmap(bm1, 50, 50, null); + return newBitmap; + } + + public Bitmap storiesCanvas_type2(Bitmap image1,Bitmap image2){ + + Bitmap bm1 = null; + Bitmap bm2 = null; + Bitmap newBitmap = null; + + bm1 = Bitmap.createScaledBitmap(image1, 904, 764, false); + bm2 = Bitmap.createScaledBitmap(image2, 904, 764, false); + + + Bitmap.Config config = bm1.getConfig(); + if (config == null) { + config = Bitmap.Config.ARGB_8888; + } + + newBitmap = Bitmap.createBitmap(1080, 1920, config); + Canvas newCanvas = new Canvas(newBitmap); + + newCanvas.drawColor(Color.WHITE); + newCanvas.rotate(90); + + newCanvas.save(); + newCanvas.rotate(-90); + newCanvas.translate(40,50); + newCanvas.drawBitmap(bm1, 50, 100, null); + newCanvas.drawBitmap(bm2, 50, 950, null); + return newBitmap; + } + public Bitmap storiesCanvas_type3(Bitmap image1,Bitmap image2){ + + Bitmap bm1 = null; + Bitmap bm2 = null; + Bitmap newBitmap = null; + + bm1 = Bitmap.createScaledBitmap(image1, 904, 992, false); + bm2 = Bitmap.createScaledBitmap(image2, 904, 592, false); + + + Bitmap.Config config = bm1.getConfig(); + if (config == null) { + config = Bitmap.Config.ARGB_8888; + } + + newBitmap = Bitmap.createBitmap(1080, 1920, config); + Canvas newCanvas = new Canvas(newBitmap); + + newCanvas.drawColor(Color.WHITE); + newCanvas.rotate(90); + + newCanvas.save(); + newCanvas.rotate(-90); + newCanvas.translate(40,50); + newCanvas.drawBitmap(bm1, 50, 100, null); + newCanvas.drawBitmap(bm2, 50, 1150, null); + return newBitmap; + } + public Bitmap storiesCanvas_type4(Bitmap image1){ + + Bitmap bm1 = null; + Bitmap newBitmap = null; + + bm1 = Bitmap.createScaledBitmap(image1, 1080, 900, false); + + + Bitmap.Config config = bm1.getConfig(); + if (config == null) { + config = Bitmap.Config.ARGB_8888; + } + + newBitmap = Bitmap.createBitmap(1080, 1920, config); + Canvas newCanvas = new Canvas(newBitmap); + + newCanvas.drawColor(Color.WHITE); + newCanvas.rotate(90); + + newCanvas.save(); + newCanvas.rotate(-90); + newCanvas.translate(0,50); + newCanvas.drawBitmap(bm1, 0, 444, null); + return newBitmap; + } + + public Bitmap storiesCanvas_type5(Bitmap image1,Bitmap image2,Bitmap image3,Bitmap image4){ + + Bitmap bm1 = null; + Bitmap bm2 = null; + Bitmap bm3 = null; + Bitmap bm4 = null; + Bitmap newBitmap = null; + + bm1 = Bitmap.createScaledBitmap(image1, 520, 490, false); + bm2 = Bitmap.createScaledBitmap(image2, 520, 490, false); + bm3 = Bitmap.createScaledBitmap(image3, 520, 490, false); + bm4 = Bitmap.createScaledBitmap(image4, 520, 490, false); + + + Bitmap.Config config = bm1.getConfig(); + if (config == null) { + config = Bitmap.Config.ARGB_8888; + } + + newBitmap = Bitmap.createBitmap(1080, 1920, config); + Canvas newCanvas = new Canvas(newBitmap); + + newCanvas.drawColor(Color.WHITE); + newCanvas.rotate(90); + + newCanvas.save(); + newCanvas.rotate(-90); + newCanvas.translate(0,50); + newCanvas.drawBitmap(bm1, 0, 344, null); + newCanvas.drawBitmap(bm2, 600, 344, null); + newCanvas.drawBitmap(bm3, 0, 944, null); + newCanvas.drawBitmap(bm4, 600, 944, null); + return newBitmap; + } + public BitmapBuilder(Context context, File[] files,String message,int bitmapType) { + this.context = context; + this.files = files; + il = new ImageLibrary(); + this.type = bitmapType; + this.message = message; + } + + public BitmapBuilder context(Context context) { + this.context = context; + il = new ImageLibrary(); + return this; + } + public Bitmap build() { + photto = new Photto(this); + + Bitmap b=null; + if(this.type == BitmapType.TYPE_1){ + b = storiesCanvas_type1(message,il.loadImageFromFile(files[0])); + }else if(this.type == BitmapType.TYPE_2){ + b = storiesCanvas_type2(il.loadImageFromFile(files[0]),il.loadImageFromFile(files[1])); + }else if(this.type == BitmapType.TYPE_3){ + b = storiesCanvas_type3(il.loadImageFromFile(files[0]),il.loadImageFromFile(files[1])); + }else if(this.type == BitmapType.TYPE_4){ + b = storiesCanvas_type4(il.loadImageFromFile(files[0])); + }else if(this.type == BitmapType.TYPE_5){ + b = storiesCanvas_type5(il.loadImageFromFile(files[0]),il.loadImageFromFile(files[1]),il.loadImageFromFile(files[2]),il.loadImageFromFile(files[3])); + } + + + return b; + } + } + + public static class PhottoBuilder { + private Context context; + private String url; + private String uniqueName; + private ImageView into; + private Uri uri; + private int drawableResourceId; + private InputStream inputStream; + private byte[] decodedString; + private File file; + + Photto photto; + ImageLibrary il; + + public interface ImageLoadListener { + public void onImageLoaded(); + + public void onError(int errorCode); + + public void onImageLoading(); + } + + private ImageLoadListener imageLoadListener; + + public boolean networkConnection() { + ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (conMgr.getActiveNetworkInfo() != null && conMgr.getActiveNetworkInfo().isAvailable() && conMgr.getActiveNetworkInfo().isConnected()) { + return true; + } else { + return false; + } + } + + + private String reverseString(String str) { + String reverse = ""; + for (int i = str.length() - 1; i >= 0; i--) { + reverse = reverse + str.charAt(i); + } + return reverse; + } + + public PhottoBuilder(Context context, String url, ImageView into) { + this.context = context; + this.url = url; + if (!url.isEmpty()) { + String str = reverseString(url.replaceAll("[^a-zA-Z0-9]", "")); + this.uniqueName = str.substring(60); + } else { + imageLoadListener.onError(2); + } + this.into = into; + } + + public PhottoBuilder(Context context, String url, ImageLoadListener imageLoadListener, ImageView into) { + this.context = context; + this.url = url; + if (!url.isEmpty()) { + String str = reverseString(url.replaceAll("[^a-zA-Z0-9]", "")); + this.uniqueName = str.substring(60); + } else { + imageLoadListener.onError(2); + } + this.into = into; + this.imageLoadListener = imageLoadListener; + } + + + public PhottoBuilder(Context context, Uri uri, ImageView into) { + this.context = context; + this.uri = uri; + this.into = into; + } + + public PhottoBuilder(Context context, File file, ImageView into) { + this.context = context; + this.file = file; + this.into = into; + } + + public PhottoBuilder(Context context, int drawableResourceId, ImageView into) { + this.context = context; + this.drawableResourceId = drawableResourceId; + this.into = into; + } + + public PhottoBuilder(Context context, InputStream inputStream, ImageView into) { + this.context = context; + this.inputStream = inputStream; + this.into = into; + } + + public PhottoBuilder(Context context, String base64Str, @Nullable byte[] decodedString, ImageView into) { + this.decodedString = Base64.decode(base64Str, Base64.DEFAULT); + this.context = context; + this.inputStream = inputStream; + this.into = into; + } + + + public PhottoBuilder context(Context context) { + this.context = context; + return this; + } + + public PhottoBuilder url(String url) { + this.url = url; + return this; + } + + public PhottoBuilder uri(Uri uri) { + this.uri = uri; + return this; + } + + public PhottoBuilder decodedString(byte[] array) { + this.decodedString = array; + return this; + } + + public PhottoBuilder inputStream(InputStream inputStream) { + this.inputStream = inputStream; + return this; + } + + public PhottoBuilder drawableResourceId(int drawableResourceId) { + this.drawableResourceId = drawableResourceId; + return this; + } + + + public PhottoBuilder into(ImageView into) { + this.into = into; + return this; + } + + public Photto build() { + photto = new Photto(this); + il = new ImageLibrary(); + + new AsyncTask() { + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + if (photto.getUri() != null) { + into.setImageURI(photto.uri); + } else if (photto.getUrl() != null) { + if (!photto.getUrl().isEmpty()) { + if (networkConnection()) { + if (imageLoadListener != null) { + into.setImageBitmap(il.loadImageFromStorage("/data/data/" + context.getPackageName() + "/app_imageDir", uniqueName + ".jpg")); + imageLoadListener.onImageLoaded(); + } + } else { + Bitmap bp = il.loadImageFromStorage("/data/data/" + context.getPackageName() + "/app_imageDir", uniqueName + ".jpg"); + if (bp != null) { + into.setImageBitmap(bp); + } + } + } + + } else if (photto.getDrawableResourceId() != 0) { + into.setImageResource(photto.drawableResourceId); + } else if (photto.getInputStream() != null) { + into.setImageDrawable(Drawable.createFromStream(inputStream, null)); + } else if (photto.getDecodedString() != null) { + Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); + into.setImageBitmap(bitmap); + } else if (photto.getFile() != null) { + into.setImageBitmap(BitmapFactory.decodeFile(photto.getFile().getAbsolutePath())); + } + + } + + @Override + protected Void doInBackground(Void... voids) { + if (photto.getUrl() != null) { + + if (!photto.getUrl().isEmpty()) { + if (networkConnection()) { + if (il.isImageInStorage("/data/data/" + context.getPackageName() + "/app_imageDir", uniqueName + ".jpg") == false) { + Bitmap bitmap = il.getBitmapFromURL(url); + il.saveImageToInternalStorage(bitmap, uniqueName + ".jpg", context.getApplicationContext()); + } + if (imageLoadListener != null) { + imageLoadListener.onImageLoading(); + } + } else { + Bitmap bp = il.loadImageFromStorage("/data/data/" + context.getPackageName() + "/app_imageDir", uniqueName + ".jpg"); + if (bp != null) { + imageLoadListener.onError(3); + } else { + imageLoadListener.onError(1); + } + } + } + } + return null; + } + }.execute(); + + + return photto; + } + } + } \ No newline at end of file diff --git a/photto/src/main/java/com/gungoronline/photto/Model/PhottoError.java b/photto/src/main/java/com/gungoronline/photto/Model/PhottoError.java index 8a4f4f9..97e82b8 100644 --- a/photto/src/main/java/com/gungoronline/photto/Model/PhottoError.java +++ b/photto/src/main/java/com/gungoronline/photto/Model/PhottoError.java @@ -1,7 +1,7 @@ -package com.gungoronline.photto.Model; - -public class PhottoError { - public static int NETWORK_ERROR = 1; - public static int URL_IS_BLANK = 2; - public static int NETWORK_ERROR_BUT_CACHE = 3; -} +package com.gungoronline.photto.Model; + +public class PhottoError { + public static int NETWORK_ERROR = 1; + public static int URL_IS_BLANK = 2; + public static int NETWORK_ERROR_BUT_CACHE = 3; +} diff --git a/photto/src/main/res/layout/activity_main.xml b/photto/src/main/res/layout/activity_main.xml index 425eac2..466e6ed 100644 --- a/photto/src/main/res/layout/activity_main.xml +++ b/photto/src/main/res/layout/activity_main.xml @@ -1,9 +1,9 @@ - - - - + + + + \ No newline at end of file diff --git a/photto/src/main/res/values/strings.xml b/photto/src/main/res/values/strings.xml index bb674f0..ef28426 100644 --- a/photto/src/main/res/values/strings.xml +++ b/photto/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - - Photto - + + Photto + diff --git a/photto/src/test/java/com/gungoronline/photto/ExampleUnitTest.java b/photto/src/test/java/com/gungoronline/photto/ExampleUnitTest.java index 4cf8b5a..2b77a86 100644 --- a/photto/src/test/java/com/gungoronline/photto/ExampleUnitTest.java +++ b/photto/src/test/java/com/gungoronline/photto/ExampleUnitTest.java @@ -1,17 +1,17 @@ -package com.gungoronline.photto; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } +package com.gungoronline.photto; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } } \ No newline at end of file