Java Code Examples for android.os.Message

The following are top voted examples for showing how to use android.os.Message. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: iconsole-android   File: BluetoothChatService.java   Source Code and License 9 votes vote down vote up
/**
 * Indicate that the connection attempt failed and notify the UI Activity.
 */
private void connectionFailed() {
    // Send a failure message back to the Activity
    Message msg = mHandler.obtainMessage(Constants.MESSAGE_TOAST);
    Bundle bundle = new Bundle();
    bundle.putString(Constants.TOAST, "Unable to connect device");
    msg.setData(bundle);
    mHandler.sendMessage(msg);

    mState = STATE_NONE;
    // Update UI title
    updateUserInterfaceTitle();

    // Start the service over to restart listening mode
    BluetoothChatService.this.startBT();
}
 
Example 2
Project: xmrwallet   File: WalletService.java   Source Code and License 9 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Running = true;
    // when the activity starts the service, it expects to start it for a new wallet
    // the service is possibly still occupied with saving the last opened wallet
    // so we queue the open request
    // this should not matter since the old activity is not getting updates
    // and the new one is not listening yet (although it will be bound)
    Timber.d("onStartCommand()");
    // For each start request, send a message to start a job and deliver the
    // start ID so we know which request we're stopping when we finish the job
    Message msg = mServiceHandler.obtainMessage();
    msg.arg2 = START_SERVICE;
    if (intent != null) {
        msg.setData(intent.getExtras());
        mServiceHandler.sendMessage(msg);
        return START_STICKY;
    } else {
        // process restart - don't do anything - let system kill it again
        stop();
        return START_NOT_STICKY;
    }
}
 
Example 3
Project: container   File: VPackageInstallerService.java   Source Code and License 9 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    final int userId = msg.arg2;
    final int n = mCallbacks.beginBroadcast();
    for (int i = 0; i < n; i++) {
        final IPackageInstallerCallback callback = mCallbacks.getBroadcastItem(i);
        final VUserHandle user = (VUserHandle) mCallbacks.getBroadcastCookie(i);
        // TODO: dispatch notifications for slave profiles
        if (userId == user.getIdentifier()) {
            try {
                invokeCallback(callback, msg);
            } catch (RemoteException ignored) {
            }
        }
    }
    mCallbacks.finishBroadcast();
}
 
Example 4
Project: GitHub   File: QueuesHandler.java   Source Code and License 7 votes vote down vote up
private void goNext(final int nextIndex) {
    if (this.mHandler == null || this.mList == null) {
        FileDownloadLog.w(this, "need go next %d, but params is not ready %s %s",
                nextIndex, this.mHandler, this.mList);
        return;
    }

    Message nextMsg = this.mHandler.obtainMessage();
    nextMsg.what = WHAT_SERIAL_NEXT;
    nextMsg.arg1 = nextIndex;
    if (FileDownloadLog.NEED_LOG) {
        FileDownloadLog.d(SerialHandlerCallback.class, "start next %s %s",
                this.mList == null ? null : this.mList.get(0) == null ? null :
                        this.mList.get(0).getOrigin().getListener(), nextMsg.arg1);
    }
    this.mHandler.sendMessage(nextMsg);
}
 
Example 5
Project: 3DPrint-Controller   File: ModelInfoPopupWindow.java   Source Code and License 7 votes vote down vote up
public void show(View parent){
    this.showAtLocation(parent, Gravity.CENTER,0,0);

    new Thread(new Runnable(){
        @Override
        public void run() {
            //此处while的条件alpha不能<= 否则会出现黑屏
            while(layoutParams.alpha > 0.5f){
                try {
                    Thread.sleep(6);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Message msg =mHandler.obtainMessage();
                msg.what = 1;
                layoutParams.alpha -= 0.01f;
                msg.obj = layoutParams;
                mHandler.sendMessage(msg);
            }
        }
    }).start();
}
 
Example 6
Project: boohee_v5.6   File: LEYUApplication.java   Source Code and License 6 votes vote down vote up
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    String smsg = msg.obj.toString();
    if (msg.what == 0) {
        try {
            LEYUApplication.dev_access_token = ((JSONObject) new JSONTokener(smsg)
                    .nextValue()).getString("access_token");
            LEYUApplication.set("leyu_dev_access_token", LEYUApplication.dev_access_token);
            LEYUApplication.this._callback.ReturnAccessToken(LEYUApplication
                    .dev_access_token);
        } catch (JSONException ex) {
            ex.printStackTrace();
            LEYUApplication.this._callback.onFailed(ex.getMessage());
        }
    } else if (msg.what == 1) {
        LEYUApplication.this._callback.OnCompleted(smsg);
    } else if (msg.what == 2) {
        LEYUApplication.this._callback.onFailed(smsg);
    }
}
 
