All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.mobile.android.splash.SplashActivity Maven / Gradle / Ivy

/***********************************************************************************************************************
 *
 * blueBill Mobile - open source birdwatching
 * ==========================================
 *
 * Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
 * http://bluebill.tidalwave.it/mobile/
 *
 ***********************************************************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 *
 ***********************************************************************************************************************
 *
 * $Id: SplashActivity.java,v 3be8977c414a 2010/08/06 09:25:27 fabrizio $
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android.splash;

import javax.annotation.Nonnull;
import org.openide.util.Lookup;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ProgressBar;
import it.tidalwave.netbeans.util.Locator;
import it.tidalwave.bluebill.mobile.taxonomy.TaxonomyPreferences;
import it.tidalwave.bluebill.mobile.android.observation.ObservationActivity;
import it.tidalwave.bluebill.mobile.android.R;
import it.tidalwave.bluebill.mobile.news.NewsController;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id: $
 *
 **********************************************************************************************************************/
public class SplashActivity extends Activity
  {
    /* package */ static final int PROGRESS_BAR_ADVANCE_DELAY = 200;
    /* package */ static final int PROGRESS_BAR_ADVANCE_STEP = 5;

    private ProgressBar progressBar;

    /* package */ volatile boolean initializationCompleted;

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    private final Runnable progressAnimator = new Runnable()
      {
        @Override
        public void run()
          {
            final int progress = progressBar.getProgress();
            progressBar.setProgress((progress <= 100 - PROGRESS_BAR_ADVANCE_STEP) ? progress + PROGRESS_BAR_ADVANCE_STEP : 0);

            if (!initializationCompleted)
              {
                progressBar.postDelayed(progressAnimator, PROGRESS_BAR_ADVANCE_DELAY);
              }
          }
      };

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    private final Runnable initializer = new Runnable()
      {
        @Override
        public void run()
          {
            initializationCompleted = false;
            Lookup.getDefault().lookup(TaxonomyPreferences.class).getTaxonomy(); // long task
            initializationCompleted = true;
            runOnUiThread(new Runnable()
              {
                public void run()
                  {
                    startActivity(new Intent(getBaseContext(), ObservationActivity.class));
                    finish();
                  }
              });
          }
      };

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    @Override
    public void onCreate (final @Nonnull Bundle savedInstanceState)
      {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_activity);
//        ((TextView)findViewById(R.id.tvVersion)).setText(Html.fromHtml(NbBundle.getMessage(SplashActivity.class, "version")));
        progressBar = (ProgressBar)findViewById(R.id.progressBar);
        new Thread(initializer).start();
        Locator.find(NewsController.class).start();
        progressBar.postDelayed(progressAnimator, PROGRESS_BAR_ADVANCE_DELAY);
      }
  }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy