Example usage for android.text.format DateUtils getRelativeTimeSpanString

List of usage examples for android.text.format DateUtils getRelativeTimeSpanString

Introduction

In this page you can find the example usage for android.text.format DateUtils getRelativeTimeSpanString.

Prototype

public static CharSequence getRelativeTimeSpanString(long time, long now, long minResolution, int flags) 

Source Link

Document

Returns a string describing 'time' as a time relative to 'now'.

Usage

From source file:com.androzic.MapFragment.java

private void onUpdateNavigationStatus() {
    if (!application.isNavigating())
        return;/*from ww  w .  j  a  va  2 s . c om*/

    long now = System.currentTimeMillis();

    double distance = application.navigationService.navDistance;
    double bearing = application.navigationService.navBearing;
    long turn = application.navigationService.navTurn;
    double vmg = application.navigationService.navVMG;
    int ete = application.navigationService.navETE;

    String[] dist = StringFormatter.distanceC(distance, StringFormatter.precisionFormat);
    String eteString = (ete == Integer.MAX_VALUE) ? getString(R.string.never)
            : (String) DateUtils.getRelativeTimeSpanString(now + (ete + 1) * 60000, now,
                    DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
    String extra = StringFormatter.speedH(vmg) + " | " + eteString;

    String trnsym = "";
    if (turn > 0) {
        trnsym = "R";
    } else if (turn < 0) {
        trnsym = "L";
        turn = -turn;
    }

    bearing = application.fixDeclination(bearing);
    distanceValue.setText(dist[0]);
    distanceUnit.setText(dist[1]);
    bearingValue.setText(StringFormatter.angleC(bearing));
    turnValue.setText(StringFormatter.angleC(turn) + trnsym);
    waypointExtra.setText(extra);

    if (application.navigationService.isNavigatingViaRoute()) {
        View rootView = getView();
        boolean hasNext = application.navigationService.hasNextRouteWaypoint();
        if (distance < application.navigationService.navProximity * 3 && !animationSet) {
            AnimationSet animation = new AnimationSet(true);
            animation.addAnimation(new AlphaAnimation(1.0f, 0.3f));
            animation.addAnimation(new AlphaAnimation(0.3f, 1.0f));
            animation.setDuration(500);
            animation.setRepeatCount(10);
            rootView.findViewById(R.id.waypointinfo).startAnimation(animation);
            if (!hasNext) {
                rootView.findViewById(R.id.routeinfo).startAnimation(animation);
            }
            animationSet = true;
        } else if (animationSet) {
            rootView.findViewById(R.id.waypointinfo).setAnimation(null);
            if (!hasNext) {
                rootView.findViewById(R.id.routeinfo).setAnimation(null);
            }
            animationSet = false;
        }

        if (application.navigationService.navXTK == Double.NEGATIVE_INFINITY) {
            xtkValue.setText("--");
            xtkUnit.setText("--");
        } else {
            String xtksym = application.navigationService.navXTK == 0 ? ""
                    : application.navigationService.navXTK > 0 ? "R" : "L";
            String[] xtks = StringFormatter.distanceC(Math.abs(application.navigationService.navXTK));
            xtkValue.setText(xtks[0] + xtksym);
            xtkUnit.setText(xtks[1]);
        }

        double navDistance = application.navigationService.navRouteDistanceLeft();
        int eta = application.navigationService.navRouteETE(navDistance);
        if (eta < Integer.MAX_VALUE)
            eta += application.navigationService.navETE;
        String etaString = (eta == Integer.MAX_VALUE) ? getString(R.string.never)
                : (String) DateUtils.getRelativeTimeSpanString(now + (eta + 1) * 60000, now,
                        DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
        extra = StringFormatter.distanceH(navDistance + distance, 1000) + " | " + etaString;
        routeExtra.setText(extra);
    }
}

From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java

private void updateOfflineMissedCalls() {

    String from_summary = "", noc = "", from_detailed = "", lt = "", ct = "";
    Cursor c;//  ww w .j a va2s  . c om
    String time = "", value;
    try {

        dbContacts = new DBContacts(mcontext);
        //   dbContacts.openToWrite();
        dbContacts.openToRead();
        c = dbContacts.fetch_details_from_MIssedCall_Offline_Table();

        if (c.getCount() > 0) {
            c.moveToFirst();
            value = c.getString(2);
            time = "&time=" + value;
            //  time = "&time=" + "1408434902";
        }

        c.close();
        dbContacts.close();

        Log.d("webService App Resume", "called");
        HttpParams p = new BasicHttpParams();
        p.setParameter("user", "1");
        HttpClient httpclient = new DefaultHttpClient(p);
        String url = "http://ip.roaming4world.com/esstel/app_resume_info.php?contact="
                + prefs.getString(stored_user_country_code, "NoValue")
                + prefs.getString(stored_user_mobile_no, "NoValue") + time;

        Log.d("url", url + " #");

        HttpGet httpget = new HttpGet(url);
        ResponseHandler<String> responseHandler;
        String responseBody;
        responseHandler = new BasicResponseHandler();
        responseBody = httpclient.execute(httpget, responseHandler);

        dbContacts.openToWrite();

        JSONObject json = new JSONObject(responseBody);

        Log.d("response11", json + " #");

        if (json.getString("verify_from_pc").equals("true")) {
            Intent i = new Intent(mcontext, DesktopVerificationcode_Activity.class);
            i.putExtra("verify_code", json.getString("verify_code"));
            i.putExtra("countdown_time", json.getString("countdown_time"));
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mcontext.startActivity(i);
        }

        prefs.edit().putString(stored_min_call_credit, json.getString("min_call_credit")).commit();
        prefs.edit().putString(stored_user_bal, json.getString("user_bal")).commit();
        prefs.edit().putString(stored_server_ipaddress, json.getString("server_ip")).commit();

        Log.d("stored_server_ip address", json.getString("server_ip") + " #");
        Log.d("stored_user_bal", json.getString("user_bal") + " #");

        if (json.getString("valid").equals("true")) {

            JSONArray summary = json.getJSONArray("summary");
            JSONArray detailed = json.getJSONArray("detailed");

            for (int i = 0; i < summary.length(); i++) {
                JSONObject summarydata = summary.getJSONObject(i);
                from_summary = summarydata.getString("from");
                noc = summarydata.getString("noc");
                lt = summarydata.getString("lt");

                Log.d("from_summary", from_summary + " #");
                Log.d("noc", noc + " #");
                Log.d("lt", lt + " #");

                dbContacts.insert_MIssedCall_Offline_detail_in_db(from_summary, lt, noc);

                /*
                mBuilder.setSmallIcon(R.drawable.notification_icon);
                mBuilder.setContentTitle("Missed call (" + noc +")");
                mBuilder.setContentText(from_summary + "   " + lt);
                mBuilder.setContentIntent(resultPendingIntent);
                mNotificationManager.notify(Integer.parseInt(lt), mBuilder.build());
                */
                String count = "Missed call (" + noc + ")";

                CharSequence dateText = DateUtils.getRelativeTimeSpanString(Long.parseLong(lt) * 1000,
                        System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
                        DateUtils.FORMAT_ABBREV_RELATIVE);

                String num_date = from_summary + "   last on " + dateText.toString();

                showNotification(count, num_date, Integer.parseInt(lt));

            }

            for (int i = 0; i < detailed.length(); i++) {
                JSONObject detaileddata = detailed.getJSONObject(i);
                from_detailed = detaileddata.getString("from");
                ct = detaileddata.getString("ct");

                Log.d("from_detailed", from_detailed + " #");
                Log.d("ct", ct + " #");

                dbContacts.insert_MIssedCall_detail_in_db(from_detailed, ct);
            }

            dbContacts.close();

        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}

From source file:com.androzic.vnspeech.MapFragment.java

private void onUpdateNavigationStatus() {
    if (!application.isNavigating())
        return;//ww  w .j a  va 2 s.  c  o m

    if (!map.isFollowing())
        map.refreshMap();

    long now = System.currentTimeMillis();

    double distance = application.navigationService.navDistance;
    double bearing = application.navigationService.navBearing;
    long turn = application.navigationService.navTurn;
    double vmg = application.navigationService.navVMG;
    int ete = application.navigationService.navETE;

    String[] dist = StringFormatter.distanceC(distance, StringFormatter.precisionFormat);
    String eteString = (ete == Integer.MAX_VALUE) ? getString(R.string.never)
            : (String) DateUtils.getRelativeTimeSpanString(now + (ete + 1) * 60000, now,
                    DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
    String extra = StringFormatter.speedH(vmg) + " | " + eteString;

    String trnsym = "";
    if (turn > 0) {
        trnsym = "R";
    } else if (turn < 0) {
        trnsym = "L";
        turn = -turn;
    }

    bearing = application.fixDeclination(bearing);
    distanceValue.setText(dist[0]);
    distanceUnit.setText(dist[1]);
    bearingValue.setText(StringFormatter.angleC(bearing));
    turnValue.setText(StringFormatter.angleC(turn) + trnsym);
    waypointExtra.setText(extra);

    if (application.navigationService.isNavigatingViaRoute()) {
        View rootView = getView();
        boolean hasNext = application.navigationService.hasNextRouteWaypoint();
        if (distance < application.navigationService.navProximity * 3 && !animationSet) {
            AnimationSet animation = new AnimationSet(true);
            animation.addAnimation(new AlphaAnimation(1.0f, 0.3f));
            animation.addAnimation(new AlphaAnimation(0.3f, 1.0f));
            animation.setDuration(500);
            animation.setRepeatCount(10);
            rootView.findViewById(R.id.waypointinfo).startAnimation(animation);
            if (!hasNext) {
                rootView.findViewById(R.id.routeinfo).startAnimation(animation);
            }
            animationSet = true;
        } else if (animationSet) {
            rootView.findViewById(R.id.waypointinfo).setAnimation(null);
            if (!hasNext) {
                rootView.findViewById(R.id.routeinfo).setAnimation(null);
            }
            animationSet = false;
        }

        if (application.navigationService.navXTK == Double.NEGATIVE_INFINITY) {
            xtkValue.setText("--");
            xtkUnit.setText("--");
        } else {
            String xtksym = application.navigationService.navXTK == 0 ? ""
                    : application.navigationService.navXTK > 0 ? "R" : "L";
            String[] xtks = StringFormatter.distanceC(Math.abs(application.navigationService.navXTK));
            xtkValue.setText(xtks[0] + xtksym);
            xtkUnit.setText(xtks[1]);
        }

        double navDistance = application.navigationService.navRouteDistanceLeft();
        int eta = application.navigationService.navRouteETE(navDistance);
        if (eta < Integer.MAX_VALUE)
            eta += application.navigationService.navETE;
        String etaString = (eta == Integer.MAX_VALUE) ? getString(R.string.never)
                : (String) DateUtils.getRelativeTimeSpanString(now + (eta + 1) * 60000, now,
                        DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
        extra = StringFormatter.distanceH(navDistance + distance, 1000) + " | " + etaString;
        routeExtra.setText(extra);
    }
}

From source file:org.onebusaway.android.ui.ArrivalsListHeader.java

private void refreshError() {
    final long now = System.currentTimeMillis();
    final long responseTime = mController.getLastGoodResponseTime();
    AlertList alerts = mController.getAlertList();
    mHasWarning = false;/* w w w  .  j a  va2 s.  c o  m*/
    mHasError = false;

    if (mResponseError != null) {
        alerts.remove(mResponseError);
    }

    if ((responseTime) != 0 && ((now - responseTime) >= 2 * DateUtils.MINUTE_IN_MILLIS)) {
        CharSequence relativeTime = DateUtils.getRelativeTimeSpanString(responseTime, now,
                DateUtils.MINUTE_IN_MILLIS, 0);
        CharSequence s = mContext.getString(R.string.stop_info_old_data, relativeTime);
        mResponseError = new ResponseError(s);
        alerts.insert(mResponseError, 0);
    }

    // If there is a warning or error alert, and show the alert icon in the header

    for (int i = 0; i < alerts.getCount(); i++) {
        AlertList.Alert a = alerts.getItem(i);
        if (a.getType() == AlertList.Alert.TYPE_WARNING) {
            mHasWarning = true;
        }
        if (a.getType() == AlertList.Alert.TYPE_ERROR) {
            mHasError = true;
        }
    }

    if (mHasError) {
        //UIHelp.showViewWithAnimation(mAlertView, mShortAnimationDuration);
        mAlertView.setVisibility(View.VISIBLE);
        mAlertView.setColorFilter(mResources.getColor(R.color.alert_icon_error));
        mAlertView.setContentDescription(mResources.getString(R.string.alert_content_description_error));
    } else if (mHasWarning) {
        //UIHelp.showViewWithAnimation(mAlertView, mShortAnimationDuration);
        mAlertView.setVisibility(View.VISIBLE);
        mAlertView.setColorFilter(mResources.getColor(R.color.alert_icon_warning));
        mAlertView.setContentDescription(mResources.getString(R.string.alert_content_description_warning));
    } else {
        // Don't show the header icon for info-level or no alerts
        //UIHelp.hideViewWithAnimation(mAlertView, mShortAnimationDuration);
        mAlertView.setVisibility(View.GONE);
        mAlertView.setContentDescription("");
    }
}