Example 7
Project: 19porn   File: PersonInfoActivity.java   Source Code and License 6 votes vote down vote up
private void setPortrait(){
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                pngBM = User.getInstance().getUserPortrait();

                Message msg = new Message();
                msg.what = 0;
                handler.sendMessage(msg);

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });
    thread.start();
}
 
Example 8
Project: GitHub   File: OkBus.java   Source Code and License 6 votes vote down vote up
public OkBus register(int tag, final Event ev, int thread) {
    SparseArray<Event> mEvent = new SparseArray<>();
    mEvent.put(thread, ev);
    if (mEventList.get(tag) != null) {
        mEventList.get(tag).add(mEvent);
    } else {
        List<SparseArray<Event>> mList = new ArrayList<>();
        mList.add(mEvent);
        mEventList.put(tag, mList);
    }
    LogUtils.e("Bus register", tag + " :" + mEventList.get(tag).size());
    if (mStickyEventList.get(tag) != null) {//注册时分发粘连事件
        final Message msg = new Message();
        msg.obj = mStickyEventList.get(tag);
        msg.what = tag;
        callEvent(msg, ev, thread);
        LogUtils.e("mStickyEvent register  and  onEvent", tag + " :" + mEventList.get(tag).size());
    }
    return this;
}
 
Example 9
Project: live_master   File: GiraffePlayer.java   Source Code and License 6 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case MESSAGE_FADE_OUT:
            log.i("isfu123", "isfu123");
            if (isShowing){
                hide(1);
            }
            break;
        case MESSAGE_HIDE_BOX:
            $.id(R.id.app_video_center_box_right).gone();
            $.id(R.id.app_video_center_box_left).gone();
            $.id(R.id.app_video_top_box_right).gone();
            show(defaultTimeout,true);
            break;
        case MESSAGE_SHOW_BOX:
            show(defaultTimeout,true);
            break;
        case MESSAGE_SEEK_NEW_POSITION:
            break;
        case MESSAGE_RESTART_PLAY:
            play(url);
            break;
    }
}
 
Example 10
Project: OpenVideoCall-Android   File: WorkerThread.java   Source Code and License 6 votes vote down vote up
public final void preview(boolean start, SurfaceView view, int uid) {
    if (Thread.currentThread() != this) {
        log.warn("preview() - worker thread asynchronously " + start + " " + view + " " + (uid & 0XFFFFFFFFL));
        Message envelop = new Message();
        envelop.what = ACTION_WORKER_PREVIEW;
        envelop.obj = new Object[]{start, view, uid};
        mWorkerHandler.sendMessage(envelop);
        return;
    }

    ensureRtcEngineReadyLock();
    if (start) {
        mRtcEngine.setupLocalVideo(new VideoCanvas(view, VideoCanvas.RENDER_MODE_HIDDEN, uid));
        mRtcEngine.startPreview();
    } else {
        mRtcEngine.stopPreview();
    }
}
 
Example 11
Project: Hotspot-master-devp   File: UIProgressRequestListener.java   Source Code and License 6 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case REQUEST_UPDATE:
            UIProgressRequestListener uiProgressRequestListener = mUIProgressRequestListenerWeakReference.get();
            if (uiProgressRequestListener != null) {
                //获得进度实体类
                ProgressModel progressModel = (ProgressModel) msg.obj;
                //回调抽象方法
                uiProgressRequestListener.onUIRequestProgress(progressModel.getCurrentBytes(), progressModel.getContentLength(), progressModel.isDone());
            }
            break;
        default:
            super.handleMessage(msg);
            break;
    }
}
 
Example 12
Project: TPlayer   File: InitActivity.java   Source Code and License 6 votes vote down vote up
@Override
public void handleMessage(Message msg) {
  InitActivity ctx = (InitActivity) mContext.get();
  switch (msg.what) {
    case 0:
      ctx.mPD.dismiss();
      Intent src = ctx.getIntent();
      Intent i = new Intent();
      i.setClassName(src.getStringExtra("package"), src.getStringExtra("className"));
      i.setData(src.getData());
      i.putExtras(src);
      i.putExtra(FROM_ME, true);
      ctx.startActivity(i);
      ctx.finish();
      break;
  }
}
 
Example 13
Project: TPlayer   File: MediaPlayer.java   Source Code and License 6 votes vote down vote up
private void updateSub(int subType, byte[] bytes, String encoding, int width, int height) {
  if (mEventHandler != null) {
    Message m = mEventHandler.obtainMessage(MEDIA_TIMED_TEXT, width, height);
    Bundle b = m.getData();
    if (subType == SUBTITLE_TEXT) {
      b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_TEXT);
      if (encoding == null) {
        b.putString(MEDIA_SUBTITLE_STRING, new String(bytes));
      } else {
        try {
          b.putString(MEDIA_SUBTITLE_STRING, new String(bytes, encoding.trim()));
        } catch (UnsupportedEncodingException e) {
          Log.e("updateSub", e);
          b.putString(MEDIA_SUBTITLE_STRING, new String(bytes));
        }
      }
    } else if (subType == SUBTITLE_BITMAP) {
      b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_BITMAP);
      b.putByteArray(MEDIA_SUBTITLE_BYTES, bytes);
    }
    mEventHandler.sendMessage(m);
  }
}
 
Example 14
Project: XPrivacy   File: XActivityThread.java   Source Code and License 6 votes vote down vote up
@Override
protected void after(XParam param) throws Throwable {
	if (mMethod == Methods.next) {
		Message msg = (Message) param.getResult();
		if (msg != null) {
			if (msg.obj instanceof Intent) {
				Intent intent = (Intent) msg.obj;
				if (intent != null)
					if (checkIntent(Binder.getCallingUid(), intent))
						param.setResult(null);
			}
		}

	} else if (mMethod == Methods.handleReceiver) {
		// Do nothing

	} else
		Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
}
 
Example 15
Project: Hitalk   File: HitalkMonitor.java   Source Code and License 6 votes vote down vote up
private void init() {
    handler = new Handler(getLooper()) {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case CHECK_HITALK_CONVERSATION:
                        MonitorEvent monitorEvent = (MonitorEvent) msg.obj;
                        Message newMsg = new Message();
                        newMsg.copyFrom(msg);
                        if (!monitorEvent.check()) {
                            IMMEDIATE_TIMES ++;
                            monitorEvent.run();
                            handler.sendMessageDelayed(newMsg,
                                    LOOP_IMMEDIATE + (IMMEDIATE_TIMES / 3) * LOOP_INCREAMENT);
                        } else {
                            IMMEDIATE_TIMES = 0;
                            handler.sendMessageDelayed(newMsg,
                                    LOOP_TIME);
                        }
                    break;
            }
        }
    };
}
 
Example 16
Project: -Pod   File: MusicFragment.java   Source Code and License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String key = intent.getStringExtra(Constants.ACTION_KEY);
    Message message = Message.obtain(handler);
    switch (key) {
        case Constants.ACTION_OK:
            message.what = 0;
            break;
        case Constants.ACTION_PREV:
            message.what = 1;
            break;
        case Constants.ACTION_NEXT:
            message.what = 2;
            break;
        case Constants.ACTION_MENU:
            message.what = 3;
            break;
        case Constants.ACTION_PLAY:
            message.what = 4;
            break;
    }
    handler.sendMessage(message);
}
 
Example 17
Project: Aurora   File: DownloadSerialQueue.java   Source Code and License 6 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    switch (msg.what) {
        case WHAT_NEXT:
            try {
                synchronized (finishCallback) {
                    if (paused) break;
                    workingTask = mTasks.take();
                    workingTask.addFinishListener(finishCallback)
                            .start();
                }

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            break;
    }
    return false;
}
 
Example 18
Project: letv   File: g.java   Source Code and License 6 votes vote down vote up
private g() {
    if (this.f == null) {
        this.f = new HandlerThread("opensdk.report.handlerthread", 10);
        this.f.start();
    }
    if (this.f.isAlive() && this.f.getLooper() != null) {
        this.g = new Handler(this, this.f.getLooper()) {
            final /* synthetic */ g a;

            public void handleMessage(Message message) {
                switch (message.what) {
                    case 1000:
                        this.a.b();
                        break;
                    case 1001:
                        this.a.e();
                        break;
                }
                super.handleMessage(message);
            }
        };
    }
}
 
Example 19
Project: AppFirCloud   File: UIProgressResponseListener.java   Source Code and License 6 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case RESPONSE_UPDATE:
            UIProgressResponseListener uiProgressResponseListener = mUIProgressResponseListenerWeakReference.get();
            if (uiProgressResponseListener != null) {
                //获得进度实体类
                ProgressModel progressModel = (ProgressModel) msg.obj;
                //回调抽象方法
                uiProgressResponseListener.onUIResponseProgress(progressModel.getCurrentBytes(), progressModel.getContentLength(), progressModel.isDone());
            }
            break;
        default:
            super.handleMessage(msg);
            break;
    }
}
 
Example 20
Project: aos-Video   File: CastDebug.java   Source Code and License 6 votes vote down vote up
public CastDebug(Context context){
    super();

    sCastDebug = this;
    mContext = context;
    mHandler = new android.os.Handler(){
        public void handleMessage(Message msg) {
            try {
                if((ArchosVideoCastManager.getInstance().isRemoteMediaPlaying()||
                        ArchosVideoCastManager.getInstance().getPlaybackStatus()== MediaStatus.PLAYER_STATE_IDLE)&&is_media_loading){
                    goToNextVideo();
                }
            } catch (TransientNetworkDisconnectionException e) {
                e.printStackTrace();
            } catch (NoConnectionException e) {
                e.printStackTrace();
            }
        }


    };
    mVideoMapper = new VideoCursorMapper();
    ArchosVideoCastManager.getInstance().addArchosCastManagerListener(this);

}
 
