Example usage for android.text.format DateFormat getDateFormat

List of usage examples for android.text.format DateFormat getDateFormat

Introduction

In this page you can find the example usage for android.text.format DateFormat getDateFormat.

Prototype

public static java.text.DateFormat getDateFormat(Context context) 

Source Link

Document

Returns a java.text.DateFormat object that can format the date in short form according to the context's locale.

Usage

From source file:com.joefernandez.irrduino.android.remote.ViewReportActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.report);/*  www . ja  v a 2 s. com*/

    reportText = (TextView) findViewById(id.report_text);
    reportText.setMovementMethod(new ScrollingMovementMethod());
    settingsChanged = true;

    // get settings
    settings = PreferenceManager.getDefaultSharedPreferences(this);

    // set time zone settings and date formatter
    priorDate.setTimeZone(TimeZone.getDefault());
    nextDate.setTimeZone(TimeZone.getDefault());

    dateFormat = DateFormat.getDateFormat(this); // set localized date-only format
    timeFormat = DateFormat.getTimeFormat(this); // set localized time-only format

    //send the report request
    if (settings.getString(Settings.SERVER_HOST_NAME, Settings.DEFAULT_SERVER_HOST)
            .compareTo(Settings.DEFAULT_SERVER_HOST) == 0) {
        // default setting, warn user
        reportText.setText("Report server is not set,\n specify a server in Settings.");
    } else {
        reportText.setText("Requesting report...");
        new IrrduinoServerRequestTask().execute(getReportServerUrl() + REPORT_JSON_FORMAT);
    }
}

From source file:com.dgsd.android.ShiftTracker.Fragment.HoursAndIncomeSummaryFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View v = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_hour_and_income_summary, null);

    mMonth = (TextView) v.findViewById(R.id.month);
    mThreeMonth = (TextView) v.findViewById(R.id.three_months);
    mSixMonth = (TextView) v.findViewById(R.id.six_months);
    mNineMonth = (TextView) v.findViewById(R.id.nine_months);
    mThisYear = (TextView) v.findViewById(R.id.year);

    AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
    b.setView(v);//from w  w w  . ja  v a2s .com

    Time time = new Time();
    time.setJulianDay(mJulianDay);

    b.setTitle(DateFormat.getDateFormat(getActivity()).format(time.toMillis(true)));

    Dialog d = b.create();
    d.setCanceledOnTouchOutside(true);

    return d;
}

From source file:de.t_animal.journeyapp.InformationFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    fragmentRootView = inflater.inflate(R.layout.fragment_information, container, false);

    JourneyProperties prop = JourneyProperties.getInstance(getActivity());
    String journeyDateString = DateFormat.getDateFormat(getActivity()).format(prop.getJourneyDate()) + " "
            + DateFormat.getTimeFormat(getActivity()).format(prop.getJourneyDate());

    ((TextView) fragmentRootView.findViewById(R.id.info_journeyName_value)).setText(prop.getJourneyName());
    ((TextView) fragmentRootView.findViewById(R.id.info_journeyDate_value)).setText(journeyDateString);
    ((TextView) fragmentRootView.findViewById(R.id.info_journeyLocation_value))
            .setText(prop.getJourneyStartLocation());
    ((TextView) fragmentRootView.findViewById(R.id.info_journeyFurtherInformation_value))
            .setText(prop.getJourneyFurtherInformation());

    locationServiceButton = (Switch) fragmentRootView.findViewById(R.id.locationServiceButton);
    info_mapFollowingUserButton = (Switch) fragmentRootView.findViewById(R.id.info_mapFollowingUserButton);

    locationServiceButton.setOnClickListener(this);
    info_mapFollowingUserButton.setOnClickListener(this);
    ((Button) fragmentRootView.findViewById(R.id.info_resetJourneyButton)).setOnClickListener(this);
    ((TextView) fragmentRootView.findViewById(R.id.info_flattr)).setOnClickListener(this);
    ((TextView) fragmentRootView.findViewById(R.id.info_acknowledgement)).setOnClickListener(this);
    ((TextView) fragmentRootView.findViewById(R.id.info_license)).setOnClickListener(this);

    return fragmentRootView;
}

