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:org.kde.kdeconnect.Plugins.MprisPlugin.MprisPlugin.java

public void setPlayerStatusUpdatedHandler(String id, Handler h) {
    playerStatusUpdated.put(id, h);/*from  w ww. j av a  2  s.  co  m*/

    h.dispatchMessage(new Message());

    //Get the status if this is the first handler we have
    if (playerListUpdated.size() == 1) {
        requestPlayerStatus();
    }
}

From source file:net.evecom.androidecssp.activity.taskresponse.TaskResponseAddActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case R.layout.afnail_picture_activity: //   

        break;//from w w w .  j a  va 2  s. c om
    case R.layout.picture_select_at: // 
        new Thread(new Runnable() {
            @Override
            public void run() {
                filebeans.removeAll(filebeans);
                filebeans = getDb().findAll(FileManageBean.class);
                Message message = new Message();
                message.what = R.layout.picture_select_at;
                pubHandler.sendMessage(message);
            }
        }).start();
        break;
    default:
        break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:net.patchingzone.ru4real.nuevo.TorchActivityPlugin.java

/** Called when the activity is first created. */
@Override/*from w w  w  . j  a v  a 2  s.  co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.camera_flash);
    button = findViewById(R.id.button);

    disablePhoneSleep();
    // turnLightOn();
    Log.i(TAG, "onCreate");

    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            if (msg.arg1 == 0) {
                turnLightOff();
            } else {
                turnLightOn();

            }

        }
    };

    int flashVal = 1;

    Message m = new Message();
    m.arg1 = flashVal;
    mHandler.sendMessage(m);

}

From source file:com.insthub.O2OMobile.View.A0_RequestListView.java

public void showView() {
    if (mFilterView.getVisibility() == View.GONE) {
        mFilterBg.setVisibility(View.VISIBLE);
        mFilterView.setVisibility(View.VISIBLE);
        AnimationUtil.showAnimationFromTop(mFilterView);

        Message msg = new Message();
        msg.what = MessageConstant.SHOW_SEARCH_VIEW;
        EventBus.getDefault().post(msg);
    } else {/*from   ww  w . java 2 s . c o m*/
        hideView();
    }
}

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

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (url.endsWith(ApiInterface.USER_CHANGE_AVATAR)) {
        ToastView toast = new ToastView(this, getString(R.string.change_avatar_success));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();//from  w w w.  j a v a 2 s . c  o  m
    } else if (url.endsWith(ApiInterface.PUSH_SWITCH)) {
        //Todo
    } else if (url.endsWith(ApiInterface.USER_SIGNOUT)) {
        mEditor.putBoolean("isLogin", false);
        mEditor.putString("user", "");
        mEditor.putInt("uid", 0);
        mEditor.putString("sid", "");
        mEditor.commit();
        SESSION.getInstance().uid = mShared.getInt("uid", 0);
        SESSION.getInstance().sid = mShared.getString("sid", "");
        ToastView toast = new ToastView(F9_SettingActivity.this, getString(R.string.logout_success));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
        Message msg = new Message();
        msg.what = MessageConstant.LOGINOUT;
        EventBus.getDefault().post(msg);
        Intent intent = new Intent(F9_SettingActivity.this, B0_SigninActivity.class);
        startActivity(intent);
        finish();
    }
}

From source file:info.guardianproject.mrapp.server.YouTubeSubmit.java