Example 21
Project: Android_Songshuhui   File: ContentActivity.java   Source Code and License 6 votes vote down vote up
public void handleMessage(Message msg){
    switch (msg.what){
        case 1:
            response = (String) msg.obj;

            //隐藏载入提示
            webView.setVisibility(View.VISIBLE);
            progressBar.setVisibility(View.GONE);

            webView.loadData(response, "text/html;charset=UTF-8", null);//以UTF-8加载HTML代码的内容,防止出现乱码

            //以下为对webView的设置
            //开启javascript
            webView.getSettings().setJavaScriptEnabled(true);

            //设置滚动条
            webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
            webView.setHorizontalScrollBarEnabled(false);

            //<IMPORTENT!>
            //保证webview里图片不会超出当前显示的设置,我也不知道原理,暂时不要更改!
            webView.getSettings().setTextZoom(180);
            webView.setInitialScale(getScale());
    }

}
 
Example 22
Project: MapDemo   File: MainActivity.java   Source Code and License 6 votes vote down vote up
@Override
public void handleMessage(Message msg) {
	int type = msg.what;
	switch (type) {
	case BaiduNaviManager.TTSPlayMsgType.PLAY_START_MSG: {
		// showToastMsg("Handler : TTS play start");
		break;
	}
	case BaiduNaviManager.TTSPlayMsgType.PLAY_END_MSG: {
		// showToastMsg("Handler : TTS play end");
		break;
	}
	default:
		break;
	}
}
 
Example 23
Project: LifeHelper   File: CaptureActivityHandler.java   Source Code and License 6 votes vote down vote up
public void quitSynchronously() {
    state = State.DONE;
    cameraManager.stopPreview();
    Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
    quit.sendToTarget();
    try {
        // Wait at most half a second; should be enough time, and onPause()
        // will timeout quickly
        decodeThread.join(500L);
    } catch (InterruptedException e) {
        // continue
    }

    // Be absolutely sure we don't send any queued up messages
    removeMessages(R.id.decode_succeeded);
    removeMessages(R.id.decode_failed);
}
 
Example 24
Project: miaosou   File: ComicReadActivity.java   Source Code and License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_comic_read);
    Intent intent = getIntent();
    comicUrlGet = intent.getStringExtra(ComicFragment.COMICREADURL);
    comicUrl = getComicUrl(comicUrlGet);
    //pictureId = comicUrl.substring(comicUrl.lastIndexOf("/") + 1,comicUrl.lastIndexOf("."));
    //.replace(".html","_2.html");
    //Log.d("url",comicUrl);
    comicSelectPage = (Button) findViewById(R.id.comic_selectPage);
    comicSelectPage.setOnClickListener(this);
    tvComicReadPage = (TextView) findViewById(R.id.comic_readPage);
    tvComicUrlLines = (TextView) findViewById(R.id.comic_change_lines);
    tvComicUrlLines.setOnClickListener(this);
    setTVComicUrlLines(tvComicUrlLines);
    progressBar = (ProgressBar) findViewById(R.id.pb_comic_progress);
    llComicReadBar = (LinearLayout) findViewById(R.id.comic_read_llbar);
    comicPagesText = (TextView) findViewById(R.id.read_comic_pages);
    viewPager = (ViewPager) findViewById(R.id.comic_read_pager);
    //viewPager.setOnLongClickListener(this);
    viewPager.setOffscreenPageLimit(1);
    pageAdapter = new MyPageAdapter(this.getSupportFragmentManager(), comicViewPagerList);
    viewPager.setAdapter(pageAdapter);
    viewPager.setPageTransformer(true, new DepthPageTransformer());
    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                llComicReadBar.setVisibility(View.GONE);
            }
        }
    };
    handler.sendEmptyMessageDelayed(1, 3000);
    queryComicUrl();
}
 
Example 25
Project: AndroidBackendlessChat   File: TwitterManager.java   Source Code and License 5 votes vote down vote up
private static Message getSuccessMessage(Object listener, Object data){
    Message msg = new Message();
    msg.what = 1;
    msg.arg1 = SUCCESS;
    msg.obj = new MessageObj(listener, data);
    return msg;
}
 
Example 26
Project: UpdateLibrary   File: HttpClient.java   Source Code and License 5 votes vote down vote up
@Override
public T apply(@NonNull HttpResult<T> tHttpResult) throws Exception {
    if (tHttpResult.getStatus() != NetWorkState.SUCCEES) {
        Message message = new Message();
        message.obj = tHttpResult.getMessage();
        handler.sendMessage(message);
        throw new ApiException();
    }
    return tHttpResult.getResult();
}
 
Example 27
Project: androidscan   File: PreviewCallback.java   Source Code and License 5 votes vote down vote up
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
    Point cameraResolution = configManager.getCameraResolution();
    Handler thePreviewHandler = previewHandler;
    if (cameraResolution != null && thePreviewHandler != null) {
        Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x,
                cameraResolution.y, data);
        message.sendToTarget();
        previewHandler = null;
    } else {
        Log.d(TAG, "Got preview callback, but no handler or resolution available");
    }
}
 
