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 42638e0
Showing
26 changed files
with
265 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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="id.flwi.example.image.encdec64" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk android:minSdkVersion="8" /> | ||
|
||
<application | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" > | ||
<activity | ||
android:label="@string/app_name" | ||
android:name=".EncDecImageActivity" > | ||
<intent-filter > | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</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 @@ | ||
to test on SharedPreferences, after you encode64 image, force close the application and open it back. |
Binary file not shown.
Binary file added
BIN
+1.26 KB
bin/classes/id/flwi/example/image/encdec64/EncDecImageActivity$1.class
Binary file not shown.
Binary file added
BIN
+1.47 KB
bin/classes/id/flwi/example/image/encdec64/EncDecImageActivity$2.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,29 @@ | ||
/* AUTO-GENERATED FILE. DO NOT MODIFY. | ||
* | ||
* This class was automatically generated by the | ||
* aapt tool from the resource data it found. It | ||
* should not be modified by hand. | ||
*/ | ||
|
||
package id.flwi.example.image.encdec64; | ||
|
||
public final class R { | ||
public static final class attr { | ||
} | ||
public static final class drawable { | ||
public static final int ic_launcher=0x7f020000; | ||
} | ||
public static final class id { | ||
public static final int buttonConvertToImage=0x7f050002; | ||
public static final int buttonLoadImage=0x7f050000; | ||
public static final int imageViewConvert=0x7f050003; | ||
public static final int textViewResult=0x7f050001; | ||
} | ||
public static final class layout { | ||
public static final int main=0x7f030000; | ||
} | ||
public static final class string { | ||
public static final int app_name=0x7f040001; | ||
public static final int hello=0x7f040000; | ||
} | ||
} |
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,40 @@ | ||
-optimizationpasses 5 | ||
-dontusemixedcaseclassnames | ||
-dontskipnonpubliclibraryclasses | ||
-dontpreverify | ||
-verbose | ||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* | ||
|
||
-keep public class * extends android.app.Activity | ||
-keep public class * extends android.app.Application | ||
-keep public class * extends android.app.Service | ||
-keep public class * extends android.content.BroadcastReceiver | ||
-keep public class * extends android.content.ContentProvider | ||
-keep public class * extends android.app.backup.BackupAgentHelper | ||
-keep public class * extends android.preference.Preference | ||
-keep public class com.android.vending.licensing.ILicensingService | ||
|
||
-keepclasseswithmembernames class * { | ||
native <methods>; | ||
} | ||
|
||
-keepclasseswithmembers class * { | ||
public <init>(android.content.Context, android.util.AttributeSet); | ||
} | ||
|
||
-keepclasseswithmembers class * { | ||
public <init>(android.content.Context, android.util.AttributeSet, int); | ||
} | ||
|
||
-keepclassmembers class * extends android.app.Activity { | ||
public void *(android.view.View); | ||
} | ||
|
||
-keepclassmembers enum * { | ||
public static **[] values(); | ||
public static ** valueOf(java.lang.String); | ||
} | ||
|
||
-keep class * implements android.os.Parcelable { | ||
public static final android.os.Parcelable$Creator *; | ||
} |
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 @@ | ||
# This file is automatically generated by Android Tools. | ||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED! | ||
# | ||
# This file must be checked in Version Control Systems. | ||
# | ||
# To customize properties used by the Ant build system use, | ||
# "ant.properties", and override values to adapt the script to your | ||
# project structure. | ||
|
||
# Project target. | ||
target=android-8 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="vertical" > | ||
|
||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="vertical" > | ||
|
||
<Button | ||
android:id="@+id/buttonLoadImage" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Load Image" /> | ||
|
||
<TextView | ||
android:id="@+id/textViewResult" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="TextView" /> | ||
|
||
<Button | ||
android:id="@+id/buttonConvertToImage" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Convert to Image" /> | ||
|
||
<ImageView | ||
android:id="@+id/imageViewConvert" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/ic_launcher" /> | ||
</LinearLayout> | ||
|
||
</ScrollView> |
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<string name="hello">Hello World, EncDecImageActivity!</string> | ||
<string name="app_name">Encode-decode64-image</string> | ||
|
||
</resources> |
116 changes: 116 additions & 0 deletions
116
src/id/flwi/example/image/encdec64/EncDecImageActivity.java
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,116 @@ | ||
package id.flwi.example.image.encdec64; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.content.SharedPreferences.Editor; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.preference.PreferenceManager; | ||
import android.util.Base64; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.Button; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
public class EncDecImageActivity extends Activity { | ||
Button buttonLoad = null; | ||
Button buttonConvert = null; | ||
TextView textEncode = null; | ||
ImageView imageConvertResult = null; | ||
|
||
static final int INTENT_REQUEST_CODE_BROWSE_PICTURE = 1; | ||
|
||
/** Called when the activity is first created. */ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.main); | ||
|
||
buttonLoad = (Button)findViewById(R.id.buttonLoadImage); | ||
buttonConvert = (Button)findViewById(R.id.buttonConvertToImage); | ||
textEncode = (TextView)findViewById(R.id.textViewResult); | ||
imageConvertResult = (ImageView)findViewById(R.id.imageViewConvert); | ||
|
||
SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this); | ||
String previouslyEncodedImage = shre.getString("image_data", ""); | ||
|
||
if( !previouslyEncodedImage.equalsIgnoreCase("") ){ | ||
byte[] b = Base64.decode(previouslyEncodedImage, Base64.DEFAULT); | ||
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length); | ||
imageConvertResult.setImageBitmap(bitmap); | ||
} | ||
|
||
|
||
buttonLoad.setOnClickListener( new OnClickListener() { | ||
|
||
@Override | ||
public void onClick(View view) { | ||
Intent intent = new Intent(); | ||
intent.setType("image/*"); | ||
intent.setAction(Intent.ACTION_GET_CONTENT); | ||
intent.addCategory(Intent.CATEGORY_OPENABLE); | ||
startActivityForResult(intent, | ||
INTENT_REQUEST_CODE_BROWSE_PICTURE); | ||
|
||
} | ||
}); | ||
|
||
buttonConvert.setOnClickListener( new OnClickListener() { | ||
|
||
@Override | ||
public void onClick(View v) { | ||
|
||
byte[] b = Base64.decode(textEncode.getText().toString(), Base64.DEFAULT); | ||
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length); | ||
imageConvertResult.setImageBitmap(bitmap); | ||
} | ||
}); | ||
} | ||
protected void onActivityResult(int requestCode, int resultCode, | ||
Intent intent) { | ||
switch (requestCode) { | ||
case INTENT_REQUEST_CODE_BROWSE_PICTURE: | ||
if( resultCode == Activity.RESULT_OK ){ | ||
|
||
InputStream stream; | ||
String filePath = null; | ||
try { | ||
stream = getContentResolver().openInputStream(intent.getData()); | ||
|
||
Bitmap realImage = BitmapFactory.decodeStream(stream); | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
realImage.compress(Bitmap.CompressFormat.JPEG, 100, baos); | ||
byte[] b = baos.toByteArray(); | ||
|
||
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT); | ||
textEncode.setText(encodedImage); | ||
|
||
SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this); | ||
Editor edit=shre.edit(); | ||
edit.putString("image_data",encodedImage); | ||
edit.commit(); | ||
|
||
} catch (FileNotFoundException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
} |