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() 

Source Link

Document

Return a new Message instance from the global pool.

Usage

From source file:com.adjust.sdk.PackageHandler.java

@Override
public void addPackage(ActivityPackage pack) {
    Message message = Message.obtain();
    message.arg1 = InternalHandler.ADD;
    message.obj = pack;
    internalHandler.sendMessage(message);
}

From source file:com.ds.kaixin.GetFriendListTask.java

@SuppressWarnings("unchecked")
protected Integer doInBackground(Object... params) {
    if (params == null || params.length == 0 || params.length != 6) {
        handler.sendEmptyMessage(Constant.RESULT_FAILED_ARG_ERR);
        return 0;
    }/*from w  w w.  ja va 2  s .co  m*/

    String start = (String) params[0];
    String number = (String) params[1];
    Kaixin kaixin = (Kaixin) params[2];
    handler = (Handler) params[3];
    resultContainer = (ArrayList<FriendInfo>) params[4];
    Context context = (Context) params[5];

    Bundle bundle = new Bundle();
    bundle.putString("start", start);
    bundle.putString("num", number);
    bundle.putString("fields", "uid,name,gender,logo50,birthday");

    try {
        String jsonResult = kaixin.request(context, RESTAPI_INTERFACE_GETFRIENDLIST, bundle, "GET");
        if (jsonResult == null) {
            handler.sendEmptyMessage(Constant.RESULT_FAILED_NETWORK_ERR);
        } else {
            KaixinError kaixinError = Util.parseRequestError(jsonResult);
            if (kaixinError != null) {
                Message msg = Message.obtain();
                msg.what = Constant.RESULT_FAILED_REQUEST_ERR;
                msg.obj = kaixinError;
                handler.sendMessage(msg);
            } else {
                ArrayList<FriendInfo> friendList = getFriendInfos(jsonResult);
                if (null != friendList) {
                    resultContainer.addAll(friendList);
                }
                if (resultContainer.size() > 0) {
                    handler.sendEmptyMessage(Constant.RESULT_GET_FRIENDS_OK);
                } else {
                    handler.sendEmptyMessage(Constant.RESULT_GET_FRIENDS_ZERO);
                }
            }
        }
    } catch (MalformedURLException e1) {
        Log.e(TAG, "", e1);
        handler.sendEmptyMessage(Constant.RESULT_FAILED_MALFORMEDURL_ERR);
    } catch (JSONException e1) {
        Log.e(TAG, "", e1);
        handler.sendEmptyMessage(Constant.RESULT_FAILED_JSON_PARSE_ERR);
    } catch (IOException e1) {
        Log.e(TAG, "", e1);
        handler.sendEmptyMessage(Constant.RESULT_FAILED_NETWORK_ERR);
    } catch (Exception e1) {
        Log.e(TAG, "", e1);
        handler.sendEmptyMessage(Constant.RESULT_FAILED);
    }

    return 1;
}

From source file:com.fishstix.dosboxfree.ButtonLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);//((action & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT);
    final int pId = ev.getPointerId(pointerIndex) + 1;
    KeyEvent evt = null;/*  w ww  . j a  va2s .c o  m*/
    Message msg = Message.obtain();
    msg.what = DBMain.HANDLER_SEND_KEYCODE;
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN: {
        Log.i("DosBoxTurbo", "button onDown()");
        int x = (int) ev.getX(pointerIndex);//(int) mWrap.getX(ev,pointerIndex);
        int width = getWidth();
        //int y = (int) mWrap.getY(ev,pointerIndex);
        float val = ((float) x / (float) width) * 4f;
        if (val < 1.0) {
            // first button
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_A) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_A);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_A);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_A;
            mDBLauncher.bButtonA.setBackgroundColor(0x80FF0000);
        } else if (val < 2.0) {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_B) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_B);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_B);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_B;
            mDBLauncher.bButtonB.setBackgroundColor(0x80FF0000);
        } else if (val < 3.0) {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_C) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_C);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_C);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_C;
            mDBLauncher.bButtonC.setBackgroundColor(0x80FF0000);
        } else {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_D) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_D);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_D);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_D;
            mDBLauncher.bButtonD.setBackgroundColor(0x80FF0000);
        }
        msg.obj = evt;
        msg.arg1 = 0;
        mDBLauncher.mSurfaceView.virtButton[pointerIndex] = true;
        mDBLauncher.mSurfaceView.mFilterLongClick = true; // prevent long click listener from getting in the way
        mDBLauncher.mHandler.sendMessage(msg);
        return true;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP: {
        Log.i("DosBoxTurbo", "button onUp()");
        msg.arg2 = virtualbutton_hm.get(pId);
        switch (msg.arg2) {
        case HardCodeWrapper.KEYCODE_VIRTUAL_A:
            mDBLauncher.bButtonA.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_B:
            mDBLauncher.bButtonB.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_C:
            mDBLauncher.bButtonC.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_D:
            mDBLauncher.bButtonD.setBackgroundColor(0x80FFFF00);
            break;
        }
        virtualbutton_hm.delete(pId);
        if (msg.arg2 == 0)
            return false;
        evt = new KeyEvent(action, msg.arg2);
        msg.obj = evt;
        msg.arg1 = 1;
        mDBLauncher.mSurfaceView.virtButton[pointerIndex] = false;
        mDBLauncher.mSurfaceView.mFilterLongClick = false;
        mDBLauncher.mHandler.sendMessage(msg);
        return true;
    }
    }
    return false;
}

From source file:com.commonsware.android.tuning.downloader.Downloader.java

