Example usage for android.os Message Message

List of usage examples for android.os Message Message

Introduction

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

Prototype

public Message() 

Source Link

Document

Constructor (but the preferred way to get a Message is to call #obtain() Message.obtain() ).

Usage

From source file:com.aquatest.dbinterface.tools.DatabaseUpdater.java

/**
 * Send message from this thread using preset handler
 * //from ww w .  ja  va 2s. c om
 * @param b
 *            message data to be sent
 * @param _code
 *            code of the message for handler to be able to determine the
 *            type of message
 */
public void sendMessage(Bundle b, int code) {
    if (h != null) {
        Message msg = new Message();
        msg.setData(b);
        msg.what = code;
        h.sendMessage(msg);
    }
}

From source file:me.ziccard.secureit.fragment.MicrophoneFragment.java

public void onSignalReceived(short[] signal) {

    /*/*  w w w  . ja va  2s .  co m*/
     * We do and average of the 512 samples
     */
    int total = 0;
    int count = 0;
    for (short peak : signal) {
        //Log.i("MicrophoneFragment", "Sampled values are: "+peak);
        if (peak != 0) {
            total += Math.abs(peak);
            count++;
        }
    }
    Log.i("MicrophoneFragment", "Total value: " + total);
    int average = 0;
    if (count > 0)
        average = total / count;
    /*
     * We compute a value in decibels 
     */
    double averageDB = 0.0;
    if (average != 0) {
        averageDB = 20 * Math.log10(Math.abs(average) / 1);
    }

    microphoneText.setText("Sampled DBs: " + averageDB);

    picker.setValues(averageDB, averageDB);
    picker.invalidate();

    if (averageDB > NOISE_THRESHOLD) {
        Message message = new Message();
        message.what = UploadService.MICROPHONE_MESSAGE;
        try {
            if (serviceMessenger != null)
                serviceMessenger.send(message);
        } catch (RemoteException e) {
            // Cannot happen
        }
    }
}

From source file:org.kde.kdeconnect.Plugins.MprisPlugin.MprisPlugin.java

@Override
public boolean onPackageReceived(NetworkPackage np) {

    if (np.has("nowPlaying") || np.has("volume") || np.has("isPlaying") || np.has("length") || np.has("pos")) {
        if (np.getString("player").equals(player)) {
            currentSong = np.getString("nowPlaying", currentSong);
            volume = np.getInt("volume", volume);
            length = np.getLong("length", length);
            if (np.has("pos")) {
                lastPosition = np.getLong("pos", lastPosition);
                lastPositionTime = System.currentTimeMillis();
            }/*from ww w.j ava  2s.  com*/
            playing = np.getBoolean("isPlaying", playing);
            playAllowed = np.getBoolean("canPlay", playAllowed);
            pauseAllowed = np.getBoolean("canPause", pauseAllowed);
            goNextAllowed = np.getBoolean("canGoNext", goNextAllowed);
            goPreviousAllowed = np.getBoolean("canGoPrevious", goPreviousAllowed);
            seekAllowed = np.getBoolean("canSeek", seekAllowed);
            for (String key : playerStatusUpdated.keySet()) {
                try {
                    playerStatusUpdated.get(key).dispatchMessage(new Message());
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("MprisControl", "Exception");
                    playerStatusUpdated.remove(key);
                }
            }
        }
    }

    List<String> newPlayerList = np.getStringList("playerList");
    if (newPlayerList != null) {
        boolean equals = false;
        if (newPlayerList.size() == playerList.size()) {
            equals = true;
            for (int i = 0; i < newPlayerList.size(); i++) {
                if (!newPlayerList.get(i).equals(playerList.get(i))) {
                    equals = false;
                    break;
                }
            }
        }
        if (!equals) {
            playerList = newPlayerList;
            for (String key : playerListUpdated.keySet()) {
                try {
                    playerListUpdated.get(key).dispatchMessage(new Message());
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("MprisControl", "Exception");
                    playerListUpdated.remove(key);
                }
            }
        }
    }

    return true;
}

From source file:com.softminds.matrixcalculator.OperationFragments.InverseFragment.java

public void RunNewGetInverse(final int pos, final ProgressDialog pq) {
    Runnable runnable = new Runnable() {
        @Override/*w w  w.  j  av  a  2s.co m*/
        public void run() {
            MatrixV2 res = SquareList.get(pos).getInverse(pq);
            Message message = new Message();
            if (res != null) {
                message.setData(res.getDataBundled());
                myHandler.sendMessage(message);
            } else {
                myHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getContext(), R.string.NoInverse, Toast.LENGTH_SHORT).show();
                    }
                }, 0);
                pq.dismiss();
            }
        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
}

