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

Resolve dialog padding from theme if present #782

Merged
merged 1 commit into from
Jun 23, 2020
Merged
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
30 changes: 22 additions & 8 deletions acra-dialog/src/main/java/org/acra/dialog/CrashReportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.InputType;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.acra.ACRA;
import org.acra.ACRAConstants;
import org.acra.config.ConfigUtils;
Expand All @@ -49,14 +50,14 @@ public class CrashReportDialog extends Activity implements DialogInterface.OnCli

private static final String STATE_EMAIL = "email";
private static final String STATE_COMMENT = "comment";
private static final int PADDING = 10;

private LinearLayout scrollable;
private EditText userCommentView;
private EditText userEmailView;
private SharedPreferencesFactory sharedPreferencesFactory;
private DialogConfiguration dialogConfiguration;
private CrashReportDialogHelper helper;
private int padding;

private AlertDialog mDialog;

Expand All @@ -71,6 +72,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
dialogConfiguration = ConfigUtils.getPluginConfiguration(helper.getConfig(), DialogConfiguration.class);
final int themeResourceId = dialogConfiguration.resTheme();
if (themeResourceId != ACRAConstants.DEFAULT_RES_VALUE) setTheme(themeResourceId);
padding = loadPaddingFromTheme();

buildAndShowDialog(savedInstanceState);
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -105,7 +107,7 @@ protected void buildAndShowDialog(@Nullable Bundle savedInstanceState) {
@NonNull
protected View buildCustomView(@Nullable Bundle savedInstanceState) {
final ScrollView root = new ScrollView(this);
root.setPadding(PADDING, PADDING, PADDING, PADDING);
root.setPadding(padding, padding, padding, padding);
root.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
root.setFocusable(true);
root.setFocusableInTouchMode(true);
Expand All @@ -116,7 +118,7 @@ protected View buildCustomView(@Nullable Bundle savedInstanceState) {
// Add an optional prompt for user comments
final View comment = getCommentLabel();
if (comment != null) {
comment.setPadding(comment.getPaddingLeft(), PADDING, comment.getPaddingRight(), comment.getPaddingBottom());
comment.setPadding(comment.getPaddingLeft(), padding, comment.getPaddingRight(), comment.getPaddingBottom());
addViewToDialog(comment);
String savedComment = null;
if (savedInstanceState != null) {
Expand All @@ -129,7 +131,7 @@ protected View buildCustomView(@Nullable Bundle savedInstanceState) {
// Add an optional user email field
final View email = getEmailLabel();
if (email != null) {
email.setPadding(email.getPaddingLeft(), PADDING, email.getPaddingRight(), email.getPaddingBottom());
email.setPadding(email.getPaddingLeft(), padding, email.getPaddingRight(), email.getPaddingBottom());
addViewToDialog(email);
String savedEmail = null;
if (savedInstanceState != null) {
Expand Down Expand Up @@ -259,7 +261,7 @@ public void onClick(DialogInterface dialog, int which) {

/*
* (non-Javadoc)
*
*
* @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
*/
@CallSuper
Expand All @@ -280,4 +282,16 @@ protected void onSaveInstanceState(@NonNull Bundle outState) {
protected AlertDialog getDialog() {
return mDialog;
}

/**
* @return value of ?dialogPreferredPadding from theme or 10 if not set.
*/
protected int loadPaddingFromTheme() {
TypedValue value = new TypedValue();
if (getTheme().resolveAttribute(android.R.attr.dialogPreferredPadding, value, true)) {
return TypedValue.complexToDimensionPixelSize(value.data, getResources().getDisplayMetrics());
}
//attribute not set, fall back to a default value
return 10;
}
}