Example usage for android.os Message obtain

List of usage examples for android.os Message obtain

Introduction

In this page you can find the example usage for android.os Message obtain.

Prototype

public static Message obtain(Handler h, int what) 

Source Link

Document

Same as #obtain() , but sets the values for both target and what members on the Message.

Usage

From source file:org.gearvrf.weartouchpad.WearInputService.java

private void sendConnectionStatus(int connectionStatus) {
    if (sendMessenger != null) {
        Message reply = Message.obtain(null, connectionStatus);
        try {//w ww. jav  a  2s  .c om
            sendMessenger.send(reply);
        } catch (RemoteException e) {
            Log.e(TAG, "Could not send reply ", e);
        }
    } else {
        Intent intent = new Intent(CONNECTION_INTENT_FILTER);
        intent.putExtra(CONNECTION_STATUS_EXTRA, connectionStatus);
        broadcastManager.sendBroadcast(intent);
    }
}

From source file:nl.pilight.illumina.activity.LocationListActivity.java

@Override
public void onBackPressed() {
    log.info("onBackPressed");
    dispatch(Message.obtain(null, PilightService.Request.PILIGHT_DISCONNECT));
    super.onBackPressed();
}

From source file:com.bangz.shotrecorder.RecordActivity.java

private void doUnbindService() {

    if (mIsBound) {

        if (mService != null) {

            try {
                Message msg = Message.obtain(null, RecordService.MSG_UNREGISTER_CLIENT);
                msg.replyTo = mMessenger;
                mService.send(msg);//  ww w .  ja va 2 s  .  co m
            } catch (RemoteException e) {

            }
        }

        unbindService(mConnection);

        mService = null;
        mIsBound = false;
    }
}

From source file:com.tsroad.map.SetTraceActivity.java

/**
 * ?AMap// w  ww.  j  a  v a  2  s.  c o m
 */
private void init() {
    replayButton = (Button) findViewById(R.id.btn_replay);
    processbar = (SeekBar) findViewById(R.id.process_bar);
    processbar.setSelected(false);
    processbar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
    // ? 
    processbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        // ?OnSeeBarChangeListener
        // OnStartTrackingTouch,?
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }

        // onProgressChanged??
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // TODO Auto-generated method stub

            latlngList_path.clear();
            if (progress != 0) {
                for (int i = 0; i < seekBar.getProgress(); i++) {
                    latlngList_path.add(latlngList.get(i));
                }
                drawLine(latlngList_path, progress);
            }

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        // onStopTrackingTouch,?
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

            latlngList_path.clear();
            int current = seekBar.getProgress();
            if (current != 0) {
                for (int i = 0; i < seekBar.getProgress(); i++) {
                    latlngList_path.add(latlngList.get(i));
                }
                drawLine(latlngList_path, current);
            }
        }
    });

    // ?runnable
    runnable = new Runnable() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            // ??
            handler.sendMessage(Message.obtain(handler, 1));
        }
    };
    // ?runnable?
    // TODO Auto-generated method stub
    if (aMap == null) {
        aMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        if (aMap != null) {
            setUpMap();
        }
    }
}

From source file:org.egov.android.controller.ServiceController.java

/**
 * After binding the service, we can send message to the service to start/stop running
 * background jobs./* w  ww .ja  v  a  2  s .  c o m*/
 * 
 * @param action
 *            => START, STOP
 * @param b
 *            => bundle data to be send
 */
