2016-07-03 10:18:23 +00:00
|
|
|
package com.android_app.matan.ara.sagi.thesocialnotework;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.os.Bundle;
|
2016-07-03 12:55:10 +00:00
|
|
|
import android.view.Window;
|
2016-07-05 14:38:58 +00:00
|
|
|
import android.view.WindowManager;
|
2016-07-03 10:18:23 +00:00
|
|
|
import android.widget.ImageView;
|
2016-07-05 14:38:58 +00:00
|
|
|
|
|
|
|
import java.util.Random;
|
2016-07-03 10:18:23 +00:00
|
|
|
|
|
|
|
public class SplashActivity extends AppCompatActivity {
|
|
|
|
|
2016-07-05 14:38:58 +00:00
|
|
|
private ImageView background;
|
|
|
|
private int timerDelay = 3500;
|
2016-07-03 10:18:23 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2016-07-05 14:38:58 +00:00
|
|
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
2016-07-03 12:55:10 +00:00
|
|
|
setContentView(R.layout.activity_splash);
|
2016-07-05 14:38:58 +00:00
|
|
|
background = (ImageView) findViewById(R.id.background);
|
|
|
|
final int sdk = android.os.Build.VERSION.SDK_INT;
|
|
|
|
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
|
|
|
background.setImageDrawable( getResources().getDrawable(rand_splash()) );
|
|
|
|
} else {
|
|
|
|
background.setImageDrawable( getResources().getDrawable(rand_splash()));
|
|
|
|
}
|
2016-07-09 14:38:54 +00:00
|
|
|
|
|
|
|
final String userData = Utils.getUserFromSharedPrefs(this);
|
2016-07-06 17:30:51 +00:00
|
|
|
|
2016-07-03 12:55:10 +00:00
|
|
|
Thread timerThread = new Thread(){
|
|
|
|
public void run(){
|
|
|
|
try{
|
|
|
|
sleep(timerDelay);
|
|
|
|
}catch(InterruptedException e){
|
|
|
|
e.printStackTrace();
|
|
|
|
}finally{
|
2016-07-07 20:40:25 +00:00
|
|
|
if(userData == null){
|
2016-07-06 17:30:51 +00:00
|
|
|
startActivity(new Intent(SplashActivity.this, LoginActivity.class));
|
|
|
|
}else{
|
|
|
|
Intent personalSpaceActivity = new Intent(SplashActivity.this, MainActivity.class);
|
|
|
|
Bundle loginUserBundle = new Bundle();
|
2016-07-07 20:40:25 +00:00
|
|
|
loginUserBundle.putString("UserData", userData);
|
2016-07-06 17:30:51 +00:00
|
|
|
personalSpaceActivity.putExtras(loginUserBundle);
|
|
|
|
startActivity(personalSpaceActivity);
|
|
|
|
}
|
2016-07-03 12:55:10 +00:00
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
timerThread.start();
|
2016-07-03 10:18:23 +00:00
|
|
|
}
|
|
|
|
|
2016-07-03 12:55:10 +00:00
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
super.onPause();
|
|
|
|
finish();
|
|
|
|
}
|
2016-07-05 14:38:58 +00:00
|
|
|
|
|
|
|
protected int rand_splash() {
|
|
|
|
int min = 2, max = 4;
|
|
|
|
// Usually this can be a field rather than a method variable
|
|
|
|
Random rand = new Random();
|
|
|
|
|
|
|
|
// nextInt is normally exclusive of the top value,
|
|
|
|
// so add 1 to make it inclusive
|
|
|
|
int randomNum = rand.nextInt((max - min) + 1) + min;
|
|
|
|
switch (randomNum){
|
|
|
|
// case 0:
|
|
|
|
// return R.drawable.splash_0;
|
|
|
|
// case 1:
|
|
|
|
// return R.drawable.splash_1;
|
|
|
|
case 2:
|
|
|
|
return R.drawable.splash_2;
|
|
|
|
case 3:
|
|
|
|
return R.drawable.splash_3;
|
|
|
|
default:
|
|
|
|
return R.drawable.splash_4;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2016-07-03 10:18:23 +00:00
|
|
|
}
|