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) 

Source Link

Document

Same as #obtain() , but sets the values for both target and what members on the Message.

Usage

From source file:com.ruesga.rview.fragments.ChangeListFragment.java

private void startLoadersWithValidContext(Bundle savedState) {
    if (getActivity() == null) {
        return;/*from w  ww .j  av  a  2s  . c om*/
    }

    mIsTwoPanel = getResources().getBoolean(R.bool.config_is_two_pane);
    if (mAdapter == null) {
        mItemsToFetch = Preferences.getAccountFetchedItems(getContext(), Preferences.getAccount(getContext()));

        // Configure the adapter
        mAdapter = new ChangesAdapter(this);
        if (savedState != null) {
            mAdapter.mChangeId = savedState.getInt(EXTRA_CHANGE_ID, NO_SELECTION);
            if (mAdapter.mChangeId != NO_SELECTION) {
                notifyItemRestored();
            }
        }

        mBinding.list
                .setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        mBinding.list.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));
        mBinding.list.setAdapter(mAdapter);
        mEndlessScroller = new EndlessRecyclerViewScrollListener(mBinding.list.getLayoutManager()) {
            @Override
            public void onLoadMore(int page, int totalItemsCount) {
                Message.obtain(mUiHandler, MESSAGE_FETCH_MORE_ITEMS).sendToTarget();
            }
        };
        mEndlessScroller.setVisibleThreshold(2);
        mBinding.list.addOnScrollListener(mEndlessScroller);

        // Configure the refresh
        setupSwipeToRefresh();

        // Fetch or join current loader
        RxLoaderManager loaderManager = RxLoaderManagerCompat.get(this);
        setupLoaders(loaderManager);
        mChangesLoader = loaderManager.create(this::fetchChanges, mLoaderObserver);
        mChangesLoader.start(mItemsToFetch, 0);

        if (mIsTwoPanel) {
            // Hide fab until things were loaded (for dual panel layout we must register
            // an scroll listener directly, because CoordinatorLayout can't directly access
            // the floating action button)
            ((BaseActivity) getActivity()).registerFabWithRecyclerView(mBinding.list);
        }
        ((BaseActivity) getActivity()).setupFab(null);
    }
}

From source file:pl.poznan.put.cs.ify.app.MainActivity.java

public void requestRecipesList() {
    if (mService != null) {
        Message msg = Message.obtain(null, ServiceHandler.REQUEST_AVAILABLE_RecipeS);
        try {/*from   w w  w .j  a v a  2 s .  c  om*/
            mService.send(msg);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.smithdtyler.prettygoodmusicplayer.NowPlaying.java

public void previous() {
    Log.d(TAG, "Previous clicked...");
    Message msg = Message.obtain(null, MusicPlaybackService.MSG_PREVIOUS);
    try {// ww w . ja  v a 2  s  .  c om
        Log.i(TAG, "Sending a request to go to previous!");
        mService.send(msg);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:com.taobao.weex.bridge.WXBridgeManager.java

public void post(Runnable r, Object token) {
    if (mJSHandler == null) {
        return;/*from w w w . j av  a  2 s .c  o  m*/
    }

    Message m = Message.obtain(mJSHandler, WXThread.secure(r));
    m.obj = token;
    m.sendToTarget();
}

From source file:com.smithdtyler.prettygoodmusicplayer.NowPlaying.java

public void jumpBack() {
    Log.d(TAG, "JumpBack clicked...");
    Message msg = Message.obtain(null, MusicPlaybackService.MSG_JUMPBACK);
    try {/* w ww  . ja va 2s . co  m*/
        Log.i(TAG, "Sending a request to jump back!");
        mService.send(msg);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:pl.poznan.put.cs.ify.app.MainActivity.java

public void disableRecipe(int id) {
    Message msg = Message.obtain(null, ServiceHandler.REQUEST_DISABLE_RECIPE);
    msg.arg1 = id;/*  w  w w .  j av  a 2s . c o m*/
    try {
        mService.send(msg);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:com.smithdtyler.prettygoodmusicplayer.NowPlaying.java

public void toggleShuffle() {
    Log.d(TAG, "Shuffle clicked...");
    Message msg = Message.obtain(null, MusicPlaybackService.MSG_TOGGLE_SHUFFLE);
    try {//from  w ww . j a v  a 2 s . c  o m
        Log.i(TAG, "Sending a request to toggle shuffle!");
        mService.send(msg);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:com.marianhello.bgloc.LocationService.java

public void handleError(JSONObject error) {
    Bundle bundle = new Bundle();
    bundle.putString("error", error.toString());
    Message msg = Message.obtain(null, MSG_ERROR);
    msg.setData(bundle);//www .  j  av a  2 s  .c om

    sendClientMessage(msg);
}

From source file:ch.nexuscomputing.android.osciprimeics.OsciPrimeService.java

@Override
public void onSourceSamples(int[] ch1, int[] ch2, int[] previewCh1, int[] previewCh2, int len, int found,
        float offch1, float offch2) {
    if (mCalibrateNextTime.get()) {
        L.d("calibrating");
        mApplication.getActiveCalibration().getCh1Offsets()[mApplication.pAttenuationSettingCh1] = offch1;
        mApplication.getActiveCalibration().getCh2Offsets()[mApplication.pAttenuationSettingCh2] = offch2;
    }/*w ww.  j  a va 2  s . c  o  m*/
    mCalibrateNextTime.set(false);
    mApplication.copyData(ch1, ch2, previewCh1, previewCh2, found);
    if (mNetworkSink != null) {
        mNetworkSink.onSamples(ch1, ch2, found);
    }
    if (mApplication.pMode == OsciPrimeApplication.MODE_SINGLESHOT && found >= 0) {
        if (mState == RUNNING)// resample?
            mState = TERMINATING;// like when STOP message is received by
                                 // the
                                 // messenger
        stop();
    }
    if (mActivityMessenger != null) {
        try {
            mActivityMessenger.send(Message.obtain(null, OsciPrimeICSActivity.SAMPLES));
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    Stats.stat(mApplication);
}

From source file:com.google.android.apps.santatracker.map.SantaMapActivity.java

private void unregisterFromService() {
    if (mIsBound) {
        if (mService != null) {
            Message msg = Message.obtain(null, SantaServiceMessages.MSG_SERVICE_UNREGISTER_CLIENT);
            msg.replyTo = mMessenger;//from   w  ww .ja  va2 s  . c om
            try {
                mService.send(msg);
            } catch (RemoteException e) {
                // ignore if service is not available
            }
            mService = null;
        }
        unbindService(mConnection);
        mIsBound = false;
    }
}