package com.sogou.sogouchat;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import com.sogou.sogouchat.os.ChatAppConstant;
import com.sogou.sogouchat.ui.SlidingActivity;
import com.sogou.sogouchat.ui.TabMainActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.Window;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.webkit.MimeTypeMap;
import android.widget.ImageView;
public class SplashActivity extends Activity {
private static final String TAG = "SplashActivity";
// private static final int Msg_Connect_Ok = 0;
// private static final int Msg_Fetch_Ok = 1;
// private View mView;
private ImageView mWall;
// private TranslateAnimation mAm;
// private Handler mAnHandler;
Timer mTimer;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
final SogouChatApp app = (SogouChatApp)getApplication();
app.mSplash = this;
requestWindowFeature(Window.FEATURE_NO_TITLE);
// mView = View.inflate(this, R.layout.activity_splash, null);
setContentView(R.layout.activity_splash);
mWall = (ImageView)findViewById(R.id.image_wall);
// Random wall paper
int wallIndex = new Random().nextInt(5);
int wallRsc = R.drawable.sogou_chat_ww1 + wallIndex;
Drawable wallDraw = this.getResources().getDrawable(wallRsc);
mWall.setImageDrawable(wallDraw);
startAnimation();
Thread th = new Thread(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
while(app.mRemoteService == null){
Log.i(TAG, "Sleep");
SystemClock.sleep(1000);
}
app.sendSrvForeMsg(ChatAppConstant.SRV_ForeMsg_FetchDb, null, null);
}
});
th.start();
}
protected void onDestroy() {
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
return true;
}
public void directTo(){
Log.i(TAG, "directTo") ;
// mAm.cancel();
mTimer.cancel();
Intent intent = new Intent();
intent.setClass(this, SlidingActivity.class);
this.startActivity(intent);
finish();
}
private void startAnimation(){
// mAm = new TranslateAnimation(0.0f, -400.0f, 0.0f, 0.0f);
// mAm.setDuration(80000);
// mAm.setRepeatCount(Animation.INFINITE);
// mAm.setRepeatMode(Animation.REVERSE);
// mWall.startAnimation(mAm);
// mAm.setAnimationListener(new AnimationListener(){
//
// @Override
// public void onAnimationStart(Animation animation) {
// // TODO Auto-generated method stub
//
// }
// @Override
// public void onAnimationEnd(Animation animation) {
// // TODO Auto-generated method stub
// }
//
// @Override
// public void onAnimationRepeat(Animation animation) {
// // TODO Auto-generated method stub
// }
//
// });
final Handler anHandler = new Handler(){
public void handleMessage(Message msg){
switch (msg.what) {
case 0:
mWall.scrollBy(1, 0);
break;
default:
break;
}
}
};
TimerTask task = new TimerTask(){
public void run() {
anHandler.sendEmptyMessage(0);
}
};
mTimer = new Timer(true);
mTimer.schedule(task, 1000, 500);
}
}