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, Object obj) 

Source Link

Document

Same as #obtain() , but sets the values of the target, what, and obj members.

Usage

From source file:com.google.android.marvin.mytalkback.ProcessorVolumeStream.java

private void handleVolumeKeyDown(int keyCode) {
    // Don't perform actions on key down, just track long-presses
    mLongPressHandler.sendMessageDelayed(
            Message.obtain(mLongPressHandler, LongPressHandler.MSG_LONG_PRESSED, keyCode),
            ViewConfiguration.getLongPressTimeout());
}

From source file:nu.firetech.android.pactrack.backend.ParcelUpdater.java

private ParcelUpdater(ArrayList<Bundle> workParcels, RefreshContext ctx) {
    mWorkParcels = workParcels;//from  w  w w  .  j av  a2  s . c  o m
    mCtx = ctx;

    if (ctx instanceof Context) {
        mAndroidCtx = (Context) ctx;
    } else if (ctx instanceof Fragment) {
        mAndroidCtx = ((Fragment) ctx).getActivity();
    } else {
        throw new IllegalArgumentException("Unknown context type!");
    }
    ParcelJsonParser.loadConsumerId(mAndroidCtx);

    mConnectivityManager = (ConnectivityManager) mAndroidCtx.getSystemService(Context.CONNECTIVITY_SERVICE);

    mHandler = ctx.startRefreshProgress(workParcels.size());
    if (mHandler != null) {
        mHandler.sendMessage(Message.obtain(mHandler, 0, workParcels.get(0)));
    }
}

From source file:org.casquesrouges.missing.HttpAdapter.java

private void processEntity(HttpResponse response) throws IllegalStateException, IOException {
    Message message;//w  ww.  ja  v  a2 s .com
    int statusCode = response.getStatusLine().getStatusCode();
    Log.d("MISSING", "status: " + statusCode);

    if (statusCode == 200) {
        HttpEntity entity = response.getEntity();
        BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
        String line, result = "";
        while ((line = br.readLine()) != null)
            result += line;
        message = Message.obtain(handler, SUCCESS, result);
    } else {
        Integer intStatusCode = new Integer(statusCode);
        message = Message.obtain(handler, HTTPERROR, intStatusCode.toString());
    }
    handler.sendMessage(message);
}

From source file:com.hotstar.player.adplayer.utils.http.AsyncHttpConnection.java

private void processEntity(HttpEntity entity) throws IllegalStateException, IOException {
    if (_isCanceled) {
        return;//  w  w w  . j a  va  2 s .co m
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));

    String str;
    StringBuffer buff = new StringBuffer();
    while ((str = br.readLine()) != null) {
        buff.append(str);
    }
    br.close();

    Message message = Message.obtain(_handler, DID_SUCCEED, buff.toString());
    _handler.sendMessage(message);
}

From source file:org.connectbot.util.UpdateHelper.java

public void run() {
    try {//  www  .  ja  v  a  2 s .co  m
        // fetch and parse the version update information as json
        // pass information off to handler to create
        JSONObject json = new JSONObject(UpdateHelper.getUrl(UPDATE_URL, userAgent));
        Message.obtain(versionHandler, -1, json).sendToTarget();

    } catch (Exception e) {
        Log.e(TAG, "Problem while fetching/parsing update response", e);

    }
}

From source file:org.hedgewars.hedgeroid.Downloader.DownloadFragment.java

public void unBindFromService() {
    if (messengerService != null) {
        try {/*from   w w w . j a  v a 2 s.c  om*/
            Message message = Message.obtain(messageHandler, DownloadService.MSG_UNREGISTER_CLIENT, pack);
            message.replyTo = messenger;
            messengerService.send(message);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    getActivity().unbindService(connection);
}

From source file:org.chronotext.cinder.CinderBridge.java

public void messageFromSketch(int what, String body) {
    sendMessage(Message.obtain(this, what, body));
}

From source file:com.abhi.barcode.fragment.BarCodeFragment.java

private void decodeOrStoreSavedBitmap(Bitmap bitmap, Result result) {
    // Bitmap isn't used yet -- will be used soon
    if (handler == null) {
        savedResultToShow = result;//from   www  .j  a  va  2  s . c o m
    } else {
        if (result != null) {
            savedResultToShow = result;
        }
        if (savedResultToShow != null) {
            Message message = Message.obtain(handler, DECODE_COMPLETE, savedResultToShow);
            handler.sendMessage(message);
        }
        savedResultToShow = null;
    }
}

From source file:org.droidkit.app.UpdateService.java

private void parseJSONResponse(String obj) {
    /* find out the current version of the application.  we use the version code for updates. */
    int currentVersion = 0;

    try {/*from   w  w w . ja v  a 2  s  . c  o m*/
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
        currentVersion = info.versionCode;
    } catch (NameNotFoundException e) {
        Log.e("DroidKit", "Wtf! How can we not find ourselves! " + e.toString());
    }

    try {
        JSONObject json = new JSONObject(obj);
        JSONArray arr = json.getJSONArray("updates");
        JSONObject update = arr.getJSONObject(0);

        int updateVersion = update.getInt("version.code");
        Log.i("DroidKit", "Latest verion: " + updateVersion);

        if (currentVersion < updateVersion) {
            /* determine if we should download the update automatically. */
            boolean download = mPreferences.getBoolean("download.updates", true);

            if (download) {
                /* display the ongoing download notification. */
                notifyDownloading(obj);
                isDownloading = true;

                boolean result = updateVersion(update.getString("apk.url"));

                mNotificationManager.cancel("Downloading update...", UPDATE_DOWNLOADING_ID);
                isDownloading = false;
                Message.obtain(mHandler, DOWNLOAD_DONE, null).sendToTarget();

                if (result) {
                    notifyUser(obj);
                }
            } else {
                notifyUser(obj);
            }
        }
    } catch (JSONException e) {
        Log.e("DroidKit", "Error parsing update server response: " + e.toString());
    }
}

From source file:nu.firetech.android.pactrack.backend.ParcelUpdater.java

@Override
public void run() {
    synchronized (sLock) {
        if (sWaitingForDataConnection) {
            Log.i(TAG, "Another update is waiting for data connection. Skipping");
            return;
        }//from  w  w  w .jav a  2  s.  com
    }

    //wait for a data connection
    while (!isDataConnected()) {
        registerConnectionListener(mAndroidCtx);
        synchronized (sLock) {
            Log.d(TAG, "No data connection, waiting for a data connection");
            try {
                sLock.wait();
            } catch (InterruptedException e) {
                Log.e(TAG, "Error while waiting for connection", e);
            }
        }
    }

    mDbAdapter = new ParcelDbAdapter(mAndroidCtx);
    mDbAdapter.open();

    NotificationManager notMgr = (NotificationManager) mAndroidCtx
            .getSystemService(Context.NOTIFICATION_SERVICE);

    for (int i = 0; i < mWorkParcels.size(); i++) {
        Bundle parcel = mWorkParcels.get(i);
        if (mHandler != null) {
            mHandler.sendMessage(Message.obtain(mHandler, i, parcel));
        }
        updateParcel(parcel, mDbAdapter, notMgr);
    }
    if (mHandler != null) {
        mHandler.sendEmptyMessage(mWorkParcels.size());
    }

    new Handler(mAndroidCtx.getMainLooper()) {
        @Override
        public void handleMessage(Message m) {
            mCtx.refreshDone();
        }
    }.sendEmptyMessage(0);

    mDbAdapter.close();
}