Example usage for android.os Message setData

List of usage examples for android.os Message setData

Introduction

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

Prototype

public void setData(Bundle data) 

Source Link

Document

Sets a Bundle of arbitrary data values.

Usage

From source file:com.zia.freshdocs.widget.CMISAdapter.java

/**
 * Download the content for the given NodeRef
 * @param ref/*from www  .  jav  a 2  s.  co  m*/
 * @param handler
 */
protected void downloadContent(final NodeRef ref, final Handler handler) {
    startProgressDlg(false);
    _progressDlg.setMax(Long.valueOf(ref.getContentLength()).intValue());

    _dlThread = new ChildDownloadThread(handler, new Downloadable() {
        public Object execute() {
            File f = null;

            try {
                CMISApplication app = (CMISApplication) getContext().getApplicationContext();
                URL url = new URL(ref.getContent());
                String name = ref.getName();
                long fileSize = ref.getContentLength();
                f = app.getFile(name, fileSize);

                if (f != null && f.length() != fileSize) {
                    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

                    FileOutputStream fos = new FileOutputStream(f);
                    InputStream is = _cmis.get(url.getPath());

                    byte[] buffer = new byte[BUF_SIZE];
                    int len = is.read(buffer);
                    int total = len;
                    Message msg = null;
                    Bundle b = null;

                    while (len != -1) {
                        msg = handler.obtainMessage();
                        b = new Bundle();
                        b.putInt("progress", total);
                        msg.setData(b);
                        handler.sendMessage(msg);

                        fos.write(buffer, 0, len);
                        len = is.read(buffer);
                        total += len;

                        if (Thread.interrupted()) {
                            fos.close();
                            f = null;
                            throw new InterruptedException();
                        }
                    }

                    fos.flush();
                    fos.close();
                }
            } catch (Exception e) {
                Log.e(CMISAdapter.class.getSimpleName(), "", e);
            }

            return f;
        }
    });
    _dlThread.start();
}

From source file:org.openbmap.activities.HostActivity.java

/**
 * Starts GPX tracking./*from   ww  w  . j a v a  2 s .c  o m*/
 * @return false on error, otherwise true
 */