From source file:copytestapp.copytestapp.GCMIntentService.java

@Override
    protected void onMessage(Context context, Intent intent) {
        Log.i(TAG, "Received message");
        String message = intent.getExtras().getString("price");
        //?? /* w ww  .  j a  v  a2 s . c o m*/
        if (message != null && !message.equals("")) {

            StringTokenizer tokens = new StringTokenizer(message, ",");
            startedStr = tokens.nextToken();
            Log.e("startedStrValue", startedStr);

            if (startedStr.toString().trim().equals("0")) {
                //0? PUSH ?
                Log.e("tokens 0 ", "in zero true");

                noti_message = new Noti_Message();

                textDTO = noti_message.notiMessage(message);

                Log.e("title", textDTO.getTitle());
                Log.e("content", textDTO.getContent());
                Log.e("pictur", textDTO.getPicturUrl());
                Log.e("link", textDTO.getLinkUrl());
                Log.e("AdcodeNum", "" + textDTO.getAdcodeNum());
                Log.e("AdNum", "" + textDTO.getAdNum());

                //?  ------------------------------6 22? 6:42   
                if (textDTO.getPicturUrl().equals("not") == true) {
                    notificationWithColorFont(getApplicationContext(), textDTO.getTitle(), textDTO.getContent(),
                            Utility.P_ICON, intro.class, "" + textDTO.getAdcodeNum(), textDTO.getLinkUrl(),
                            textDTO.getAdNum());

                } else {
                    //? ?
                    new Thread() {
                        @Override
                        public void run() {
                            super.run();
                            try {
                                Log.e("Thread In", "start");
                                bitmap = getBitmapFromURL(textDTO.getPicturUrl());
                                Message msg = new Message();
                                msg.obj = bitmap;
                                msg.what = 0;
                                noti_handler.sendMessage(msg);

                            } catch (Exception e) {
                                noti_handler.sendEmptyMessage(2);
                            }
                        }
                    }.start();
                }

                /*
                *  ?? ? 0 ~ 4    
                *  4? ? ?  ?  ? not?? ?  .???
                *
                * */

            } else {
                Log.e("tokens 1 ", "in one true");
            }

        } else {
            message = " !";
        }

        CommonUtilities.displayMessage(context, message);
        // notifies user

        Log.e("onMessage", "onMessage");
    }

From source file:com.uwindsor.elgg.project.http.AsyncHttpResponseHandler.java

protected Message obtainMessage(int responseMessage, Object response) {

    Message msg = null;/*w  ww. ja  v  a 2s. c o m*/
    if (handler != null) {
        msg = this.handler.obtainMessage(responseMessage, response);
    } else {
        msg = new Message();
        msg.what = responseMessage;
        msg.obj = response;
    }
    return msg;
}

From source file:com.firesoft.member.Activity.B0_SigninActivity.java

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (url.endsWith(ApiInterface.USER_SIGNIN)) {
        usersigninResponse usersigninResponse = new usersigninResponse();
        usersigninResponse.fromJson(jo);
        if (usersigninResponse.succeed == 1) {

            Message msg = new Message();
            msg.what = MessageConstant.SIGN_IN_SUCCESS;
            EventBus.getDefault().post(msg);
            Intent intent = new Intent(B0_SigninActivity.this, MainActivity.class);
            startActivity(intent);//  w w  w.  j a  v a  2  s. c o  m
            finish();
        } else {
            ToastShow(getString(R.string.mobile_phone_or_password_error));
            mPassword.requestFocus();
        }

    }

}

From source file:com.skalski.raspberrycontrol.Custom_WebSocketClient.java

