Java Code Examples for android.text.format.DateFormat#getDateFormat()

The following examples show how to use android.text.format.DateFormat#getDateFormat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapCoverageLayer.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
public MapCoverageLayer(Context context, Map map, Index mapIndex, float scale) {
    super(map);
    mContext = context;
    mMapIndex = mapIndex;
    mPresentAreaStyle = AreaStyle.builder().fadeScale(FADE_ZOOM).blendColor(COLOR_ACTIVE).blendScale(10).color(Color.fade(COLOR_ACTIVE, AREA_ALPHA)).build();
    mOutdatedAreaStyle = AreaStyle.builder().fadeScale(FADE_ZOOM).blendColor(COLOR_OUTDATED).blendScale(10).color(Color.fade(COLOR_OUTDATED, AREA_ALPHA)).build();
    mMissingAreaStyle = AreaStyle.builder().fadeScale(FADE_ZOOM).blendColor(COLOR_MISSING).blendScale(10).color(Color.fade(COLOR_MISSING, AREA_ALPHA)).build();
    mDownloadingAreaStyle = AreaStyle.builder().fadeScale(FADE_ZOOM).blendColor(COLOR_DOWNLOADING).blendScale(10).color(Color.fade(COLOR_DOWNLOADING, AREA_ALPHA)).build();
    mSelectedAreaStyle = AreaStyle.builder().fadeScale(FADE_ZOOM).blendColor(COLOR_SELECTED).blendScale(10).color(Color.fade(COLOR_SELECTED, AREA_ALPHA)).build();
    mDeletedAreaStyle = AreaStyle.builder().fadeScale(FADE_ZOOM).blendColor(COLOR_DELETED).blendScale(10).color(Color.fade(COLOR_DELETED, AREA_ALPHA)).build();
    mLineStyle = LineStyle.builder().fadeScale(FADE_ZOOM + 1).color(Color.fade(Color.DKGRAY, 0.6f)).strokeWidth(0.5f * scale).fixed(true).build();
    mTextStyle = TextStyle.builder().fontSize(11 * scale).fontStyle(Paint.FontStyle.BOLD).color(COLOR_TEXT).strokeColor(COLOR_TEXT_OUTLINE).strokeWidth(7f).build();
    mSmallTextStyle = TextStyle.builder().fontSize(8 * scale).fontStyle(Paint.FontStyle.BOLD).color(COLOR_TEXT).strokeColor(COLOR_TEXT_OUTLINE).strokeWidth(5f).build();
    mHillshadesBitmap = getHillshadesBitmap(Color.fade(Color.DKGRAY, 0.8f));
    mPresentHillshadesBitmap = getHillshadesBitmap(Color.WHITE);
    mDateFormat = DateFormat.getDateFormat(context);
    mMapIndex.addMapStateListener(this);
    mAccountHillshades = Configuration.getHillshadesEnabled();
}
 
Example 2
Source File: BackupManager.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
public static LinkedHashMap<File, String> getAvailableBackups(Context context) {
	LinkedHashMap<File, String> backups = new LinkedHashMap<>();
	File[] files = Preferences.getDownloadDirectory().listFiles();
	if (files != null) {
		Arrays.sort(files, COMPARATOR);
		java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
		java.text.DateFormat dateFormat = DateFormat.getDateFormat(context);
		for (File file : files) {
			Matcher matcher = NAME_PATTERN.matcher(file.getName());
			if (matcher.matches()) {
				long date = Long.parseLong(matcher.group(1));
				String dateString = dateFormat.format(date) + " " + timeFormat.format(date);
				backups.put(file, dateString);
			}
		}
	}
	return backups;
}
 
Example 3
Source File: AdapterBaseImpl.java    From microMathematics with GNU General Public License v3.0 5 votes vote down vote up
protected AdapterBaseImpl(Context ctx_, int mode_)
{
    ctx = ctx_;
    mode = mode_;
    mInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    localeDateFormat = DateFormat.getDateFormat(ctx);
    localeTimeFormat = DateFormat.getTimeFormat(ctx);
    density = ctx.getResources().getDisplayMetrics().density;
}
 
Example 4
Source File: DigitalWatchFaceService.java    From wear-os-samples with Apache License 2.0 4 votes vote down vote up
private void initFormats() {
    mDayOfWeekFormat = new SimpleDateFormat("EEEE", Locale.getDefault());
    mDayOfWeekFormat.setCalendar(mCalendar);
    mDateFormat = DateFormat.getDateFormat(DigitalWatchFaceService.this);
    mDateFormat.setCalendar(mCalendar);
}
 