From source file:com.yeldi.yeldibazaar.ManageRepo.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false))
        setTheme(R.style.AppThemeLight);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.repolist);//from  w  w  w.  jav  a2 s  . c om

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    TextView tv_lastCheck = (TextView) findViewById(R.id.lastUpdateCheck);
    long lastUpdate = prefs.getLong("lastUpdateCheck", 0);
    String s_lastUpdateCheck = "";
    if (lastUpdate == 0) {
        s_lastUpdateCheck = getString(R.string.never);
    } else {
        Date d = new Date(lastUpdate);
        s_lastUpdateCheck = DateFormat.getDateFormat(this).format(d) + " "
                + DateFormat.getTimeFormat(this).format(d);
    }
    tv_lastCheck.setText(getString(R.string.last_update_check, s_lastUpdateCheck));

    reposToRemove = new ArrayList<String>();
    reposToDisable = new ArrayList<String>();
}

From source file:de.persoapp.android.activity.fragment.CertificateFragment.java

public static String dateToString(Context context, Date date) {
    return DateFormat.getDateFormat(context).format(date);
}

From source file:com.androzic.GPSInfo.java

private void updateGPSInfo() {
    switch (application.gpsStatus) {
    case LocationService.GPS_OK:
        satsValue.setText(String.valueOf(application.gpsFSats) + "/" + String.valueOf(application.gpsTSats));
        break;/*from  ww  w  .  ja  v a  2s .  c  o  m*/
    case LocationService.GPS_OFF:
        satsValue.setText(R.string.sat_stop);
        break;
    case LocationService.GPS_SEARCHING:
        satsValue.setText(String.valueOf(application.gpsFSats) + "/" + String.valueOf(application.gpsTSats));
        satsValue.startAnimation(shake);
        break;
    }
    float hdop = application.getHDOP();
    if (!Float.isNaN(hdop))
        hdopValue.setText(String.format("%.1f", hdop));
    float vdop = application.getVDOP();
    if (!Float.isNaN(vdop))
        vdopValue.setText(String.format("%.1f", vdop));

    if (application.lastKnownLocation != null) {
        Date date = new Date(application.lastKnownLocation.getTime());
        lastfixValue.setText(DateFormat.getDateFormat(application).format(date) + " "
                + DateFormat.getTimeFormat(application).format(date));
        accuracyValue.setText(application.lastKnownLocation.hasAccuracy()
                ? StringFormatter.distanceH(application.lastKnownLocation.getAccuracy(), "%.1f", 1000)
                : "N/A");
    }
}

From source file:net.reichholf.dreamdroid.activities.DreamDroidShareActivity.java

@SuppressWarnings("deprecation")
private void playOnDream(Profile p) {
    String url = null;//w w  w .j  ava  2  s  .c o m
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    mShc = SimpleHttpClient.getInstance(p);
    if (Intent.ACTION_SEND.equals(i.getAction()))
        url = extras.getString(Intent.EXTRA_TEXT);
    else if (Intent.ACTION_VIEW.equals(i.getAction()))
        url = i.getDataString();

    if (url != null) {
        Log.i(LOG_TAG, url);
        Log.i(LOG_TAG, p.getHost());

        String time = DateFormat.getDateFormat(this).format(new Date());
        String title = getString(R.string.sent_from_dreamdroid, time);
        if (extras != null) {
            // semperVidLinks sends "artist" and "song" attributes for the
            // youtube video titles
            String song = extras.getString("song");
            if (song != null) {
                String artist = extras.getString("artist");
                if (artist != null)
                    title = artist + " - " + song;
            } else {
                String tmp = extras.getString("title");
                if (tmp != null)
                    title = tmp;
            }
        }
        mTitle = new String(title);

        url = URLEncoder.encode(url).replace("+", "%20");
        title = URLEncoder.encode(title).replace("+", "%20");

        String ref = "4097:0:1:0:0:0:0:0:0:0:" + url + ":" + title;
        Log.i(LOG_TAG, ref);
        ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("file", ref));
        execSimpleResultTask(params);
    } else {
        finish();
    }
}

From source file:net.reichholf.dreamdroid.activities.ShareActivity.java

@SuppressWarnings("deprecation")
private void playOnDream(Profile p) {
    String url = null;//  ww  w . jav  a 2  s. co  m
    Intent i = getIntent();
    Bundle extras = i.getExtras();
    mShc = SimpleHttpClient.getInstance(p);
    if (Intent.ACTION_SEND.equals(i.getAction()))
        url = extras.getString(Intent.EXTRA_TEXT);
    else if (Intent.ACTION_VIEW.equals(i.getAction()))
        url = i.getDataString();

    if (url != null) {
        Log.i(LOG_TAG, url);
        Log.i(LOG_TAG, p.getHost());

        String time = DateFormat.getDateFormat(this).format(new Date());
        String title = getString(R.string.sent_from_dreamdroid, time);
        if (extras != null) {
            // semperVidLinks sends "artist" and "song" attributes for the
            // youtube video titles
            String song = extras.getString("song");
            if (song != null) {
                String artist = extras.getString("artist");
                if (artist != null)
                    title = artist + " - " + song;
            } else {
                String tmp = extras.getString("title");
                if (tmp != null)
                    title = tmp;
            }
        }
        mTitle = title;

        url = URLEncoder.encode(url).replace("+", "%20");
        title = URLEncoder.encode(title).replace("+", "%20");

        String ref = "4097:0:1:0:0:0:0:0:0:0:" + url + ":" + title;
        Log.i(LOG_TAG, ref);
        ArrayList<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("file", ref));
        execSimpleResultTask(params);
    } else {
        finish();
    }
}

