Java Code Examples for android.os.Handler#sendEmptyMessageDelayed()

The following examples show how to use android.os.Handler#sendEmptyMessageDelayed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationUsageStats.java    From android_9.0.0_r45 with Apache License 2.0 7 votes vote down vote up
public NotificationUsageStats(Context context) {
    mContext = context;
    mLastEmitTime = SystemClock.elapsedRealtime();
    mSQLiteLog = ENABLE_SQLITE_LOG ? new SQLiteLog(context) : null;
    mHandler = new Handler(mContext.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_EMIT:
                    emit();
                    break;
                default:
                    Log.wtf(TAG, "Unknown message type: " + msg.what);
                    break;
            }
        }
    };
    mHandler.sendEmptyMessageDelayed(MSG_EMIT, EMIT_PERIOD);
}
 
Example 2
Source File: VideoLoadingProgressbar.java    From videoplay with Apache License 2.0 6 votes vote down vote up
public VideoLoadingProgressbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mPaint = new Paint();
    mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaint.setAntiAlias(true);
    mPaint.setColor(mColor);

    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            invalidate();
            this.sendEmptyMessageDelayed(1, mTimePeriod);
        }
    };
    if (getVisibility() == VISIBLE) {
        mHandler.sendEmptyMessageDelayed(1, mTimePeriod);
    }
}
 
Example 3
Source File: PartyLightView.java    From android-Flashlight with Apache License 2.0 6 votes vote down vote up
private void init() {
    mEvaluator = new ArgbEvaluator();
    mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            mCurrentColor = getColor(mProgress, mColors[mFromColorIndex],
                    mColors[mToColorIndex]);
            postInvalidate();
            mProgress += 0.1;
            if (mProgress > 1.0) {
                mFromColorIndex = mToColorIndex;
                // Find a new color.
                mToColorIndex++;
                if (mToColorIndex >= mColors.length) {
                    mToColorIndex = 0;
                }
            }
            mHandler.sendEmptyMessageDelayed(0, 100);
        }
    };
}
 
Example 4
Source File: SampleTvInputProvider.java    From ChannelSurfer with MIT License 6 votes vote down vote up
@Override
public boolean onTune(Channel channel) {
    this.currentChannel = channel;
    Program p = getProgramRightNow(channel);
    if(shouldShowToasts())
        Toast.makeText(SampleTvInputProvider.this, "Tuning to "+channel.getName()+" with program "+p.getTitle()+" at "+p.getInternalProviderData(), Toast.LENGTH_SHORT).show();
    Log.d(TAG, "Tuning to " + channel.getName());
    Log.d(TAG, "Playing "+p.getTitle());
    Log.d(TAG, "Play the video "+p.getInternalProviderData());
    play(getProgramRightNow(channel).getInternalProviderData());
    if(currentChannel.getNumber().equals("4")) {
        Handler h = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                setOverlayEnabled(true);
            }
        };
        h.sendEmptyMessageDelayed(0, 16);
    }
    return true;
}
 
Example 5
Source File: HandlerThreadActivity.java    From Android_Blog_Demos with Apache License 2.0 6 votes vote down vote up
private void initBackThread()
{
    mCheckMsgThread = new HandlerThread("check-message-coming");
    mCheckMsgThread.start();
    mCheckMsgHandler = new Handler(mCheckMsgThread.getLooper())
    {
        @Override
        public void handleMessage(Message msg)
        {
            checkForUpdate();
            if (isUpdateInfo)
            {
                mCheckMsgHandler.sendEmptyMessageDelayed(MSG_UPDATE_INFO, 1000);
            }
        }
    };


}
 
Example 6
Source File: RxTextViewVertical.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
/**
 * 间隔时间
 *
 * @param time
 */