Example 5
Source File: CertificateViewer.java    From delion with Apache License 2.0 4 votes vote down vote up
private void addCertificateDetails(Certificate cert, byte[] sha256Digest, byte[] sha1Digest) {
    LinearLayout certificateView = new LinearLayout(mContext);
    mViews.add(certificateView);
    certificateView.setOrientation(LinearLayout.VERTICAL);

    X509Certificate x509 = (X509Certificate) cert;
    SslCertificate sslCert = new SslCertificate(x509);

    mTitles.add(sslCert.getIssuedTo().getCName());

    addSectionTitle(certificateView, nativeGetCertIssuedToText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedTo().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedTo().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedTo().getUName());
    addItem(certificateView, nativeGetCertInfoSerialNumberText(),
            formatBytes(x509.getSerialNumber().toByteArray(), ':'));

    addSectionTitle(certificateView, nativeGetCertIssuedByText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedBy().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedBy().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedBy().getUName());

    addSectionTitle(certificateView, nativeGetCertValidityText());
    java.text.DateFormat dateFormat = DateFormat.getDateFormat(mContext);
    addItem(certificateView, nativeGetCertIssuedOnText(),
            dateFormat.format(sslCert.getValidNotBeforeDate()));
    addItem(certificateView, nativeGetCertExpiresOnText(),
            dateFormat.format(sslCert.getValidNotAfterDate()));

    addSectionTitle(certificateView, nativeGetCertFingerprintsText());
    addItem(certificateView, nativeGetCertSHA256FingerprintText(),
            formatBytes(sha256Digest, ' '));
    addItem(certificateView, nativeGetCertSHA1FingerprintText(),
            formatBytes(sha1Digest, ' '));
}
 
Example 6
Source File: CertificateViewer.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void addCertificateDetails(Certificate cert, byte[] sha256Digest, byte[] sha1Digest) {
    LinearLayout certificateView = new LinearLayout(mContext);
    mViews.add(certificateView);
    certificateView.setOrientation(LinearLayout.VERTICAL);

    X509Certificate x509 = (X509Certificate) cert;
    SslCertificate sslCert = new SslCertificate(x509);

    mTitles.add(sslCert.getIssuedTo().getCName());

    addSectionTitle(certificateView, nativeGetCertIssuedToText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedTo().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedTo().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedTo().getUName());
    addItem(certificateView, nativeGetCertInfoSerialNumberText(),
            formatBytes(x509.getSerialNumber().toByteArray(), ':'));

    addSectionTitle(certificateView, nativeGetCertIssuedByText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedBy().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedBy().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedBy().getUName());

    addSectionTitle(certificateView, nativeGetCertValidityText());
    java.text.DateFormat dateFormat = DateFormat.getDateFormat(mContext);
    addItem(certificateView, nativeGetCertIssuedOnText(),
            dateFormat.format(sslCert.getValidNotBeforeDate()));
    addItem(certificateView, nativeGetCertExpiresOnText(),
            dateFormat.format(sslCert.getValidNotAfterDate()));

    addSectionTitle(certificateView, nativeGetCertFingerprintsText());
    addItem(certificateView, nativeGetCertSHA256FingerprintText(),
            formatBytes(sha256Digest, ' '));
    addItem(certificateView, nativeGetCertSHA1FingerprintText(),
            formatBytes(sha1Digest, ' '));
}
 
