Android Open Source - GuiLib Version Info Dialog






From Project

Back to project page GuiLib.

License

The source code is released under:

Apache License

If you think the Android project GuiLib 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 com.gandulf.guilib.view;
//  w ww  . j  a v  a2s .c  o  m
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebView;

import com.gandulf.guilib.R;
import com.gandulf.guilib.util.Debug;
import com.gandulf.guilib.util.ResUtil;

/**
 * @author Ganymede
 * 
 */
public class VersionInfoDialog extends AlertDialog {

  public static final String KEY_NEWS_VERSION = "newsversion";

  private WebView webView;

  private String content;

  private int seenVersion = -1;

  private boolean donateVersion;

  private Integer donateContentId;

  private String donateUrl;

  private Class<?> rawClass;

  public static boolean newsShown = false;

  private SharedPreferences preferences;

  /**
   * @param context
   */
  public VersionInfoDialog(Context context) {
    super(context);
    init();
  }

  /**
   * @param context
   * @param theme
   */
  public VersionInfoDialog(Context context, int theme) {
    super(context, theme);
    init();
  }

  /**
   * @param context
   * @param cancelable
   * @param cancelListener
   */
  public VersionInfoDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
    super(context, cancelable, cancelListener);
    init();
  }

  public boolean isDonateVersion() {
    return donateVersion;
  }

  public void setDonateVersion(boolean donateVersion) {
    this.donateVersion = donateVersion;
  }

  public Integer getDonateContentId() {
    return donateContentId;
  }

  public void setDonateContentId(Integer donateContentId) {
    this.donateContentId = donateContentId;
  }

  public Class<?> getRawClass() {
    return rawClass;
  }

  public void setRawClass(Class<?> rawClass) {
    this.rawClass = rawClass;
  }

  protected void init() {
    preferences = PreferenceManager.getDefaultSharedPreferences(getContext());

    setTitle(R.string.news_title);

    webView = new WebView(getContext());
    webView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    setButton(BUTTON_POSITIVE, getContext().getString(R.string.label_ok), new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
      }
    });

    setView(webView);
  }

  public boolean hasContent() {
    return !TextUtils.isEmpty(content);
  }

  public int getPackageVersion() {
    int version = -1;
    try {
      PackageInfo manager = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
      version = manager.versionCode;
    } catch (NameNotFoundException e) {
      // Handle exception
    }
    return version;
  }

  public void show(boolean showAll) {
    if (showAll) {
      seenVersion = -1;
    } else {
      seenVersion = preferences.getInt(KEY_NEWS_VERSION, -1);
    }
    show();
  }

  /*
   * (non-Javadoc)
   * 
   * @see android.app.Dialog#onStart()
   */
  @Override
  protected void onStart() {
    newsShown = true;
    setSeenVersion(seenVersion);

    super.onStart();
  }

  private void updateView() {
    if (!TextUtils.isEmpty(donateUrl) && isDonateVersion()) {
      Debug.verbose("Setting donate button");
      setButton(BUTTON_NEGATIVE, getContext().getString(R.string.label_donate),
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();

              Uri uriUrl = Uri.parse(VersionInfoDialog.this.donateUrl);
              final Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
              getContext().startActivity(launchBrowser);
            }
          });
    }
  }

  private void setSeenVersion(Integer seenVersion) {

    StringBuilder summary = new StringBuilder();

    if (donateVersion && donateContentId != null) {

      if (donateContentId > 0) {
        String content = ResUtil.loadResToString(donateContentId, getContext());
        if (content != null)
          summary.append(content);
      }

    }

    int version = getPackageVersion();
    if (version > seenVersion) {

      while (version > seenVersion) {

        int stringId = ResUtil.getString(rawClass, "news_" + version);
        if (stringId > 0) {
          String content = ResUtil.loadResToString(stringId, getContext());
          if (content != null)
            summary.append(content);
        }
        version--;
      }

    }

    Editor editor = preferences.edit();
    editor.putInt(KEY_NEWS_VERSION, version);
    editor.commit();

    if (!TextUtils.isEmpty(summary)) {
      content = summary.toString();
    } else {
      content = null;
    }

    if (webView != null && content != null) {
      webView.loadDataWithBaseURL("/fake", content, "text/html", "utf-8", null);
    }
  }

  public String getDonateUrl() {
    return donateUrl;
  }

  public void setDonateUrl(String donateUrl) {
    this.donateUrl = donateUrl;
    updateView();
  }

}




Java Source Code List

