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"});
}
}