Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ereza committed Sep 21, 2015
2 parents ee89f5a + 191081b commit 53448d3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@

package cat.ereza.customactivityoncrash.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import android.widget.Toast;
import cat.ereza.customactivityoncrash.CustomActivityOnCrash;
import cat.ereza.customactivityoncrash.R;

Expand Down Expand Up @@ -75,6 +81,13 @@ public void onClick(View v) {
.setTitle(R.string.customactivityoncrash_error_activity_error_details_title)
.setMessage(CustomActivityOnCrash.getAllErrorDetailsFromIntent(DefaultErrorActivity.this, getIntent()))
.setPositiveButton(R.string.customactivityoncrash_error_activity_error_details_close, null)
.setNeutralButton(R.string.customactivityoncrash_error_activity_error_details_copy,
new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
copyErrorToClipboard();
Toast.makeText(DefaultErrorActivity.this, R.string.customactivityoncrash_error_activity_error_details_copied, Toast.LENGTH_SHORT).show();
}
})
.show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.customactivityoncrash_error_activity_error_details_text_size));
Expand All @@ -84,4 +97,19 @@ public void onClick(View v) {
moreInfoButton.setVisibility(View.GONE);
}
}

@SuppressLint("NewApi")
private void copyErrorToClipboard() {
String errorInformation =
CustomActivityOnCrash.getAllErrorDetailsFromIntent(DefaultErrorActivity.this, getIntent());

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(errorInformation);
} else {
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Error information", errorInformation);
clipboard.setPrimaryClip(clip);
}
}
}
2 changes: 2 additions & 0 deletions library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
<string name="customactivityoncrash_error_activity_error_details">Error details</string>
<string name="customactivityoncrash_error_activity_error_details_title">Error details</string>
<string name="customactivityoncrash_error_activity_error_details_close">Close</string>
<string name="customactivityoncrash_error_activity_error_details_copy">Copy to clipboard</string>
<string name="customactivityoncrash_error_activity_error_details_copied">Copied to clipboard</string>
</resources>

0 comments on commit 53448d3

Please sign in to comment.