Set progress from Splash-Screen checks

0

How can I replace the CountDownTimer that is responsible for simulating the progress of the progress bar to this form:

My idea is to check if there are four tables in the database that the application must have created and also verify the existence of data within each one of them. As you go checking the stocks, the fence bar increases until you check that everything is correct and reaches 100% and move to the main activity

Class outline:

public class SplashScreenActivity extends Activity {

// Set the duration of the splash screen
public ProgressBar splash_screenProgressBar;
public int MAX_VALUE = 30;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set portrait orientation
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.splash_screen);

    splash_screenProgressBar = (ProgressBar) findViewById(R.id.splash_screenProgressBar);
    splash_screenProgressBar.setMax(MAX_VALUE);

    new CountDownTimer(3000, 100) {

        int progreso = 1; // Variable que va a ir aumentando del progreso
        @Override
        public void onTick(long millisUntilFinished) {
            splash_screenProgressBar.setProgress(progreso);
            progreso += (1);
        }

        @Override
        public void onFinish() {
            splash_screenProgressBar.setProgress(MAX_VALUE);

            // Start the next activity
            Intent mainIntent = new Intent().setClass(SplashScreenActivity.this, MainActivity.class);
            startActivity(mainIntent);

            // Close the activity so the user won't able to go back this activity pressing Back button
            finish();
        }
    }.start();
}

}

The class that is responsible for creating the database, this is the class that handles one of the tables. The other classes are similar.

public class EstadoSQLiteOpenHelper extends SQLiteOpenHelper{

public EstadoSQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
    super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {
    //Se ejecuta las sentencias SQL de creación de las tablas
    String query="CREATE TABLE ESTADO (id_estado INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, situacion BOOLEAN);";
    db.execSQL(query);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    //En caso de cambio de version se ejecutaria esta bloque de codigo
    db.execSQL("DROP TABLE IF EXISTS ESTADO;");
    db.execSQL("CREATE TABLE ESTADO (id_estado INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, situacion BOOLEAN);");
}

//Metodo que me permite abrir la tabla
public void abrirBDEstado(){
    this.getWritableDatabase();
}

//Metodo que me permite cerrar la tabla
public void cerrarBDEstado(){
    this.close();
}

//Metodo que me permite realizar insert en la tabla
public void insertarEstado(boolean situacion){
    ContentValues valores = new ContentValues();
    valores.put("situacion", situacion);
    this.getWritableDatabase().insert("valor", null, valores);
}

//Metodo que me permite realizar update en la tabla
public void modificarEstado(boolean situacion){
    ContentValues valores = new ContentValues();
    valores.put("situacion", situacion);
    this.getWritableDatabase().update("estado", valores, "id_estado = ?",new String[] {"1"});
}
}
    
asked by Eduardo 02.05.2017 в 10:44
source

1 answer

1

You can do a progress increment, that is, your SplashScreen is 4 steps

int steps = 0

For each table validation, increase the value steps

You can do Runable that every second:

Depending on the value step with the total steps, you can determine that porciento load is made, you can set the value of the progressbar from 0 to 100 or from 0 to total steps. Check the value of step if you have reached 4, load the main screen.

In pseudo code

Iniciar SplashScreen step = 0; stepMax = 4;
Asyntask
 Comprobar Tabla1
    Si no existe Crearla
    step++;
 ...

 Cada segundo
 Actualizar UI barra 0=0% y 4=100% ( paso 2*100/4 =50%)
 Comprobar si es step es 4, cargar pantalla principal.
    
answered by 02.05.2017 в 12:07