From source file:org.sufficientlysecure.keychain.ui.ViewCertActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (data.moveToFirst()) {
        String signeeKey = PgpKeyHelper.convertKeyIdToHex(data.getLong(INDEX_MASTER_KEY_ID));
        mSigneeKey.setText(signeeKey);/*ww  w .ja v a2s.c  om*/

        String signeeUid = data.getString(INDEX_USER_ID);
        mSigneeUid.setText(signeeUid);

        Date creationDate = new Date(data.getLong(INDEX_CREATION) * 1000);
        mCreation.setText(DateFormat.getDateFormat(getApplicationContext()).format(creationDate));

        mCertifierKeyId = data.getLong(INDEX_KEY_ID_CERTIFIER);
        String certifierKey = PgpKeyHelper.convertKeyIdToHex(mCertifierKeyId);
        mCertifierKey.setText(certifierKey);

        String certifierUid = data.getString(INDEX_SIGNER_UID);
        if (certifierUid != null) {
            mCertifierUid.setText(certifierUid);
        } else {
            mCertifierUid.setText(R.string.unknown_uid);
        }

        WrappedSignature sig = WrappedSignature.fromBytes(data.getBlob(INDEX_DATA));
        try {
            ProviderHelper providerHelper = new ProviderHelper(this);

            WrappedPublicKeyRing signeeRing = providerHelper
                    .getWrappedPublicKeyRing(data.getLong(INDEX_MASTER_KEY_ID));
            WrappedPublicKeyRing signerRing = providerHelper.getWrappedPublicKeyRing(sig.getKeyId());

            try {
                sig.init(signerRing.getSubkey());
                if (sig.verifySignature(signeeRing.getSubkey(), signeeUid)) {
                    mStatus.setText(R.string.cert_verify_ok);
                    mStatus.setTextColor(getResources().getColor(R.color.bbutton_success));
                } else {
                    mStatus.setText(R.string.cert_verify_failed);
                    mStatus.setTextColor(getResources().getColor(R.color.alert));
                }
            } catch (PgpGeneralException e) {
                mStatus.setText(R.string.cert_verify_error);
                mStatus.setTextColor(getResources().getColor(R.color.alert));
            }
        } catch (ProviderHelper.NotFoundException e) {
            mStatus.setText(R.string.cert_verify_unavailable);
            mStatus.setTextColor(getResources().getColor(R.color.black));
        }

        String algorithmStr = PgpKeyHelper.getAlgorithmInfo(this, sig.getKeyAlgorithm(), 0);
        mAlgorithm.setText(algorithmStr);

        mRowReason.setVisibility(View.GONE);
        switch (data.getInt(INDEX_TYPE)) {
        case WrappedSignature.DEFAULT_CERTIFICATION:
            mType.setText(R.string.cert_default);
            break;
        case WrappedSignature.NO_CERTIFICATION:
            mType.setText(R.string.cert_none);
            break;
        case WrappedSignature.CASUAL_CERTIFICATION:
            mType.setText(R.string.cert_casual);
            break;
        case WrappedSignature.POSITIVE_CERTIFICATION:
            mType.setText(R.string.cert_positive);
            break;
        case WrappedSignature.CERTIFICATION_REVOCATION: {
            mType.setText(R.string.cert_revoke);
            if (sig.isRevocation()) {
                try {
                    mReason.setText(sig.getRevocationReason());
                } catch (PgpGeneralException e) {
                    mReason.setText(R.string.none);
                }
                mRowReason.setVisibility(View.VISIBLE);
            }
            break;
        }
        }
    }

    // can't do this before the data is initialized
    mViewCertifierButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent viewIntent = new Intent(ViewCertActivity.this, ViewKeyActivity.class);

            try {
                ProviderHelper providerHelper = new ProviderHelper(ViewCertActivity.this);
                long signerMasterKeyId = providerHelper
                        .getCachedPublicKeyRing(KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId))
                        .getMasterKeyId();
                viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId));
                startActivity(viewIntent);
            } catch (PgpGeneralException e) {
                // TODO notify user of this, maybe offer download?
                Log.e(Constants.TAG, "key not found!", e);
            }
        }
    });
}

