List of usage examples for android.os Looper getMainLooper
public static Looper getMainLooper()
From source file:com.rks.musicx.ui.activities.MainActivity.java
@Override protected void function() { fragmentLoader(setContainerId(), setFragment()); permissionManager.checkPermissions(MainActivity.this); if (!Extras.getInstance().getWidgetTrack()) { permissionManager.widgetPermission(MainActivity.this); }//from w w w . j a v a2s .c o m if (!Extras.getInstance().getSettings()) { permissionManager.settingPermission(MainActivity.this); } ateKey = returnAteKey(); accentcolor = Config.accentColor(this, ateKey); primarycolor = Config.primaryColor(this, ateKey); if (mNavigationView != null) { mNavigationView.setNavigationItemSelectedListener(MainActivity.this); } count = Extras.getInstance().getInitValue(MainActivity.this, "first", "last"); if (count == 0) { Intent intent = new Intent(); intent.setClass(MainActivity.this, IntroActivity.class); startActivity(intent); count++; Extras.getInstance().setInitValue(MainActivity.this, count, "first", "last"); } songDetail.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(MainActivity.this, PlayingActivity.class); startActivityForResult(i, NAV); } }); logoLayout = (RelativeLayout) mNavigationHeader.findViewById(R.id.logolayout); logoLayout.setBackgroundColor(primarycolor); mRequestManager = Glide.with(MainActivity.this); if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) { SongArtist.setTextColor(Color.WHITE); SongTitle.setTextColor(Color.WHITE); } else { SongArtist.setTextColor(Color.WHITE); SongTitle.setTextColor(Color.WHITE); } ShortcutsHandler.create(MainActivity.this); SongTitle.setTypeface(Helper.getFont(MainActivity.this)); SongArtist.setTypeface(Helper.getFont(MainActivity.this)); songProgressHandler = new Handler(Looper.getMainLooper()); progressRunnable = new ProgressRunnable(MainActivity.this); helper = new Helper(this); pause = ContextCompat.getDrawable(MainActivity.this, R.drawable.aw_ic_pause); play = ContextCompat.getDrawable(MainActivity.this, R.drawable.aw_ic_play); playToggle.setOnClickListener(onClick); }
From source file:com.jrummyapps.android.safetynet.SafetyNetHelper.java
@Override public void onConnected(@Nullable Bundle bundle) { Runnable runnable = new Runnable() { @Override//from w ww . jav a 2 s. c o m public void run() { try { requestTimestamp = System.currentTimeMillis(); SafetyNetApi.AttestationResult result = SafetyNet.SafetyNetApi.attest(googleApiClient, nonce) .await(); if (cancel) { return; } if (!result.getStatus().isSuccess()) { onError(RESPONSE_FAILED_ATTESTATION, "An error occurred while communicating with SafetyNet."); return; } try { SafetyNetResponse response = getSafetyNetResponseFromJws(result.getJwsResult()); SafetyNetVerification verification = verify(response); onFinished(response, verification); } catch (SafetyNetError e) { onError(RESPONSE_FAILED_PARSING_JWS, e.getLocalizedMessage()); } } catch (Exception e) { onError(UNKNOWN_ERROR, e.getLocalizedMessage()); } } }; if (Looper.getMainLooper() == Looper.myLooper()) { new Thread(runnable).start(); } else { runnable.run(); } }
From source file:com.facebook.Session.java
/** * Used by version 2 of the serialization proxy, do not modify. *///from w w w . java 2 s. co m private Session(String applicationId, SessionState state, AccessToken tokenInfo, Date lastAttemptedTokenExtendDate, boolean shouldAutoPublish, AuthorizationRequest pendingAuthorizationRequest, Set<String> requestedPermissions) { this.applicationId = applicationId; this.state = state; this.tokenInfo = tokenInfo; this.lastAttemptedTokenExtendDate = lastAttemptedTokenExtendDate; this.pendingAuthorizationRequest = pendingAuthorizationRequest; handler = new Handler(Looper.getMainLooper()); currentTokenRefreshRequest = null; tokenCachingStrategy = null; callbacks = new ArrayList<StatusCallback>(); }
From source file:ru.orangesoftware.financisto.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;/*ww w . j a va 2 s.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; } } /** * 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) + "...", 80); //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))); try { httpPush(nameValuePairs, "balances"); } catch (Exception e) { sendBackTrace(e); } } notifyUser(context.getString(R.string.integrity_fix), 85); new IntegrityFix(dba).fix(); 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.door43.translationstudio.ui.dialogs.BackupDialog.java
/** * restore the dialogs that were displayed before rotation */// ww w . j a va2 s . c o m private void restoreDialogs() { Handler hand = new Handler(Looper.getMainLooper()); hand.post(new Runnable() { // wait for backup dialog to be drawn before showing popups @Override public void run() { switch (mDialogShown) { case PUSH_REJECTED: showPushRejection(targetTranslation); break; case AUTH_FAILURE: showAuthFailure(); break; case BACKUP_FAILED: showUploadFailedDialog(targetTranslation); break; case NO_INTERNET: showNoInternetDialog(); break; case SHOW_BACKUP_RESULTS: showBackupResults(mDialogMessage); break; case SHOW_PUSH_SUCCESS: showPushSuccess(mDialogMessage); break; case MERGE_CONFLICT: showMergeConflict(targetTranslation); break; case EXPORT_TO_USFM_PROMPT: showExportToUsfmPrompt(); break; case EXPORT_PROJECT_PROMPT: showExportProjectPrompt(); break; case EXPORT_TO_USFM_RESULTS: showUsfmExportResults(mDialogMessage); break; case EXPORT_PROJECT_OVERWRITE: showExportProjectOverwrite(mDialogMessage); break; case EXPORT_USFM_OVERWRITE: showExportUsfmOverwrite(mDialogMessage); break; case NONE: break; default: Logger.e(TAG, "Unsupported restore dialog: " + mDialogShown.toString()); break; } } }); }
From source file:com.chao.facebookzc.Session.java
/** * Used by version 2 of the serialization proxy, do not modify. */// w w w . j ava 2s. c o m private Session(String applicationId, SessionState state, AccessToken tokenInfo, Date lastAttemptedTokenExtendDate, boolean shouldAutoPublish, AuthorizationRequest pendingAuthorizationRequest, Set<String> requestedPermissions) { this.applicationId = applicationId; this.state = state; this.tokenInfo = tokenInfo; this.lastAttemptedTokenExtendDate = lastAttemptedTokenExtendDate; this.pendingAuthorizationRequest = pendingAuthorizationRequest; this.requestedPermissions = requestedPermissions; handler = new Handler(Looper.getMainLooper()); currentTokenRefreshRequest = null; tokenCachingStrategy = null; callbacks = new ArrayList<StatusCallback>(); }
From source file:com.ryan.ryanreader.fragments.CommentListingFragment.java
private void makeFirstRequest(final Context context) { final RedditAccount user = RedditAccountManager.getInstance(context).getDefaultAccount(); final CacheManager cm = CacheManager.getInstance(context); // TODO parameterise limit request = new CacheRequest(url, user, session, Constants.Priority.API_COMMENT_LIST, 0, downloadType, Constants.FileType.COMMENT_LIST, true, true, false, context) { @Override//from w ww . j a va 2s .c om protected void onDownloadNecessary() { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { listFooter.addView(loadingView); adapter.notifyDataSetChanged(); } }); } @Override protected void onDownloadStarted() { loadingView.setIndeterminate(context.getString(R.string.download_connecting)); } @Override protected void onCallbackException(final Throwable t) { request = null; BugReportActivity.handleGlobalError(context, t); } @Override protected void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { request = null; if (!isAdded()) return; if (loadingView != null) loadingView.setDoneNoAnim(R.string.download_failed); final RRError error = General.getGeneralErrorForFailure(context, type, t, status); new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { notifications.addView(new ErrorView(getSupportActivity(), error)); } }); } @Override protected void onProgress(final long bytesRead, final long totalBytes) { } @Override protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, final long timestamp, final UUID session, final boolean fromCache, final String mimetype) { request = null; } @Override public void onJsonParseStarted(final JsonValue value, final long timestamp, final UUID session, final boolean fromCache) { if (isAdded() && loadingView != null) loadingView.setIndeterminate("Downloading..."); // TODO pref (currently 10 mins) // TODO xml if (fromCache && RRTime.since(timestamp) > 10 * 60 * 1000) { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (isDetached()) return; final TextView cacheNotif = new TextView(context); cacheNotif.setText(context.getString(R.string.listing_cached) + " " + RRTime.formatDateTime(timestamp, context)); final int paddingPx = General.dpToPixels(context, 6); final int sidePaddingPx = General.dpToPixels(context, 10); cacheNotif.setPadding(sidePaddingPx, paddingPx, sidePaddingPx, paddingPx); cacheNotif.setTextSize(13f); listHeaderNotifications.addView(cacheNotif); adapter.notifyDataSetChanged(); } }); } ((SessionChangeListener) getSupportActivity()).onSessionChanged(session, SessionChangeListener.SessionChangeType.COMMENTS, timestamp); // TODO {"error": 403} is received for unauthorized subreddits try { // Download main post if (value.getType() == JsonValue.Type.ARRAY) { // lol, reddit api final JsonBufferedArray root = value.asArray(); final JsonBufferedObject thing = root.get(0).asObject(); final JsonBufferedObject listing = thing.getObject("data"); final JsonBufferedArray postContainer = listing.getArray("children"); final RedditThing postThing = postContainer.getObject(0, RedditThing.class); final RedditPost post = postThing.asPost(); // TODO show upvote/downvote/etc buttons final RedditSubreddit parentSubreddit = new RedditSubreddit("/r/" + post.subreddit, post.subreddit, false); CommentListingFragment.this.post = new RedditPreparedPost(context, cm, 0, post, timestamp, true, parentSubreddit, false, false, false, user); final ViewGroup selfText; if (post.is_self && post.selftext != null && post.selftext.trim().length() > 0) { selfText = RedditCommentTextParser.parse(StringEscapeUtils.unescapeHtml4(post.selftext)) .generate(context, 14f * commentFontScale, null, new ActiveTextView.OnLinkClickedListener() { public void onClickUrl(String url) { if (url != null) LinkHandler.onLinkClicked(getSupportActivity(), url, false); } public void onClickText(Object attachment) { } }, CommentListingFragment.this.post); } else { selfText = null; } new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { final RedditPostHeaderView postHeader = new RedditPostHeaderView( getSupportActivity(), CommentListingFragment.this.post, CommentListingFragment.this); listHeaderPost.addView(postHeader); if (selfText != null) { selfText.setFocusable(false); selfText.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); final int paddingPx = General.dpToPixels(context, 10); listHeaderSelftext.addView(selfText); listHeaderSelftext.setPadding(paddingPx, paddingPx, paddingPx, paddingPx); listHeaderNotifications.setBackgroundColor(Color.argb(35, 128, 128, 128)); } if (!General.isTablet(context, PreferenceManager.getDefaultSharedPreferences(context))) { getSupportActivity().getSupportActionBar().setTitle(post.title); } } }); } // Download comments final JsonBufferedObject thing; if (value.getType() == JsonValue.Type.ARRAY) { thing = value.asArray().get(1).asObject(); } else { thing = value.asObject(); } final JsonBufferedObject listing = thing.getObject("data"); final JsonBufferedArray topLevelComments = listing.getArray("children"); final HashSet<String> needsChanging = RedditChangeDataManager.getInstance(context) .getChangedForParent(parentPostIdAndType, user); for (final JsonValue commentThingValue : topLevelComments) { buildComments(commentThingValue, null, timestamp, needsChanging); } commentHandler.sendMessage(General.handlerMessage(0, buffer)); } catch (Throwable t) { notifyFailure(RequestFailureType.PARSE, t, null, "Parse failure"); return; } if (isAdded() && loadingView != null) loadingView.setDoneNoAnim(R.string.download_done); } private ArrayList<RedditPreparedComment> buffer = new ArrayList<RedditPreparedComment>(); private void buildComments(final JsonValue value, final RedditPreparedComment parent, final long timestamp, final HashSet<String> needsChanging) throws IOException, InterruptedException, IllegalAccessException, java.lang.InstantiationException, NoSuchMethodException, InvocationTargetException { final RedditThing commentThing = value.asObject(RedditThing.class); if (commentThing.getKind() != RedditThing.Kind.COMMENT) return; final RedditComment comment = commentThing.asComment(); final RedditPreparedComment preparedComment = new RedditPreparedComment(context, comment, parent, timestamp, needsChanging.contains(comment.name), post, user, headerItems); after = preparedComment.idAndType; buffer.add(preparedComment); if (buffer.size() >= 40) { commentHandler.sendMessage(General.handlerMessage(0, buffer)); buffer = new ArrayList<RedditPreparedComment>(); } if (comment.replies.getType() == JsonValue.Type.OBJECT) { final JsonBufferedObject replies = comment.replies.asObject(); final JsonBufferedArray children = replies.getObject("data").getArray("children"); for (final JsonValue v : children) { buildComments(v, preparedComment, timestamp, needsChanging); } } } }; cm.makeRequest(request); }
From source file:com.vk.sdk.dialogs.VKShareDialog.java
private void loadAndAddPhoto(final String photoUrl, final int attempt) { if (attempt > 10) return;//from w ww . j a v a 2 s . c om VKImageOperation op = new VKImageOperation(photoUrl); op.setImageOperationListener(new VKImageOperation.VKImageOperationListener() { @Override public void onComplete(VKImageOperation operation, Bitmap image) { if (image == null) { new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { @Override public void run() { loadAndAddPhoto(photoUrl, attempt + 1); } }, 1000); return; } addBitmapToPreview(image); } }); VKHttpClient.enqueueOperation(op); }
From source file:com.flowzr.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 ww w . java 2s .co 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.networking.ApiTestActivity.java
public void createAnUser(View view) { AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER) .addBodyParameter("firstname", "Suman").addBodyParameter("lastname", "Shekhar").setTag(this) .setPriority(Priority.LOW).build().setAnalyticsListener(new AnalyticsListener() { @Override//from www . j a v a 2 s. c o m 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()); } } }); }