Example 28
Project: AgentWeb   File: FileUpLoadChooserImpl.java   Source Code and License 5 votes vote down vote up
@Override
public boolean handleMessage(final Message msg) {

    AgentWebUtils.runInUiThread(new Runnable() {
        @Override
        public void run() {
            AboveLCallback.this.safeHandleMessage(msg);
        }
    });
    return false;
}
 
Example 29
Project: ChenYan   File: MyDynnamicActivity.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {

    if (msg.what == DynamicAdapter.REPLY_COMMENT) {

        DComment comment = (DComment) msg.obj;
        int position = msg.arg1;
        if (comment.getAuthor().getObjectId().equals(BmobUser.getCurrentUser(User.class).getObjectId())) {
            return;
        }
        showReplyPopup(comment.getDynamicId(), position, comment.getAuthor());
        popupInputMethodWindow();

    }
}
 
Example 30
Project: hanoi-animation   File: MainActivity.java   Source Code and License 5 votes vote down vote up
@Override
protected Void doInBackground(Integer... params) {
    final int totalDisk = params[0];
    final CancellationSignal cancellationSignal = new CancellationSignal();

    Brain.solveHanoi(totalDisk, new Brain.Callback() {
        @Override
        public void onMoveDisk(int disk, int from, int to) {
            if (isCancelled()) {
                cancellationSignal.cancel();
            }

            Message message = mainUIHandler.obtainMessage(disk, from, to);
            mainUIHandler.sendMessageDelayed(message, (++step) * 1000) ;
        }

        @Override
        public void onFinished() {
            Log.i(TAG, "Finish solving puzzle in " + step + " steps!");
        }

        @Override
        public void onCanceled() {
            Log.i(TAG, "Cancel solving puzzle!");
        }
    }, cancellationSignal);

    return null;
}
 
Example 31
Project: UiLib   File: SuperVideoPlayer.java   Source Code and License 5 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    if (msg.what == MSG_UPDATE_PLAY_TIME) {
        updatePlayTime();
        updatePlayProgress();
    } else if (msg.what == MSG_HIDE_CONTROLLER) {
        showOrHideController();
    } else if (msg.what == MSG_PLAY_ON_TV_RESULT) {
        shareToTvResult(msg);
    } else if (msg.what == MSG_EXIT_FORM_TV_RESULT) {
        exitFromTvResult(msg);
    }
    return false;
}
 
Example 32
Project: LQRWeChat   File: VideoThumbLoader.java   Source Code and License 5 votes vote down vote up
public void handleMessage(Message msg) {

            if (imgView.getTag().equals(path)) {
                Bitmap btp = (Bitmap) msg.obj;
                imgView.setImageBitmap(btp);
            }
        }
 
Example 33
Project: ZxingScanner   File: DecodeHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message message) {
    if (!running) {
        return;
    }
    switch (message.what) {
        case QRCodeScanner.decode:
            decode((byte[]) message.obj, message.arg1, message.arg2);
            break;
        case QRCodeScanner.quit:
            running = false;
            Looper.myLooper().quit();
            break;
    }
}
 
Example 34
Project: pay-java-android   File: Utils.java   Source Code and License 5 votes vote down vote up
static void flushStackLocalLeaks(Looper looper) {
    Handler handler = new Handler(looper) {
        @Override public void handleMessage(Message msg) {
            sendMessageDelayed(obtainMessage(), THREAD_LEAK_CLEANING_MS);
        }
    };
    handler.sendMessageDelayed(handler.obtainMessage(), THREAD_LEAK_CLEANING_MS);
}
 
Example 35
Project: mpr121-androidthings   File: PassiveBuzzerHelper.java   Source Code and License 5 votes vote down vote up
private void playNote(int frequency) {
    handler.removeMessages(HANDLER_MSG_STOP);

    Message msg = new Message();
    msg.what = frequency == 0 ? HANDLER_MSG_STOP : HANDLER_MSG_PLAY;
    msg.arg1 = frequency;
    handler.sendMessage(msg);
}
 
Example 36
Project: androidtools   File: DatePickerView.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    if (Math.abs(mMoveLen) < SPEED) {
        mMoveLen = 0;
        if (mTask != null) {
            mTask.cancel();
            mTask = null;
            performSelect();
        }
    } else {
        // Here, mMoveLen / Math.abs (mMoveLen) is designed to hold the mMoveLen plus or minus sign to achieve roll or roll down.
        mMoveLen = mMoveLen - mMoveLen / Math.abs(mMoveLen) * SPEED;
    }
    invalidate();
}
 