au.com.bytecode.opencsv.CSVReader.java
com.ecloud.pulltozoomview.PullToZoomScrollView.java
com.gandulf.guilib.data.OpenArrayAdapter.java
com.gandulf.guilib.data.OpenFilter.java
com.gandulf.guilib.download.AbstractDownloader.java
com.gandulf.guilib.download.DownloadBroadcastReceiver.java
com.gandulf.guilib.download.DownloaderGinger.java
com.gandulf.guilib.download.DownloaderWrapper.java
com.gandulf.guilib.download.Downloader.java
com.gandulf.guilib.download.MediaScannerWrapper.java
com.gandulf.guilib.download.UnzipIntentService.java
com.gandulf.guilib.listener.CheckableListenable.java
com.gandulf.guilib.listener.OnCheckedChangeListener.java
com.gandulf.guilib.util.ColorUtil.java
com.gandulf.guilib.util.Debug.java
com.gandulf.guilib.util.DefaultTextWatcher.java
com.gandulf.guilib.util.DirectoryFileFilter.java
com.gandulf.guilib.util.FileFileFilter.java
com.gandulf.guilib.util.ListViewCompat.java
com.gandulf.guilib.util.MathUtil.java
com.gandulf.guilib.util.ResUtil.java
com.gandulf.guilib.view.ColorPickerDialog.java
com.gandulf.guilib.view.DynamicListViewEx.java
com.gandulf.guilib.view.HackeyDrawerLayout.java
com.gandulf.guilib.view.SeekBarEx.java
com.gandulf.guilib.view.VersionInfoDialog.java
com.gandulf.guilib.view.ViewScroller.java
com.gandulf.guilib.view.adapter.MultiFragmentPagerAdapter.java
com.getbase.floatingactionbutton.AddFloatingActionButton.java
com.getbase.floatingactionbutton.FloatingActionButton.java
com.getbase.floatingactionbutton.FloatingActionsMenu.java
com.github.amlcurran.showcaseview.AnimationFactory.java
com.github.amlcurran.showcaseview.AnimatorAnimationFactory.java
com.github.amlcurran.showcaseview.ApiUtils.java
com.github.amlcurran.showcaseview.Calculator.java
com.github.amlcurran.showcaseview.NewShowcaseDrawer.java
com.github.amlcurran.showcaseview.OnShowcaseEventListener.java
com.github.amlcurran.showcaseview.ShotStateStore.java
com.github.amlcurran.showcaseview.ShowcaseAreaCalculator.java
com.github.amlcurran.showcaseview.ShowcaseDrawer.java
com.github.amlcurran.showcaseview.ShowcaseView.java
com.github.amlcurran.showcaseview.StandardShowcaseDrawer.java
com.github.amlcurran.showcaseview.TextDrawer.java
com.github.amlcurran.showcaseview.targets.ActionBarReflector.java
com.github.amlcurran.showcaseview.targets.ActionBarViewWrapper.java
com.github.amlcurran.showcaseview.targets.ActionItemTarget.java
com.github.amlcurran.showcaseview.targets.ActionViewTarget.java
com.github.amlcurran.showcaseview.targets.AppCompatReflector.java
com.github.amlcurran.showcaseview.targets.PointTarget.java
com.github.amlcurran.showcaseview.targets.ReflectorFactory.java
com.github.amlcurran.showcaseview.targets.Reflector.java
com.github.amlcurran.showcaseview.targets.SherlockReflector.java
com.github.amlcurran.showcaseview.targets.Target.java
com.github.amlcurran.showcaseview.targets.ViewTarget.java
com.sothree.slidinguppanel.SlidingUpPanelLayout.java
com.sothree.slidinguppanel.ViewDragHelper.java
com.thebnich.floatinghintedittext.FloatingHintEditText.java
com.thebnich.floatinghintedittext.FloatingHintTextView.java
com.wefika.flowlayout.FlowLayout.java
de.hdodenhof.circleimageview.CircleImageView.java
uk.co.senab.photoview.Compat.java
uk.co.senab.photoview.PhotoViewAttacher.java
uk.co.senab.photoview.PhotoView.java
uk.co.senab.photoview.SDK16.java
uk.co.senab.photoview.ScrollerProxy.java
uk.co.senab.photoview.VersionedGestureDetector.java
uk.me.lewisdeane.ldialogs.BaseDialog.java
uk.me.lewisdeane.ldialogs.CustomDialog.java
uk.me.lewisdeane.ldialogs.CustomListAdapter.java