@Override
public void onHandleIntent(Intent i) {
    HttpGet getMethod = new HttpGet(i.getData().toString());
    int result = Activity.RESULT_CANCELED;

    try {//  www.  j av  a 2  s .  c om
        ResponseHandler<byte[]> responseHandler = new ByteArrayResponseHandler();
        byte[] responseBody = client.execute(getMethod, responseHandler);
        File output = new File(Environment.getExternalStorageDirectory(), i.getData().getLastPathSegment());

        if (output.exists()) {
            output.delete();
        }

        FileOutputStream fos = new FileOutputStream(output.getPath());

        fos.write(responseBody);
        fos.close();
        result = Activity.RESULT_OK;
    } catch (IOException e2) {
        Log.e(getClass().getName(), "Exception in download", e2);
    }

    Bundle extras = i.getExtras();

    if (extras != null) {
        Messenger messenger = (Messenger) extras.get(EXTRA_MESSENGER);
        Message msg = Message.obtain();

        msg.arg1 = result;

        try {
            messenger.send(msg);
        } catch (android.os.RemoteException e1) {
            Log.w(getClass().getName(), "Exception sending message", e1);
        }
    }
}

From source file:com.adjust.sdk.PackageHandler.java

@Override
public void sendFirstPackage() {
    Message message = Message.obtain();
    message.arg1 = InternalHandler.SEND_FIRST;
    internalHandler.sendMessage(message);
}

From source file:net.carlh.toast.State.java

private void changed(int p) {
    for (Handler h : handlers) {
        Message m = Message.obtain();
        Bundle b = new Bundle();
        b.putInt("property", p);
        m.setData(b);//from  w  w w . j av  a  2  s.c  om
        h.sendMessage(m);
    }
}

From source file:org.zywx.wbpalmstar.plugin.uexCalendarView.EUExCalendarView.java

private void sendMessageInProgress(int msgType, String[] params) {
    if (mHandler == null) {
        return;/*from   w  w w. jav a 2 s.c  o  m*/
    }
    Message msg = Message.obtain();
    msg.what = msgType;
    msg.obj = this;
    Bundle b = new Bundle();
    b.putStringArray(ECalendarViewUtils.CALENDAR_PARAMS_KEY_FUNCTION, params);
    msg.setData(b);
    mHandler.sendMessage(msg);
}

From source file:com.example.cuisoap.agrimac.homePage.demand.machineSelectDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
    View view = inflater.inflate(R.layout.dialog_select_machine, container);
    list = (ListView) view.findViewById(R.id.machine_select_list);
    adapter = new machineSelectAdapter(mContext);
    data = new ArrayList<>();
    list.setAdapter(adapter);/* ww w  .j av a 2s .c  om*/
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            JSONObject jo = new JSONObject();
            HashMap<String, String> item = (HashMap<String, String>) adapter.getItem(position);
            Intent i = new Intent();
            i.setAction("select_machine");
            i.putExtra("id", item.get("id"));
            i.putExtra("name", item.get("machine_name"));
            mContext.sendBroadcast(i);
            dismiss();
        }
    });
    Message m = Message.obtain();
    JSONObject o = new JSONObject();
    try {
        o.put("status", 0);
        JSONArray oo = new JSONArray("[{\n" + "    \"driveType\": \"\",\n"
                + "    \"driverName\": \"p\",\n" + "    \"driverAge\": \"p\",\n"
                + "    \"driverGender\": \"female\",\n" + "    \"driverLicenseType\": \"R\",\n"
                + "    \"driverLicense\": \"/sdcard/agrimac/driver2016_05_31_09_38_15.png\",\n"
                + "    \"machineType\": \"\",\n" + "    \"machineName\": \"p\",\n"
                + "    \"machinePower\": \"1\",\n" + "    \"passengerNum\": \"1\",\n"
                + "    \"wheelDistance\": \"1\",\n" + "    \"checkTime\": \"1\",\n"
                + "    \"payType\": \"loan\",\n" + "    \"machinePowerType\": \"\",\n"
                + "    \"machineLicense1\": \"/sdcard/agrimac/machineinfo2016_05_31_09_38_34.png\",\n"
                + "    \"machineLicense2\": \"/sdcard/agrimac/machineinfo2016_05_31_09_38_37.png\",\n"
                + "    \"leaseMonth\": \"1\",\n" + "    \"leaseTime\": \"1\",\n"
                + "    \"workCondition\": \"\",\n" + "    \"needType\": \"all\",\n"
                + "    \"houseType\": \"normal_house\",\n" + "    \"id\": \"1\"\n" + "}]");
        o.put("data", oo);
        m.obj = o;
        m.setTarget(h);
        m.sendToTarget();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return view;
}

From source file:com.adjust.sdk.ActivityHandler.java

private ActivityHandler(AdjustConfig adjustConfig) {
    super(LOGTAG, MIN_PRIORITY);
    setDaemon(true);/*  w ww .ja va  2s .co  m*/
    start();

    logger = AdjustFactory.getLogger();
    sessionHandler = new SessionHandler(getLooper(), this);
    enabled = true;
    init(adjustConfig);

    Message message = Message.obtain();
    message.arg1 = SessionHandler.INIT;
    sessionHandler.sendMessage(message);
}

From source file:com.adjust.sdk.PackageHandler.java

@Override
public void sendNextPackage() {
    Message message = Message.obtain();
    message.arg1 = InternalHandler.SEND_NEXT;
    internalHandler.sendMessage(message);
}