public void setTextStillTime(final long time) {
    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case FLAG_START_AUTO_SCROLL:
                    if (textList.size() > 0) {
                        currentId++;
                        setText(textList.get(currentId % textList.size()));
                    }
                    handler.sendEmptyMessageDelayed(FLAG_START_AUTO_SCROLL, time);
                    break;
                case FLAG_STOP_AUTO_SCROLL:
                    handler.removeMessages(FLAG_START_AUTO_SCROLL);
                    break;
            }
        }
    };
}
 
Example 7
Source File: CumulusWebPlayer.java    From CumulusTV with MIT License 5 votes vote down vote up
public void onPageFinished(WebView v, String url) {
    super.onPageFinished(v, url);
    Handler h = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            mListener.onPageFinished();
        }
    };
    h.sendEmptyMessageDelayed(0, 1000);
}
 
Example 8
Source File: DefaultLocation.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
private WXLocationListener(LocationManager locationManager, WXSDKInstance instance, String watchId, String sucCallback, String errorCallback, boolean enableAddress) {
  this.mWatchId = watchId;
  if (instance != null) {
    this.mSucCallback = new SimpleJSCallback(instance.getInstanceId(), sucCallback);
    this.mErrorCallback = new SimpleJSCallback(instance.getInstanceId(), errorCallback);
    mContext = instance.getContext();
  }
  this.mEnableAddress = enableAddress;
  mHandler = new Handler(this);
  mLocationManager = locationManager;
  mHandler.sendEmptyMessageDelayed(TIME_OUT_WHAT, GPS_TIMEOUT);
}
 
Example 9
Source File: LeanbackFragment.java    From CumulusTV with MIT License 5 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    ActivityUtils.onConnected(CloudStorageProvider.getInstance().getClient());
    Log.d(TAG, "onConnected");

    sm.setGoogleDriveSyncable(CloudStorageProvider.getInstance().getClient(), new DriveSettingsManager.GoogleDriveListener() {
        @Override
        public void onActionFinished(boolean cloudToLocal) {
            Log.d(TAG, "Sync req after drive action");
            final String info = TvContract.buildInputId(ActivityUtils.TV_INPUT_SERVICE);
            CumulusJobService.requestImmediateSync1(mActivity, info, CumulusJobService.DEFAULT_IMMEDIATE_EPG_DURATION_MILLIS,
                    new ComponentName(mActivity, CumulusJobService.class));
            if (cloudToLocal) {
                Toast.makeText(getActivity(), R.string.download_complete, Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getActivity(), R.string.upload_complete, Toast.LENGTH_SHORT).show();
            }
        }
    }); //Enable GDrive
    Log.d(TAG, sm.getString(R.string.sm_google_drive_id) + "<< for onConnected");
    if(sm.getString(R.string.sm_google_drive_id).isEmpty()) {
        //We need a new file
        ActivityUtils.createDriveData(mActivity, CloudStorageProvider.getInstance().getClient(),
                driveContentsCallback);
    } else {
        //Great, user already has sync enabled, let's resync
        ActivityUtils.readDriveData(mActivity, CloudStorageProvider.getInstance().getClient());
        Handler h = new Handler(Looper.getMainLooper()){
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                refreshUI();
            }
        };
        h.sendEmptyMessageDelayed(0, 4000);
    }
}
 
Example 10
Source File: AutoScrollTextView.java    From AutoScrollTextView with Apache License 2.0 5 votes vote down vote up
private void init() {
    textList = new ArrayList<String>();
    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case FLAG_START_AUTO_SCROLL:
                    if (textList.size() > 0) {
                        currentId++;
                        setText(textList.get(currentId % textList.size()));
                    }
                    handler.sendEmptyMessageDelayed(FLAG_START_AUTO_SCROLL, scrollDuration);
                    break;
                case FLAG_STOP_AUTO_SCROLL:
                    handler.removeMessages(FLAG_START_AUTO_SCROLL);
                    break;
            }
        }
    };

    setFactory(this);
    Animation in = new TranslateAnimation(0, 0, 300, 0);
    in.setDuration(animDuration);
    in.setInterpolator(new AccelerateInterpolator());
    Animation out = new TranslateAnimation(0, 0, 0, -300);
    out.setDuration(animDuration);
    out.setInterpolator(new AccelerateInterpolator());
    setInAnimation(in);
    setOutAnimation(out);
}
 
