Back to project page SeeKampf.
The source code is released under:
GNU General Public License
If you think the Android project SeeKampf listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.avedo.seekampf.core; //from www . j ava 2 s.c o m import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import net.avedo.seekampf.R; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetManager; import android.preference.PreferenceManager; import android.view.ContextThemeWrapper; import android.view.ViewGroup.LayoutParams; import android.webkit.WebView; public class ChangeLog { public static final String PREFS_VERSION_KEY = "pref_version_key"; public static final String DEFAULT_VERSION = ""; private SharedPreferences prefs; private Context context; private String oldVersion; private String newVersion; public ChangeLog(Context context) { // Store the context. this.context = context; // Load the SharedPreferences ... this.prefs = (SharedPreferences) PreferenceManager .getDefaultSharedPreferences(context); // ... and fetch the version numbers. this.oldVersion = this.prefs.getString(PREFS_VERSION_KEY, DEFAULT_VERSION); try { this.newVersion = context.getPackageManager().getPackageInfo( context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { this.newVersion = DEFAULT_VERSION; } } public String getNewVersion() { return this.newVersion; } public String getOldVersion() { return this.oldVersion; } public boolean firstRunAfterUpdate() { return !this.newVersion.equals(this.oldVersion); } public boolean firstRunAfterInstallation() { return this.oldVersion.equals(DEFAULT_VERSION); } public AlertDialog getDialog() { // Initialize a webview to display the contents of the log ... WebView mainView = new WebView(this.context); mainView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); // ... and assign the data from an asset. mainView.loadData(this.fetchLog(), "text/html", "UTF-8"); // Finally setup a new AllertDialog and return it. AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(this.context, android.R.style.Theme_Dialog)); builder.setTitle(context.getResources().getString(R.string.changelog)) .setView(mainView) .setCancelable(false) .setPositiveButton( context.getResources().getString( R.string.okBtn), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { updateVersionInPrefs(); } }); return builder.create(); } private void updateVersionInPrefs() { this.prefs.edit().putString(PREFS_VERSION_KEY, this.newVersion).commit(); } private String fetchLog() { AssetManager localAssetManager = this.context.getAssets(); String body = ""; try { BufferedReader reader = new BufferedReader(new InputStreamReader( localAssetManager.open("changelog.html"))); String line; while ((line = reader.readLine()) != null) { body += line; } reader.close(); } catch (IOException e) { } return body; } }