com.newshiqi.yushi.SplashScreen.java Source code

Java tutorial

Introduction

Here is the source code for com.newshiqi.yushi.SplashScreen.java

Source

package com.newshiqi.yushi;

import java.util.List;

import cn.jpush.android.api.JPushInterface;
import cn.sharesdk.framework.ShareSDK;

import com.mine.common.command.HttpDataRequest;
import com.mine.common.command.HttpTagDispatch;
import com.mine.common.command.HttpTagDispatch.HttpTag;
import com.mine.common.constant.Constant;
import com.mine.common.http.HttpEngine.HttpCode;
import com.mine.common.http.request.HttpReqFactory;
import com.mine.common.model.BaseDataLoader;
import com.mine.common.model.BaseReq;
import com.mine.common.model.CacheDataLoader;
import com.mine.common.sharepreference.SharedPreferencesConst;
import com.newshiqi.yushi.business.BaseInfoLoader;
import com.newshiqi.yushi.model.AreaInfo;
import com.newshiqi.yushi.model.CommonType;
import com.newshiqi.yushi.receiver.NetStatusReceiver;
import com.newshiqi.yushi.R;
import com.umeng.analytics.MobclickAgent;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Toast;

/**
 * @author star
 * 
 *  ??
 *  
 */

public class SplashScreen extends BaseActivity {

    private BaseInfoLoader baseInfoLoader;

    private final static int CHANGE_ACTIVITY = 0x202;

    public static final String TAG_PROP_LOADER = "tag_prop_loader";

