Skip to content

Commit

Permalink
Merge pull request #436 from F43nd1r/dialog
Browse files Browse the repository at this point in the history
Add configuration for dialog theme
  • Loading branch information
william-ferguson-au committed Apr 16, 2016
2 parents a28d565 + ccc2854 commit 36fc404
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/acra/annotation/ReportsCrashes.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;

import org.acra.ACRA;
import org.acra.ACRAConstants;
Expand Down Expand Up @@ -139,6 +140,12 @@
*/
@StringRes int resDialogTitle() default ACRAConstants.DEFAULT_RES_VALUE;

/**
*
* @return resource id for the crash dialog theme
*/
@StyleRes int resDialogTheme() default ACRAConstants.DEFAULT_RES_VALUE;

/**
* @return Resource id for the icon in the status bar notification. Default
* is the system error notification icon.
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/acra/config/ACRAConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;

import org.acra.ACRA;
import org.acra.ACRAConstants;
Expand Down Expand Up @@ -101,6 +102,8 @@ public final class ACRAConfiguration implements Serializable {
private int resDialogText;
@StringRes
private int resDialogTitle;
@StyleRes
private int resDialogTheme;
@DrawableRes
private int resNotifIcon;
@StringRes
Expand Down Expand Up @@ -164,6 +167,7 @@ public final class ACRAConfiguration implements Serializable {
resDialogOkToast = builder.resDialogOkToast();
resDialogText = builder.resDialogText();
resDialogTitle = builder.resDialogTitle();
resDialogTheme = builder.resDialogTheme();
resNotifIcon = builder.resNotifIcon();
resNotifText = builder.resNotifText();
resNotifTickerText = builder.resNotifTickerText();
Expand Down Expand Up @@ -896,6 +900,11 @@ public int resDialogTitle() {
return resDialogTitle;
}

@StyleRes
public int resDialogTheme() {
return resDialogTheme;
}

@DrawableRes
public int resNotifIcon() {
return resNotifIcon;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/acra/config/ConfigurationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;

import org.acra.ACRA;
import org.acra.ReportField;
Expand Down Expand Up @@ -87,6 +88,7 @@ public final class ConfigurationBuilder {
@StringRes private Integer resDialogOkToast;
@StringRes private Integer resDialogText;
@StringRes private Integer resDialogTitle;
@StyleRes private Integer resDialogTheme;
@DrawableRes private Integer resNotifIcon;
@StringRes private Integer resNotifText;
@StringRes private Integer resNotifTickerText;
Expand Down Expand Up @@ -147,6 +149,7 @@ public ConfigurationBuilder(@NonNull Application app) {
resDialogOkToast = annotationConfig.resDialogOkToast();
resDialogText = annotationConfig.resDialogText();
resDialogTitle = annotationConfig.resDialogTitle();
resDialogTheme = annotationConfig.resDialogTheme();
resNotifIcon = annotationConfig.resNotifIcon();
resNotifText = annotationConfig.resNotifText();
resNotifTickerText = annotationConfig.resNotifTickerText();
Expand Down Expand Up @@ -478,6 +481,16 @@ public ConfigurationBuilder setResDialogTitle(@StringRes int resId) {
return this;
}

/**
* @param resId The resource id, see {@link ReportsCrashes#resDialogTheme()}
* @return this instance
*/
@NonNull
public ConfigurationBuilder setResDialogTheme(@StyleRes int resId) {
resDialogTheme = resId;
return this;
}

/**
* Use this method if the id you wanted to give to
* {@link ReportsCrashes#resNotifIcon()} comes from an Android Library
Expand Down Expand Up @@ -911,6 +924,14 @@ int resDialogTitle() {
return DEFAULT_RES_VALUE;
}

@StyleRes
int resDialogTheme() {
if (resDialogTheme != null) {
return resDialogTheme;
}
return DEFAULT_RES_VALUE;
}

@DrawableRes
int resNotifIcon() {
if (resNotifIcon != null) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/acra/dialog/CrashReportDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ protected void init(@Nullable Bundle savedInstanceState) {
scrollable = new LinearLayout(this);
scrollable.setOrientation(LinearLayout.VERTICAL);
sharedPreferencesFactory = new SharedPreferencesFactory(getApplicationContext(), getConfig());
final int themeResourceId = getConfig().resDialogTheme();
if(themeResourceId != ACRAConstants.DEFAULT_RES_VALUE) setTheme(themeResourceId);

buildAndShowDialog(savedInstanceState);
}
Expand Down

0 comments on commit 36fc404

Please sign in to comment.