public class LoginActivity extends FragmentActivity {
UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.login");
@InjectView(R.id.photo_welcome)
RoundedImageView photoWelcome;
@InjectView(R.id.photo_welcome_con)
FrameLayout photoWelcomeCon;
@InjectView(R.id.photo_slogan)
ImageView photoSlogan;
@InjectView(R.id.login_type_title)
TextView loginTypeTitle;
@InjectView(R.id.login_type_title_con)
FrameLayout loginTypeTitleCon;
@InjectView(R.id.btn_mobile)
FloatingActionButton btnMobile;
@InjectView(R.id.btn_wechat)
FloatingActionButton btnWechat;
@InjectView(R.id.btn_sina)
FloatingActionButton btnSina;
@InjectView(R.id.btn_qq)
FloatingActionButton btnQq;
@InjectView(R.id.action_con)
LinearLayout actionCon;
@InjectView(R.id.real_con)
LinearLayout realCon;
private Activity mContext;
private RoundProgressDialog nProgress;
private SHARE_MEDIA[] mPlatformsMap;
public String deviceToken = "";
private Timer tokenTimer;
private int waitTime = 120;
private int tokenCount = 0;
private View.OnLongClickListener toggleServer = new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (SystemUtils.debug) {
ApiUtils.mDomain = ApiUtils.testDomain.equalsIgnoreCase(ApiUtils.mDomain) ? ApiUtils.realDomain : ApiUtils.testDomain;
BuyueApp.get().setTestMode(ApiUtils.testDomain.equalsIgnoreCase(ApiUtils.mDomain));
SystemUtils.showMsg("change to: \n " + ApiUtils.mDomain, mContext);
EventDao evtDao = new EventDao(BuyueApp.get().getApplicationContext());
BoardDao boardDao = new BoardDao(BuyueApp.get().getApplicationContext());
CardDao cardDao = new CardDao(BuyueApp.get().getApplicationContext());
SyncDao syncDao = new SyncDao(BuyueApp.get().getApplicationContext());
syncDao.markDirty(Sync.EVENT);
syncDao.markDirty(Sync.BOARD);
try {
evtDao.deleteAll();
boardDao.deleteAll();
cardDao.deleteAll();
} catch (SQLException e) {
SystemUtils.attemptPrintError(e);
}
}
return false;
}
};
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = LoginActivity.this;
BuyueApp.get().addActivity(LoginActivity.this);
setContentView(R.layout.activity_login);
ButterKnife.inject(this);
//首次执行导入.db文件
DataManager dbHelper = new DataManager(this);
dbHelper.openDatabase();
dbHelper.closeDatabase();
// umeng message
PushAgent mPushAgent = PushAgent.getInstance(mContext);
mPushAgent.enable();
// umeng analytics
MobclickAgent.updateOnlineConfig(mContext);
// umeng upadate
UmengUpdateAgent.update(this);
UmengUpdateAgent.setUpdateOnlyWifi(false);
deviceToken = "";
tokenTimer = new Timer();
TimerTask tokenTask = new TimerTask() {
@Override
public void run() {
if (deviceToken != null && !"".equalsIgnoreCase(deviceToken)) {
SpUtils.setSpStr(SpUtils.TEP_TOKEN,deviceToken);
tokenTimer.cancel();
} else {
deviceToken = UmengRegistrar.getRegistrationId(mContext);
tokenCount++;
}
if (tokenCount > 300) {
tokenTimer.cancel();
}
}
};
tokenTimer.schedule(tokenTask, 0, 100);
PushAgent.getInstance(mContext).onAppStart();
FileUtils.deleteSave();
FileUtils.clearCache();
regCasts();
adjustMyLayout();
initLogin();
TextView typeTitle = (TextView) findViewById(R.id.login_type_title);
typeTitle.setOnLongClickListener(toggleServer);
}
private void adjustMyLayout() {
}
private void regCasts() {
SystemUtils.registerReceiver(receiver, NameUitls.ACTION_DO_LOGIN, mContext);
SystemUtils.registerReceiver(finishReceiver, NameUitls.ACTION_LOGOUT, mContext);
SystemUtils.registerReceiver(timeOutReceiver, NameUitls.ACTION_TIMEOUT, mContext);
}
private void unRegCasts() {
SystemUtils.unregisterReceiver(receiver, mContext);
SystemUtils.unregisterReceiver(finishReceiver, mContext);
SystemUtils.unregisterReceiver(timeOutReceiver, mContext);
}
private void initPlatformMap() {
mPlatformsMap = new SHARE_MEDIA[]{SHARE_MEDIA.GOOGLEPLUS, SHARE_MEDIA.WEIXIN, SHARE_MEDIA.SINA, SHARE_MEDIA.QQ};
}