public final boolean requestGpxTracking() {
    // TODO check whether services have already been connected (i.e. received MSG_SERVICE_READY signal)
    Log.d(TAG, "Requesting gpx tracking");
    try {
        if (mPositionServiceManager == null) {
            Log.w(TAG, "gpsPositionServiceManager is null. No message will be sent");
            return false;
        }

        final int session = mDataHelper.getActiveSessionId();

        if (session == RadioBeacon.SESSION_NOT_TRACKING) {
            Log.e(TAG, "Couldn't start tracking, no active session");
            return false;
        }

        Log.d(TAG, "Resuming session " + session);

        final Bundle aSessionIdBundle = new Bundle();
        aSessionIdBundle.putInt(RadioBeacon.MSG_KEY, session);

        final Message msgGpsUp = new Message();
        msgGpsUp.what = RadioBeacon.MSG_START_TRACKING;
        msgGpsUp.setData(aSessionIdBundle);

        mPositionServiceManager.sendAsync(msgGpsUp);

        return true;
    } catch (final RemoteException e) {
        // service communication failed
        e.printStackTrace();
        return false;
    } catch (final NumberFormatException e) {
        e.printStackTrace();
        return false;
    } catch (final Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.openbmap.activities.HostActivity.java

/**
 * Starts broadcasting GPS position./*  ww  w . j a v a2 s .com*/
 * @param provider
 * @return false on error, otherwise true
 */
public final boolean requestPositionUpdates(final State provider) {
    // TODO check whether services have already been connected (i.e. received MSG_SERVICE_READY signal)
    Log.d(TAG, "Requesting position updates");
    try {
        if (mPositionServiceManager == null) {
            Log.w(TAG, "gpsPositionServiceManager is null. No message will be sent");
            return false;
        }

        final int session = mDataHelper.getActiveSessionId();

        if (session == RadioBeacon.SESSION_NOT_TRACKING) {
            Log.e(TAG, "Couldn't start tracking, no active session");
            return false;
        }

        final Bundle aProviderBundle = new Bundle();
        aProviderBundle.putString("provider", provider.toString());

        final Message msgGpsUp = new Message();
        msgGpsUp.what = RadioBeacon.MSG_START_TRACKING;
        msgGpsUp.setData(aProviderBundle);

        mPositionServiceManager.sendAsync(msgGpsUp);

        // update recording indicator
        //((StatusBar) findViewById(R.id.gpsStatus)).manageRecordingIndicator(true);

        updateUI();
        mSelectedProvider = provider;
        return true;
    } catch (final RemoteException e) {
        // service communication failed
        e.printStackTrace();
        return false;
    } catch (final NumberFormatException e) {
        e.printStackTrace();
        return false;
    } catch (final Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.openbmap.activities.HostActivity.java

/**
 * Starts wireless tracking.//w  w  w .j  a  va 2 s.c  o  m
 * @return false on error, otherwise true
 */
public final boolean requestWirelessUpdates() {
    // TODO check whether services have already been connected (i.e. received MSG_SERVICE_READY signal)
    Log.d(TAG, "Requesting wireless updates");
    try {
        if (mWirelessServiceManager == null) {
            Log.w(TAG, "wirelessServiceManager is null. No message will be sent");
            return false;
        }

        final int session = mDataHelper.getActiveSessionId();

        if (session == RadioBeacon.SESSION_NOT_TRACKING) {
            Log.e(TAG, "Couldn't start tracking, no active session");
            return false;
        }

        final Bundle aSessionIdBundle = new Bundle();
        aSessionIdBundle.putInt(RadioBeacon.MSG_KEY, session);

        final Message msgWirelessUp = new Message();
        msgWirelessUp.what = RadioBeacon.MSG_START_TRACKING;
        msgWirelessUp.setData(aSessionIdBundle);

        mWirelessServiceManager.sendAsync(msgWirelessUp);

        updateUI();
        return true;
    } catch (final RemoteException e) {
        // service communication failed
        e.printStackTrace();
        return false;
    } catch (final NumberFormatException e) {
        e.printStackTrace();
        return false;
    } catch (final Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:com.yangtsaosoftware.pebblemessenger.services.MessageProcessingService.java

@Override
public void onCreate() {
    super.onCreate();
    phone_is_ontalking = false;/*from   w  ww. java  2s  .  com*/
    loadPrefs();
    Thread proceedthread = new ProcessThread();
    proceedthread.start();
    messageHandler = new MessageHandler(Looper.getMainLooper());
    mMessenger = new Messenger(messageHandler);
    MessageProcessingService._context = getApplicationContext();
    fdb = new FontDbHandler(_context);
    fdb.open();
    mdb = new MessageDbHandler(_context);
    mdb.open();
    bindService(new Intent(this, PebbleCenter.class), connToPebbleCenter, Context.BIND_AUTO_CREATE);
    BroadcastReceiver br = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            int command = intent.getIntExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_PREFER_CHANGED);
            switch (command) {
            case Constants.BROADCAST_PREFER_CHANGED:
                loadPrefs();
                break;
            case Constants.BROADCAST_CALL_INCOMING:
                String number = intent.getStringExtra(Constants.BROADCAST_PHONE_NUM);
                String name = intent.getStringExtra(Constants.BROADCAST_NAME);

                if (callQuietEnable) {
                    Calendar c = Calendar.getInstance();
                    Calendar now = new GregorianCalendar(0, 0, 0, c.get(Calendar.HOUR_OF_DAY),
                            c.get(Calendar.MINUTE));
                    Constants.log(TAG_NAME, "Checking quiet hours. Now: " + now.toString() + " vs "
                            + quiet_hours_before.toString() + " and " + quiet_hours_after.toString());
                    if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) {
                        Constants.log(TAG_NAME, "Time is before or after the quiet hours time. Returning.");
                        addNewCall(number, name, MessageDbHandler.NEW_ICON);
                    } else {
                        Bundle b = new Bundle();
                        b.putLong(MessageDbHandler.COL_CALL_ID,
                                addNewCall(number, name, MessageDbHandler.OLD_ICON));
                        b.putString(MessageDbHandler.COL_CALL_NUMBER, number);
                        b.putString(MessageDbHandler.COL_CALL_NAME, name);
                        Message innerMsg = processHandler.obtainMessage(INNER_CALL_PROCEED);
                        innerMsg.setData(b);
                        processHandler.sendMessage(innerMsg);
                    }
                } else {
                    Bundle b = new Bundle();
                    if (phone_is_ontalking) {
                        b.putString(MessageDbHandler.COL_MESSAGE_APP, "Call");
                        b.putString(MessageDbHandler.COL_MESSAGE_CONTENT, name + "\n" + number);
                        addNewCall(number, name, MessageDbHandler.NEW_ICON);
                        b.putLong(MessageDbHandler.COL_MESSAGE_ID, addNewMessage(b, MessageDbHandler.OLD_ICON));
                        Message innerMsg = processHandler.obtainMessage(INNER_MESSAGE_PROCEED);
                        innerMsg.setData(b);
                        processHandler.sendMessage(innerMsg);
                    } else {
                        b.putLong(MessageDbHandler.COL_CALL_ID,
                                addNewCall(number, name, MessageDbHandler.OLD_ICON));
                        b.putString(MessageDbHandler.COL_CALL_NUMBER, number);
                        b.putString(MessageDbHandler.COL_CALL_NAME, name);
                        Message innerMsg = processHandler.obtainMessage(INNER_CALL_PROCEED);
                        innerMsg.setData(b);
                        processHandler.sendMessage(innerMsg);
                    }
                }
                break;
            case Constants.BROADCAST_CALL_HOOK:
                phone_is_ontalking = true;
                break;
            case Constants.BROADCAST_CALL_IDLE:
                phone_is_ontalking = false;
                break;
            case Constants.BROADCAST_SMS_INCOMING: {
                Message msg = Message.obtain();
                msg.what = MSG_NEW_MESSAGE;
                Bundle b = new Bundle();
                b.putString(MessageDbHandler.COL_MESSAGE_APP, "SMS");
                b.putString(MessageDbHandler.COL_MESSAGE_CONTENT,
                        intent.getStringExtra(Constants.BROADCAST_SMS_BODY));
                msg.setData(b);
                messageHandler.sendMessage(msg);
            }
            }
        }
    };
    IntentFilter intentFilter = new IntentFilter(MessageProcessingService.class.getName());
    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(br, intentFilter);

}

From source file:de.androvdr.activities.AndroVDR.java

public void initWorkspaceView(Bundle savedInstanceState) {
    if (!Preferences.alternateLayout)
        setTheme(R.style.Theme_Original);

    logger.debug("Model: {}", Build.MODEL);
    logger.debug("SDK Version: {}", Build.VERSION.SDK_INT);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    logger.debug("Width: {}", metrics.widthPixels);
    logger.debug("Height: {}", metrics.heightPixels);
    logger.debug("Density: {}", metrics.densityDpi);

    Configuration conf = getResources().getConfiguration();
    boolean screenSmall = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_SMALL) == Configuration.SCREENLAYOUT_SIZE_SMALL);
    boolean screenNormal = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_NORMAL) == Configuration.SCREENLAYOUT_SIZE_NORMAL);
    boolean screenLong = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_LONG_YES) == Configuration.SCREENLAYOUT_LONG_YES);
    boolean screenLarge = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_LARGE) == Configuration.SCREENLAYOUT_SIZE_LARGE);
    boolean screenXLarge = ((conf.screenLayout
            & Configuration.SCREENLAYOUT_SIZE_XLARGE) == Configuration.SCREENLAYOUT_SIZE_XLARGE);

    logger.debug("Screen Small: {}", screenSmall);
    logger.debug("Screen Normal: {}", screenNormal);
    logger.debug("Screen Long: {}", screenLong);
    logger.debug("Screen Large: {}", screenLarge);
    logger.debug("Screen XLarge: {}", screenXLarge);

    if (screenSmall)
        Preferences.screenSize = Preferences.SCREENSIZE_SMALL;
    if (screenNormal)
        Preferences.screenSize = Preferences.SCREENSIZE_NORMAL;
    if (screenLong)
        Preferences.screenSize = Preferences.SCREENSIZE_LONG;
    if (screenLarge)
        Preferences.screenSize = Preferences.SCREENSIZE_LARGE;
    if (screenXLarge)
        Preferences.screenSize = Preferences.SCREENSIZE_XLARGE;
    logger.trace("Screen size: {}", Preferences.screenSize);

    // --- init default text size for buttons ---
    TextResizeButton.resetDefaultTextSize();
    TextResizeButton rb = (TextResizeButton) LayoutInflater.from(this).inflate(R.layout.reference_button, null);
    if ((Preferences.screenSize >= Preferences.SCREENSIZE_LARGE)
            && (metrics.widthPixels > metrics.heightPixels))
        rb.setTextSizeAsDefault(metrics.widthPixels / 2 / 5, 100);
    else/*from   w  w  w.j  a  v a 2  s . c o m*/
        rb.setTextSizeAsDefault(Math.min(metrics.widthPixels, metrics.heightPixels) / 4, 100);
    logger.debug("Default TextSize (px): {}", rb.getTextSize());

    // --- landscape mode only on large displays ---
    if (Preferences.screenSize < Preferences.SCREENSIZE_LARGE) {
        logger.trace("setting SCREEN_ORIENTATION_PORTRAIT");
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    setContentView(R.layout.remote_pager);
    mPagerAdapter = new PagerAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);

    LinePageIndicator indicator = (LinePageIndicator) findViewById(R.id.titles);
    if (mPagerAdapter.getCount() > 1) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        int last = sp.getInt("remote_last_page", 0);
        if (last < mPagerAdapter.getCount())
            indicator.setViewPager(mPager, last);
        else
            indicator.setViewPager(mPager);
    } else {
        indicator.setVisibility(View.GONE);
    }

    // --- show current channel in status bar ---
    if (Preferences.screenSize < Preferences.SCREENSIZE_XLARGE)
        mDevices.addOnSensorChangeListener("VDR.channel", 1, new OnSensorChangeListener() {
            @Override
            public void onChange(String result) {
                logger.trace("Channel: {}", result);
                Message msg = Message.obtain(mSensorHandler, SENSOR_CHANNEL);
                Bundle bundle = new Bundle();
                bundle.putString(MSG_RESULT, result);
                msg.setData(bundle);
                msg.sendToTarget();
            }
        });

    mDevices.startSensorUpdater(0);
}