@Override
public void onTextMessage(String payload) {

    Message payload_msg = new Message();
    boolean send_message = false;

    try {//from  w w w. j a  v a  2s .co  m

        JSONObject jsonObj = new JSONObject(payload);

        if (jsonObj.has(TAG_HAN_GPIOSTATE))
            if ((this.ClientHandler != null) && (this.ClientFilter.equals(TAG_HAN_GPIOSTATE)))
                send_message = true;

        if (jsonObj.has(TAG_HAN_TEMPSENSORS))
            if ((this.ClientHandler != null) && (this.ClientFilter.equals(TAG_HAN_TEMPSENSORS)))
                send_message = true;

        if (jsonObj.has(TAG_HAN_PROCESSES))
            if ((this.ClientHandler != null) && (this.ClientFilter.equals(TAG_HAN_PROCESSES)))
                send_message = true;

        if (jsonObj.has(TAG_HAN_STATISTICS))
            if ((this.ClientHandler != null) && (this.ClientFilter.equals(TAG_HAN_STATISTICS)))
                send_message = true;

        if (jsonObj.has(TAG_ERROR))
            if (this.ClientHandler != null)
                send_message = true;

        if (jsonObj.has(TAG_HAN_NOTIFICATION)) {

            if (Activity_Settings.pref_notifications_disabled(getBaseContext())) {

                Log.i(LOGTAG, LOGPREFIX + "notification: disabled");

            } else {
                int notification_id;

                if (Activity_Settings.pref_multiple_notifications_disabled(getBaseContext()))
                    notification_id = 0;
                else
                    notification_id = (int) System.currentTimeMillis();

                Notification new_notification = new Notification.Builder(this)
                        .setContentTitle(getResources().getString(R.string.app_name))
                        .setContentText(jsonObj.getString(TAG_HAN_NOTIFICATION))
                        .setSmallIcon(R.drawable.ic_launcher).build();
                new_notification.defaults |= Notification.DEFAULT_ALL;
                NotificationManager notificationManager = (NotificationManager) getSystemService(
                        NOTIFICATION_SERVICE);
                notificationManager.notify(notification_id, new_notification);

                Log.i(LOGTAG, LOGPREFIX + "notification: " + notification_id);
            }
        }

    } catch (JSONException e) {
        Log.e(LOGTAG, LOGPREFIX + "can't parse JSON object");
    }

    if (send_message) {
        payload_msg.obj = payload;
        ClientHandler.sendMessage(payload_msg);
    }
}

From source file:com.app.jdy.ui.FaceValueActivity.java

public void getData() {
    params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("memberId", ID));
    Thread thread = new Thread(new Runnable() {

        @Override//w w  w . j  a v a  2  s.  com
        public void run() {
            Message msg = new Message();
            dataJson = HttpUtils.request(params, URLs.USER_FACE_VALUE);
            if (dataJson.length() != 0 && !dataJson.equals("0x110")) {
                msg.what = 1;
            } else {
                msg.what = 0;
            }
            handler.sendMessage(msg);
        }
    });
    thread.start();
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventsListFragment.java

public void acknowledgeSingleEvent(final int position) {
    //Log.e("acknowledgeSingleEvent","Am in acknowledgeSingleEvent with position " + Integer.toString(position));

    setInProgress(position);/*  ww w.j a v a 2s . c o m*/

    new Thread() {
        public void run() {
            Message msg = new Message();
            Bundle bndle = new Bundle();
            msg.what = ACKEVENTHANDLER_FAILURE;
            bndle.putInt("position", position);
            msg.setData(bndle);
            try {
                if (null != mService && mBound) {
                    try {
                        if (null == mService.API) {
                            //Log.e("acknowledgeSingleEvent","mService.API was null");
                            mService.PrepAPI(true, true);
                        }
                        //Log.e("acknowledgeSingleEvent","Logging in...");
                        ZenossCredentials credentials = new ZenossCredentials(getActivity());
                        mService.API.Login(credentials);

                        //Log.e("acknowledgeSingleEvent","Acknowledging event");
                        mService.API.AcknowledgeEvent(listOfZenossEvents.get(position).getEVID());

                    } catch (Exception e) {
                        e.printStackTrace();
                        BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "AckAllThread", e);
                        msg.what = ACKEVENTHANDLER_FAILURE;
                    }
                } else {
                    //AckSingleEventHandler.sendEmptyMessage(ACKEVENTHANDLER_FAILURE);
                    msg.what = ACKEVENTHANDLER_FAILURE;
                }

                //TODO Check it actually succeeded
                //AckSingleEventHandler.sendEmptyMessage(ACKEVENTHANDLER_SUCCESS);
                msg.what = ACKEVENTHANDLER_SUCCESS;
            } catch (Exception e) {
                e.printStackTrace();
                //AckSingleEventHandler.sendEmptyMessage(ACKEVENTHANDLER_FAILURE);
                msg.what = ACKEVENTHANDLER_FAILURE;
                BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "AckAllThread outer catch",
                        e);
            }

            //Log.e("acknowledgeSingleEvent","Sending Handler message");
            if (null != AckSingleEventHandler)
                AckSingleEventHandler.sendMessage(msg);
        }
    }.start();
}