diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8c4b1be..101521c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,12 +25,20 @@ + + + + + + + + + - - - + + diff --git a/app/src/main/java/uk/co/ashtonbrsc/intentexplode/Explode.java b/app/src/main/java/uk/co/ashtonbrsc/intentexplode/Explode.java index f9cba6b..5795228 100644 --- a/app/src/main/java/uk/co/ashtonbrsc/intentexplode/Explode.java +++ b/app/src/main/java/uk/co/ashtonbrsc/intentexplode/Explode.java @@ -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; @@ -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; @@ -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(); /** @@ -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(), @@ -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); diff --git a/app/src/main/res/drawable-hdpi/checkerboard.png b/app/src/main/res/drawable-hdpi/checkerboard.png new file mode 100644 index 0000000..cf17d34 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/checkerboard.png differ diff --git a/app/src/main/res/drawable-mdpi/checkerboard.png b/app/src/main/res/drawable-mdpi/checkerboard.png new file mode 100644 index 0000000..7aea968 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/checkerboard.png differ diff --git a/app/src/main/res/drawable-xhdpi/checkerboard.png b/app/src/main/res/drawable-xhdpi/checkerboard.png new file mode 100644 index 0000000..8795fea Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/checkerboard.png differ diff --git a/app/src/main/res/drawable-xxhdpi/checkerboard.png b/app/src/main/res/drawable-xxhdpi/checkerboard.png new file mode 100644 index 0000000..eab73a1 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/checkerboard.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/checkerboard.png b/app/src/main/res/drawable-xxxhdpi/checkerboard.png new file mode 100644 index 0000000..ff2b958 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/checkerboard.png differ diff --git a/app/src/main/res/drawable/checkerboard.png b/app/src/main/res/drawable/checkerboard.png new file mode 100644 index 0000000..6943665 Binary files /dev/null and b/app/src/main/res/drawable/checkerboard.png differ diff --git a/app/src/main/res/drawable/checkerboard_pattern.xml b/app/src/main/res/drawable/checkerboard_pattern.xml new file mode 100644 index 0000000..f19db54 --- /dev/null +++ b/app/src/main/res/drawable/checkerboard_pattern.xml @@ -0,0 +1,5 @@ + + \ No newline at end of file