Android Open Source - SuiviConsoFreeMobile Afficher Suiviconso Detaille Activity






From Project

Back to project page SuiviConsoFreeMobile.

License

The source code is released under:

Ce logiciel est dans le domaine public.

If you think the Android project SuiviConsoFreeMobile 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.yvesd.scfm;
//from www  .  ja  v  a 2  s.  c o  m
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;

public class AfficherSuiviconsoDetailleActivity extends Activity implements
    CanWaitForStream {

  ProgressDialog progressDialog;
  List<String> progressMessages = new ArrayList<String>(); // TODO refactor
  SharedPreferences settings;
  protected static final String CLE_BUNDLE_SAUVEGARDE_ETAT_DETAIL = "net.yvesd.scfm.detailConso";
  public static final String CLE_BUNDLE_LOGIN = "net.yvesd.scfm.detailConso.login";
  public static final String CLE_BUNDLE_PWD = "net.yvesd.scfm.detailConso.pwd";
  protected static final String NO_DATA = "Pas de conso dtaille  afficher. Erreur ou pas de conso dtaille disponible";

  /**
   * Donns de suivi conso  afficher
   */
  String donnees = NO_DATA;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    chargerPreferences();

    GestionnaireThemes gt = new GestionnaireThemes(this);
    gt.chargerThemeChoisi();

    super.onCreate(savedInstanceState);

    setContentView(R.layout.conso_detaillee);

    if (savedInstanceState == null) {
      lancerRequete();

    } else {

      String donneesSauvegardees = savedInstanceState
          .getString(CLE_BUNDLE_SAUVEGARDE_ETAT_DETAIL);

      if (donneesSauvegardees != null
          && donneesSauvegardees instanceof String) {

        donnees = donneesSauvegardees;
        displayData(donnees);

      } else {
        // TODO Encore utile ici ?!
        lancerRequete();
      }

    }

    Button retour = (Button) findViewById(R.id.bouton_retour_consodet);
    retour.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        finish();
      }
    });
  }

  @Override
  protected void onResume() {
    super.onResume();
    displayData(donnees); // TODO refactor. Doublon avec handleResult
  }

  protected void chargerPreferences() {
    settings = getSharedPreferences(
        SuiviConsoFreeMobileActivity.PREFS_NAME, 0);
  }

  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putString(CLE_BUNDLE_SAUVEGARDE_ETAT_DETAIL, donnees);
  }

  protected void lancerRequete() {
    displayData("");
    progressMessages.clear();

    progressDialog = new ProgressDialog(this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setTitle(getString(R.string.app_name));
    progressDialog.setMessage(""); // Contournement d'un problme : pas de
                    // messages sinon
    progressDialog.show();

    // Arrt si aucun compte n'est slectionn
    if ("".equals(getIntent().getExtras().getString(CLE_BUNDLE_LOGIN))) {
      addToProgress(getString(R.string.log_aucuncompte_consodet));
      setProgressStatus(100);

      return;
    }

    addToProgress("Identification auprs de Free Mobile"); // TODO
                                // externalize
                                // string
    setProgressStatus(12);

    TelechargeurSuiviConsoDetaille dataRecuperator = new TelechargeurSuiviConsoDetaille(
        this, new MyHttpClient(this));
    // DataRecuperatorMock dataRecuperator = new DataRecuperatorMock(this);
    DataRecuperatorParams params = new DataRecuperatorParams();
    params.setLoginAbo(getIntent().getExtras().getString(CLE_BUNDLE_LOGIN));
    params.setPwdAbo(getIntent().getExtras().getString(CLE_BUNDLE_PWD));
    dataRecuperator.execute(params);
  }

  protected void addToProgress(String... strings) {
    for (String value : strings)
      progressMessages.add(value);

    String displayed = "";
    for (String message : progressMessages) {
      displayed += "* " + message + "\n";
    }
    progressDialog.setMessage(displayed);
  }

  @Override
  public void addToProgress(int res, Object... args) {
    addToProgress(getString(res, args));
  }

  @Override
  public void setProgressStatus(int p) {
    progressDialog.setProgress(p);
  }

  @Override
  public void handleResult(List<String> results) {

    String rawHtmlData = results.get(0);

    if (rawHtmlData == null)
      return;

    donnees = rawHtmlData;

    displayData(donnees);
    progressDialog.dismiss();
  }

  private void displayData(String donnees) {

    WebView webview = (WebView) findViewById(R.id.consoDetailleeView);

    WebSettings ws = webview.getSettings();
    ws.setBuiltInZoomControls(true);

    // http://stackoverflow.com/questions/3961589/android-webview-and-loaddata
    String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";

    webview.loadData(header + donnees, "text/html", "UTF-8");
  }

}




Java Source Code List

net.yvesd.scfm.AfficherSuiviconsoDetailleActivity.java
net.yvesd.scfm.CanWaitForStream.java
net.yvesd.scfm.DataInterpreter.java
net.yvesd.scfm.DataRecuperatorMock.java
net.yvesd.scfm.DataRecuperatorParams.java
net.yvesd.scfm.DonnesCompteur.java
net.yvesd.scfm.EditAccountActivity.java
net.yvesd.scfm.EditAccountsActivity.java
net.yvesd.scfm.ExtracteurErreur.java
net.yvesd.scfm.GestionIcones.java
net.yvesd.scfm.GestionnaireThemes.java
net.yvesd.scfm.MyHttpClient.java
net.yvesd.scfm.OptionActivity.java
net.yvesd.scfm.SuiviConsoFreeMobileActivity.java
net.yvesd.scfm.TelechargeurDonnesConso.java
net.yvesd.scfm.TelechargeurGenerique.java
net.yvesd.scfm.TelechargeurSuiviConsoDetaille.java