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.jackie.movies.ui.DetailActivity.java

private void updateMark() {
    new Thread() {
        @Override/*from  w w w . j av a  2 s. c  o m*/
        public void run() {
            super.run();
            synchronized (TAG) {
                ContentValues values = new ContentValues();
                boolean favour = detail.isFavour();
                values.put(MovieContract.Movie.FAVOUR, !favour);
                Uri uri = MovieContract.Movie.buildMovieUri(detail.getId());
                ContentResolver contentResolver = getContentResolver();
                int update = contentResolver.update(uri, values, null, null);

                if (update == 1) {
                    Message message = new Message();
                    message.what = WHAT_IS_CHECK_FAVOUR;
                    message.getData().putBoolean(EXTRA_FAVOUR, !favour);
                    handler.sendMessage(message);
                }
            }
        }
    }.start();
}

From source file:com.cleanwiz.applock.ui.activity.SplashActivity.java

public void showUpdateDialog(String intro) {
    final AlertDialog updateDialogDlg = new AlertDialog.Builder(this).create();
    updateDialogDlg.show();/*w  ww  .j av  a2s. c  om*/
    Window win = updateDialogDlg.getWindow();
    win.setContentView(R.layout.dialog_update);
    TextView tvMsg = (TextView) win.findViewById(R.id.tvMsg);
    tvMsg.setText(intro);
    Button btOk = (Button) win.findViewById(R.id.btOk);
    ImageView closeImageView = (ImageView) win.findViewById(R.id.updateclose);
    closeImageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            updateDialogDlg.dismiss();
            SplashHandler handler = new SplashHandler();
            Message msg = new Message();
            msg.what = CHECKVERSION_CANCEL;
            handler.sendMessage(msg);
        }
    });

    btOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            SplashHandler handler = new SplashHandler();
            Message msg = new Message();
            msg.what = CHECKVERSION_DOWN;
            handler.sendMessage(msg);
        }
    });

    updateDialogDlg.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub
            List<UpdateVersionManafer> updateVersionManafers = updateVersionManagerService.getVersionManafers();
            for (UpdateVersionManafer updateVersionManafer : updateVersionManafers) {
                updateVersionManafer.setLasttipdate(new Date().getTime());
                updateVersionManagerService.modifyTipsDate(updateVersionManafer);
                break;
            }
            SplashHandler handler = new SplashHandler();
            Message msg = new Message();
            msg.what = CHECKVERSION_CANCEL;
            handler.sendMessage(msg);
        }
    });
}

From source file:com.simplelife.seeds.android.utils.gridview.gridviewui.ImageGridFragment.java

private void addOrCancelFromFavList(MenuItem item) {

    if (mDBAdapter.isSeedSaveToFavorite(mSeedLocalId)) {
        mFavTag = true;// w  w  w  .  j ava 2  s .  co  m
    } else {
        mFavTag = false;
    }

    // Set up a thread to operate with the database
    new Thread() {
        @Override
        public void run() {
            try {
                // Get the DB adapter instance
                SeedsDBAdapter mDBAdapter = SeedsDBAdapter.getAdapter(getActivity());

                // Set the favorite key 
                if (mFavTag) {
                    mDBAdapter.updateSeedEntryFav(mSeedLocalId, false);
                    mFavTag = false;
                    ProgressDialog.show(getActivity(), "Cancelling Favorites...", "Done!", true, false);
                } else {
                    mDBAdapter.updateSeedEntryFav(mSeedLocalId, true);
                    mFavTag = true;

                    ProgressDialog.show(getActivity(), "Adding to Favorites...", "Done!", true, false);
                }

            } catch (Exception e) {
                // Show the error message here
            }

            Message t_MsgListData = new Message();
            t_MsgListData.what = 1;
            handler.sendMessage(t_MsgListData);
        }
    }.start();
}

From source file:com.spoiledmilk.ibikecph.map.SMHttpRequest.java

public void sendMsg(int what, Object response, SMHttpRequestListener listener) {
    if (listener != null) {
        Message msg = new Message();
        msg.what = what;//from ww  w .j  a va2s.com
        msg.obj = new Result(response, listener);
        handler.sendMessage(msg);
    }
}

From source file:com.sabdroidex.controllers.couchpotato.CouchPotatoController.java

/**
 * Retrieve possible download profiles from CouchPotat
 * //  ww  w.  j a v  a2s  .  c  om
 * @param messageHandler Handler
 */
public synchronized static void getProfiles(final Handler messageHandler) {
    if (executingCommand || !Preferences.isSet(Preferences.COUCHPOTATO_URL)) {
        return;
    }

    Thread thread = new Thread() {

        @Override
        public void run() {
            try {
                String result = makeApiCall(MESSAGE.PROFILE_LIST.toString().toLowerCase());

                JSONObject jsonObject = new JSONObject(result);

                if (jsonObject.getBoolean("success") && profiles == null) {
                    profiles = new HashMap<Integer, String>();
                    JSONArray profileList = jsonObject.getJSONArray("list");
                    for (int i = 0; i < profileList.length(); i++) {
                        profiles.put(profileList.getJSONObject(i).getInt("id"),
                                profileList.getJSONObject(i).getString("label"));
                    }
                }

                Message message = new Message();
                message.setTarget(messageHandler);
                message.what = MESSAGE.PROFILE_LIST.hashCode();
                message.obj = profiles;
                message.sendToTarget();
            } catch (IOException e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } catch (Throwable e) {
                Log.w(TAG, " " + e.getLocalizedMessage());
            } finally {
                executingCommand = false;
            }
        }
    };

    executingCommand = true;
    sendUpdateMessageStatus(messageHandler, MESSAGE.MOVIE_DELETE.toString());
    thread.start();
}

