If you think the Android project opensudoku listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.moire.opensudoku.gui;
/*fromwww.java2s.com*/import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import android.webkit.WebView;
import org.moire.opensudoku.R;
import org.moire.opensudoku.utils.AndroidUtils;
publicclass Changelog {
privatestaticfinal String TAG = "Changelog";
privatestaticfinal String PREF_FILE_CHANGELOG = "changelog";
private Context mContext;
private SharedPreferences mPrefs;
public Changelog(Context context) {
mContext = context;
mPrefs = mContext.getSharedPreferences(PREF_FILE_CHANGELOG, Context.MODE_PRIVATE);
}
publicvoid showOnFirstRun() {
String versionKey = "changelog_" + AndroidUtils.getAppVersionCode(mContext);
if (!mPrefs.getBoolean(versionKey, false)) {
showChangelogDialog();
Editor editor = mPrefs.edit();
editor.putBoolean(versionKey, true);
editor.commit();
}
}
privatevoid showChangelogDialog() {
String changelog = getChangelogFromResources();
WebView webView = new WebView(mContext);
webView.loadData(changelog, "text/html", "utf-8");
AlertDialog changelogDialog = new AlertDialog.Builder(mContext)
.setIcon(android.R.drawable.ic_menu_info_details)
.setTitle(R.string.what_is_new)
.setView(webView)
.setPositiveButton(R.string.close, null).create();
changelogDialog.show();
}
private String getChangelogFromResources() {
InputStream is = null;
try {
is = mContext.getResources().openRawResource(R.raw.changelog);
finalchar[] buffer = newchar[0x10000];
StringBuilder out = new StringBuilder();
Reader in = new InputStreamReader(is, "UTF-8");
int read;
do {
read = in.read(buffer, 0, buffer.length);
if (read > 0) {
out.append(buffer, 0, read);
}
} while (read >= 0);
return out.toString();
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, "Error when reading changelog from raw resources.", e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, "Error when reading changelog from raw resources.", e);
}
}
}
return"";
}
}