Android Open Source - VirginMobileMinutesChecker Minutes Graph Drawable






From Project

Back to project page VirginMobileMinutesChecker.

License

The source code is released under:

Copyright 2011 Jay Goel. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Red...

If you think the Android project VirginMobileMinutesChecker 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

/**
 *//ww w  .  j a  v a  2s  .  c om
 */
package com.baker.vm.ui;

import java.util.Calendar;
import java.util.GregorianCalendar;

import android.graphics.drawable.ShapeDrawable;

import com.baker.vm.VMAccount;

/**
 * @author baker
 *
 */
public abstract class MinutesGraphDrawable extends ShapeDrawable
{


  private boolean hasMinutes;
  private boolean hasDates;

  private float minutesPercent;
  private float datePercent;

  private VMAccount account;

  public String string = "unset";

  public MinutesGraphDrawable(final VMAccount iAccount)
  {
    super();

    updateModel(iAccount);
  }

  protected void updateModel(final VMAccount iAccount)
  {
    account = iAccount;

    if (account != null && account.canParseMinutes())
    {
      minutesPercent =
        account.getMinutesUsedInt() / (float) account.getMinutesTotal();
      hasMinutes = true;
    }
    else
    {
      minutesPercent = -1;
      hasMinutes = false;
    }

    if (account != null && account.canParseChargedOnDate())
    {
      final Calendar end = account.getChargedOnCal();
      final Calendar start = (Calendar) end.clone();
      start.add(Calendar.MONTH, -1);
            start.set(Calendar.HOUR_OF_DAY, 0);
            start.set(Calendar.MINUTE, 0);
      final Calendar now = new GregorianCalendar();
      
      final long total = end.getTimeInMillis() - start.getTimeInMillis();
      final long millis = now.getTimeInMillis() - start.getTimeInMillis();

      string = toString(end);
      datePercent = millis / (float) total;
      hasDates = true;
    }
    else
    {
      datePercent = -1;
      hasDates = false;
    }
  }

  private String toString(final Calendar end)
  {
    return end.get(Calendar.MONTH) + "/" + end.get(Calendar.DAY_OF_MONTH) + "/" + end.get(Calendar.YEAR) + " " + end.get(Calendar.HOUR_OF_DAY) + ":" + end.get(Calendar.MINUTE);
  }

  /**
   * @return true if the minutes value is valid
   */
  protected final boolean hasMinutes()
  {
    return hasMinutes;
  }

  /**
   * @return the percent of minutes the account has used
   */
  protected final float getMinutesPercent()
  {
    return minutesPercent;
  }

  /**
   * @return true if the dates value is valid
   */
  protected final boolean hasDates()
  {
    return hasDates;
  }

  /**
   * @return the percent of time that has elapsed during this billing period
   */
  protected final float getDatePercent()
  {
    return datePercent;
  }

  /**
   * @return the account that populated the percent or null
   */
  protected final VMAccount getAccount()
  {
    return account;
  }
}




Java Source Code List

.MinutesBarGraph.java
com.baker.vm.PreferencesUtil.java
com.baker.vm.ScraperUtil.java
com.baker.vm.UsernamePassword.java
com.baker.vm.VMAccount.java
com.baker.vm.service.NotifyRemainingMinutes.java
com.baker.vm.ui.AboutActivity.java
com.baker.vm.ui.FetchAccountTask.java
com.baker.vm.ui.MinutesGraphDrawable.java
com.baker.vm.ui.MinutesPieGraphDrawable.java
com.baker.vm.ui.MultipleAccountsActivity.java
com.baker.vm.widget.PieGraphWidget.java
com.baker.vm.widget.Simple2x1Widget.java
com.baker.vm.widget.WidgetUtil.java
com.drfloob.VirginMobileMinutesChecker.call_trigger.CallEventReceiver.java
com.drfloob.VirginMobileMinutesChecker.call_trigger.MinutesService.java
com.jaygoel.virginminuteschecker.IVMCScraper.java
com.jaygoel.virginminuteschecker.MinutesChecker.java
com.jaygoel.virginminuteschecker.Preferences.java
com.jaygoel.virginminuteschecker.ReferenceScraper.java
com.jaygoel.virginminuteschecker.UpdateService.java
com.jaygoel.virginminuteschecker.ViewMinutes.java
com.jaygoel.virginminuteschecker.WebsiteScraper.java
com.jaygoel.virginminuteschecker.Widget.java