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.lovejoy777sarootool.rootool.preview.IconPreview.java

private static void queueJob(final File uri, final ImageView imageView) {
    /* Create handler in UI thread. */
    final Handler handler = new Handler() {
        @Override/*from   www .ja v  a 2s . c om*/
        public void handleMessage(Message msg) {
            String tag = imageViews.get(imageView);
            if (tag != null && tag.equals(uri.getAbsolutePath())) {
                if (msg.obj != null) {
                    imageView.setImageBitmap((Bitmap) msg.obj);
                } else {
                    imageView.setImageBitmap(null);
                }
            }
        }
    };

    pool.submit(new Runnable() {
        public void run() {
            final Bitmap bmp = getPreview(uri);
            Message message = Message.obtain();
            message.obj = bmp;

            handler.sendMessage(message);
        }
    });
}

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

@Override
public void trackSubsessionStart() {
    Message message = Message.obtain();
    message.arg1 = SessionHandler.START;
    sessionHandler.sendMessage(message);
}

From source file:com.darshancomputing.BatteryIndicator.CurrentInfoFragment.java

private void sendServiceMessage(int what) {
    Message outgoing = Message.obtain();
    outgoing.what = what;//from  w ww .jav a  2 s.c o m
    outgoing.replyTo = messenger;
    try {
        serviceMessenger.send(outgoing);
    } catch (android.os.RemoteException e) {
    }
}

From source file:com.cloverstudio.spika.utils.BitmapManager.java

public void queueJob(final String url, final ImageView imageView, final ProgressBar pbLoading) {
    /* Create handler in UI thread. */
    final Handler handler = new Handler() {
        @Override//from ww w. ja va  2 s. c  o m
        public void handleMessage(Message msg) {
            String tag = imageViews.get(imageView);
            if (tag != null && tag.equals(url)) {
                if (msg.obj != null) {
                    if (smallImg) {
                        imageView.setScaleType(ImageView.ScaleType.CENTER);
                    } else {
                        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                    }
                    imageView.setImageBitmap((Bitmap) msg.obj);
                    if (pbLoading != null)
                        pbLoading.setVisibility(View.GONE);
                } else {
                    //                  imageView.setImageBitmap(placeholder);
                    imageView.setImageResource(R.drawable.image_stub);
                    if (pbLoading != null)
                        pbLoading.setVisibility(View.GONE);
                }
            }
        }
    };

    pool.submit(new Runnable() {
        @Override
        public void run() {
            final Bitmap bmp = downloadBitmap(url);
            Message message = Message.obtain();
            message.obj = bmp;

            handler.sendMessage(message);
        }
    });
}

From source file:com.open.file.manager.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    actcontext = getApplicationContext();
    operator = new FileOperations(this);
    setContentView(R.layout.fragment_pager_layout);
    mPager = (ViewPager) findViewById(R.id.pager);
    mAdapter = new FragmentAdapter(getSupportFragmentManager(), this);
    if (savedInstanceState != null) {
        ArrayList<String> oldfrags = savedInstanceState.getStringArrayList("fragments");
        for (String curfrag : oldfrags) {
            mAdapter.addFragment(GridFragment.newInstance(curfrag));
        }//w w  w . ja  va  2 s .  c o m
        ArrayList<String> oldselected = savedInstanceState.getStringArrayList("selectedfiles");
        for (String curselected : oldselected) {
            selectedfiles.add(new File(curselected));
        }
    }
    mPager.setAdapter(mAdapter);
    if (mAdapter.selectpathmissing()) {
        mAdapter.addFragment(SelectPathFragment.newInstance());
    }

    if (selectedfiles.size() > 0) {
        mMode = startActionMode(getCutCopyCallback());
    }
    curfrag = mAdapter.getcurrentfrag();
    mPager.setCurrentItem(curfrag);
    acthandler = new ActivityHandler();

    if (!restoreOperations(savedInstanceState) && operator.isMyServiceRunning()) {
        Log.d("servicerunning?", Boolean.toString(operator.isMyServiceRunning()));
        Log.d("restart", "activity");
        Message restartmsg = Message.obtain();
        restartmsg.what = Consts.MSG_ACTIVITYRESTART;
        CutCopyService.mHandler.sendMessage(restartmsg);
    }
}

From source file:android.tether.system.WebserviceTask.java

public boolean downloadFile(String url, String destinationDirectory, String destinationFilename) {
    boolean filedownloaded = true;
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(String.format(url));
    Message msg = Message.obtain();
    try {//w w w  .j av a 2 s. co m
        HttpResponse response = client.execute(request);
        StatusLine status = response.getStatusLine();
        Log.d(MSG_TAG, "Request returned status " + status);
        if (status.getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            InputStream instream = entity.getContent();
            int fileSize = (int) entity.getContentLength();
            FileOutputStream out = new FileOutputStream(
                    new File(destinationDirectory + "/" + destinationFilename));
            byte buf[] = new byte[8192];
            int len;
            int totalRead = 0;
            while ((len = instream.read(buf)) > 0) {
                msg = Message.obtain();
                msg.what = MainActivity.MESSAGE_DOWNLOAD_PROGRESS;
                totalRead += len;
                msg.arg1 = totalRead / 1024;
                msg.arg2 = fileSize / 1024;
                MainActivity.currentInstance.viewUpdateHandler.sendMessage(msg);
                out.write(buf, 0, len);
            }
            out.close();
        } else {
            throw new IOException();
        }
    } catch (IOException e) {
        Log.d(MSG_TAG, "Can't download file '" + url + "' to '" + destinationDirectory + "/"
                + destinationFilename + "'.");
        filedownloaded = false;
    }
    msg = Message.obtain();
    msg.what = MainActivity.MESSAGE_DOWNLOAD_COMPLETE;
    MainActivity.currentInstance.viewUpdateHandler.sendMessage(msg);
    return filedownloaded;
}

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

@Override
public void trackSubsessionEnd() {
    Message message = Message.obtain();
    message.arg1 = SessionHandler.END;
    sessionHandler.sendMessage(message);
}

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

@Override
public void trackEvent(AdjustEvent event) {
    if (activityState == null) {
        trackSubsessionStart();/*from   w ww .  ja v a2s.  c o  m*/
    }

    Message message = Message.obtain();
    message.arg1 = SessionHandler.EVENT;
    message.obj = event;
    sessionHandler.sendMessage(message);
}

From source file:com.frand.easyandroid.http.FFHttpRespHandler.java

/**
 * response ??message//from   w w  w.  j  a v  a 2  s.  c o  m
 * @param processCode START_MESSAGE
 * @param processObject ?urlresult
 * @return
 */
protected Message obtainMessage(int processCode, Object processObject) {
    Message msg = null;
    if (handler != null) {
        msg = handler.obtainMessage(processCode, processObject);
    } else {
        msg = Message.obtain();
        msg.what = processCode;
        msg.obj = processObject;
    }
    return msg;
}

From source file:andlabs.lounge.service.LoungeServiceImpl.java

@Override
public void reconnect() {
    Ln.v("reconnect():");
    try {//w ww.j  a va2s.c o  m
        Message message = Message.obtain();
        message.what = 1;
        message.setData(Bundle.EMPTY);
        mMessageHandler.send(message);
    } catch (NullPointerException npe) {
        Ln.e(npe, "reconnect(): caught exception while sending message");
    }
}