Android Open Source - PalmaBici Welcome Activity






From Project

Back to project page PalmaBici.

License

The source code is released under:

GNU General Public License

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

/*
 * Copyright 2012 Sergio Garcia Villalonga (yayalose@gmail.com)
 */*  w ww.  j  ava 2s .  c  o m*/
 * This file is part of PalmaBici.
 *
 *    PalmaBici is free software: you can redistribute it and/or modify
 *    it under the terms of the Affero GNU General Public License version 3
 *    as published by the Free Software Foundation.
 *
 *    PalmaBici is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    Affero GNU General Public License for more details
 *    (https://www.gnu.org/licenses/agpl-3.0.html).
 *    
 */

package com.poguico.palmabici;

import com.poguico.palmabici.map.OpenStreetMapConstants;
import com.poguico.palmabici.network.synchronizer.NetworkSynchronizer;
import com.poguico.palmabici.network.synchronizer.NetworkSynchronizer.NetworkSynchronizationState;
import com.poguico.palmabici.util.NetworkInformation;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.widget.TextView;

public class WelcomeActivity extends    FragmentActivity
                               implements SynchronizableElement,
                                        OpenStreetMapConstants    {

  private static final int DEFERRED_FINALIZATION_TIME = 2000;
  
  private NetworkSynchronizer synchronizer;
  private Intent              nextActivity = null;
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    
  @Override
  protected void onStart() {
    NetworkSynchronizationState syncState;
    SharedPreferences conf = PreferenceManager.getDefaultSharedPreferences(this);
    super.onStart();
    
    setContentView(R.layout.welcome);
    
    synchronizer = NetworkSynchronizer.getInstance(this.getApplicationContext());
    synchronizer.addSynchronizableElement(this);
    
    if (conf.getBoolean("autoupdate", true)) {
      syncState = synchronizer.sync(false);
      
      if (syncState == NetworkSynchronizationState.UPDATED) {
        onSuccessfulNetworkSynchronization();
      } else if (syncState == NetworkSynchronizationState.ERROR) {
        onUnsuccessfulNetworkSynchronization();
      }
    }
  }

  @Override
  public void onDestroy() {
    synchronizer.detachSynchronizableElement(this);
    super.onDestroy();
  }
  
  @Override
  public void onSuccessfulNetworkSynchronization() {
    TextView text = (TextView)findViewById(R.id.textView1);
      text.setText(R.string.refresh_succesful);
      instantiateMainActivity();
  }

  @Override
  public void onUnsuccessfulNetworkSynchronization() {
    TextView text = (TextView)findViewById(R.id.textView1);
      text.setText(R.string.connectivity_error);
      (new DeferredFinalizationClass(this, DEFERRED_FINALIZATION_TIME))
        .execute((Void [])null);;
  }

  @Override
  public void onLocationSynchronization() {}

  @Override
  public FragmentActivity getSynchronizableActivity() {
    return this;
  }
  
  public synchronized void instantiateMainActivity () {
    nextActivity = new Intent(this, MainActivity.class);
    synchronizer.detachSynchronizableElement((SynchronizableElement)this);
    this.startActivity(nextActivity);
    this.finish();
  }
  
  private class DeferredFinalizationClass extends AsyncTask <Void, Void, Void> {
    private WelcomeActivity    activity;
    private NetworkInformation network;
    private long              timeToDie;
    
    public DeferredFinalizationClass (WelcomeActivity activity, long timeToDie) {
      this.activity  = activity;
      this.timeToDie = timeToDie;
      this.network   = NetworkInformation.getInstance(this.activity.getApplicationContext());
    }
    
      protected Void doInBackground(Void... params) {        
        try {
        Thread.sleep(timeToDie);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
            return null;
        }

        protected void onPostExecute(Void params) {
          if (network.getLastUpdateTime() > 0) {
            activity.instantiateMainActivity();
          } else {
            System.exit(0);
          }
        }
    }
}




Java Source Code List

com.poguico.palmabici.DatabaseManager.java
com.poguico.palmabici.MainActivity.java
com.poguico.palmabici.PreferencesActivity.java
com.poguico.palmabici.ShareActivity.java
com.poguico.palmabici.SynchronizableElement.java
com.poguico.palmabici.WelcomeActivity.java
com.poguico.palmabici.map.OpenStreetMapConstants.java
com.poguico.palmabici.map.ResourceProxyImpl.java
com.poguico.palmabici.map.StationMapFragment.java
com.poguico.palmabici.network.synchronizer.NetworkStationAlarm.java
com.poguico.palmabici.network.synchronizer.NetworkSyncCallback.java
com.poguico.palmabici.network.synchronizer.NetworkSynchronizerTask.java
com.poguico.palmabici.network.synchronizer.NetworkSynchronizer.java
com.poguico.palmabici.notification.NotificationManager.java
com.poguico.palmabici.parsers.Parser.java
com.poguico.palmabici.synchronizers.LocationSynchronizer.java
com.poguico.palmabici.util.BikeLane.java
com.poguico.palmabici.util.Formatter.java
com.poguico.palmabici.util.NetworkInformation.java
com.poguico.palmabici.util.Station.java
com.poguico.palmabici.widgets.CreditsDialog.java
com.poguico.palmabici.widgets.NewFeaturesDialog.java
com.poguico.palmabici.widgets.SidebarMenu.java
com.poguico.palmabici.widgets.StationInfoWidget.java