Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to view raw Bitmap images. #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="file" />

<data android:scheme="rtsp" />
<data android:scheme="rtmp" />
<data android:scheme="ftp" />
<data android:scheme="sftp" />

<data android:mimeType="*/*" />
</intent-filter>
<intent-filter android:label="@string/intent_filter_label">
<action android:name="android.intent.action.VIEW" >
</action>

<intent-filter android:label="@string/intent_filter_label">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

Expand Down
83 changes: 82 additions & 1 deletion app/src/main/java/uk/co/ashtonbrsc/intentexplode/Explode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
Expand All @@ -35,12 +36,14 @@
import android.text.style.LeadingMarginSpan;
import android.text.style.ParagraphStyle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
Expand All @@ -58,7 +61,6 @@
import uk.co.ashtonbrsc.android.intentintercept.R;

//TODO add icon -which icon - app icons???
//TODO add bitmaps/images (from intent extras?)
//TODO add getCallingActivity() - will only give details for startActivityForResult();

/**
Expand Down Expand Up @@ -321,6 +323,52 @@ private void showAllIntentData(TextView textViewToIgnore) {
Typeface.ITALIC, STANDARD_INDENT_SIZE_IN_DIP,
extrasLayout);
}
} else if(extraItem instanceof Bitmap) {
addBitmapToLayout(getString(R.string.extra_item_value_title) + BLANK,
Typeface.ITALIC, STANDARD_INDENT_SIZE_IN_DIP,
(Bitmap) extraItem, extrasLayout);
} else if(extraItem instanceof Bundle) {
Bundle bundle = (Bundle) extraItem;
StringBuilder stringBuilder = new StringBuilder("Bundle{");
for (String key : bundle.keySet()) {
stringBuilder
.append("\n ")
.append(key)
.append(": ")
.append(bundle.get(key));
}
stringBuilder.append("\n}");
addTextToLayout(getString(R.string.extra_item_value_title) + BLANK + stringBuilder
.toString(),
Typeface.ITALIC, STANDARD_INDENT_SIZE_IN_DIP,
extrasLayout);
} else if(extraItem.getClass().isArray()) {
// Item is an array, preview first 20 elements.
Object[] items = (Object[]) extraItem;
int max = Math.min(items.length, 20);
StringBuilder stringBuilder = new StringBuilder(extraItem.getClass().getComponentType().getSimpleName());
stringBuilder
.append('[').append(items.length).append("]{");
for (int i = 0; i < max; i++) {
stringBuilder
.append("\n ")
.append(i)
.append(": ")
.append(items[i]);
}
if(max < items.length) {
// preview of the end of the array.
stringBuilder
.append("\n...\n ")
.append(items.length - 1)
.append(": ")
.append(items[items.length -1]);
}
stringBuilder.append("\n}");
addTextToLayout(getString(R.string.extra_item_value_title) + BLANK + stringBuilder
.toString(),
Typeface.ITALIC, STANDARD_INDENT_SIZE_IN_DIP,
extrasLayout);
} else {
addTextToLayout(getString(R.string.extra_item_value_title) + BLANK + extraItem
.toString(),
Expand Down Expand Up @@ -401,6 +449,39 @@ private void checkAndShowMatchingActivites() {
}
}

private void addBitmapToLayout(String text, int typeface, int paddingLeft, Bitmap bitmap, LinearLayout linearLayout) {
LinearLayout bitmapLayout = new LinearLayout(this);
TextView textView = new TextView(this);
ParagraphStyle style_para = new LeadingMarginSpan.Standard(0,
(int) (STANDARD_INDENT_SIZE_IN_DIP * density));
SpannableString styledText = new SpannableString(text);
styledText.setSpan(style_para, 0, styledText.length(),
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(styledText);
textView.setTextAppearance(this, R.style.TextFlags);
textView.setTypeface(null, typeface);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
textView.setTextIsSelectable(true);
}
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
params.setMargins((int) (paddingLeft * density), 0, 0, 0);

// At most 144dsp.
float maxHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 144, getResources().getDisplayMetrics());
int height = (int) Math.min(bitmap.getHeight(), maxHeight);
int width = bitmap.getWidth() * (height/bitmap.getHeight());

LinearLayout.LayoutParams bitmapParams = new LayoutParams(width, height);
ImageView bitmapView = new ImageView(this);
bitmapView.setImageBitmap(bitmap);
bitmapView.setBackgroundResource(R.drawable.checkerboard_pattern);
bitmapLayout.setOrientation(LinearLayout.HORIZONTAL);
bitmapLayout.addView(textView);
bitmapLayout.addView(bitmapView, bitmapParams);
linearLayout.addView(bitmapLayout, params);
}

private void addTextToLayout(String text, int typeface, int paddingLeft,
LinearLayout layout) {
TextView textView = new TextView(this);
Expand Down
Binary file added app/src/main/res/drawable-hdpi/checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/checkerboard_pattern.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:src="@drawable/checkerboard"
android:tileMode="repeat" />