Android Open Source - SeeKampf Change Log






From Project

Back to project page SeeKampf.

License

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.

Java Source Code

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;
  }
}




Java Source Code List

net.avedo.seekampf.BuildConfig.java
net.avedo.seekampf.core.ChangeLog.java
net.avedo.seekampf.core.CustomAdapter.java
net.avedo.seekampf.core.MainActivity.java
net.avedo.seekampf.core.OceanView.java
net.avedo.seekampf.core.OverScrollerCompat.java
net.avedo.seekampf.core.RestDetailsActivity.java
net.avedo.seekampf.core.ScaleGestureDetectorCompat.java
net.avedo.seekampf.core.VolleyActivity.java
net.avedo.seekampf.core.Zoomer.java
net.avedo.seekampf.fragments.AboutFragment.java
net.avedo.seekampf.fragments.AllianceListFragment.java
net.avedo.seekampf.fragments.AuctionListFragment.java
net.avedo.seekampf.fragments.HomeDetailsFragment.java
net.avedo.seekampf.fragments.HomeFragment.java
net.avedo.seekampf.fragments.IslandDetailsFragment.java
net.avedo.seekampf.fragments.IslandListFragment.java
net.avedo.seekampf.fragments.MessageDetailsFragment.java
net.avedo.seekampf.fragments.MessageListFragment.java
net.avedo.seekampf.fragments.OceanFragment.java
net.avedo.seekampf.fragments.PlayerListFragment.java
net.avedo.seekampf.fragments.RestDetailsFragment.java
net.avedo.seekampf.fragments.RestListFragment.java
net.avedo.seekampf.fragments.SettingsFragment.java
net.avedo.seekampf.models.Alliance.java
net.avedo.seekampf.models.Auction.java
net.avedo.seekampf.models.BaseModel.java
net.avedo.seekampf.models.Island.java
net.avedo.seekampf.models.Message.java
net.avedo.seekampf.models.Player.java
net.avedo.seekampf.utils.AuthGsonRequest.java
net.avedo.seekampf.utils.Constants.java
net.avedo.seekampf.utils.Interfaces.java
net.avedo.seekampf.utils.VolleyErrorHelper.java