Android Open Source - VirginMobileMinutesChecker Fetch Account Task






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

/**
 *//www  .  ja v  a 2 s  . co m
 */
package com.baker.vm.ui;

import java.util.ArrayList;
import java.util.List;

import android.os.AsyncTask;
import android.view.View;
import android.widget.ProgressBar;

import com.baker.vm.ScraperUtil;
import com.baker.vm.UsernamePassword;
import com.baker.vm.VMAccount;
import com.baker.vm.widget.WidgetUtil;
import com.jaygoel.virginminuteschecker.IVMCScraper;
import com.jaygoel.virginminuteschecker.R;
import com.jaygoel.virginminuteschecker.ReferenceScraper;

/**
 * @author baker
 *
 */
public class FetchAccountTask
  extends AsyncTask<UsernamePassword, VMAccount, List<VMAccount>>
{

  private final MultipleAccountsActivity activity;
  private int i = 0;

  public FetchAccountTask(final MultipleAccountsActivity iActivity)
  {
    activity = iActivity;
  }

    @Override
    protected void onCancelled()
    {
        super.onCancelled();

        activity.findViewById(R.id.progresslayout).setVisibility(View.GONE);
    }

    @Override
    protected void onPreExecute()
    {
        super.onPreExecute();

        activity.findViewById(R.id.progresslayout).setVisibility(View.VISIBLE);
    }

    @Override
    protected void onPostExecute(final List<VMAccount> result)
    {
        super.onPostExecute(result);

        activity.updateLayout(result);
        activity.findViewById(R.id.progresslayout).setVisibility(View.GONE);
        
        WidgetUtil.updateAllWidgets(activity.getApplicationContext());
    }

    @Override
    protected void onProgressUpdate(final VMAccount... values)
    {
        super.onProgressUpdate(values);

        final ProgressBar bar = (ProgressBar) activity.findViewById(R.id.progress);
        bar.setProgress(i);
        activity.findViewById(R.id.progresslayout).setVisibility(View.VISIBLE);

        if (values != null && values.length > 0)
        {
            for (final VMAccount acct : values)
            {
              activity.updateLayout(acct);
            }
        }
    }

    @Override
    protected List<VMAccount> doInBackground(final UsernamePassword... params)
    {
        ((ProgressBar) activity.findViewById(R.id.progress)).setMax(params.length);
        publishProgress();

        final IVMCScraper scraper= new ReferenceScraper();

        final List<VMAccount> accts = new ArrayList<VMAccount>();
        for (final UsernamePassword a : params)
        {
            final VMAccount acct = ScraperUtil.scrape(a, scraper);

            ++i;
            if (acct != null)
            {
              accts.add(acct);
              publishProgress(acct);
            }
            else
            {
              publishProgress();
            }
        }
        return accts;
    }
}




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