Example 7
Source File: OpenScale.java    From openScale with GNU General Public License v3.0 4 votes vote down vote up
public int addScaleMeasurement(final ScaleMeasurement scaleMeasurement, boolean silent) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    // Check user id and do a smart user assign if option is enabled
    if (scaleMeasurement.getUserId() == -1) {
        if (prefs.getBoolean("smartUserAssign", false)) {
            scaleMeasurement.setUserId(getSmartUserAssignment(scaleMeasurement.getWeight(), 15.0f));
        } else {
            scaleMeasurement.setUserId(getSelectedScaleUser().getId());
        }

        // don't add scale data if no user is selected
        if (scaleMeasurement.getUserId() == -1) {
            Timber.e("to be added measurement are thrown away because no user is selected");
            return -1;
        }
    }

    // Assisted weighing
    if (getScaleUser(scaleMeasurement.getUserId()).isAssistedWeighing()) {
        int assistedWeighingRefUserId = prefs.getInt("assistedWeighingRefUserId", -1);
        if (assistedWeighingRefUserId != -1) {
            ScaleMeasurement lastRefScaleMeasurement = getLastScaleMeasurement(assistedWeighingRefUserId);

            if (lastRefScaleMeasurement != null) {
                float refWeight = lastRefScaleMeasurement.getWeight();
                float diffToRef = scaleMeasurement.getWeight() - refWeight;
                scaleMeasurement.setWeight(diffToRef);
            }
        } else {
            Timber.e("assisted weighing reference user id is -1");
        }
    }

    // Calculate the amputation correction factor for the weight, if available
    scaleMeasurement.setWeight((scaleMeasurement.getWeight() * 100.0f) / getScaleUser(scaleMeasurement.getUserId()).getAmputationCorrectionFactor());

    // If option is enabled then calculate body measurements from generic formulas
    MeasurementViewSettings settings = new MeasurementViewSettings(prefs, WaterMeasurementView.KEY);
    if (settings.isEnabled() && settings.isEstimationEnabled()) {
        EstimatedWaterMetric waterMetric = EstimatedWaterMetric.getEstimatedMetric(
                EstimatedWaterMetric.FORMULA.valueOf(settings.getEstimationFormula()));
        scaleMeasurement.setWater(waterMetric.getWater(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
    }

    settings = new MeasurementViewSettings(prefs, FatMeasurementView.KEY);
    if (settings.isEnabled() && settings.isEstimationEnabled()) {
        EstimatedFatMetric fatMetric = EstimatedFatMetric.getEstimatedMetric(
                EstimatedFatMetric.FORMULA.valueOf(settings.getEstimationFormula()));
        scaleMeasurement.setFat(fatMetric.getFat(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
    }

    // Must be after fat estimation as one formula is based on fat
    settings = new MeasurementViewSettings(prefs, LBMMeasurementView.KEY);
    if (settings.isEnabled() && settings.isEstimationEnabled()) {
        EstimatedLBMMetric lbmMetric = EstimatedLBMMetric.getEstimatedMetric(
                EstimatedLBMMetric.FORMULA.valueOf(settings.getEstimationFormula()));
        scaleMeasurement.setLbm(lbmMetric.getLBM(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
    }

    // Insert measurement into the database, check return if it was successful inserted
    if (measurementDAO.insert(scaleMeasurement) != -1) {
        Timber.d("Added measurement: %s", scaleMeasurement);
        if (!silent) {
            ScaleUser scaleUser = getScaleUser(scaleMeasurement.getUserId());

            final java.text.DateFormat dateFormat = DateFormat.getDateFormat(context);
            final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
            final Date dateTime = scaleMeasurement.getDateTime();

            final Converters.WeightUnit unit = scaleUser.getScaleUnit();

            String infoText = String.format(context.getString(R.string.info_new_data_added),
                    Converters.fromKilogram(scaleMeasurement.getWeight(), unit), unit.toString(),
                    dateFormat.format(dateTime) + " " + timeFormat.format(dateTime),
                    scaleUser.getUserName());
            runUiToastMsg(infoText);
        }

        syncInsertMeasurement(scaleMeasurement);
        alarmHandler.entryChanged(context, scaleMeasurement);
        triggerWidgetUpdate();
    } else {
        Timber.d("to be added measurement is thrown away because measurement with the same date and time already exist");
        if (!silent) {
            runUiToastMsg(context.getString(R.string.info_new_data_duplicated));
        }
    }

    return scaleMeasurement.getUserId();
}
 
Example 8
Source File: CustomDatePicker.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void reorderPickers(String[] months) {
    java.text.DateFormat format;
    String order;

    /*
     * If the user is in a locale where the medium date format is
     * still numeric (Japanese and Czech, for example), respect
     * the date format order setting.  Otherwise, use the order
     * that the locale says is appropriate for a spelled-out date.
     */

    if (months[0].startsWith("1")) {
        format = DateFormat.getDateFormat(getContext());
    } else {
        format = DateFormat.getMediumDateFormat(getContext());
    }

    if (format instanceof SimpleDateFormat) {
        order = ((SimpleDateFormat) format).toPattern();
    } else {
        // Shouldn't happen, but just in case.
        order = new String(DateFormat.getDateFormatOrder(getContext()));
    }

    /* Remove the 3 pickers from their parent and then add them back in the
     * required order.
     */
    LinearLayout parent = (LinearLayout) findViewById(R.id.parent);
    parent.removeAllViews();

    boolean quoted = false;
    boolean didDay = false, didMonth = false, didYear = false;

    for (int i = 0; i < order.length(); i++) {
        char c = order.charAt(i);

        if (c == '\'') {
            quoted = !quoted;
        }

        if (!quoted) {
            if (c == DATE && !didDay) {
                parent.addView(mDayPicker);
                didDay = true;
            } else if ((c == MONTH || c == 'L') && !didMonth) {
                parent.addView(mMonthPicker);
                didMonth = true;
            } else if (c == YEAR && !didYear) {
                parent.addView(mYearPicker);
                didYear = true;
            }
        }
    }

    // Shouldn't happen, but just in case.
    if (!didMonth) {
        parent.addView(mMonthPicker);
    }
    if (!didDay) {
        parent.addView(mDayPicker);
    }
    if (!didYear) {
        parent.addView(mYearPicker);
    }
}
 
Example 9
Source File: CertificateViewer.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void addCertificateDetails(Certificate cert, byte[] sha256Digest, byte[] sha1Digest) {
    LinearLayout certificateView = new LinearLayout(mContext);
    mViews.add(certificateView);
    certificateView.setOrientation(LinearLayout.VERTICAL);

    X509Certificate x509 = (X509Certificate) cert;
    SslCertificate sslCert = new SslCertificate(x509);

    mTitles.add(sslCert.getIssuedTo().getCName());

    addSectionTitle(certificateView, nativeGetCertIssuedToText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedTo().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedTo().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedTo().getUName());
    addItem(certificateView, nativeGetCertInfoSerialNumberText(),
            formatBytes(x509.getSerialNumber().toByteArray(), ':'));

    addSectionTitle(certificateView, nativeGetCertIssuedByText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedBy().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedBy().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedBy().getUName());

    addSectionTitle(certificateView, nativeGetCertValidityText());
    java.text.DateFormat dateFormat = DateFormat.getDateFormat(mContext);
    addItem(certificateView, nativeGetCertIssuedOnText(),
            dateFormat.format(sslCert.getValidNotBeforeDate()));
    addItem(certificateView, nativeGetCertExpiresOnText(),
            dateFormat.format(sslCert.getValidNotAfterDate()));

    addSectionTitle(certificateView, nativeGetCertFingerprintsText());
    addItem(certificateView, nativeGetCertSHA256FingerprintText(),
            formatBytes(sha256Digest, ' '));
    addItem(certificateView, nativeGetCertSHA1FingerprintText(),
            formatBytes(sha1Digest, ' '));
}
 
Example 10
Source File: CertificateViewer.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void addCertificateDetails(Certificate cert, byte[] sha256Digest, byte[] sha1Digest) {
    LinearLayout certificateView = new LinearLayout(mContext);
    mViews.add(certificateView);
    certificateView.setOrientation(LinearLayout.VERTICAL);

    X509Certificate x509 = (X509Certificate) cert;
    SslCertificate sslCert = new SslCertificate(x509);

    mTitles.add(sslCert.getIssuedTo().getCName());

    addSectionTitle(certificateView, nativeGetCertIssuedToText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedTo().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedTo().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedTo().getUName());
    addItem(certificateView, nativeGetCertInfoSerialNumberText(),
            formatBytes(x509.getSerialNumber().toByteArray(), ':'));

    addSectionTitle(certificateView, nativeGetCertIssuedByText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedBy().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedBy().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedBy().getUName());

    addSectionTitle(certificateView, nativeGetCertValidityText());
    java.text.DateFormat dateFormat = DateFormat.getDateFormat(mContext);
    addItem(certificateView, nativeGetCertIssuedOnText(),
            dateFormat.format(sslCert.getValidNotBeforeDate()));
    addItem(certificateView, nativeGetCertExpiresOnText(),
            dateFormat.format(sslCert.getValidNotAfterDate()));

    addSectionTitle(certificateView, nativeGetCertFingerprintsText());
    addItem(certificateView, nativeGetCertSHA256FingerprintText(),
            formatBytes(sha256Digest, ' '));
    addItem(certificateView, nativeGetCertSHA1FingerprintText(),
            formatBytes(sha1Digest, ' '));
}