From source file:com.google.ytd.SubmitActivity.java

public void asyncUpload(final Uri uri, final Handler handler) {
    new Thread(new Runnable() {
        @Override//w  ww .  j  a v a 2s  .  co  m
        public void run() {
            Message msg = new Message();
            Bundle bundle = new Bundle();
            msg.setData(bundle);

            String videoId = null;
            int submitCount = 0;
            try {
                while (submitCount <= MAX_RETRIES && videoId == null) {
                    try {
                        submitCount++;
                        videoId = startUpload(uri);
                        assert videoId != null;
                    } 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));
                        } 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());
                handler.sendMessage(msg);
                return;
            } catch (YouTubeAccountException e) {
                e.printStackTrace();
                bundle.putString("error", e.getMessage());
                handler.sendMessage(msg);
                return;
            } catch (SAXException e) {
                e.printStackTrace();
                bundle.putString("error", e.getMessage());
                handler.sendMessage(msg);
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
                bundle.putString("error", e.getMessage());
                handler.sendMessage(msg);
            }

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

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void CreateShop(final String city, final String type, final String legalperson, final String phone,
        final String idcard, final String address, final String positive_pic, final String opposite_pic,
        final String license_pic, final int KEY, final String islocal) {
    new Thread() {
        Message msg = new Message();

        public void run() {
            String data = "&userid=" + user.getUserId() + "&city=" + city + "&legalperson=" + legalperson
                    + "&phone=" + phone + "&type=" + type + "&businesslicense=123" + "&address=" + address
                    + "&idcard=" + idcard + "&positive_pic=" + positive_pic + "&opposite_pic=" + opposite_pic
                    + "&license_pic=" + license_pic + "&islocal=" + islocal;
            Log.e("data is ", data);
            String result_data = NetUtil.getResponse(WebAddress.CREATESHOP, data);
            Log.e("successful", result_data);
            try {
                JSONObject obj = new JSONObject(result_data);
                msg.what = KEY;/*w  ww  .j  a v  a2 s .c om*/
                msg.obj = obj;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:cm.aptoide.pt.RemoteInSearch.java

private void installApk(String apk_pkg, int position) {
    pkginfo = mPm.getPackageArchiveInfo(apk_pkg, 0); //variavel global usada no retorno da instalacao
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + apk_pkg), "application/vnd.android.package-archive");

    Message msg = new Message();
    msg.arg1 = 1;/*w  w w.j av  a2  s  . com*/
    download_handler.sendMessage(msg);

    startActivityForResult(intent, position);
}

From source file:com.mk4droid.IMC_Activities.Fragment_List.java

/** on Resume this fragment  */
@Override//  w ww  . j  a v a 2 s .  c o  m
public void onResume() {

    resources = setResources();

    //set initial state
    if (MyIssuesSW) {
        btListMyIss.setCompoundDrawablesWithIntrinsicBounds(
                resources.getDrawable(R.drawable.my_issues_icon_white32), null, null, null);
        btListMyIss.setBackgroundDrawable(resources.getDrawable(R.drawable.bt_custom_click_orange));
        btListMyIss.setTextColor(Color.WHITE);
        btListMyIss.setClickable(false);

        btListAllIss.setCompoundDrawablesWithIntrinsicBounds(
                resources.getDrawable(R.drawable.all_issues_icon_gray32), null, null, null);
        btListAllIss.setBackgroundDrawable(resources.getDrawable(android.R.drawable.btn_default));
        btListAllIss.setTextColor(Color.BLACK);
        btListAllIss.setClickable(true);

    } else {
        btListAllIss.setCompoundDrawablesWithIntrinsicBounds(
                resources.getDrawable(R.drawable.all_issues_icon_white32), null, null, null);
        btListAllIss.setBackgroundDrawable(resources.getDrawable(R.drawable.bt_custom_click_orange));
        btListAllIss.setTextColor(Color.WHITE);
        btListAllIss.setClickable(false);

        btListMyIss.setCompoundDrawablesWithIntrinsicBounds(
                resources.getDrawable(R.drawable.my_issues_icon_gray32), null, null, null);
        btListMyIss.setBackgroundDrawable(resources.getDrawable(android.R.drawable.btn_default));
        btListMyIss.setTextColor(Color.BLACK);
        btListMyIss.setClickable(true);
    }

    if (UserID_STR.length() == 0) {
        ll_listissues_MyIssues.setVisibility(View.GONE);
    } else {
        ll_listissues_MyIssues.setVisibility(View.VISIBLE);
    }

    if (InternetConnCheck.getInstance(ctx).isOnline(ctx)) {

        //-------------- Check if distance has changed -------------
        int distanceData = mshPrefs.getInt("distanceData", Constants_API.initRange);
        int distanceDataOLD = mshPrefs.getInt("distanceDataOLD", Constants_API.initRange);

        //---------- Check if IssuesNo has changed ---------
        int IssuesNoAR = Integer.parseInt(mshPrefs.getString("IssuesNoAR", "40"));
        int IssuesNoAROLD = Integer.parseInt(mshPrefs.getString("IssuesNoAROLD", "40"));

        if (distanceData != distanceDataOLD) {
            Message msg = new Message();
            msg.arg1 = 2;
            handlerBroadcastRefresh.sendMessage(msg);
        } else if (IssuesNoAR != IssuesNoAROLD) {
            Message msg = new Message();
            msg.arg1 = 3;
            handlerBroadcastRefresh.sendMessage(msg);
        }
    }

    super.onResume();
}

From source file:etsii_upm.obdii.EnviarService.java

private void consolaUpdate(String texto) {
    Message lMsg = new Message();
    lMsg.obj = texto;/*from w ww . j a  va 2s.  c om*/
    try {
        messenger.send(lMsg);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}