From source file:org.sufficientlysecure.keychain.ui.dialog.EditSubkeyExpiryDialogFragment.java

/**
 * Creates dialog//  w  w w .j av  a  2  s.co m
 */
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Activity activity = getActivity();

    mMessenger = getArguments().getParcelable(ARG_MESSENGER);
    long creation = getArguments().getLong(ARG_CREATION);
    long expiry = getArguments().getLong(ARG_EXPIRY);

    final Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    creationCal.setTimeInMillis(creation * 1000);
    Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    expiryCal.setTimeInMillis(expiry * 1000);

    // date picker works with default time zone, we need to convert from UTC to default timezone
    creationCal.setTimeZone(TimeZone.getDefault());
    expiryCal.setTimeZone(TimeZone.getDefault());

    // Explicitly not using DatePickerDialog here!
    // DatePickerDialog is difficult to customize and has many problems (see old git versions)
    CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);

    alert.setTitle(R.string.expiry_date_dialog_title);

    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.edit_subkey_expiry_dialog, null);
    alert.setView(view);

    final CheckBox noExpiry = (CheckBox) view.findViewById(R.id.edit_subkey_expiry_no_expiry);
    final DatePicker datePicker = (DatePicker) view.findViewById(R.id.edit_subkey_expiry_date_picker);
    final TextView currentExpiry = (TextView) view.findViewById(R.id.edit_subkey_expiry_current_expiry);
    final LinearLayout expiryLayout = (LinearLayout) view.findViewById(R.id.edit_subkey_expiry_layout);

    noExpiry.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                expiryLayout.setVisibility(View.GONE);
            } else {
                expiryLayout.setVisibility(View.VISIBLE);
            }
        }
    });

    if (expiry == 0L) {
        noExpiry.setChecked(true);
        expiryLayout.setVisibility(View.GONE);

        currentExpiry.setText(R.string.btn_no_date);
    } else {
        noExpiry.setChecked(false);
        expiryLayout.setVisibility(View.VISIBLE);

        currentExpiry.setText(DateFormat.getDateFormat(getActivity()).format(expiryCal.getTime()));
    }

    // date picker works based on default time zone
    Calendar todayCal = Calendar.getInstance(TimeZone.getDefault());
    if (creationCal.after(todayCal)) {
        // NOTE: This is just for the rare cases where creation is _after_ today
        // Min Date: Creation date + 1 day

        Calendar creationCalPlusOne = (Calendar) creationCal.clone();
        creationCalPlusOne.add(Calendar.DAY_OF_YEAR, 1);
        datePicker.setMinDate(creationCalPlusOne.getTime().getTime());
        datePicker.init(creationCalPlusOne.get(Calendar.YEAR), creationCalPlusOne.get(Calendar.MONTH),
                creationCalPlusOne.get(Calendar.DAY_OF_MONTH), null);
    } else {
        // Min Date: today + 1 day

        // at least one day after creation (today)
        todayCal.add(Calendar.DAY_OF_YEAR, 1);
        datePicker.setMinDate(todayCal.getTime().getTime());
        datePicker.init(todayCal.get(Calendar.YEAR), todayCal.get(Calendar.MONTH),
                todayCal.get(Calendar.DAY_OF_MONTH), null);
    }

    alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dismiss();

            long expiry;
            if (noExpiry.isChecked()) {
                expiry = 0L;
            } else {
                Calendar selectedCal = Calendar.getInstance(TimeZone.getDefault());
                //noinspection ResourceType
                selectedCal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
                // date picker uses default time zone, we need to convert to UTC
                selectedCal.setTimeZone(TimeZone.getTimeZone("UTC"));

                long numDays = (selectedCal.getTimeInMillis() / 86400000)
                        - (creationCal.getTimeInMillis() / 86400000);
                if (numDays <= 0) {
                    Activity activity = getActivity();
                    if (activity != null) {
                        Notify.create(activity, R.string.error_expiry_past, Style.ERROR).show();
                    }
                    return;
                }
                expiry = selectedCal.getTime().getTime() / 1000;
            }

            Bundle data = new Bundle();
            data.putSerializable(MESSAGE_DATA_EXPIRY, expiry);
            sendMessageToHandler(MESSAGE_NEW_EXPIRY, data);
        }
    });

    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dismiss();
        }
    });

    return alert.show();
}