Example 11
Source File: SetupTvInputProviderActivity.java    From ChannelSurfer with MIT License 5 votes vote down vote up
public void setupTvInputProvider() {
    Log.d(TAG, "Requesting sync");
    requestSync();
    Handler h = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            finish();
        }
    };
    h.sendEmptyMessageDelayed(0, 5000);
}
 
Example 12
Source File: DefaultLocation.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
private WXLocationListener(LocationManager locationManager, WXSDKInstance instance, String watchId, String sucCallback, String errorCallback, boolean enableAddress) {
      mWXSDKInstance = instance;
      this.mWatchId = watchId;
      this.mSucCallback = sucCallback;
      this.mErrorCallback = errorCallback;
      this.mEnableAddress = enableAddress;
      mHandler = new Handler(this);
      mLocationManager = locationManager;
//      WVThreadPool.getInstance().execute(new Runnable() {
//        public void run() {
          mHandler.sendEmptyMessageDelayed(TIME_OUT_WHAT, GPS_TIMEOUT);
//        }
//      });
    }
 
Example 13
Source File: RemoteHandler.java    From AppOpsX with MIT License 5 votes vote down vote up
RemoteHandler(Map<String, String> params) throws IOException {
  System.out.println("params --> " + params);
  boolean isRoot = TextUtils.equals(params.get("type"), "root");
  String path = params.get("path");
  String token = params.get("token");
  boolean allowBg = TextUtils.equals(params.get("bgrun"), "1");
  boolean debug = TextUtils.equals(params.get("debug"), "1");

  server = new OpsXServer(path, token, this);
  server.allowBackgroundRun = this.allowBg = allowBg;


  if (!allowBg) {
    HandlerThread thread1 = new HandlerThread("watcher-ups");
    thread1.start();
    handler = new Handler(thread1.getLooper()) {
      @Override
      public void handleMessage(Message msg) {
        super.handleMessage(msg);
        switch (msg.what) {
          case MSG_TIMEOUT:
            destory();
            break;
        }
      }
    };
    handler.sendEmptyMessageDelayed(MSG_TIMEOUT, timeOut);
  }
}
 
Example 14
Source File: FriendRefreshView.java    From LQRWeChat with MIT License 5 votes vote down vote up
/**
 * 初始化handler,当ViewDragHelper释放了mContentView时,
 * 我们通过循环发送消息刷新mRainbowView的位置和角度
 */
private void initHandler() {
    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    if (rainbowTop > rainbowStartTop) {
                        rainbowTop -= 10;
                        requestLayout();
                        mHandler.sendEmptyMessageDelayed(0, 15);
                    }
                    break;
                case 1:
                    if (rainbowTop <= rainbowStickyTop) {
                        if (rainbowTop < rainbowStickyTop) {
                            rainbowTop += 10;
                            if (rainbowTop > rainbowStickyTop) {
                                rainbowTop = rainbowStickyTop;
                            }
                        }
                        mRainbowView.setRotation(rainbowRotateAngle -= 10);
                    } else {
                        mRainbowView.setRotation(rainbowRotateAngle += 10);
                    }

                    requestLayout();

                    mHandler.sendEmptyMessageDelayed(1, 15);
                    break;
            }
        }
    };
}
 
