Android Open Source - RingMyPhoneAndroid Purchase






From Project

Back to project page RingMyPhoneAndroid.

License

The source code is released under:

MIT License

If you think the Android project RingMyPhoneAndroid 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.darkrockstudios.apps.ringmyphone;
//  w ww.  jav  a 2 s. com
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;

import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * Created by Adam on 12/28/13.
 */
public class Purchase
{
  public static final Uri  PURCHASE_URI = Uri.parse( "ringmyphone://com.darkrockstudios.apps.ringmyphone/purchase" );
  public static final long TRIAL_LENGTH = TimeUnit.DAYS.toMillis( 7 );
  // For testing
  //public static final long TRIAL_LENGTH = TimeUnit.HOURS.toMillis( 4 );

  public static boolean isActive( final Context context )
  {
    return isPurchased( context ) || !isTrialPeriodOver( context );
  }

  public static boolean isPurchased( final Context context )
  {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences( context );
    return settings.getBoolean( Preferences.KEY_IS_PRO, false );
  }

  public static boolean isTrialPeriodOver( final Context context )
  {
    boolean isPast = true;

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences( context );
    long installTimeStamp = settings.getLong( Preferences.KEY_FIRST_INSTALL_DATE, 0 );
    if( installTimeStamp > 0 )
    {
      Date now = new Date();
      long timeSinceInstall = now.getTime() - installTimeStamp;

      if( timeSinceInstall < TRIAL_LENGTH )
      {
        isPast = false;
      }
    }

    return isPast;
  }

  public static long trialTimeRemaining( final Context context )
  {
    long timeRemaining = -1;

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences( context );
    long installTimeStamp = settings.getLong( Preferences.KEY_FIRST_INSTALL_DATE, 0 );
    if( installTimeStamp > 0 )
    {
      Date now = new Date();
      long timeSinceInstall = now.getTime() - installTimeStamp;

      timeRemaining = TRIAL_LENGTH - timeSinceInstall;
    }

    return timeRemaining;
  }
}




Java Source Code List

com.darkrockstudios.apps.ringmyphone.AboutFragment.java
com.darkrockstudios.apps.ringmyphone.BillingActivity.java
com.darkrockstudios.apps.ringmyphone.BillingSecurity.java
com.darkrockstudios.apps.ringmyphone.Debug.java
com.darkrockstudios.apps.ringmyphone.MainActivity.java
com.darkrockstudios.apps.ringmyphone.NotificationId.java
com.darkrockstudios.apps.ringmyphone.OsUtil.java
com.darkrockstudios.apps.ringmyphone.PebbleApp.java
com.darkrockstudios.apps.ringmyphone.PebbleMessageReceiver.java
com.darkrockstudios.apps.ringmyphone.PreferencesBackupAgent.java
com.darkrockstudios.apps.ringmyphone.Preferences.java
com.darkrockstudios.apps.ringmyphone.Purchase.java
com.darkrockstudios.apps.ringmyphone.RingerService.java
com.darkrockstudios.apps.ringmyphone.SettingsActivity.java
com.darkrockstudios.apps.ringmyphone.SettingsFragment.java
com.darkrockstudios.apps.ringmyphone.StopRingingReceiver.java
com.darkrockstudios.apps.ringmyphone.UpgradeReceiver.java