@Override public void handleMessage(Message msg) { // TODO Auto-generated method stub switch (msg.what) { case BACK_SCALE: float scale = (scaleY / 2 + imgHeight) / (imgHeight); // 得到缩放倍数 if (scaleY > 0) { isBacking = true; matrix.set(currentMatrix); ListView.LayoutParams relativeLayout = new ListView.LayoutParams((int) (scale * imgWidth), (int) (scale * imgHeight)); imageView.setLayoutParams(relativeLayout); matrix.postScale(scale, scale, imgWidth / 2, 0); imageView.setImageMatrix(matrix); scaleY = (float) (scaleY / 2 - 1); mHandler.sendEmptyMessageDelayed(BACK_SCALE, 20); } else { scaleY = 0; ListView.LayoutParams relativeLayout = new ListView.LayoutParams((int) imgWidth, (int) imgHeight); imageView.setLayoutParams(relativeLayout); matrix.set(defaultMatrix); imageView.setImageMatrix(matrix); isBacking = false; } break; default: break; } super.handleMessage(msg); }
private void cacheHidenSubtitle() { if (getTag() == null || !(getTag() instanceof Element)) return; Element currElement = (Element) getTag(); long currTime = getCurrentTime(); long endTime = currElement.getEndTime().getTime(); if (currTime >= endTime + SUBTITLE_DELAY_TIME_MAX / 10) { // for Fast Forward mHandler.removeCallbacksAndMessages(null); mHandler.sendEmptyMessage(MESSAGE_SUBTITLE_START); } else { if (endTime - currTime > SUBTITLE_DELAY_TIME_MAX) { Element preElement = getElement(currTime); if (preElement != null && preElement.getStartTime().getTime() < endTime - SUBTITLE_DELAY_TIME_MAX) { // for Fast back mHandler.removeCallbacksAndMessages(null); mHandler.sendEmptyMessage(MESSAGE_SUBTITLE_START); return; } mHandler.sendEmptyMessageDelayed(MESSAGE_SUBTITLE_HIDEN_CACHE, SUBTITLE_DELAY_TIME_MAX); } else { mHandler.sendEmptyMessageDelayed(MESSAGE_SUBTITLE_END_HIDEN, endTime - currTime); } } }
// audio 상태 변경 private void statAudioSet(int stat) { if (stat == 0) { mMediaPlayer.pause(); mProgressHandler.sendEmptyMessageDelayed(0, 0); viewSwitchSet(0); } else { mMediaPlayer.start(); mProgressHandler.sendEmptyMessageDelayed(0, 100); viewSwitchSet(1); } }
// video 상태 변경 private void statVideoSet(int stat) { if (stat == 0) { mVideoView.pause(); mProgressHandler2.sendEmptyMessageDelayed(0, 0); viewSwitchSet(0); } else { mVideoView.start(); mProgressHandler2.sendEmptyMessageDelayed(0, 100); viewSwitchSet(1); } }
private void requestReloadingDialpads() { boolean isReloadTimeout = false; if (mHandler.hasMessages(RELOAD_DIALPADS_TIMEOUT)) { isReloadTimeout = true; mHandler.removeMessages(RELOAD_DIALPADS_TIMEOUT); } mHandler.sendEmptyMessageDelayed(RELOAD_DIALPADS_TIMEOUT, RELOAD_DIALPADS_DELAYTIME); loge("isReloadTimeout=" + isReloadTimeout); mHandler.removeMessages(RELOAD_DIALPADS); mHandler.sendEmptyMessageDelayed( RELOAD_DIALPADS, isReloadTimeout ? RELOAD_DIALPADS_DELAYTIME : 0); }
private void gameMove() { if (moveTetrominoDown()) { handler.removeMessages(MSG_TETROMINO_MOVE); handler.sendEmptyMessageDelayed( MSG_TETROMINO_MOVE, (int) (TETROMINO_MOVE_INTERVAL / moveSpeed)); } else { Log.d(TAG, "can not move tetromino down, send new tetromino message"); handler.sendEmptyMessageDelayed( MSG_NEW_TETROMINO, (int) (TETROMINO_NEW_INTERVAL / moveSpeed)); } }
@Override public boolean onTouchEvent(MotionEvent ev) { if (getChildCount() == 0) return false; final int action = ev.getAction(); final float x = ev.getX(); switch (action) { case MotionEvent.ACTION_DOWN: autoScroll = false; currentWhat++; mLastMotionX = x; if (!scroller.isFinished()) { scroller.abortAnimation(); } // Log.i("TAG","ACTION_DOWN"); return true; case MotionEvent.ACTION_MOVE: final int deltaX = (int) (mLastMotionX - x); // boolean xMoved = Math.abs(deltaX) > mTouchSlop; mLastMotionX = x; if ((0 == currentScreenIndex && deltaX < 0) || (getChildCount() - 1 == currentScreenIndex && deltaX > 0)) scrollBy(deltaX / 4, 0); else // Log.i("TAG","ACTION_MOVE"); // if (xMoved) scrollBy(deltaX, 0); final int screenWidth = getWidth(); currentScreenIndex = (getScrollX() + (screenWidth / 2)) / screenWidth; return true; case MotionEvent.ACTION_UP: snapToDestination(); if (!autoScroll) { autoScroll = true; handler.sendEmptyMessageDelayed(currentWhat, scrollTime); } break; case MotionEvent.ACTION_CANCEL: snapToDestination(); if (!autoScroll) { autoScroll = true; handler.sendEmptyMessageDelayed(currentWhat, scrollTime); } } return false; }
private void init() { SharedPreferences perPreferences = getSharedPreferences("Fengnan", MODE_PRIVATE); isFirstIn = perPreferences.getBoolean("isFirstIn", true); if (!isFirstIn) { mHandler.sendEmptyMessageDelayed(GO_HOME, TIME); } else { mHandler.sendEmptyMessageDelayed(GO_GUIDE, TIME); SharedPreferences.Editor editor = perPreferences.edit(); editor.putBoolean("isFirstIn", false); editor.commit(); } }
private void showStartSubtitle() { if (getTag() == null || !(getTag() instanceof Element)) return; Element elementShow = (Element) getTag(); setText(elementShow.getText()); long tempShowTime = getCurrentTime(); long endTime = elementShow.getEndTime().getTime(); if (endTime - tempShowTime > SUBTITLE_DELAY_TIME_MAX) { mHandler.sendEmptyMessageDelayed(MESSAGE_SUBTITLE_HIDEN_CACHE, SUBTITLE_DELAY_TIME_MAX); } else { mHandler.sendEmptyMessageDelayed(MESSAGE_SUBTITLE_END_HIDEN, endTime - tempShowTime); } }
private void init() { SharedPreferences preferences = getSharedPreferences("storeFirstIn", MODE_PRIVATE); isFirstIn = preferences.getBoolean("isFirstIn", true); // 判断是否是首次进入 if (!isFirstIn) { // mHandler.sendEmptyMessageDelayed(GO_WEATHER_ATY, DELAY_TIME); } else { mHandler.sendEmptyMessageDelayed(GOO_GUIDE_ATY, DELAY_TIME); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("isFirstIn", false); editor.commit(); } }
@Override public void handleMessage(Message msg) { switch (msg.what) { case SPLASH_MSG: startSplashAnimation(); mHandler.sendEmptyMessageDelayed(GATHER_MSG, 3000); break; case GATHER_MSG: startGatherAnimation(); mHandler.sendEmptyMessageDelayed(SPLASH_MSG, 3000); break; } }
@Override public void handleMessage(Message m) { switch (m.what) { case MSG_START: mHandler.sendEmptyMessage(MSG_UPDATE); break; case MSG_STOP: mHandler.removeMessages(MSG_UPDATE); break; case MSG_UPDATE: int[] pids = mMemoryService.getTrackedProcesses(); final int N = getChildCount(); if (pids.length != N) initViews(); else for (int i = 0; i < N; i++) { ProcessWatcher pw = ((ProcessWatcher) getChildAt(i)); if (indexOf(pids, pw.getPid()) < 0) { initViews(); break; } pw.update(); } mHandler.sendEmptyMessageDelayed(MSG_UPDATE, UPDATE_RATE); break; } }
/** * Route a message to a bluetooth service. If the bluetooth server is connected, send to that * service otherwise, send to the client bluetooth to be sent */ protected void sentToService() { try { expirePackets(); if (mPackets.size() > 0 && isBluetoothEnabled()) { if (mServerService.isConnected()) { if (!mServerService.isSending()) { Log.d(TAG, "sentToService: serviceService running"); mServerService.sendIntent(mPackets.poll()); } } else { if (!mClientService.isRunning()) { if (lastClientError + 5000 < System.currentTimeMillis()) { Log.d(TAG, "sentToService: clientService not running"); mClientService.startConnection(); } else { Log.d(TAG, "sentToService: clientService error delay"); mHandler.sendEmptyMessageDelayed(ROUTER_MESSAGE_SEND_QUEUED_MESSAGES, 1000); } } else if (!mServerService.isSending()) { Log.d(TAG, "sentToService: sending to clientService"); mClientService.sendIntent(mPackets.poll()); } } } } catch (Exception e) { Log.e(TAG, "Failed to route message", e); } }
private void startTime() { stopTime(); if (handler != null) { handler.sendEmptyMessageDelayed(LOCATION_EVENT_START, Constant.LOCATION_SCAN_Span_Time); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); rl = (RelativeLayout) findViewById(R.id.rl); setBackground(); startService(new Intent(this, PhoneService.class)); preferences = getSharedPreferences("config", MODE_PRIVATE); copyDataBase("address.db"); // copy the database of phone tracking copyDataBase("antivirus.db"); System.out.println("start to update"); // update the virus database updataVirus(); if (preferences.getBoolean("auto_update", true)) { checkVersion(); } else { // if user doesn't check the new version, delay for 2s, then go to homepage handler.sendEmptyMessageDelayed(ENTER_HOME_DIRECTLY, 1000); } // graduate change splashpage AlphaAnimation anim = new AlphaAnimation(0.3f, 1f); anim.setDuration(1000); rl.startAnimation(anim); AdManager.getInstance(this).init("879ed71bbc111e86", "e20e455762cc5ef5", true); OffersManager.getInstance(this).onAppLaunch(); }
public void handleMessage(android.os.Message msg) { int currentItem = mViewPager.getCurrentItem(); currentItem++; mViewPager.setCurrentItem(currentItem); // 切换到下一条广告 mHandler.sendEmptyMessageDelayed(0, 3000); // 继续延时3秒发消息,形成无限循环 };
private void showOverlay() { rlOverlayTitle.setVisibility(View.VISIBLE); llOverlay.setVisibility(View.VISIBLE); mHandler.sendEmptyMessage(SHOW_PROGRESS); mHandler.removeMessages(HIDE_OVERLAY); mHandler.sendEmptyMessageDelayed(HIDE_OVERLAY, 5 * 1000); }
private void ntpSucc() { mHandler.removeMessages(UPDATE_TIME); long delay = 1000 - ntpTrustedTime.currentTimeMillis() % 1000; mHandler.sendEmptyMessageDelayed(UPDATE_TIME, delay); unCachedButton.setBackgroundResource(R.drawable.cached_ntp_time); }
@Override public void handleMessage(Message msg) { if (!EMWifi.sIsInitialed) { showDialog(DIALOG_WIFI_ERROR); return; } if (HANDLER_EVENT_RX == msg.what) { long[] i4Rx = new long[2]; long i4RxCntOk = -1; long i4RxCntFcsErr = -1; long i4RxPer = -1; Xlog.i(TAG, "The Handle event is : HANDLER_EVENT_RX"); try { i4RxPer = Long.parseLong(mTvPer.getText().toString()); } catch (NumberFormatException e) { Xlog.d(TAG, "Long.parseLong NumberFormatException: " + e.getMessage()); } EMWifi.getPacketRxStatus(i4Rx, 2); Xlog.d(TAG, "after rx test: rx ok = " + String.valueOf(i4Rx[0])); Xlog.d(TAG, "after rx test: fcs error = " + String.valueOf(i4Rx[1])); i4RxCntOk = i4Rx[0] /* - i4Init[0] */; i4RxCntFcsErr = i4Rx[1] /* - i4Init[1] */; if (i4RxCntFcsErr + i4RxCntOk != 0) { i4RxPer = i4RxCntFcsErr * PERCENT / (i4RxCntFcsErr + i4RxCntOk); } mTvFcs.setText(String.valueOf(i4RxCntFcsErr)); mTvRx.setText(String.valueOf(i4RxCntOk)); mTvPer.setText(String.valueOf(i4RxPer)); } mHandler.sendEmptyMessageDelayed(HANDLER_EVENT_RX, HANDLER_RX_DELAY_TIME); }
private void remainingSecondsChanged(int newVal) { mRemainingSecs = newVal; if (newVal == 0) { // Countdown has finished setVisibility(View.INVISIBLE); if (mListener != null) mListener.onCountDownFinished(); } else { Locale locale = getResources().getConfiguration().locale; String localizedValue = String.format(locale, "%d", newVal); mRemainingSecondsView.setText(localizedValue); // Fade-out animation mCountDownAnim.reset(); mRemainingSecondsView.clearAnimation(); mRemainingSecondsView.startAnimation(mCountDownAnim); // Play sound effect for the last 3 seconds of the countdown // if (mPlaySound) { // if (newVal == 1) { // mSoundPool.play(mBeepTwice, 1.0f, 1.0f, 0, 0, 1.0f); // } else if (newVal <= 3) { // mSoundPool.play(mBeepOnce, 1.0f, 1.0f, 0, 0, 1.0f); // } // } // Schedule the next remainingSecondsChanged() call in 1 second mHandler.sendEmptyMessageDelayed(SET_TIMER_TEXT, 1000); } }
private void moveScreenSaverTo(int x, int y) { if (!mScreenSaverMode) return; final View saver_view = findViewById(R.id.saver_view); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); if (x < 0 || y < 0) { int myWidth = saver_view.getMeasuredWidth(); int myHeight = saver_view.getMeasuredHeight(); x = (int) (mRNG.nextFloat() * (metrics.widthPixels - myWidth)); y = (int) (mRNG.nextFloat() * (metrics.heightPixels - myHeight)); } if (DEBUG) Log.d( LOG_TAG, String.format("screen saver: %d: jumping to (%d,%d)", System.currentTimeMillis(), x, y)); saver_view.setLayoutParams( new AbsoluteLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, x, y)); // Synchronize our jumping so that it happens exactly on the second. mHandy.sendEmptyMessageDelayed( SCREEN_SAVER_MOVE_MSG, SCREEN_SAVER_MOVE_DELAY + (1000 - (System.currentTimeMillis() % 1000))); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupViews(); initData(); mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { case SEND_MSG_ID: boolean ret = requestRegister(); if (!ret) { finish(); } break; default: break; } } }; mHandler.sendEmptyMessageDelayed(SEND_MSG_ID, 1000); }
@Override public boolean handleMessage(Message message) { mUpdater.removeMessages(0); if (isResumed()) { try { LegacyVpnInfo info = mService.getLegacyVpnInfo(); if (mInfo != null) { VpnPreference preference = mPreferences.get(mInfo.key); if (preference != null) { preference.update(-1); } mInfo = null; } if (info != null) { VpnPreference preference = mPreferences.get(info.key); if (preference != null) { preference.update(info.state); mInfo = info; } } } catch (Exception e) { // ignore } mUpdater.sendEmptyMessageDelayed(0, 1000); } return true; }
@Override public void onHWRenderFailed() { if (Build.VERSION.SDK_INT < 11 && mIsHWCodec) { vPlayerHandler.sendEmptyMessage(HW_FAILED); vPlayerHandler.sendEmptyMessageDelayed(HW_FAILED, 200); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_acoustic); price = (TextView) this.findViewById(R.id.price); price.setText(getIntent().getStringExtra("price")); AssetManager mgr = getAssets(); Typeface tf = Typeface.createFromAsset(mgr, "fonts/arial.ttf"); price.setTypeface(tf); mSinVoicePlayer = new SinVoicePlayer(CODEBOOK); mSinVoicePlayer.setListener(this); mRecognition = new SinVoiceRecognition(CODEBOOK); mRecognition.setListener(this); mSinVoicePlayer.play(Utils.sendStr(price.getText().toString().substring(2)), true, 1000); image = (ImageView) this.findViewById(R.id.image); animationDrawable = (AnimationDrawable) image.getBackground(); animationDrawable.start(); Intent mIntent = new Intent(Utils.ACTION_NAME_SONIC_OPEN); sendBroadcast(mIntent); handler.sendEmptyMessageDelayed(MSG_END, Utils.DELAY); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); tvVersion = (TextView) findViewById(R.id.tv_version); tvProgress = (TextView) findViewById(R.id.tv_progress); // 得到版本名 getVersionName(); // 动态设置版本名 tvVersion.setText("版本名:" + getVersionName()); // 调拷贝归属地查询数据 copyDb("address.db"); // 拷贝常用号码拷贝数据库 copyDb("commonnum.db"); // 拷贝病毒数据库 copyDb("antivirus.db"); // 开启渐变动画 RelativeLayout rlRoot = (RelativeLayout) findViewById(R.id.rl_root); AlphaAnimation anim = new AlphaAnimation(0.3f, 1); anim.setDuration(2000); rlRoot.startAnimation(anim); // 检查版本, boolean autoUpdate = PrefUtils.getBoolean(this, "auto_update", false); if (autoUpdate) { // 判断设置选项是否为需要自动更新 checkVersion(); } else { mHandler.sendEmptyMessageDelayed(CODE_ENTER_HOME, 2000); } // 创建快捷方式 createShortcut(); }
public boolean moveTetrominoRight() { Log.d(TAG, "move tetromino to right"); synchronized (lockObj) { if (currentTetromino.moveRight(oldMap)) { currentMap.copyFrom(oldMap); currentTetromino.putOnMap(currentMap); lastMoveMap.copyFrom(currentMap); // if old position will collision but new moved position will not, then need remove the new // tetromino message and send tetromino move message= if (!currentTetromino.isCollisionY( currentTetromino.getY() + 1, currentTetromino.getSharp(), oldMap)) { if (handler.hasMessages(MSG_NEW_TETROMINO)) { handler.removeMessages(MSG_NEW_TETROMINO); handler.sendEmptyMessageDelayed(MSG_TETROMINO_MOVE, TETROMINO_MOVE_INTERVAL_RESEND); } } for (ITetrisListener listener : customizedListeners) { listener.onTetrominoMove(); } return true; } return false; } }
public void handleMessage(Message msg) { if (msg.what == TAG_SCORLL) { mCurrentPosition++; mViewPager.setCurrentItem(mCurrentPosition); handler.sendEmptyMessageDelayed(TAG_SCORLL, mContinuedTime * 1000); } }
@Override public void handleMessage(Message msg) { switch (msg.what) { case MarsARActivity.RESTART_PREVIEW: { if (mStatus == SNAPSHOT_IN_PROGRESS) { // We are still in the processing of taking the picture, wait. // This is is strange. Why are we polling? // TODO remove polling mHandler.sendEmptyMessageDelayed(MarsARActivity.RESTART_PREVIEW, 100); } break; } case MarsARActivity.SHOW_LOADING: { stopPreview(); break; } case MarsARActivity.HIDE_LOADING: { startPreview(); break; } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); File filesDir = getFilesDir(); String dataDir = filesDir.getParent(); dbDir = dataDir + "/databases"; backup = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Acfun"; setContentView(R.layout.activity_splash); mHandler.sendEmptyMessageDelayed(0, 1200L); // 版本号更改后,清除原有缓存 try { PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0); int oldVersion = AcApp.getConfig().getInt("versionCode", 0); if (oldVersion != info.versionCode) { clearCache(); AcApp.putInt("versionCode", info.versionCode); } } catch (NameNotFoundException e) { e.printStackTrace(); } File bak = new File(backup + appDb); if (bak.exists()) { new Thread() { public void run() { copy(backup + appDb, dbDir + appDb); copy(backup + downloadDb, dbDir + downloadDb); new File(backup + appDb).delete(); new File(backup + downloadDb).delete(); } }.start(); } }