Example 37
Project: sealtalk-android-master   File: AsyncHttpResponseHandler.java   Source Code and License 5 votes vote down vote up
protected Message obtainMessage(int responseMessage, Object response) {
    Message msg;
    if (handler != null) {
        msg = handler.obtainMessage(responseMessage, response);
    } else {
        msg = Message.obtain();
        if (msg != null) {
            msg.what = responseMessage;
            msg.obj = response;
        }
    }
    return msg;
}
 
Example 38
Project: AndroidProgramming3e   File: ThumbnailDownloader.java   Source Code and License 5 votes vote down vote up
@Override
protected void onLooperPrepared() {
    mRequestHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == MESSAGE_DOWNLOAD) {
                T target = (T) msg.obj;
                Log.i(TAG, "Got a request for URL: " + mRequestMap.get(target));
                handleRequest(target);
            }
        }
    };
}
 
Example 39
Project: microbit   File: PluginService.java   Source Code and License 5 votes vote down vote up
/**
 * Handler of incoming messages from BLEListener.
 */
private void handleMicroBitMessage(Message msg) {
    Bundle data = msg.getData();
    CmdArg cmd = new CmdArg(data.getInt(IPCConstants.BUNDLE_DATA), data.getString(IPCConstants.BUNDLE_VALUE));

    logi("handleMicrobitMessage() ## msg.arg1 = " + msg.arg1 + " ## data.getInt=" + data.getInt(IPCConstants
            .BUNDLE_DATA) + " ## data.getString=" + data.getString(IPCConstants.BUNDLE_VALUE));

    AbstractPlugin abstractPlugin = pluginsCreator.createPlugin(msg.arg1, pluginHandler);

    if(abstractPlugin != null) {
        abstractPlugin.handleEntry(cmd);
    }
}
 
