| 80 | } |
| 81 | |
| 82 | private void load() { |
| 83 | Uri uri = getIntent().getData(); |
| 84 | Log.i("DSN uri=" + uri); |
| 85 | |
| 86 | Bundle args = new Bundle(); |
| 87 | args.putParcelable("uri", uri); |
| 88 | |
| 89 | new SimpleTask<Spanned>() { |
| 90 | @Override |
| 91 | protected void onPreExecute(Bundle args) { |
| 92 | pbWait.setVisibility(View.VISIBLE); |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | protected void onPostExecute(Bundle args) { |
| 97 | pbWait.setVisibility(View.GONE); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | protected Spanned onExecute(Context context, Bundle args) throws Throwable { |
| 102 | Uri uri = args.getParcelable("uri"); |
| 103 | |
| 104 | NoStreamException.check(uri, context); |
| 105 | |
| 106 | ContentResolver resolver = context.getContentResolver(); |
| 107 | try (InputStream is = resolver.openInputStream(uri)) { |
| 108 | if (is == null) |
| 109 | throw new FileNotFoundException(uri.toString()); |
| 110 | |
| 111 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 112 | Helper.copy(is, bos); |
| 113 | |
| 114 | String headers = bos.toString(StandardCharsets.UTF_8.name()); |
| 115 | headers = MessageHelper.decodeMime(headers); |
| 116 | return HtmlHelper.highlightHeaders(context, |
| 117 | null, null, null, headers, false, false); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | protected void onExecuted(Bundle args, Spanned result) { |
| 123 | tvHeaders.setText(result); |
| 124 | grpReady.setVisibility(View.VISIBLE); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | protected void onException(Bundle args, Throwable ex) { |
| 129 | if (ex instanceof NoStreamException) |
| 130 | ((NoStreamException) ex).report(ActivityDSN.this); |
| 131 | else |
| 132 | Log.unexpectedError(getSupportFragmentManager(), ex, false); |
| 133 | } |
| 134 | }.execute(this, args, "disposition:decode"); |
| 135 | } |
| 136 | } |