public void asyncUpload(final File videoFile, final String contentType, final String uploadEndPoint) {
    new Thread(new Runnable() {
        @Override//  w  ww  . ja  v a 2 s  .  co  m
        public void run() {
            Message msg = new Message();
            Bundle bundle = new Bundle();
            msg.setData(bundle);
            msg.what = 888;

            int submitCount = 0;
            try {
                while (submitCount <= MAX_RETRIES && videoId == null) {
                    try {
                        submitCount++;
                        videoId = startUpload(videoFile, contentType, uploadEndPoint);
                        assert videoId != null;
                        break;
                    } catch (Internal500ResumeException e500) { // TODO - this should not really happen
                        if (submitCount < MAX_RETRIES) {
                            Log.w(LOG_TAG, e500.getMessage());
                            Log.d(LOG_TAG, String.format("Upload retry :%d.", submitCount, Locale.US));
                        } else {
                            Log.d(LOG_TAG, "Giving up");
                            Log.e(LOG_TAG, e500.getMessage());
                            throw new IOException(e500.getMessage());
                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
                bundle.putString("error", e.getMessage());
                msg.what = -1;

                handler.sendMessage(msg);
                return;
            } catch (YouTubeAccountException e) {
                e.printStackTrace();
                msg.what = -1;

                bundle.putString("err", e.getMessage());
                handler.sendMessage(msg);
                return;
            } catch (SAXException e) {
                e.printStackTrace();
                msg.what = -1;

                bundle.putString("err", e.getMessage());
                handler.sendMessage(msg);
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
                msg.what = -1;

                bundle.putString("err", e.getMessage());
                handler.sendMessage(msg);
            }

            bundle.putString("videoId", videoId);
            handler.sendMessage(msg);
        }
    }).start();
}

From source file:com.nextgis.firereporter.ScanexHttpLogin.java

@Override
protected Void doInBackground(String... urls) {
    if (HttpGetter.IsNetworkAvailible(mContext)) {
        String sUser = urls[0];//from  w w  w.  j a  v  a  2s .  c  o  m
        String sPass = urls[1];

        try {

            // Create a new HttpClient
            HttpClient httpclient = new DefaultHttpClient();

            // step 1. open login dialog
            String sRedirect = "http://fires.kosmosnimki.ru/SAPI/oAuthCallback.html&authServer=MyKosmosnimki";
            String sURL = "http://fires.kosmosnimki.ru/SAPI/LoginDialog.ashx?redirect_uri="
                    + Uri.encode(sRedirect);
            HttpGet httpget = new HttpGet(sURL);
            HttpParams params = httpget.getParams();
            params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE);
            httpget.setParams(params);
            HttpResponse response = httpclient.execute(httpget);

            //2 get cookie and params            
            Header head = response.getFirstHeader("Set-Cookie");
            String sCookie = head.getValue();

            head = response.getFirstHeader("Location");
            String sLoc = head.getValue();

            Uri uri = Uri.parse(sLoc);
            String sClientId = uri.getQueryParameter("client_id");
            String sScope = uri.getQueryParameter("scope");
            String sState = uri.getQueryParameter("state");

            String sPostUri = "http://my.kosmosnimki.ru/Account/LoginDialog?redirect_uri="
                    + Uri.encode(sRedirect) + "&client_id=" + sClientId + "&scope=" + sScope + "&state="
                    + sState;

            HttpPost httppost = new HttpPost(sPostUri);

            params = httppost.getParams();
            params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE);
            httppost.setHeader("Cookie", sCookie);

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("email", sUser));
            nameValuePairs.add(new BasicNameValuePair("password", sPass));
            nameValuePairs.add(new BasicNameValuePair("IsApproved", "true"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            response = httpclient.execute(httppost);
            head = response.getFirstHeader("Set-Cookie");

            if (head == null) {
                mError = mContext.getString(R.string.noNetwork);
                return null;
            }

            sCookie += "; " + head.getValue();
            head = response.getFirstHeader("Location");
            sLoc = head.getValue();

            uri = Uri.parse(sLoc);
            String sCode = uri.getQueryParameter("code");
            sState = uri.getQueryParameter("state");

            //3 get 
            String sGetUri = "http://fires.kosmosnimki.ru/SAPI/Account/logon/?authServer=MyKosmosnimki&code="
                    + sCode + "&state=" + sState;
            httpget = new HttpGet(sGetUri);
            httpget.setHeader("Cookie", sCookie);
            params = httpget.getParams();
            params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE);
            httpget.setParams(params);
            response = httpclient.execute(httpget);

            head = response.getFirstHeader("Set-Cookie");
            if (head == null) {
                mError = mContext.getString(R.string.noNetwork);
                return null;
            }
            sCookie += "; " + head.getValue();

            Bundle bundle = new Bundle();
            if (sCookie.length() > 0) {
                //if(bGetCookie){
                bundle.putBoolean(GetFiresService.ERROR, false);
                bundle.putString(GetFiresService.JSON, sCookie);
                //bundle.putString("json", mContent);
            } else {
                bundle.putBoolean(GetFiresService.ERROR, true);
            }

            bundle.putInt(GetFiresService.SOURCE, mnType);
            Message msg = new Message();
            msg.setData(bundle);
            if (mEventReceiver != null) {
                mEventReceiver.sendMessage(msg);
            }

        } catch (ClientProtocolException e) {
            mError = e.getMessage();
            return null;
        } catch (IOException e) {
            mError = e.getMessage();
            return null;
        } catch (Exception e) {
            mError = e.getMessage();
            return null;
        }
    } else {
        Bundle bundle = new Bundle();
        bundle.putBoolean(GetFiresService.ERROR, true);
        bundle.putString(GetFiresService.ERR_MSG, mContext.getString(R.string.noNetwork));
        bundle.putInt(GetFiresService.SOURCE, mnType);

        Message msg = new Message();
        msg.setData(bundle);
        if (mEventReceiver != null) {
            mEventReceiver.sendMessage(msg);
        }
    }
    return null;
}

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

public void setPlayerListUpdatedHandler(String id, Handler h) {
    playerListUpdated.put(id, h);/*ww w. j  av  a  2s.  c  om*/

    h.dispatchMessage(new Message());

    //Get the status if this is the first handler we have
    if (playerListUpdated.size() == 1) {
        requestPlayerList();
    }
}

From source file:com.samknows.measurement.ManualTest.java

@Override
public void run() {
    isExecuting = true;//ww  w  .  j  av a 2  s  .  c om
    // Start collectors for the passive metrics
    // Start tests
    long startTime = System.currentTimeMillis();
    JSONObject batch = new JSONObject();
    TestContext tc = TestContext.create(ctx);
    TestExecutor te = new TestExecutor(tc);
    List<JSONObject> testsResults = new ArrayList<JSONObject>();
    List<JSONObject> passiveMetrics = new ArrayList<JSONObject>();
    te.startInBackGround();
    Message msg;
    long testsBytes = 0;
    for (TestDescription td : mTestDescription) {
        // check if a stop command has been received
        if (!run.get()) {
            Logger.d(this, "Manual test interrupted by the user.");
            break;
        }
        com.samknows.measurement.test.TestResult tr = new com.samknows.measurement.test.TestResult();
        ObservableExecutor oe = new ObservableExecutor(te, td, tr);
        Thread t = new Thread(oe);
        t.start();
        while (true) {
            try {
                t.join(100);
                if (!t.isAlive())
                    break;
            } catch (InterruptedException ie) {
                Logger.e(this, ie.getMessage());
            }
            for (JSONObject pm : progressMessage(td, te)) {
                msg = new Message();
                msg.obj = pm;
                mHandler.sendMessage(msg);
            }

        }
        testsBytes += te.getLastTestByte();

        List<JSONObject> currResults = new ArrayList<JSONObject>();
        for (String out : tr.results) {
            currResults.addAll(TestResult.testOutput(out));
        }
        for (JSONObject cr : currResults) {
            // publish results
            msg = new Message();
            msg.obj = cr;
            mHandler.sendMessage(msg);
        }
        testsResults.addAll(currResults);
    }
    Logger.d(this, "bytes used by the tests: " + testsBytes);
    AppSettings.getInstance().appendUsedBytes(testsBytes);
    // stops collectors
    te.stop();

    te.save(JSON_MANUAL_TEST);

    // Gather data from collectors
    for (BaseDataCollector collector : tc.config.dataCollectors) {
        if (collector.isEnabled) {
            for (JSONObject o : collector.getPassiveMetric()) {
                // update interface
                msg = new Message();
                msg.obj = PassiveMetric.passiveMetricToCurrentTest(o);
                mHandler.sendMessage(msg);
                // save metric
                passiveMetrics.add(o);
            }
        }
    }
    // insert batch in the database
    try {
        batch.put(TestBatch.JSON_DTIME, startTime);
        batch.put(TestBatch.JSON_RUNMANUALLY, "1");
    } catch (JSONException je) {
        Logger.e(this, "Error in creating test batch object: " + je.getMessage());
    }

    // insert the results in the database only if we didn't receive a stop
    // command
    if (run.get()) {
        DBHelper db = new DBHelper(ctx);

        db.insertTestBatch(batch, testsResults, passiveMetrics);

    }
    // Send completed message to the interface
    msg = new Message();
    JSONObject jtc = new JSONObject();
    try {
        Thread.sleep(1000);
        jtc.put(TestResult.JSON_TYPE_ID, "completed");
        msg.obj = jtc;

    } catch (JSONException je) {
        Logger.e(this, "Error in creating json object: " + je.getMessage());
    } catch (InterruptedException e) {
        Logger.e(this, "Sleep interrupted in the manual test view: " + e.getMessage());
    }
    mHandler.sendMessage(msg);

    try {
        // Submitting test results
        if (AppSettings.getInstance().anonymous) {
            new SubmitTestResultsAnonymousAction(ctx).execute();
        } else {
            new SubmitTestResultsAction(ctx).execute();
        }
    } catch (Throwable t) {
        Logger.e(this, "Submit result. ", t);
    }

    Logger.d(this, "Exiting manual test");

    isExecuting = false;
}

From source file:io.radio.streamer.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Allow keys to change volume without playing
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);

    // Initialize Remote Controls if SDK Version >=14
    initializeRemoteControls();/*from www.j a  v a 2  s  .c  o m*/

    initializeVariables();
    initializeSideBar();

    updateApiData();

    // first page in the menu (homepage) on first load
    if (savedInstanceState == null) {
        selectItem(0);
    }

    // Get the fxView
    fxView = (FXView) findViewById(R.id.audioFxView);

    apiTimer = new Timer();
    apiTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            try {
                updateApiData();
            } catch (Exception e) {
                Log.e("api", "exception", e);
            }
        }
    }, 0, 10000);

    progressTimer = new Timer();
    progressTimer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            try {
                Message m = new Message();
                m.what = Util.PROGRESSUPDATE;

                mMessenger.send(m);

            } catch (Exception e) {
                Log.e("api", "exception", e);
            }
        }
    }, 0, 1000);
}