public void sendMessageToService(int action, Bundle b) {
    if (isBound && myService != null) {
        try {
            Message msg = Message.obtain(null, action);
            msg.setData(b);
            myService.send(msg);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}

From source file:fr.mixit.android.ui.fragments.BoundServiceDialogFragment.java

protected void doUnbindService() {
    if (DEBUG_MODE) {
        Log.d(TAG, "doUnbindService()");
    }//  w w w .j av a2  s  . com
    if (mIsBound) {
        // If we have received the mService, and hence registered with it, then now is the time to unregister.
        if (mService != null) {
            try {
                final Message msg = Message.obtain(null, MixItService.MSG_UNREGISTER_CLIENT);
                msg.replyTo = mMessenger;
                mService.send(msg);
            } catch (final RemoteException e) {
                // There is nothing special we need to do if the mService has crashed.
            }
        }

        // Detach our existing connection.
        if (getActivity() == null || isDetached()) {
            if (DEBUG_MODE) {
                Log.d(TAG,
                        "Fragment is detached from hos activity or getActivity is null, so impossible to unbind service");
            }
        } else {
            getActivity().unbindService(mConnection);
        }
        mIsBound = false;
    }
}

From source file:fr.mixit.android.ui.GenericMixItActivity.java

protected void doUnbindService() {
    if (DEBUG_MODE) {
        Log.d(TAG, "doUnbindService()");
    }//from ww w . jav  a  2  s  .  c  o m
    if (mIsBound) {
        // If we have received the mService, and hence registered with it, then now is the time to unregister.
        if (mService != null) {
            try {
                final Message msg = Message.obtain(null, MixItService.MSG_UNREGISTER_CLIENT);
                msg.replyTo = mMessenger;
                mService.send(msg);
            } catch (final RemoteException e) {
                // There is nothing special we need to do if the mService has crashed.
            }
        }

        // Detach our existing connection.
        unbindService(mConnection);
        mIsBound = false;
    }
}

From source file:io.github.hidroh.materialistic.data.SyncDelegate.java

void performSync(@NonNull Job job) {
    // assume that connection wouldn't change until we finish syncing
    mJob = job;//  w w w  . j a v a  2 s.c  om
    if (!TextUtils.isEmpty(mJob.id)) {
        Message message = Message.obtain(mHandler, this::stopSync);
        message.what = Integer.valueOf(mJob.id);
        mHandler.sendMessageDelayed(message, TIMEOUT_MILLIS);
        mSyncProgress = new SyncProgress(mJob);
        sync(mJob.id);
    } else {
        syncDeferredItems();
    }
}

From source file:ch.luklanis.esscan.history.HistoryActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.history_menu_send_dta_save:
    case R.id.history_menu_send_dta_other:
    case R.id.history_menu_send_dta_email: {
        Message message = Message.obtain(mDataSentHandler, item.getItemId());
        createDTAFile(message);/*w w  w.  j  a v  a 2  s  .  c  om*/
    }
        break;
    case R.id.history_menu_send_csv: {
        CharSequence history = mHistoryManager.buildHistory();
        Uri historyFile = HistoryManager.saveHistory(history.toString());

        String[] recipients = new String[] { PreferenceManager.getDefaultSharedPreferences(this)
                .getString(PreferencesActivity.KEY_EMAIL_ADDRESS, "") };

        if (historyFile == null) {
            setOkAlert(R.string.msg_unmount_usb);
        } else {
            Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            intent.putExtra(Intent.EXTRA_EMAIL, recipients);
            String subject = getResources().getString(R.string.history_email_title);
            intent.putExtra(Intent.EXTRA_SUBJECT, subject);
            intent.putExtra(Intent.EXTRA_TEXT, subject);
            intent.putExtra(Intent.EXTRA_STREAM, historyFile);
            intent.setType("text/csv");
            startActivity(intent);
        }
    }
        break;
    case R.id.history_menu_clear: {
        new CancelOkDialog(R.string.msg_sure).setOkClickListener(new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                mHistoryManager.clearHistory();
                dialogInterface.dismiss();
                finish();
            }
        }).show(getFragmentManager(), "HistoryActivity.onOptionsItemSelected");
    }
        break;
    case android.R.id.home: {

        int error = PsDetailActivity.savePaymentSlip(this);

        if (error > 0) {
            setCancelOkAlert(this, error);
            return true;
        }

        NavUtils.navigateUpTo(this, new Intent(this, CaptureActivity.class));
        return true;
    }
    case R.id.history_menu_copy_code_row: {
        PsDetailFragment fragment = (PsDetailFragment) getFragmentManager()
                .findFragmentById(R.id.ps_detail_container);

        if (fragment != null) {
            String completeCode = fragment.getHistoryItem().getResult().getCompleteCode();

            addCodeRowToClipboard(completeCode);
        }
    }
        break;
    case R.id.history_menu_send_code_row: {
        PsDetailFragment fragment = (PsDetailFragment) getFragmentManager()
                .findFragmentById(R.id.ps_detail_container);

        if (fragment != null) {
            IEsrSender sender = getEsrSender();

            if (sender != null) {
                mSendingProgressDialog.show();

                fragment.send(PsDetailFragment.SEND_COMPONENT_CODE_ROW, sender,
                        this.historyFragment.getActivatedPosition());
            } else {
                Message message = Message.obtain(mDataSentHandler, R.id.es_send_failed);
                message.sendToTarget();
            }
        }
    }
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:net.named_data.nfd.MainFragment.java

/**
 * Convenience method to send a message to the NfdService
 * through a Messenger.//w  w  w. j a v  a2 s .co m
 *
 * @param message Message from a set of predefined NfdService messages.
 */
private void sendNfdServiceMessage(int message) {
    if (m_nfdServiceMessenger == null) {
        G.Log("NfdService not yet connected");
        return;
    }
    try {
        Message msg = Message.obtain(null, message);
        msg.replyTo = m_clientMessenger;
        m_nfdServiceMessenger.send(msg);
    } catch (RemoteException e) {
        // If Service crashes, nothing to do here
        G.Log("Service Disconnected: " + e);
    }
}