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:com.android.mms.ui.MessageListItem.java

private void sendMessage(MessageItem messageItem, int message) {
    if (mHandler != null) {
        Message msg = Message.obtain(mHandler, message);
        msg.obj = messageItem;/*from   w w w . jav a2s. c om*/
        msg.sendToTarget(); // See ComposeMessageActivity.mMessageListItemHandler.handleMessage
    }
}

From source file:org.navitproject.navit.Navit.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case Navit.NavitDownloaderSelectMap_id:
        if (resultCode == Activity.RESULT_OK) {
            Message msg = dialogs.obtainMessage(NavitDialogs.MSG_START_MAP_DOWNLOAD,
                    data.getIntExtra("map_index", -1), 0);
            msg.sendToTarget();/*from  ww w  .  j  a  va2  s  .co m*/
        }
        break;
    case NavitAddressSearch_id:
        if (resultCode == Activity.RESULT_OK) {
            Bundle destination = data.getExtras();
            Toast.makeText(getApplicationContext(),
                    getString(R.string.address_search_set_destination) + "\n" + destination.getString(("q")),
                    Toast.LENGTH_LONG).show(); //TRANS

            Message msg = Message.obtain(N_NavitGraphics.callback_handler,
                    NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal());
            msg.setData(destination);
            msg.sendToTarget();
        }
        break;
    case NavitSelectStorage_id:
        if (resultCode == RESULT_OK) {
            String newDir = data.getStringExtra(FileBrowserActivity.returnDirectoryParameter);
            Log.d(TAG, "selected path= " + newDir);
            if (!newDir.contains("/navit"))
                newDir = newDir + "/navit/";
            else
                newDir = newDir + "/";
            SharedPreferences prefs = this.getSharedPreferences(NAVIT_PREFS, MODE_PRIVATE);
            SharedPreferences.Editor prefs_editor = prefs.edit();
            prefs_editor.putString("filenamePath", newDir);
            prefs_editor.commit();
            Toast.makeText(this, String
                    .format(Navit._("New location set to %s\nRestart Navit to apply the changes."), newDir),
                    Toast.LENGTH_LONG).show();
        } else
            Log.w(TAG, "select path failed");
        break;
    default:
        //Log.e("Navit", "onActivityResult " + requestCode + " " + resultCode);
        ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data);
        break;
    }
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

