Example usage for android.os Looper myLooper

List of usage examples for android.os Looper myLooper

Introduction

In this page you can find the example usage for android.os Looper myLooper.

Prototype

public static @Nullable Looper myLooper() 

Source Link

Document

Return the Looper object associated with the current thread.

Usage

From source file:com.xhr.mvpdemo.repository.datasource.MemoryUserDataStore.java

@Override
public void getUser(final String userName, final OnGetUserListener listener) {

    Observable.just(userName).map(new Func1<String, User>() {
        @Override//from w  w  w  .  jav a2 s  . c  o  m
        public User call(String s) {//??
            if (Looper.myLooper() == Looper.getMainLooper())
                Log.e("MemoryUserDataStore.getUser", "MainThread");
            else
                Log.e("MemoryUserDataStore.getUser", "SubThread");
            if (!s.equals("xhrong")) {
                User user = new User();
                user.login = "test";
                user.email = "test";
                user.id = 12;
                return user;
            } else
                return null;
        }
    }).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Subscriber<User>() {//?
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    listener.onFail();
                }

                @Override
                public void onNext(User s) {
                    if (Looper.myLooper() == Looper.getMainLooper())
                        Log.e("MemoryUserDataStore.getUser", "MainThread");
                    else
                        Log.e("MemoryUserDataStore.getUser", "SubThread");
                    if (s == null) {
                        listener.onFail();
                    } else {
                        listener.onSuccess();
                    }
                }
            });
}

From source file:org.jitsi.service.osgi.OSGiDialogFragment.java

/**
 * Convenience method for running code on UI thread looper(instead of
 * getActivity().runOnUIThread()). It is never guaranteed that
 * <tt>getActivity()</tt> will return not <tt>null</tt> value, hence it must
 * be checked in the <tt>action</tt>.
 *
 * @param action <tt>Runnable</tt> action to execute on UI thread.
 *///from  w w  w  .ja  v a2 s . c  o  m
protected void runOnUiThread(Runnable action) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        action.run();
        return;
    }
    // Post action to the ui looper
    OSGiActivity.uiHandler.post(action);
}

From source file:de.schildbach.wallet.ui.send.DeriveKeyTask.java

public DeriveKeyTask(final Handler backgroundHandler, final int scryptIterationsTarget) {
    this.backgroundHandler = backgroundHandler;
    this.callbackHandler = new Handler(Looper.myLooper());
    this.scryptIterationsTarget = scryptIterationsTarget;
}

From source file:com.mike.aframe.http.HttpCallBack.java

public HttpCallBack() {
    // handler???
    if (Looper.myLooper() != null) {
        handler = new Handler() {
            @Override/*ww  w .jav  a2  s  .  co  m*/
            public void handleMessage(Message msg) {
                HttpCallBack.this.handleMessage(msg);
            }
        };
    }
}

From source file:zenghao.com.study.banner4.BannerController.java

public BannerController(Context pContext) {
    this.confing = BannerConfig.sConfig(pContext);
    mHandler = new MyHandler(Looper.myLooper(), this);
}

From source file:com.waz.zclient.testutils.FragmentTest.java

public FragmentTest(Class<A> activityType) {
    this.activityType = activityType;
    activityTestRule = new ActivityTestRule<>(activityType, false, false);
    if (Looper.myLooper() == null) {
        Looper.prepare();/*from   w  ww .j  a v  a  2  s . c  o  m*/
    }
}

From source file:zenghao.com.study.banner4.BannerController.java

public BannerController(BannerConfig pBannerConfig) {
    this.confing = pBannerConfig;
    mHandler = new MyHandler(Looper.myLooper(), this);
}

From source file:com.lurencun.cfuture09.androidkit.http.async.AsyncHttpResponseHandler.java

public AsyncHttpResponseHandler() {
    // handler???
    if (Looper.myLooper() != null) {
        handler = new Handler() {
            @Override// w w w.j a  v  a2  s . c om
            public void handleMessage(Message msg) {
                AsyncHttpResponseHandler.this.handleMessage(msg);
            }
        };
    }
}

From source file:cc.wulian.smarthomev5.fragment.singin.handler.DecodeHandler.java

@Override
public void handleMessage(Message message) {
    int msgID = message.what;
    if (msgID == R.id.decode) {
        decode((byte[]) message.obj, message.arg1, message.arg2);
    } else if (msgID == R.id.quit) {
        Looper.myLooper().quit();
    }//from w w  w.  ja  v a 2  s. c o  m
}

From source file:com.dciets.cumets.service.MyGcmListenerService.java

/**
 * Called when message is received.//from   ww  w  .j a v  a  2  s. c  o m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    if (Looper.myLooper() == null) {
        Looper.prepare();
    }
    List<String> providers = locationManager.getProviders(true);
    if (providers.size() > 0) {
        if (Build.VERSION.SDK_INT >= 23) {
            if (checkSelfPermission(
                    Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                Log.i(TAG, "start Location request Marshmallow");
                for (String provider : providers) {
                    locationManager.requestLocationUpdates(provider, 30000, 0, locationListener);
                    Location l = locationManager.getLastKnownLocation(provider);
                    if (l != null) {
                        Server.pushLocation(getApplicationContext(), String.valueOf(l.getLongitude()),
                                String.valueOf(l.getLatitude()));
                    }
                }
            } else {
                Server.pushLocation(this, null, null);
            }
        } else {
            Log.i(TAG, "start Location request normal");
            for (String provider : providers) {
                locationManager.requestLocationUpdates(provider, 30000, 0, locationListener);
                Location l = locationManager.getLastKnownLocation(provider);
                if (l != null) {
                    Server.pushLocation(getApplicationContext(), String.valueOf(l.getLongitude()),
                            String.valueOf(l.getLatitude()));
                }
            }
        }
    } else {
        Server.pushLocation(this, null, null);
    }
}