Skip to content

Commit d910935

Browse files
committed
Merge pull request #289 from NativeScript/plamen5kov/copy_error_to_clipboard
users will be able to copy the shown exception
2 parents b506af4 + 9dcdcd0 commit d910935

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/src/com/tns/ErrorReport.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import android.app.Activity;
1010
import android.app.PendingIntent;
1111
import android.app.PendingIntent.CanceledException;
12+
import android.content.ClipData;
13+
import android.content.ClipboardManager;
1214
import android.content.Context;
1315
import android.content.Intent;
1416
import android.graphics.drawable.GradientDrawable;
@@ -140,44 +142,42 @@ static boolean hasIntent(Intent intent)
140142
void buildUI()
141143
{
142144
Context context = activity;
143-
145+
Intent intent = activity.getIntent();
146+
final String msg = intent.getStringExtra(EXTRA_ERROR_REPORT_MSG);
147+
148+
//container
144149
LinearLayout layout = new LinearLayout(context);
145150
layout.setOrientation(LinearLayout.VERTICAL);
146151
activity.setContentView(layout);
147152

153+
//header
148154
TextView txtHeader = new TextView(context);
149-
txtHeader.setText("Callstack");
150-
151-
layout.addView(txtHeader);
155+
txtHeader.setText("Unhandled Exception");
152156

153-
Intent intent = activity.getIntent();
154-
String msg = intent.getStringExtra(EXTRA_ERROR_REPORT_MSG);
155-
157+
//error + stacktrace
156158
TextView txtErrorMsg = new TextView(context);
157159
txtErrorMsg.setText(msg);
158160
txtErrorMsg.setHeight(1000);
159161
txtErrorMsg.setMovementMethod(new ScrollingMovementMethod());
160162

161-
GradientDrawable gd = new GradientDrawable();
162-
gd.setColor(0xFFFFFFFF);
163-
gd.setCornerRadius(5);
164-
gd.setStroke(1, 0xFF000000);
165-
txtErrorMsg.setBackground(gd);
166-
167-
layout.addView(txtErrorMsg);
168-
169-
Button btnClose = new Button(context);
170-
btnClose.setText("Close");
171-
btnClose.setOnClickListener(new OnClickListener()
163+
// copy button
164+
Button copyToClipboard = new Button(context);
165+
copyToClipboard.setText("Copy to clipboard");
166+
copyToClipboard.setOnClickListener(new OnClickListener()
172167
{
173168
@Override
174169
public void onClick(View v)
175170
{
176-
activity.finish();
171+
172+
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
173+
ClipData clip = ClipData.newPlainText("nsError", msg);
174+
clipboard.setPrimaryClip(clip);
177175
}
178176
});
179-
180-
layout.addView(btnClose);
177+
178+
layout.addView(txtHeader);
179+
layout.addView(txtErrorMsg);
180+
layout.addView(copyToClipboard);
181181
}
182182

183183
private static void createErrorFile(final Context context)

0 commit comments

Comments
 (0)