Example 15
Source File: MainActivity.java    From Chorus-RF-Laptimer with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    Handler delayedDisconnect = new Handler() {
        public void handleMessage(Message msg) {
            if (AppState.getInstance().conn != null) {
                AppState.getInstance().conn.disconnect();
            }
        }
    };

    switch (id) {
        case R.id.menuBTConnect:
            bt.setDeviceTarget(BluetoothState.DEVICE_OTHER);
            Intent intent = new Intent(getApplicationContext(), DeviceList.class);
            startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
            break;
        case R.id.menuUDPConnect:
            preferWifiAndConnectUDP();
            break;
        case R.id.menuUSBConnect:
            checkUSBPermissionsAndConnectIfAllowed();
            break;
        case R.id.menuDisconnect:
            AppState.getInstance().onBeforeDisconnect();
            delayedDisconnect.sendEmptyMessageDelayed(0, 100);
            break;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 16
Source File: FireflyView.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
public void startAnimation() {
    //if (mHandler != null) return;
    HandlerThread fireThread = new HandlerThread(this.getClass().getName());
    fireThread.start();
    mHandler = new Handler(fireThread.getLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Canvas mCanvas = mHolder.lockCanvas(null);
            if (mCanvas != null) {
                synchronized (mHolder) {
                    // 清屏
                    mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
                    for (FloatParticle fp : mListParticles) {
                        fp.drawParticle(mCanvas);
                    }
                }
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (mCanvas != null) {
                mHolder.unlockCanvasAndPost(mCanvas);
            }
            mHandler.sendEmptyMessageDelayed(EMPTY_FLAG, mParticleMoveRate);
        }
    };
    mHandler.sendEmptyMessage(EMPTY_FLAG);
}
 
Example 17
Source File: QueuedWork.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Queue a work-runnable for processing asynchronously.
 *
 * @param work The new runnable to process
 * @param shouldDelay If the message should be delayed
 */
public static void queue(Runnable work, boolean shouldDelay) {
    Handler handler = getHandler();

    synchronized (sLock) {
        sWork.add(work);

        if (shouldDelay && sCanDelay) {
            handler.sendEmptyMessageDelayed(QueuedWorkHandler.MSG_RUN, DELAY);
        } else {
            handler.sendEmptyMessage(QueuedWorkHandler.MSG_RUN);
        }
    }
}
 
Example 18
Source File: PauseAllMarker.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
public void startPauseAllLooperCheck() {
    pauseAllChecker = new HandlerThread("PauseAllChecker");
    pauseAllChecker.start();
    pauseAllHandler = new Handler(pauseAllChecker.getLooper(), this);
    pauseAllHandler.sendEmptyMessageDelayed(PAUSE_ALL_CHECKER_WHAT, PAUSE_ALL_CHECKER_PERIOD);
}
 
Example 19
Source File: AndroidOpenAccessoryBridge.java    From android-open-accessory-bridge with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    Looper.prepare();
    mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case STOP_THREAD:
                Looper.myLooper().quit();
                break;
            case MAYBE_READ:
                final boolean readResult;
                try {
                    readResult = mReadBuffer.read(mInputStream);
                } catch (IOException exception) {
                    terminate();
                    break;
                }
                if (readResult) {
                    if (mReadBuffer.size == 0) {
                        mHandler.sendEmptyMessage(STOP_THREAD);
                    } else {
                        mListener.onAoabRead(mReadBuffer);
                        mReadBuffer.reset();
                        mHandler.sendEmptyMessage(MAYBE_READ);
                    }
                } else {
                    mHandler.sendEmptyMessageDelayed(MAYBE_READ, READ_COOLDOWN_MS);
                }
                break;
            }
        }
    };
    detectAccessory();
    Looper.loop();
    detachAccessory();
    mIsShutdown = true;
    mListener.onAoabShutdown();

    // Clean stuff up
    mHandler = null;
    mListener = null;
    mUsbManager = null;
    mReadBuffer = null;
    mInternalThread = null;
}
 
Example 20
Source File: HandlerUtils.java    From UltimateAndroid with Apache License 2.0 2 votes vote down vote up
/**
 * Sends a Message containing only the what value, to be delivered after the specified amount of time elapses.
 * @param handler
 * @param what
 * @param delayTime
 */
public static void sendMessageHandlerDelay(Handler handler, int what, long delayTime) {
    handler.sendEmptyMessageDelayed(what,delayTime);
}