Skip to content

Commit

Permalink
configurable background color
Browse files Browse the repository at this point in the history
  • Loading branch information
Karsten Priegnitz committed Aug 8, 2015
1 parent 4d7d945 commit 7463985
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 60 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="sheetrock.panda.changelog"
android:versionCode="7"
android:versionName="2.2.2">
android:versionName="2.3">
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="20"/>
<application android:icon="@drawable/icon"
Expand Down
4 changes: 4 additions & 0 deletions res/raw-de/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
</style>
</head>
<body>
$ 2.3
% Version 2.3
_ 2015-08-08
* Hintergrundfarbe ist jetzt konfigurierbar (string: background_color)
$ 2.2.2
% Version 2.2.2
_ 2013-06-19
Expand Down
4 changes: 4 additions & 0 deletions res/raw/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
</style>
</head>
<body>
$ 2.3
% Version 2.3
_ 2015-08-08
* configurable background color (string: background_color)
$ 2.2.2
% Version 2.2.2
_ 2013-06-19
Expand Down
2 changes: 2 additions & 0 deletions res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<string name="changelog_title">letzte Änderungen</string>
<string name="changelog_ok_button">OK</string>
<string name="changelog_show_full">mehr …</string>

<string name="background_color">black</string>
</resources>
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
<string name="changelog_show_full">more …</string>

<string name="promptLastVersion">choose last version</string>