From source file:com.cttapp.bby.mytlc.layer8apps.CalendarHandler.java

/************
 *  PURPOSE: Used to send our errors back to the main thread
 *  ARGUMENTS: String error/*from   w  w  w  . j  av  a  2 s  .c o  m*/
 *  RETURNS: VOID
 *  AUTHOR: Devin Collins <agent14709@gmail.com>
 *************/
private void showError(String error) {
    Message msg = Message.obtain();
    Bundle data = new Bundle();
    data.putString("status", "ERROR");
    data.putString("error", error);
    msg.setData(data);
    try {
        messenger.send(msg);
    } catch (Exception e) {
        // TODO: Error reporting?
    }
}

From source file:org.ymkm.lib.controller.support.ControlledDialogFragment.java

@Override
public void onPause() {
    super.onPause();
    if (null != mControllerMessenger) {
        Message m = Message.obtain();
        m.what = FragmentController.MSG_DETACH_MESSAGE;
        m.arg1 = getControlId();/*from  ww w  . j  a v a 2s .  co  m*/
        m.obj = this;
        Bundle b = new Bundle();
        b.putString("controllableName", mControllableName);
        m.setData(b);
        try {
            mControllerMessenger.send(m);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
    mControllerMessenger = null;
}

From source file:com.android.kalite27.ScriptActivity.java

private void sendmsg(String key, String value) {
    Message message = installerHandler.obtainMessage();
    Bundle bundle = new Bundle();
    bundle.putString(key, value);/*from  w  w  w  .jav  a2s  . co  m*/
    message.setData(bundle);
    installerHandler.sendMessage(message);
}

From source file:org.ymkm.lib.controller.support.ControlledDialogFragment.java

@Override
public void onResume() {
    super.onResume();
    Activity activity = getActivity();//from ww w  .ja v  a 2s. co  m
    if (activity instanceof ControllableActivity) {
        FragmentController controller = ((ControllableActivity) activity).getController();
        mControllerMessenger = controller.getMessenger();
    }

    if (null != mControllerMessenger) {
        Message m = Message.obtain();
        m.what = FragmentController.MSG_ATTACH_MESSAGE;
        m.arg1 = getControlId();
        m.obj = this;
        Bundle b = new Bundle();
        b.putString("controllableName", mControllableName);
        m.setData(b);
        try {
            mControllerMessenger.send(m);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}