    public static final String A_GET_TYPE_LIST = "GetTypeList";
    public static final String A_GET_STYLE_LIST = "GetStyleList";
    public static final String A_GET_THEME_LIST = "GetThemeList";
    public static final String A_GET_AREA_LIST = "GetAreaList";

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg != null && msg.what == CHANGE_ACTIVITY) {

                SharedPreferences pref = getSharedPreferences(SharedPreferencesConst.NAME, Context.MODE_PRIVATE);

                boolean isFirst = pref.getBoolean(SharedPreferencesConst.FIRST_ENTRY, true);
                int ver = pref.getInt(SharedPreferencesConst.LAST_VERSION_CODE, 0);
                int currentVersionCode = Constant.BRIEF_VERSION_CODE;

                // TODO
                //            isFirst = true;
                if (isFirst) {
                    // ?
                    go(Brief.class);

                    Editor editor = pref.edit();
                    editor.putBoolean(SharedPreferencesConst.FIRST_ENTRY, false);
                    editor.putInt(SharedPreferencesConst.LAST_VERSION_CODE, currentVersionCode);
                    editor.commit();
                } else {
                    // TODO ??
                    go(MainTabActivity.class);
                    //               go(MainTab.class);
                }

                SplashScreen.this.finish();
                overridePendingTransition(R.anim.zoom_in, R.anim.fade_out_long);
            }
        }
    };

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

        this.init();

        ShareSDK.initSDK(this);
        ShareSDK.setConnTimeout(20000);
        ShareSDK.setReadTimeout(20000);

        MobclickAgent.setDebugMode(true);
        MobclickAgent.updateOnlineConfig(this);

        mHandler.sendEmptyMessageDelayed(CHANGE_ACTIVITY, 2000L);
        //????
        /*AlphaAnimation aa = new AlphaAnimation(0.3f,1.0f);
        aa.setDuration(2000);
        View view = findViewById(R.id.root);
        view.startAnimation(aa);
        aa.setAnimationListener(new AnimationListener()
        {
        @Override
        public void onAnimationEnd(Animation arg0) {
           go(MainTabActivity.class);
           SplashScreen.this.finish();
        overridePendingTransition(R.anim.zoom_in, R.anim.fade_out_long);
        }
        @Override
        public void onAnimationRepeat(Animation animation) {}
        @Override
        public void onAnimationStart(Animation animation) {}
                                                                         
        });*/

        //      System.out.println(getDeviceInfo(this));
        //      String channelId = ((Application)getApplication()).getChannelId();
        //      if (channelId == null) {
        //         ((Application)getApplication()).initChannelId();
        //         channelId = ((Application)getApplication()).getChannelId();
        //      }
        //      StatConfig.setInstallChannel(channelId);
        //      
        //      StatConfig.setDebugEnable(false);
        //      initMTAConfig(false);
        //      StatService.trackCustomEvent(this, "onCreate", "");
        //      
        //      NBSAppAgent.setLicenseKey("e4f9b0bf663242d8a2e3f837ef7b2f54").start(this);
        //   
        //      ShareSDK.initSDK(this);
        //      
        //      // ?IP
        //      NetworkSwitch ns = NetworkSwitch.getInstance();
        //      ns.init(SplashScreen.this);
        //      ns.initSetting();
        //      
        //      Application.getInstance().uploadJPushId();

        //      String json = "{"result":"success","data":[{"id":"1","name":""},{"id":"2","name":""},{"id":"4","name":""},{"id":"5","name":""},{"id":"10","name":" "},{"id":"14","name":""},{"id":"6","name":""},{"id":"7","name":""},{"id":"11","name":"?"},{"id":"8","name":""},{"id":"9","name":""},{"id":"15","name":""},{"id":"16","name":"?"},{"id":"17","name":""},{"id":"18","name":""}]}"
    }

    public static String getDeviceInfo(Context context) {
        try {
            org.json.JSONObject json = new org.json.JSONObject();
            android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);

            String device_id = tm.getDeviceId();

            android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) context
                    .getSystemService(Context.WIFI_SERVICE);

            String mac = wifi.getConnectionInfo().getMacAddress();
            json.put("mac", mac);

            if (TextUtils.isEmpty(device_id)) {
                device_id = mac;
            }

            if (TextUtils.isEmpty(device_id)) {
                device_id = android.provider.Settings.Secure.getString(context.getContentResolver(),
                        android.provider.Settings.Secure.ANDROID_ID);
            }

            json.put("device_id", device_id);

            return json.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /*private void initMTAConfig(boolean isDebugMode) {
      if (isDebugMode) {
        
     StatConfig.setDebugEnable(true);
     StatConfig.setAutoExceptionCaught(false);
     StatConfig.setEnableSmartReporting(false);
     Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable ex) {
           logger.error("setDefaultUncaughtExceptionHandler");
        }
     });
     StatConfig.setStatSendStrategy(StatReportStrategy.BATCH);
     StatConfig.setReportEventsByOrder(false);
     StatConfig.setNumEventsCachedInMemory(30);
     StatConfig.setFlushDBSpaceMS(10 * 1000);
     StatService.flushDataToDB(getApplicationContext());
        
     StatConfig.setEnableSmartReporting(false);
     StatConfig.setSendPeriodMinutes(1);
     StatConfig.setStatSendStrategy(StatReportStrategy.PERIOD);
      } else {
     StatConfig.setDebugEnable(false);
     StatConfig.setAutoExceptionCaught(true);
     StatConfig.setStatSendStrategy(StatReportStrategy.APP_LAUNCH);
      }
    }*/

    private void init() {
        setContentView(R.layout.activity_first);
        baseInfoLoader = BaseInfoLoader.getInstance();

        int flag = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        Window w = getWindow();
        w.setFlags(flag, flag);

        if (NetStatusReceiver.netStatus == NetStatusReceiver.NETSTATUS_INAVAILABLE) {
            Toast.makeText(SplashScreen.this, "???", Toast.LENGTH_SHORT).show();
            return;
        }
        this.initRequest();
    }

    private void initGetRequest(String a) {
        BaseReq req = new BaseReq();
        req.setM("Search");
        req.setA(a);

        HttpDataRequest request = HttpReqFactory.getInstance().get(req);

        CacheDataLoader initLoader = new CacheDataLoader(a, this);
        initLoader.loadData(BaseDataLoader.LOADER_FROM_SRV_AND_CACHE, request);
    }

    private void initRequest() {
        initGetRequest(A_GET_TYPE_LIST);
        initGetRequest(A_GET_STYLE_LIST);
        initGetRequest(A_GET_THEME_LIST);
        initGetRequest(A_GET_AREA_LIST);
    }

    @Override
    protected void onPause() {
        JPushInterface.onPause(this);
        super.onPause();
    }

    @Override
    protected void onResume() {
        JPushInterface.onResume(this);
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
        }

        super.onDestroy();
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return false;
    }

    @Override
    public void onQueryError(BaseDataLoader dataloader, HttpCode retCode, String buisCode, String errorMsg) {
        super.onQueryError(dataloader, retCode, buisCode, errorMsg);
    }

    @Override
    public void onQueryComplete(BaseDataLoader dataloader, boolean cache) {
        super.onQueryComplete(dataloader, cache);
        Object data = dataloader.getData();
        if (data != null) {
            if (A_GET_TYPE_LIST.equals(dataloader.getTag())) {
                Object obj = HttpTagDispatch.dispatch(HttpTag.GET_TYPE_LIST, data.toString());
                if (obj != null) {
                    List<CommonType> typeList = (List<CommonType>) obj;
                    if (typeList != null && typeList.size() > 0) {
                        baseInfoLoader.setTypeList(typeList);
                    }
                }
            } else if (A_GET_STYLE_LIST.equals(dataloader.getTag())) {
                Object obj = HttpTagDispatch.dispatch(HttpTag.GET_STYLE_LIST, data.toString());
                if (obj != null) {
                    List<CommonType> styleList = (List<CommonType>) obj;
                    if (styleList != null && styleList.size() > 0) {
                        baseInfoLoader.setStyleList(styleList);
                    }
                }
            } else if (A_GET_THEME_LIST.equals(dataloader.getTag())) {
                Object obj = HttpTagDispatch.dispatch(HttpTag.GET_THEME_LIST, data.toString());
                if (obj != null) {
                    List<CommonType> themeList = (List<CommonType>) obj;
                    if (themeList != null && themeList.size() > 0) {
                        baseInfoLoader.setThemeList(themeList);
                    }
                }
            } else if (A_GET_AREA_LIST.equals(dataloader.getTag())) {
                Object obj = HttpTagDispatch.dispatch(HttpTag.GET_AREA_LIST, data.toString());
                if (obj != null) {
                    List<AreaInfo> areaList = (List<AreaInfo>) obj;
                    if (areaList != null && areaList.size() > 0) {
                        baseInfoLoader.setAreaList(areaList);
                    }
                }
            }
        }
    }
}