<string name="background_color">black</string>
</resources>
84 changes: 34 additions & 50 deletions src/sheetrock/panda/changelog/ChangeLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public class ChangeLog {
/**
* Constructor
*
* Retrieves the version names and stores the new version name in
* SharedPreferences
* Retrieves the version names and stores the new version name in SharedPreferences
*
* @param context
*/
Expand All @@ -55,8 +54,7 @@ public ChangeLog(Context context) {
/**
* Constructor
*
* Retrieves the version names and stores the new version name in
* SharedPreferences
* Retrieves the version names and stores the new version name in SharedPreferences
*
* @param context
* @param sp
Expand All @@ -69,8 +67,8 @@ public ChangeLog(Context context, SharedPreferences sp) {
this.lastVersion = sp.getString(VERSION_KEY, NO_VERSION);
Log.d(TAG, "lastVersion: " + lastVersion);
try {
this.thisVersion = context.getPackageManager().getPackageInfo(
context.getPackageName(), 0).versionName;
this.thisVersion = context.getPackageManager().getPackageInfo(context.getPackageName(),
0).versionName;
} catch (NameNotFoundException e) {
this.thisVersion = NO_VERSION;
Log.e(TAG, "could not get version name from manifest!");
Expand All @@ -80,10 +78,9 @@ public ChangeLog(Context context, SharedPreferences sp) {
}

/**
* @return The version name of the last installation of this app (as
* described in the former manifest). This will be the same as
* returned by <code>getThisVersion()</code> the second time this
* version of the app is launched (more precisely: the second time
* @return The version name of the last installation of this app (as described in the former
* manifest). This will be the same as returned by <code>getThisVersion()</code> the
* second time this version of the app is launched (more precisely: the second time
* ChangeLog is instantiated).
* @see AndroidManifest.xml#android:versionName
*/
Expand All @@ -100,27 +97,24 @@ public String getThisVersion() {
}

/**
* @return <code>true</code> if this version of your app is started the
* first time
* @return <code>true</code> if this version of your app is started the first time
*/
public boolean firstRun() {
return !this.lastVersion.equals(this.thisVersion);
}

/**
* @return <code>true</code> if your app including ChangeLog is started the
* first time ever. Also <code>true</code> if your app was
* deinstalled and installed again.
* @return <code>true</code> if your app including ChangeLog is started the first time ever.
* Also <code>true</code> if your app was deinstalled and installed again.
*/
public boolean firstRunEver() {
return NO_VERSION.equals(this.lastVersion);
}

/**
* @return An AlertDialog displaying the changes since the previous
* installed version of your app (what's new). But when this is the
* first run of your app including ChangeLog then the full log
* dialog is show.
* @return An AlertDialog displaying the changes since the previous installed version of your
* app (what's new). But when this is the first run of your app including ChangeLog then
* the full log dialog is show.
*/
public AlertDialog getLogDialog() {
return this.getDialog(this.firstRunEver());
Expand All @@ -133,29 +127,24 @@ public AlertDialog getFullLogDialog() {
return this.getDialog(true);
}

private AlertDialog getDialog(boolean full) {
protected AlertDialog getDialog(boolean full) {
WebView wv = new WebView(this.context);

wv.setBackgroundColor(Color.BLACK);
wv.loadDataWithBaseURL(null, this.getLog(full), "text/html", "UTF-8",
null);
wv.setBackgroundColor(Color.parseColor(context.getResources().getString(
R.string.background_color)));
wv.loadDataWithBaseURL(null, this.getLog(full), "text/html", "UTF-8", null);

AlertDialog.Builder builder = new AlertDialog.Builder(
new ContextThemeWrapper(
this.context, android.R.style.Theme_Dialog));
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this.context,
android.R.style.Theme_Dialog));
builder.setTitle(
context.getResources().getString(
full ? R.string.changelog_full_title
: R.string.changelog_title))
full ? R.string.changelog_full_title : R.string.changelog_title))
.setView(wv)
.setCancelable(false)
// OK button
.setPositiveButton(
context.getResources().getString(
R.string.changelog_ok_button),
.setPositiveButton(context.getResources().getString(R.string.changelog_ok_button),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
public void onClick(DialogInterface dialog, int which) {
updateVersionInPreferences();
}
});
Expand All @@ -173,10 +162,9 @@ public void onClick(DialogInterface dialog, int id) {
return builder.create();
}

private void updateVersionInPreferences() {
protected void updateVersionInPreferences() {
// save new version number to preferences
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(context);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = sp.edit();
editor.putString(VERSION_KEY, thisVersion);
// // on SDK-Versions > 9 you should use this:
Expand All @@ -189,8 +177,8 @@ private void updateVersionInPreferences() {
}

/**
* @return HTML displaying the changes since the previous installed version
* of your app (what's new)
* @return HTML displaying the changes since the previous installed version of your app (what's
* new)
*/
public String getLog() {
return this.getLog(false);
Expand All @@ -212,17 +200,16 @@ private enum Listmode {
private StringBuffer sb = null;
private static final String EOCL = "END_OF_CHANGE_LOG";

private String getLog(boolean full) {
protected String getLog(boolean full) {
// read changelog.txt file
sb = new StringBuffer();
try {
InputStream ins = context.getResources().openRawResource(
R.raw.changelog);
InputStream ins = context.getResources().openRawResource(R.raw.changelog);
BufferedReader br = new BufferedReader(new InputStreamReader(ins));

String line = null;
boolean advanceToEOVS = false; // if true: ignore further version
// sections
// sections
while ((line = br.readLine()) != null) {
line = line.trim();
char marker = line.length() > 0 ? line.charAt(0) : 0;
Expand All @@ -243,20 +230,17 @@ private String getLog(boolean full) {
case '%':
// line contains version title
this.closeList();
sb.append("<div class='title'>"
+ line.substring(1).trim() + "</div>\n");
sb.append("<div class='title'>" + line.substring(1).trim() + "</div>\n");
break;
case '_':
// line contains version title
this.closeList();
sb.append("<div class='subtitle'>"
+ line.substring(1).trim() + "</div>\n");
sb.append("<div class='subtitle'>" + line.substring(1).trim() + "</div>\n");
break;
case '!':
// line contains free text
this.closeList();
sb.append("<div class='freetext'>"
+ line.substring(1).trim() + "</div>\n");
sb.append("<div class='freetext'>" + line.substring(1).trim() + "</div>\n");
break;
case '#':
// line contains numbered list item
Expand Down Expand Up @@ -284,7 +268,7 @@ private String getLog(boolean full) {
return sb.toString();
}

private void openList(Listmode listMode) {
protected void openList(Listmode listMode) {
if (this.listMode != listMode) {
closeList();
if (listMode == Listmode.ORDERED) {
Expand All @@ -296,7 +280,7 @@ private void openList(Listmode listMode) {
}
}

private void closeList() {
protected void closeList() {
if (this.listMode == Listmode.ORDERED) {
sb.append("</ol></div>\n");
} else if (this.listMode == Listmode.UNORDERED) {
Expand Down
9 changes: 0 additions & 9 deletions strings.xml

This file was deleted.

0 comments on commit 7463985

Please sign in to comment.