/**
 * Sets the graph mode representation./*from  w w  w  . j  a v a  2  s . c  o  m*/
 * @see {@link #GRAPH_MODE_BARS}
 * @see {@link #GRAPH_MODE_BARS_STACK}
 * @see {@link #GRAPH_MODE_BARS_SIDE_BY_SIDE}
 */
public void setGraphMode(int mode) {
    if (mode != mGraphMode) {
        mGraphMode = mode;
        Message.obtain(mBackgroundHandler, MSG_COMPUTE_DATA).sendToTarget();
    }
}

From source file:tv.piratemedia.flightcontroller.BluetoothComputerFragment.java

@Override
public void run() {
    int ret = 0;//from w  ww .  j a v a2  s .  c  om
    byte[] buffer = new byte[16384];
    int i;

    while (ret >= 0) {
        try {
            ret = mInputStream.read(buffer);
        } catch (IOException e) {
            break;
        }

        i = 0;
        while (i < ret) {
            int len = ret - i;

            switch (buffer[i]) {
            case 0x1:
                if (len >= 2) {
                    Message m = Message.obtain(mHandler, LED_STATE);
                    m.obj = buffer[i + 1] == 0x1;
                    //mHandler.sendMessage(m);
                }
                i += 2;
                break;
            case 0x2:
                if (len >= 2) {
                    Message m = Message.obtain(mHandler, LED_HUE);
                    m.obj = (float) buffer[i + 1] / 0.708f;
                    //mHandler.sendMessage(m);
                }
                i += 2;
            }
        }

    }
}

From source file:com.nuvolect.securesuite.main.ContactListActivity.java

/**
 * Stops the communications framework.// w ww  . jav  a  2s .c  om
 */
void doUnbindService() {

    if (mIsBound) {
        // If we have received the service, and hence registered with
        // it, then now is the time to unregister.
        if (mService != null) {
            try {
                Message msg = Message.obtain(null, WorkerService.MSG_UNREGISTER_CLIENT);
                msg.replyTo = mMessenger;
                mService.send(msg);
            } catch (RemoteException e) {
                // There is nothing special we need to do if the service has crashed
            }
        }
        // Detach our existing connection.
        unbindService(mConnection);
        mIsBound = false;
    }
}

From source file:ac.robinson.bettertogether.hotspot.HotspotManagerService.java

@SuppressFBWarnings("ANDROID_BROADCAST")
private void sendBroadcastMessageToAllLocalClients(BroadcastMessage msg) {
    for (int i = mClients.size() - 1; i >= 0; i--) {
        try {/*from   ww w. j  a  v  a2  s  . c om*/
            // local directly connected activities (i.e., ours)
            Messenger client = mClients.get(i);
            Message message = Message.obtain(null, MSG_BROADCAST);
            message.replyTo = mMessenger;
            Bundle bundle = new Bundle(1);
            bundle.putSerializable(PluginIntent.KEY_BROADCAST_MESSAGE, msg);
            message.setData(bundle);
            client.send(message);

            // local unconnected activities (i.e., plugins)
            Log.d(TAG,
                    "Sending broadcast message to all local clients with package "
                            + mConnectionOptions.mPluginPackage + " - type: " + msg.getType() + ", message: "
                            + msg.getMessage());
            Intent broadcastIntent = new Intent(PluginIntent.ACTION_MESSAGE_RECEIVED);
            broadcastIntent.setClassName(mConnectionOptions.mPluginPackage, PluginIntent.MESSAGE_RECEIVER);
            // TODO: source is only necessary for internal plugins - remove later?
            broadcastIntent.putExtra(PluginIntent.EXTRA_SOURCE, HotspotManagerService.this.getPackageName());
            broadcastIntent.putExtra(PluginIntent.KEY_BROADCAST_MESSAGE, msg);
            sendBroadcast(broadcastIntent);
        } catch (RemoteException e) {
            e.printStackTrace();
            mClients.remove(i); // client is dead - ok to remove here as we're reversing through the list
        }
    }
}

From source file:com.justone.android.main.MainActivity.java

/** 
*  //from ww  w.  java  2 s  .  com
*/
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

    /*System.out.println(this.tabs.getCurrentView().getLayoutDirection());
    System.out.println(R.layout.home_item);
    System.out.println(this.tabs.getCurrentView().getId());
    System.out.println(R.id.homeScrollView);
    System.out.println(this.tabs.getCurrentTab());
    System.out.println(this.homeListView.getId());
    int currentViewId = this.tabs.getCurrentView().getId();
    */
    if (e1.getX() - e2.getX() < -200) {

        if (currentId == maxId || currentId == 0) {
            viewHandler.sendMessage(Message.obtain(viewHandler, 2));
        } else {
            this.leftOrRight = 2;
            this.isUpdate = true;
        }

    } else if (e1.getX() - e2.getX() > 200) {

        if (currentId == 1)
            viewHandler.sendMessage(Message.obtain(viewHandler, 3));
        else {
            this.leftOrRight = 1;
            this.isUpdate = true;
        }

    }
    return true;
}

From source file:ac.robinson.bettertogether.hotspot.HotspotManagerService.java

private void sendSystemMessageToAllLocalClients(int type, String data) {
    for (int i = mClients.size() - 1; i >= 0; i--) {
        try {//from w w  w .  j  a  va  2 s .  co m
            Messenger client = mClients.get(i);
            Message message = Message.obtain(null, type);
            message.replyTo = mMessenger;
            if (data != null) {
                Bundle bundle = new Bundle(1);
                bundle.putString(PluginIntent.KEY_SERVICE_MESSAGE, data);
                message.setData(bundle);
            }
            client.send(message);
        } catch (RemoteException e) {
            e.printStackTrace();
            mClients.remove(i); // client is dead - ok to remove here as we're reversing through the list
        }
    }
}

From source file:com.androzic.Androzic.java

private void updateCoveringMaps() {
    if (mapsHandler.hasMessages(1))
        mapsHandler.removeMessages(1);/*www .  ja v a 2 s.c om*/

    Message m = Message.obtain(mapsHandler, new Runnable() {
        @Override
        public void run() {
            Log.d(TAG, "updateCoveringMaps()");
            Bounds area = new Bounds();
            int[] xy = new int[2];
            double[] ll = new double[2];
            currentMap.getXYByLatLon(mapCenter[0], mapCenter[1], xy);
            currentMap.getLatLonByXY(xy[0] + (int) coveringScreen.left, xy[1] + (int) coveringScreen.top, ll);
            area.maxLat = ll[0];
            area.minLon = ll[1];
            currentMap.getLatLonByXY(xy[0] + (int) coveringScreen.right, xy[1] + (int) coveringScreen.bottom,
                    ll);
            area.minLat = ll[0];
            area.maxLon = ll[1];
            area.fix();
            List<BaseMap> cmr = new ArrayList<>();
            if (coveringMaps != null)
                cmr.addAll(coveringMaps);
            List<BaseMap> cma = maps.getCoveringMaps(currentMap, area, coveredAll, coveringBestMap);
            Iterator<BaseMap> icma = cma.iterator();
            while (icma.hasNext()) {
                BaseMap map = icma.next();
                Log.i(TAG, "-> " + map.title);
                try {
                    if (!map.activated())
                        map.activate(mapHolder, currentMap.getMPP(), false);
                    else
                        map.zoomTo(currentMap.getMPP());
                    cmr.remove(map);
                } catch (Throwable e) {
                    icma.remove();
                    e.printStackTrace();
                }
            }
            synchronized (Androzic.this) {
                for (BaseMap map : cmr) {
                    if (map != currentMap)
                        map.deactivate();
                }
                coveringMaps = cma;
                invalidCoveringMaps = false;
            }
            if (mapHolder != null)
                mapHolder.refreshMap();
        }
    });
    m.what = 1;
    mapsHandler.sendMessage(m);
}

From source file:com.google.android.apps.santatracker.launch.StartupActivity.java

private void unregisterFromService() {
    if (mIsBound) {
        if (mService != null) {
            Message msg = Message.obtain(null, SantaServiceMessages.MSG_SERVICE_UNREGISTER_CLIENT);
            msg.replyTo = mMessenger;/*from www  . j av  a 2 s. com*/
            try {
                mService.send(msg);
            } catch (RemoteException e) {
                // ignore if service is not available
            }
        }
        unbindService(mConnection);
        mIsBound = false;
    }
}