List of usage examples for android.os Looper getMainLooper
public static Looper getMainLooper()
From source file:de.vanita5.twittnuker.provider.TwidereDataProvider.java
@Override public boolean onCreate() { final Context context = getContext(); final TwittnukerApplication app = TwittnukerApplication.getInstance(context); mHandler = new Handler(Looper.getMainLooper()); mDatabaseWrapper = new SQLiteDatabaseWrapper(this); mHostAddressResolver = app.getHostAddressResolver(); mPreferences = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); mImagePreloader = new ImagePreloader(context, app.getImageLoader()); restoreUnreadItems();/*from ww w . j a v a2s . co m*/ mNotificationHelper = new NotificationHelper(context); // final GetWritableDatabaseTask task = new // GetWritableDatabaseTask(context, helper, mDatabaseWrapper); // task.executeTask(); return true; }
From source file:com.networking.ApiTestActivity.java
public void createAnUserJSONObject(View view) { JSONObject jsonObject = new JSONObject(); try {/* w w w .j a v a 2 s .co m*/ jsonObject.put("firstname", "Rohit"); jsonObject.put("lastname", "Kumar"); } catch (JSONException e) { e.printStackTrace(); } AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER).addJSONObjectBody(jsonObject) .setTag(this).setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() { @Override public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getAsJSONObject(new JSONObjectRequestListener() { @Override public void onResponse(JSONObject response) { Log.d(TAG, "onResponse object : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); } @Override public void onError(ANError error) { if (error.getErrorCode() != 0) { // received ANError from server // error.getErrorCode() - the ANError code from server // error.getErrorBody() - the ANError body from server // error.getErrorDetail() - just a ANError detail Log.d(TAG, "onError errorCode : " + error.getErrorCode()); Log.d(TAG, "onError errorBody : " + error.getErrorBody()); Log.d(TAG, "onError errorDetail : " + error.getErrorDetail()); } else { // error.getErrorDetail() : connectionError, parseError, requestCancelledError Log.d(TAG, "onError errorDetail : " + error.getErrorDetail()); } } }); }
From source file:com.networking.OkHttpResponseTestActivity.java
public void createAnUserJSONObject(View view) { JSONObject jsonObject = new JSONObject(); try {/*w w w . j a v a 2s . c om*/ jsonObject.put("firstname", "Rohit"); jsonObject.put("lastname", "Kumar"); } catch (JSONException e) { e.printStackTrace(); } AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER).addJSONObjectBody(jsonObject) .setTag(this).setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() { @Override public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getAsOkHttpResponseAndJSONObject(new OkHttpResponseAndJSONObjectRequestListener() { @Override public void onResponse(Response okHttpResponse, JSONObject response) { Log.d(TAG, "onResponse object : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); if (okHttpResponse.isSuccessful()) { Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString()); } else { Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString()); } } @Override public void onError(ANError anError) { Utils.logError(TAG, anError); } }); }
From source file:com.vk.sdk.payments.VKIInAppBillingService.java
/** * Method for save transaction if you can't use * VKIInAppBillingService mService = new VKIInAppBillingService(IInAppBillingService.Stub.asInterface(service)); * WARNING!!! this method must call before consume google and is it returned true * * @param apiVersion - version google apis * @param purchaseToken - purchase token * @return true is send is ok/*from w w w .j a v a 2 s .c om*/ * @throws android.os.RemoteException */ public static boolean consumePurchaseToVk(final int apiVersion, @NonNull final String purchaseToken) throws android.os.RemoteException { if (Looper.getMainLooper().equals(Looper.myLooper())) { throw new RuntimeException("Network on main thread"); } final Context ctx = VKUIHelper.getApplicationContext(); if (ctx == null) { return false; } final PurchaseData purchaseData = new PurchaseData(); if (!VKPaymentsServerSender.isNotVkUser()) { final SyncServiceConnection serviceConnection = new SyncServiceConnection() { @Override public void onServiceConnectedImpl(ComponentName name, IBinder service) { Object iInAppBillingService = null; final Class<?> iInAppBillingServiceClassStub; try { iInAppBillingServiceClassStub = Class .forName("com.android.vending.billing.IInAppBillingService$Stub"); Method asInterface = iInAppBillingServiceClassStub.getMethod("asInterface", android.os.IBinder.class); iInAppBillingService = asInterface.invoke(iInAppBillingServiceClassStub, service); } catch (ClassNotFoundException e) { throw new RuntimeException(PARAMS_ARE_NOT_VALID_ERROR); } catch (Exception e) { throw new RuntimeException(e); } try { purchaseData.purchaseData = getPurchaseData(iInAppBillingService, apiVersion, ctx.getPackageName(), purchaseToken); } catch (Exception e) { Log.e("VKSDK", "error", e); purchaseData.hasError = true; } } @Override public void onServiceDisconnectedImpl(ComponentName name) { } }; Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); if (!ctx.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) { // bind ctx.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE); // wait bind synchronized (serviceConnection.syncObj) { while (!serviceConnection.isFinish) { try { serviceConnection.syncObj.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } // unbind ctx.unbindService(serviceConnection); } else { return false; } } else { return true; } if (purchaseData.hasError) { return false; } else if (!TextUtils.isEmpty(purchaseData.purchaseData)) { VKPaymentsServerSender.getInstance(ctx).saveTransaction(purchaseData.purchaseData); } return true; }
From source file:com.digium.respokesdk.RespokeGroup.java
/** * Notify the group that a connection has joined. This is used internally to the SDK and should not be called directly by your client application. * * @param connection The connection that has joined the group *///from ww w.j a v a 2 s.c o m public void connectionDidJoin(final RespokeConnection connection) { members.add(connection); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { Listener listener = listenerReference.get(); if (null != listener) { listener.onJoin(connection, RespokeGroup.this); } } }); }
From source file:com.vendsy.bartsy.venue.BartsyApplication.java
synchronized private void update() { if (Looper.myLooper() == Looper.getMainLooper()) { // We're in the main thread - execute the update in the background with a new asynchronous task Log.w(TAG, "Running updateOrders() in an async task"); // mHandler.post(new Runnable() { // @Override // public void run() { new Thread() { @Override//from w ww . j ava 2 s . co m public void run() { accessOrders(BartsyApplication.ACCESS_ORDERS_UPDATE); }; }.start(); // }; // }); // new UpdateAsync().execute(); } else { // We're not in the main thread - don't spin up a thread Log.w(TAG, "Running updateOrders()"); accessOrders(ACCESS_ORDERS_UPDATE); } return; }
From source file:com.amazon.android.tv.tenfoot.ui.fragments.ContentDetailsFragment.java
/** * Since we do not have direct access to the details overview actions row, we are adding a * delayed handler that waits for some time, searches for the row and then updates the * properties. This is not a fool-proof method, * > In slow devices its possible that this does not succeed in achieving the desired result. * > In fast devices its possible that the update is clearly visible to the user. * TODO: Find a better approach to update action properties *//* ww w .j a v a 2 s .c o m*/ private void updateActionsProperties() { Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(() -> { View view = getView(); if (view != null) { HorizontalGridView horizontalGridView = (HorizontalGridView) view .findViewById(R.id.details_overview_actions); if (horizontalGridView != null) { // This is required to make sure this button gets the focus whenever // detailsFragment is resumed. horizontalGridView.requestFocus(); for (int i = 0; i < horizontalGridView.getChildCount(); i++) { final Button button = (Button) horizontalGridView.getChildAt(i); if (button != null) { // Button objects are recreated every time MovieDetailsFragment is // created or restored, so we have to bind OnKeyListener to them on // resuming the Fragment. button.setOnKeyListener((v, keyCode, keyEvent) -> { if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { button.performClick(); } return false; }); } } } } }, 400); }
From source file:com.gsoc.ijosa.liquidgalaxycontroller.PW.NearbyBeaconsFragment.java
/** * Notify the view that the underlying data has been changed. * <p/>/*ww w.ja v a 2 s .c om*/ * We need to make sure the view is visible because if it's not, * the view will become visible when we notify it. */ private void safeNotifyChange() { if (getListView().getVisibility() == View.VISIBLE) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { mNearbyDeviceAdapter.notifyDataSetChanged(); } }); } }
From source file:com.facebook.unity.FB.java
private static void ActivateApp(String appId) { if (!activateAppCalled.compareAndSet(false, true)) { Log.w(TAG, "Activite app only needs to be called once"); return;/*ww w . ja va2s. com*/ } final Activity unityActivity = getUnityActivity(); if (appId != null) { AppEventsLogger.activateApp(unityActivity.getApplication(), appId); } else { AppEventsLogger.activateApp(unityActivity.getApplication()); } // We already have a running activity so we need to call create activity to ensure the // logging is correct new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { // These calls should be run on the ui thread. ActivityLifecycleTracker.onActivityCreated(unityActivity); ActivityLifecycleTracker.onActivityResumed(unityActivity); } }); }
From source file:com.digium.respokesdk.RespokeGroup.java
/** * Notify the group that a connection has left. This is used internally to the SDK and should not be called directly by your client application. * * @param connection The connection that has left the group *//* ww w. j a v a2 s. co m*/ public void connectionDidLeave(final RespokeConnection connection) { members.remove(connection); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { Listener listener = listenerReference.get(); if (null != listener) { listener.onLeave(connection, RespokeGroup.this); } } }); }