List of usage examples for android.os Looper getMainLooper
public static Looper getMainLooper()
From source file:cn.ismartv.tvrecyclerview.util.MessageThreadUtil.java
@Override public MainThreadCallback<T> getMainThreadProxy(final MainThreadCallback<T> callback) { return new MainThreadCallback<T>() { final private MessageQueue mQueue = new MessageQueue(); final private Handler mMainThreadHandler = new Handler(Looper.getMainLooper()); private static final int UPDATE_ITEM_COUNT = 1; private static final int ADD_TILE = 2; private static final int REMOVE_TILE = 3; @Override/* w ww .j a v a 2 s . c o m*/ public void updateItemCount(int generation, int itemCount) { sendMessage(SyncQueueItem.obtainMessage(UPDATE_ITEM_COUNT, generation, itemCount)); } @Override public void addTile(int generation, TileList.Tile<T> tile) { sendMessage(SyncQueueItem.obtainMessage(ADD_TILE, generation, tile)); } @Override public void removeTile(int generation, int position) { sendMessage(SyncQueueItem.obtainMessage(REMOVE_TILE, generation, position)); } private void sendMessage(SyncQueueItem msg) { mQueue.sendMessage(msg); mMainThreadHandler.post(mMainThreadRunnable); } private Runnable mMainThreadRunnable = new Runnable() { @Override public void run() { SyncQueueItem msg = mQueue.next(); while (msg != null) { switch (msg.what) { case UPDATE_ITEM_COUNT: callback.updateItemCount(msg.arg1, msg.arg2); break; case ADD_TILE: //noinspection unchecked callback.addTile(msg.arg1, (TileList.Tile<T>) msg.data); break; case REMOVE_TILE: callback.removeTile(msg.arg1, msg.arg2); break; default: Log.e("ThreadUtil", "Unsupported message, what=" + msg.what); } msg = mQueue.next(); } } }; }; }
From source file:com.android.volley.toolbox.ClearCacheRequest.java
@Override public boolean isCanceled() { // This is a little bit of a hack, but hey, why not. mCache.clear();//from w w w . j a va2s. com if (mCallback != null) { Handler handler = new Handler(Looper.getMainLooper()); handler.postAtFrontOfQueue(mCallback); } return true; }
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/* ww w. ja v a2s .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:com.erevacation.challenge.injection.modules.ActivityModule.java
@Provides
@PerActivity
Handler provideHandler() {
return new Handler(Looper.getMainLooper());
}
From source file:com.doplgangr.secrecy.utils.Util.java
public static void alert(final Context context, final String title, final String message, final DialogInterface.OnClickListener ok) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override//from ww w. j av a 2s . c om public void run() { AlertDialog.Builder a = new AlertDialog.Builder(context); if (title != null) a.setTitle(title); if (message != null) a.setMessage(message); if (ok != null) a.setPositiveButton("OK", ok); a.setCancelable(false); a.show(); } }); }
From source file:com.dragondevs.pubnubexample.DrawingActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent();/* w w w .java 2 s.com*/ channelName = intent.getStringExtra("CHANNEL"); //Create Handler to update screen from PubnubClient mHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message inputMessage) { if (inputMessage.obj instanceof JSONObject) { JSONObject json = (JSONObject) inputMessage.obj; int x = -1; int y = -1; int state = -1; try { x = json.getInt("X"); y = json.getInt("Y"); state = json.getInt("STATE"); } catch (JSONException e) { Log.d(TAG, "Error: " + e.toString()); } Log.d(TAG, "Drawing coord at x, y, state: " + x + " " + y + " " + state); if (x >= 0 && y >= 0 && state >= 0) myView.drawLine(x, y, state); else Log.d(TAG, "Json values read was not valid"); } } }; myView = new MyView(this, mHandler); setContentView(myView); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); }
From source file:com.hippo.largeimageview.GestureRecognizer.java
public GestureRecognizer(Context context, Listener listener) { mListener = listener;/* www . j a v a2 s .c om*/ final Handler handler = new Handler(Looper.getMainLooper()); mGestureDetector = new GestureDetectorCompat(context, this, handler); mGestureDetector.setOnDoubleTapListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { mScaleDetector = new ScaleGestureDetector(context, this, handler); } else { mScaleDetector = new ScaleGestureDetector(context, this); } }
From source file:com.example.gcmandroid.GcmService.java
private void sendNotification(final String msg) { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override/* www . j av a2 s. c o m*/ public void run() { Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show(); if (MainActivity.mTextView != null) { MainActivity.mTextView.setText(msg); } } }); }
From source file:com.erevacation.challenge.injection.modules.FragmentModule.java
@Provides
@PerFragment
Handler provideHandler() {
return new Handler(Looper.getMainLooper());
}
From source file:com.alucas.snorlax.module.feature.gym.EjectNotification.java
void show(final int pokemonNumber, final String pokemonName, final String gymName, final Double gymLatitude, final Double gymLongitude) { new Handler(Looper.getMainLooper()).post(() -> { Notification notification = createNotification(pokemonNumber, pokemonName, gymName, gymLatitude, gymLongitude);// w ww .j a v a2 s.co m hideIcon(notification); mNotificationManager.notify(NotificationId.getUniqueID(), notification); }); }