List of usage examples for android.os Looper getMainLooper
public static Looper getMainLooper()
From source file:com.chao.facebookzc.Session.java
Session(Context context, String applicationId, TokenCachingStrategy tokenCachingStrategy, boolean loadTokenFromCache) { // if the application ID passed in is null, try to get it from the // meta-data in the manifest. if ((context != null) && (applicationId == null)) { applicationId = Utility.getMetadataApplicationId(context); }/*w ww . ja va2 s . com*/ Validate.notNull(applicationId, "applicationId"); initializeStaticContext(context); if (tokenCachingStrategy == null) { tokenCachingStrategy = new SharedPreferencesTokenCachingStrategy(staticContext); } this.applicationId = applicationId; this.tokenCachingStrategy = tokenCachingStrategy; this.state = SessionState.CREATED; this.pendingAuthorizationRequest = null; this.callbacks = new ArrayList<StatusCallback>(); this.handler = new Handler(Looper.getMainLooper()); Bundle tokenState = loadTokenFromCache ? tokenCachingStrategy.load() : null; if (TokenCachingStrategy.hasTokenInformation(tokenState)) { Date cachedExpirationDate = TokenCachingStrategy.getDate(tokenState, TokenCachingStrategy.EXPIRATION_DATE_KEY); Date now = new Date(); if ((cachedExpirationDate == null) || cachedExpirationDate.before(now)) { // If expired or we require new permissions, clear out the // current token cache. tokenCachingStrategy.clear(); this.tokenInfo = AccessToken.createEmptyToken(Collections.<String>emptyList()); } else { // Otherwise we have a valid token, so use it. this.tokenInfo = AccessToken.createFromCache(tokenState); this.state = SessionState.CREATED_TOKEN_LOADED; } } else { this.tokenInfo = AccessToken.createEmptyToken(Collections.<String>emptyList()); } }
From source file:com.rxsampleapp.RxApiTestActivity.java
public void createAnUser(View view) { RxAndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER) .addBodyParameter("firstname", "Amit").addBodyParameter("lastname", "Shekhar").build() .setAnalyticsListener(new AnalyticsListener() { @Override// w w w .j av a2 s .c om 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); } }).getJSONObjectObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<JSONObject>() { @Override public void onCompleted() { Log.d(TAG, "onComplete Detail : createAnUser completed"); } @Override public void onError(Throwable e) { if (e instanceof ANError) { ANError anError = (ANError) e; if (anError.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 : " + anError.getErrorCode()); Log.d(TAG, "onError errorBody : " + anError.getErrorBody()); Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail()); } else { // error.getErrorDetail() : connectionError, parseError, requestCancelledError Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail()); } } else { Log.d(TAG, "onError errorMessage : " + e.getMessage()); } } @Override public void onNext(JSONObject response) { Log.d(TAG, "onResponse object : " + response.toString()); Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper())); } }); }
From source file:com.alibaba.android.layoutmanager.example.OnePlusNLayoutActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); mFirstText = (TextView) findViewById(R.id.first); mLastText = (TextView) findViewById(R.id.last); mCountText = (TextView) findViewById(R.id.count); mTotalOffsetText = (TextView) findViewById(R.id.total_offset); final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view); findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() { @Override/* w w w .j a v a2 s. c om*/ public void onClick(View v) { EditText position = (EditText) findViewById(R.id.position); if (!TextUtils.isEmpty(position.getText())) { try { int pos = Integer.parseInt(position.getText().toString()); recyclerView.scrollToPosition(pos); } catch (Exception e) { Log.e("VlayoutActivity", e.getMessage(), e); } } else { recyclerView.requestLayout(); } } }); final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this); recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) { } @Override public void onScrolled(RecyclerView recyclerView, int i, int i2) { mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition()); mLastText.setText( "Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes); mCountText.setText("Count: " + recyclerView.getChildCount()); mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart()); } }); recyclerView.setLayoutManager(layoutManager); // layoutManager.setReverseLayout(true); RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() { public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { int position = ((LayoutParams) view.getLayoutParams()).getViewPosition(); outRect.set(4, 4, 4, 4); } }; final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool(); recyclerView.setRecycledViewPool(viewPool); // recyclerView.addItemDecoration(itemDecoration); viewPool.setMaxRecycledViews(0, 20); final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true); recyclerView.setAdapter(delegateAdapter); List<DelegateAdapter.Adapter> adapters = new LinkedList<>(); if (BANNER_LAYOUT) { adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) { @Override public void onViewRecycled(MainViewHolder holder) { if (holder.itemView instanceof ViewPager) { ((ViewPager) holder.itemView).setAdapter(null); } } @Override public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (viewType == 1) return new MainViewHolder(LayoutInflater.from(OnePlusNLayoutActivity.this) .inflate(R.layout.view_pager, parent, false)); return super.onCreateViewHolder(parent, viewType); } @Override public int getItemViewType(int position) { return 1; } @Override protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) { } @Override public void onBindViewHolder(MainViewHolder holder, int position) { if (holder.itemView instanceof ViewPager) { ViewPager viewPager = (ViewPager) holder.itemView; viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200)); // from position to get adapter viewPager.setAdapter(new PagerAdapter(this, viewPool)); } } }); } if (GRID_LAYOUT) { GridLayoutHelper layoutHelper; layoutHelper = new GridLayoutHelper(4); layoutHelper.setMargin(0, 10, 0, 10); layoutHelper.setHGap(3); layoutHelper.setAspectRatio(4f); adapters.add(new SubAdapter(this, layoutHelper, 8)); } if (HORIZONTAL_SCROLL_LAYOUT) { } if (GRID_LAYOUT) { GridLayoutHelper layoutHelper; layoutHelper = new GridLayoutHelper(2); layoutHelper.setMargin(0, 10, 0, 10); layoutHelper.setHGap(3); layoutHelper.setAspectRatio(3f); adapters.add(new SubAdapter(this, layoutHelper, 2)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setMargin(10, 10, 10, 10); helper.setPadding(10, 10, 10, 10); adapters.add(new SubAdapter(this, helper, 3) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); // layoutParams.leftMargin = 10; // layoutParams.topMargin = 10; // layoutParams.rightMargin = 10; // layoutParams.bottomMargin = 10; // holder.itemView.setLayoutParams(layoutParams); } }); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 4)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f }); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); helper.setColWeights(new float[] { 20f, 80f, 0f, 60f, 20f }); helper.setAspectRatio(4); adapters.add(new SubAdapter(this, helper, 5)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 6)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); adapters.add(new SubAdapter(this, helper, 7)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xff876384); helper.setMargin(0, 10, 0, 10); helper.setColWeights(new float[] { 40f, 45f, 15f, 60f, 0f, 30f, 30f }); adapters.add(new SubAdapter(this, helper, 7)); } if (ONEN_LAYOUT) { OnePlusNLayoutHelperEx helper = new OnePlusNLayoutHelperEx(); helper.setBgColor(0xffed7612); // helper.setMargin(10, 10, 10, 10); // helper.setPadding(10, 10, 10, 10); helper.setColWeights(new float[] { 30f, 20f, 50f, 40f, 30f, 35f, 35f }); adapters.add(new SubAdapter(this, helper, 7) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); // LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300); // layoutParams.leftMargin = 10; // layoutParams.topMargin = 10; // layoutParams.rightMargin = 10; // layoutParams.bottomMargin = 10; // holder.itemView.setLayoutParams(layoutParams); } }); } if (STICKY_LAYOUT) { StickyLayoutHelper layoutHelper = new StickyLayoutHelper(); layoutHelper.setAspectRatio(4); adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100))); } if (SCROLL_FIX_LAYOUT) { ScrollFixLayoutHelper layoutHelper = new ScrollFixLayoutHelper(FixLayoutHelper.BOTTOM_RIGHT, 20, 20); layoutHelper.setShowType(ScrollFixLayoutHelper.SHOW_ON_LEAVE); adapters.add(new SubAdapter(this, layoutHelper, 1) { @Override public void onBindViewHolder(MainViewHolder holder, int position) { super.onBindViewHolder(holder, position); LayoutParams layoutParams = new LayoutParams(50, 50); holder.itemView.setLayoutParams(layoutParams); } }); } if (LINEAR_LAYOUT) adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 100)); delegateAdapter.setAdapters(adapters); final Handler mainHandler = new Handler(Looper.getMainLooper()); trigger = new Runnable() { @Override public void run() { // recyclerView.scrollToPosition(22); // recyclerView.getAdapter().notifyDataSetChanged(); recyclerView.requestLayout(); // mainHandler.postDelayed(trigger, 1000); } }; mainHandler.postDelayed(trigger, 1000); }
From source file:com.libreteam.taxi.Customer_Boarding.java
public void didUpdatePosition() { if (timer == null) timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override//from ww w. j av a2s. co m public void run() { Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { // startTracking(driverLatLng); setUpMapView(); } }); } }, 0, 6000); }
From source file:com.nextgis.mobile.activity.MainActivity.java
protected void stopRefresh(final MenuItem refreshItem) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) return;// w w w. j a v a 2 s . c o m Handler handler = new Handler(Looper.getMainLooper()); final Runnable r = new Runnable() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) public void run() { if (refreshItem != null && refreshItem.getActionView() != null) { refreshItem.getActionView().clearAnimation(); refreshItem.setActionView(null); } } }; handler.post(r); }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java
public static String create(Context p_context, DatabaseAdapter p_dba, DefaultHttpClient p_http) { startTimestamp = System.currentTimeMillis(); if (isRunning == true) { isCanceled = true;//from w ww. ja va 2s . c o m isRunning = false; } isRunning = true; boolean recordSyncTime = true; dba = p_dba; db = dba.db(); em = dba.em(); http_client = p_http; context = p_context; last_sync_ts = MyPreferences.getFlowzrLastSync(context); FLOWZR_BASE_URL = "https://" + MyPreferences.getSyncApiUrl(context); FLOWZR_API_URL = FLOWZR_BASE_URL + "/financisto3/"; nsString = MyPreferences.getFlowzrAccount(context).replace("@", "_"); //urlsafe Log.i(TAG, "init sync engine, last sync was " + new Date(last_sync_ts).toLocaleString()); //if (true) { if (!checkSubscriptionFromWeb()) { Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.icon) .setTicker(context.getString(R.string.flowzr_subscription_required)) .setContentTitle(context.getString(R.string.flowzr_sync_error)) .setContentText(context.getString(R.string.flowzr_subscription_required, MyPreferences.getFlowzrAccount(context))) .setContentIntent(pendingIntent).setAutoCancel(true).build(); notificationManager.notify(0, notification); Log.w("flowzr", "subscription rejected from web"); isCanceled = true; MyPreferences.unsetAutoSync(context); return null; } else { mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Sets an ID for the notification, so it can be updated mNotifyBuilder = new NotificationCompat.Builder(context).setAutoCancel(true) .setContentTitle(context.getString(R.string.flowzr_sync)) .setContentText(context.getString(R.string.flowzr_sync_inprogress)) .setSmallIcon(R.drawable.icon); } if (!isCanceled) { notifyUser("fix created entities", 5); fixCreatedEntities(); } /** * pull delete */ if (!isCanceled) { notifyUser(context.getString(R.string.flowzr_sync_receiving) + " ...", 10); try { pullDelete(last_sync_ts); } catch (Exception e) { sendBackTrace(e); recordSyncTime = false; } } /** * push delete */ if (!isCanceled) { notifyUser(context.getString(R.string.flowzr_sync_sending) + " ...", 15); try { pushDelete(); } catch (Exception e) { sendBackTrace(e); recordSyncTime = false; } } /** * pull update */ if (!isCanceled && last_sync_ts == 0) { notifyUser(context.getString(R.string.flowzr_sync_receiving) + " ...", 20); try { pullUpdate(); } catch (IOException e) { sendBackTrace(e); recordSyncTime = false; } catch (JSONException e) { sendBackTrace(e); recordSyncTime = false; } catch (Exception e) { sendBackTrace(e); recordSyncTime = false; } } /** * push update */ if (!isCanceled) { notifyUser(context.getString(R.string.flowzr_sync_sending) + " ...", 35); try { pushUpdate(); } catch (ClientProtocolException e) { e.printStackTrace(); sendBackTrace(e); recordSyncTime = false; } catch (IOException e) { e.printStackTrace(); sendBackTrace(e); recordSyncTime = false; } catch (JSONException e) { e.printStackTrace(); sendBackTrace(e); recordSyncTime = false; } catch (Exception e) { e.printStackTrace(); recordSyncTime = false; } } /** * pull update */ if (!isCanceled && last_sync_ts > 0) { notifyUser(context.getString(R.string.flowzr_sync_receiving) + " ...", 20); try { pullUpdate(); } catch (IOException e) { sendBackTrace(e); recordSyncTime = false; } catch (JSONException e) { sendBackTrace(e); recordSyncTime = false; } catch (Exception e) { sendBackTrace(e); recordSyncTime = false; } } notifyUser(context.getString(R.string.integrity_fix), 80); new IntegrityFix(dba).fix(); /** * send account balances boundaries */ if (!isCanceled) { //if (true) { //will generate a Cloud Messaging request if prev. aborted notifyUser(context.getString(R.string.flowzr_sync_sending) + "...", 85); //nm.notify(NOTIFICATION_ID, mNotifyBuilder.build()); ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("action", "balancesRecalc")); nameValuePairs.add(new BasicNameValuePair("last_sync_ts", String.valueOf(last_sync_ts))); String serialNumber = Build.SERIAL != Build.UNKNOWN ? Build.SERIAL : Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); nameValuePairs.add(new BasicNameValuePair("serialNumber", serialNumber)); List<Account> accountsList = em.getAllAccountsList(); for (Account account : accountsList) { nameValuePairs.add(new BasicNameValuePair(account.remoteKey, String.valueOf(account.totalAmount))); Log.i("flowzr", account.remoteKey + " " + String.valueOf(account.totalAmount)); } try { httpPush(nameValuePairs, "balances"); } catch (Exception e) { sendBackTrace(e); } } notifyUser("Widgets ...", 90); AccountWidget.updateWidgets(context); Handler refresh = new Handler(Looper.getMainLooper()); refresh.post(new Runnable() { public void run() { if (currentActivity != null) { //currentActivity.refreshCurrentTab(); } } }); if (!isCanceled && MyPreferences.doGoogleDriveUpload(context)) { notifyUser(context.getString(R.string.flowzr_sync_sending) + " Google Drive", 95); pushAllBlobs(); } else { Log.i("flowzr", "picture upload desactivated in prefs"); } notifyUser(context.getString(R.string.flowzr_sync_success), 100); if (isCanceled == false) { if (recordSyncTime == true) { last_sync_ts = System.currentTimeMillis(); SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); editor.putLong("PROPERTY_LAST_SYNC_TIMESTAMP", last_sync_ts); editor.commit(); } } // mNotificationManager.cancel(NOTIFICATION_ID); isRunning = false; isCanceled = false; if (context instanceof FlowzrSyncActivity) { ((FlowzrSyncActivity) context).setIsFinished(); } return FLOWZR_BASE_URL; }
From source file:com.digium.respokesdk.RespokeCall.java
/** * Tear down the call and release resources * * @param shouldSendHangupSignal Send a hangup signal to the remote party if signal is not false and we have not received a hangup signal from the remote party. *//*from w w w .j a v a 2 s . c o m*/ public void hangup(boolean shouldSendHangupSignal) { if (!isHangingUp) { isHangingUp = true; if (shouldSendHangupSignal) { try { JSONObject data = new JSONObject("{'signalType':'bye','version':'1.0'}"); data.put("target", directConnectionOnly ? "directConnection" : "call"); data.put("sessionId", sessionID); data.put("signalId", Respoke.makeGUID()); // Keep a second reference to the listener since the disconnect method will clear it before the success handler is fired final WeakReference<Listener> hangupListener = listenerReference; if (null != signalingChannel) { signalingChannel.sendSignal(data, toEndpointId, toConnection, toType, true, new Respoke.TaskCompletionListener() { @Override public void onSuccess() { if (null != hangupListener) { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { Listener listener = hangupListener.get(); if (null != listener) { listener.onHangup(RespokeCall.this); } } }); } } @Override public void onError(String errorMessage) { postErrorToListener(errorMessage); } }); } } catch (JSONException e) { postErrorToListener("Error encoding signal to json"); } } disconnect(); } }
From source file:com.ifoer.util.NetPOSPrinter.java
public void resultToast(int result) { new Handler(Looper.getMainLooper()).post(new C07551(result)); }
From source file:com.wuman.androidimageloader.ImageLoader.java
private void enqueueRequest(ImageRequest request) { if (Looper.myLooper() != Looper.getMainLooper()) { throw new RuntimeException("Must be called in the main thread."); }/*from ww w. j a v a2s.co m*/ ImageTask task = new ImageTask(); task.executeOnExecutor(ImageTask.LIFO_THREAD_POOL_EXECUTOR, request); }
From source file:com.ryan.ryanreader.fragments.ImageViewFragment.java
private void revertToWeb() { LinkHandler.onLinkClicked(getSupportActivity(), url.toString(), true); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { getSupportActivity().finish(); }/*from w w w. j ava 2 s . c o m*/ }); }