Example 40
Project: popomusic   File: MainActivty.java   Source Code and License 5 votes vote down vote up
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
    mServiceMessenger = new Messenger(iBinder);
    //连接到服务
    if (null != mServiceMessenger) {
        Message msgToService = Message.obtain();
        msgToService.replyTo = mMessengerClient;
        msgToService.what = Constant.MAIN_ACTIVITY;
        try {
            mServiceMessenger.send(msgToService);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}
 
Example 41
Project: CustomAndroidOneSheeld   File: ColorDetectionShield.java   Source Code and License 5 votes vote down vote up
public void showPreview(float x, float y, int width, int height) throws RemoteException {
    Message msg = Message.obtain(null, CameraHeadService.SHOW_PREVIEW);
    msg.replyTo = mMessenger;
    Bundle b = new Bundle();
    b.putFloat("x", x);
    b.putFloat("y", y);
    b.putInt("w", width);
    b.putInt("h", height);
    msg.setData(b);
    if (mService != null)
        mService.send(msg);
    else
        bindService();

}
 
Example 42
Project: weex-uikit   File: WXDomModule.java   Source Code and License 5 votes vote down vote up
public void addRule(String type, JSONObject options) {
  if (TextUtils.isEmpty(type) || options == null) {
    return;
  }

  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  task.args = new ArrayList<>();
  task.args.add(type);
  task.args.add(options);
  msg.what = WXDomHandler.MsgType.WX_DOM_ADD_RULE;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example 43
Project: VirtualAPK   File: MessengerActivity.java   Source Code and License 5 votes vote down vote up
public void onServiceConnected(ComponentName className, IBinder service) {
    mService = new Messenger(service);
    Log.d(TAG, "bind service");
    Message msg = Message.obtain(null, MyConstants.MSG_FROM_CLIENT);
    Bundle data = new Bundle();
    data.putString("msg", "hello, this is client.");
    msg.setData(data);
    msg.replyTo = mGetReplyMessenger;
    try {
        mService.send(msg);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
Example 44
Project: SliderImageLayout   File: SliderImageLayout.java   Source Code and License 5 votes vote down vote up
public void setSliderImg(int imgId)
{
    imgSize += 1;
    Bitmap bitmap = BitmapFactory.decodeResource(getResources() , imgId);
    Message msg = new Message();
    msg.what = 0x123;
    msg.obj = bitmap;
    handler.sendMessage(msg);
}
 
Example 45
Project: yyox   File: OnekeyShareThemeImpl.java   Source Code and License 5 votes vote down vote up
private void toast(final String resOrName) {
	UIHandler.sendEmptyMessage(0, new Callback() {
		public boolean handleMessage(Message msg) {
			int resId = ResHelper.getStringRes(context, resOrName);
			if (resId > 0) {
				Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
			} else {
				Toast.makeText(context, resOrName, Toast.LENGTH_SHORT).show();
			}
			return false;
		}
	});
}
 
Example 46
Project: sctalk   File: MGAutoUpdate.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg){
	switch(msg.what){
	case UPDATE:
		mProgressDialog.setProgress((int)(mCount / 1000));
		break;
	}
}
 
Example 47
Project: weex-uikit   File: WXDomModule.java   Source Code and License 5 votes vote down vote up
/**
 * Update attributes
 * @param ref
 * @param attr the expected attr
 */
public void updateAttrs(String ref, JSONObject attr) {
  if (TextUtils.isEmpty(ref) || attr == null || attr.size() < 1) {
    return;
  }
  Message msg = Message.obtain();
  WXDomTask task = new WXDomTask();
  task.instanceId = mWXSDKInstance.getInstanceId();
  task.args = new ArrayList<>();
  task.args.add(ref);
  task.args.add(attr);
  msg.what = WXDomHandler.MsgType.WX_DOM_UPDATE_ATTRS;
  msg.obj = task;
  WXSDKManager.getInstance().getWXDomManager().sendMessage(msg);
}
 
Example 48
Project: LeCatApp   File: MyCountDownTimer.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {

    synchronized (MyCountDownTimer.this) {
        if (mCancelled) {
            return;
        }

        final long millisLeft = mStopTimeInFuture - SystemClock.elapsedRealtime();

        if (millisLeft <= 0) {
            onFinish();
        } else if (millisLeft < mCountdownInterval) {
            // no tick, just delay until done
            sendMessageDelayed(obtainMessage(MSG), millisLeft);
        } else {
            long lastTickStart = SystemClock.elapsedRealtime();
            onTick(millisLeft);

            // take into account user's onTick taking time to execute
            long delay = lastTickStart + mCountdownInterval - SystemClock.elapsedRealtime();

            // special case: user's onTick took more than interval to
            // complete, skip to next interval
            while (delay < 0) delay += mCountdownInterval;

            sendMessageDelayed(obtainMessage(MSG), delay);
        }
    }
}
 
Example 49
Project: xlight_android_native   File: xltDevice.java   Source Code and License 5 votes vote down vote up
public void sendDeviceStatusMessage(final Bundle data) {
    Handler handler;
    Message msg;
    for (int i = 0; i < m_lstEH_DevST.size(); i++) {
        handler = m_lstEH_DevST.get(i);
        if (handler != null) {
            msg = handler.obtainMessage();
            if (msg != null) {
                msg.setData(data);
                handler.sendMessage(msg);
            }
        }
    }
}
 
Example 50
Project: Hitalk   File: StateMachine.java   Source Code and License 5 votes vote down vote up
/** @see StateMachine#deferMessage(Message) */
private final void deferMessage(Message msg) {
    if (mDbg) mSm.log("deferMessage: msg=" + msg.what);

    /* Copy the "msg" to "newMsg" as "msg" will be recycled */
    Message newMsg = obtainMessage();
    newMsg.copyFrom(msg);

    mDeferredMessages.add(newMsg);
}
 
Example 51
Project: PlayerBase   File: DefaultPlayerControllerCover.java   Source Code and License 5 votes vote down vote up
@Override
protected void _handleMessage(Message msg) {
    super._handleMessage(msg);
    switch (msg.what){
        case MSG.MSG_CODE_DELAY_HIDDEN_CONTROLLER:
            setControllerState(false);
            break;
        case MSG.MSG_CODE_SEEK_TO:
            if(player==null)
                return;
            int progress = (int) msg.obj;
            seekTo(progress);
            break;
    }
}
 
Example 52
Project: rongyunDemo   File: UserDetailActivity.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    if (msg != null) {
        UserDetailActivity activity = mActivity.get();
        if (activity != null) {
            activity.mUserLineStatus.setVisibility(View.VISIBLE);
            switch (msg.arg1) {
                case 0:
                case 4:
                    activity.mUserLineStatus.setText(R.string.pc_online);
                    activity.mUserLineStatus.setTextColor(Color.parseColor("#60E23F"));
                    break; //PC
                case 1:
                case 2:
                    activity.mUserLineStatus.setText(R.string.phone_online);
                    activity.mUserLineStatus.setTextColor(Color.parseColor("#60E23F"));
                    break; //phone
                case 3:
                    activity.mUserLineStatus.setText(R.string.pc_online);
                    activity.mUserLineStatus.setTextColor(Color.parseColor("#60E23F"));
                    break; //web
                case 5:
                    activity.mUserLineStatus.setTextColor(Color.parseColor("#666666"));
                    activity.mUserLineStatus.setText(R.string.offline);
                    break; // offline
            }
        }
    }
}
 
Example 53
Project: SmingZZick_App   File: MusicListenService.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    if (SmingManager.getInstance().isVibrateSongEnd() == true) {
        Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(SmingManager.getInstance().getVibratePattern(), -1);
    }
}
 
Example 54
Project: ZXingAndroidExt   File: CaptureActivityHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message message) {
    int what = message.what;
    if (what == R.id.restart_preview) {
        restartPreviewAndDecode();
    } else if (what == R.id.decode_succeeded) {
        state = State.SUCCESS;
        Bundle bundle = message.getData();
        Bitmap barcode = null;
        float scaleFactor = 1.0f;
        if (bundle != null) {
            byte[] compressedBitmap = bundle.getByteArray(DecodeThread.BARCODE_BITMAP);
            if (compressedBitmap != null) {
                barcode = BitmapFactory.decodeByteArray(compressedBitmap, 0, compressedBitmap.length, null);
                // Mutable copy:
                barcode = barcode.copy(Bitmap.Config.ARGB_8888, true);
            }
            scaleFactor = bundle.getFloat(DecodeThread.BARCODE_SCALED_FACTOR);
        }
        activity.handleDecode((Result) message.obj, barcode, scaleFactor);
    } else if (what == R.id.decode_failed) {
        // We're decoding as fast as possible, so when one decode fails, start another.
        state = State.PREVIEW;
        cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
    } else if (what == R.id.return_scan_result) {
        activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
        activity.finish();
    } else if (what == R.id.launch_product_query) {
        String url = (String) message.obj;

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
        intent.setData(Uri.parse(url));

        ResolveInfo resolveInfo =
                activity.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
        String browserPackageName = null;
        if (resolveInfo != null && resolveInfo.activityInfo != null) {
            browserPackageName = resolveInfo.activityInfo.packageName;
            Log.d(TAG, "Using browser in package " + browserPackageName);
        }

        // Needed for default Android browser / Chrome only apparently
        if ("com.android.browser".equals(browserPackageName) || "com.android.chrome".equals(browserPackageName)) {
            intent.setPackage(browserPackageName);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(Browser.EXTRA_APPLICATION_ID, browserPackageName);
        }

        try {
            activity.startActivity(intent);
        } catch (ActivityNotFoundException ignored) {
            Log.w(TAG, "Can't find anything to handle VIEW of URI " + url);
        }
    }
}
 
