-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 92c0ae3
Showing
34 changed files
with
1,539 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches/build_file_checksums.ser | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Peach Android Networking Library | ||
|
||
### In Project Level : | ||
|
||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://www.jitpack.io' } | ||
} | ||
} | ||
|
||
### In App Level : | ||
|
||
Note that the minSdkVersion must be 16 | ||
|
||
dependencies { | ||
... | ||
implementation 'com.github.AndroThink:Peach:1.0.0' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
minSdkVersion 15 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.androthink.peach"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
<application /> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.androthink.peach; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
|
||
public class FileUtils { | ||
|
||
public static File getFileFromDrawable(Context context, int drawableId, String fileNameWithoutExtension, String mimeType){ | ||
try | ||
{ | ||
File file = createTempFile(context, | ||
(getCurrentTimeStamp() + "_" + fileNameWithoutExtension) | ||
.replace(" ","") | ||
.replace("-",""), | ||
mimeType); | ||
|
||
InputStream inputStream = context.getResources().openRawResource(drawableId); | ||
OutputStream out=new FileOutputStream(file); | ||
byte buf[]=new byte[1024]; | ||
int len; | ||
while((len=inputStream.read(buf))>0) | ||
out.write(buf,0,len); | ||
out.close(); | ||
inputStream.close(); | ||
|
||
return file; | ||
} | ||
catch (IOException e){ | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
public static File getFileFromBitmap(Context context, Bitmap bitmap, String fileNameWithoutExtension, String mimeType){ | ||
try | ||
{ | ||
File file = createTempFile(context, | ||
(getCurrentTimeStamp() + "_" + fileNameWithoutExtension) | ||
.replace(" ","") | ||
.replace("-",""), | ||
mimeType); | ||
|
||
OutputStream os = new BufferedOutputStream(new FileOutputStream(file)); | ||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os); | ||
os.close(); | ||
|
||
return file; | ||
} | ||
catch (IOException e){ | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
private static File createTempFile(Context context, String fileNameWithoutExtension,String mimeType) | ||
throws IOException { | ||
File externalCacheDir = context.getExternalCacheDir(); | ||
File internalCacheDir = context.getCacheDir(); | ||
File cacheDir; | ||
if (externalCacheDir == null && internalCacheDir == null) { | ||
throw new IOException("No cache directory available"); | ||
} | ||
if (externalCacheDir == null) { | ||
cacheDir = internalCacheDir; | ||
} | ||
else if (internalCacheDir == null) { | ||
cacheDir = externalCacheDir; | ||
} else { | ||
cacheDir = externalCacheDir.getFreeSpace() > internalCacheDir.getFreeSpace() ? | ||
externalCacheDir : internalCacheDir; | ||
} | ||
return File.createTempFile(fileNameWithoutExtension, mimeType, cacheDir); | ||
} | ||
|
||
private static String getCurrentTimeStamp() { | ||
|
||
@SuppressLint("SimpleDateFormat") | ||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy-HH-mm_aa", Locale.ENGLISH); | ||
return dateFormat.format(new Date()); | ||
} | ||
} |
Oops, something went wrong.