Example 55
Project: FlickLauncher   File: FileLog.java   Source Code and License 5 votes vote down vote up
public static void print(String tag, String msg, Exception e) {
    if (!ProviderConfig.IS_DOGFOOD_BUILD) {
        return;
    }
    String out = String.format("%s %s %s", DATE_FORMAT.format(new Date()), tag, msg);
    if (e != null) {
        out += "\n" + Log.getStackTraceString(e);
    }
    Message.obtain(getHandler(), LogWriterCallback.MSG_WRITE, out).sendToTarget();
}
 
Example 56
Project: homescreenarcade   File: PinballWallpaper.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    switch (msg.what) {
        case 0:
            field.setLeftFlippersEngaged(false);
            break;
        case 1:
            field.setRightFlippersEngaged(false);
            break;
    }
}
 
Example 57
Project: astrobee_android   File: AndroidRosBridgeService.java   Source Code and License 5 votes vote down vote up
/**
 * @param messenger What client to send msg to
 * @param typeOfMsg What type of msg is the service sending to client
 * @param strToSend What String to send to client
 */
private static Message messageComposer(Messenger messenger, int typeOfMsg, String strToSend) {
    // Send data as a String
    Bundle bundle = new Bundle();
    bundle.putString("robotResponse", strToSend);
    Message msg = Message.obtain(null, typeOfMsg);
    msg.setData(bundle);
    return msg;
}
 
Example 58
Project: JKCloud   File: ShareOpportunityActivity.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    switch (msg.what) {

        case GET_ERROR:
            dismissLoading();
            break;
        case GET_SUCCESS:
            dismissLoading();
            break;
        default:
            break;
    }
}
 
Example 59
Project: Hitalk   File: StateMachine.java   Source Code and License 5 votes vote down vote up
/**
 * Enqueue a message to the front of the queue for this state machine.
 * Protected, may only be called by instances of StateMachine.
 *
 * Message is ignored if state machine has quit.
 */
protected final void sendMessageAtFrontOfQueue(Message msg) {
    // mSmHandler can be null if the state machine has quit.
    SmHandler smh = mSmHandler;
    if (smh == null) return;

    smh.sendMessageAtFrontOfQueue(msg);
}
 
Example 60
Project: TPlayer   File: HCallbackStub.java   Source Code and License 5 votes vote down vote up
@Override
public boolean handleMessage(Message msg) {
    if (!mCalling) {
        mCalling = true;
        try {
            if (LAUNCH_ACTIVITY == msg.what) {
                if (!handleLaunchActivity(msg)) {
                    return true;
                }
            } else if (CREATE_SERVICE == msg.what) {
                if (!VClientImpl.get().isBound()) {
                    ServiceInfo info = Reflect.on(msg.obj).get("info");
                    VClientImpl.get().bindApplication(info.packageName, info.processName);
                }
            } else if (SCHEDULE_CRASH == msg.what) {
                // to avoid the exception send from System.
                return true;
            }
            if (otherCallback != null) {
                boolean desired = otherCallback.handleMessage(msg);
                mCalling = false;
                return desired;
            } else {
                mCalling = false;
            }
        } finally {
            mCalling = false;
        }
    }
    return false;
}