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:net.phase.wallet.Currency.java

private String getTimeStampString(Date d) {
    String result = DateFormat.getDateFormat(context).format(d);

    result += " " + DateFormat.format("h:mmaa", d).toString();

    return result;
}

From source file:org.alfresco.mobile.android.application.fragments.search.AdvancedSearchFragment.java

@Override
public void onDatePicked(String dateId, GregorianCalendar gregorianCalendar) {
    if (DATE_FROM.equalsIgnoreCase(dateId)) {
        modificationDateFromValue = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        modificationDateFromValue.setTime(gregorianCalendar.getTime());
        modificationDateFrom//from www  .ja va 2  s.  c om
                .setText(DateFormat.getDateFormat(getActivity()).format(modificationDateFromValue.getTime()));
    } else if (DATE_TO.equalsIgnoreCase(dateId)) {
        modificationDateToValue = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        modificationDateToValue.setTime(gregorianCalendar.getTime());
        modificationDateTo
                .setText(DateFormat.getDateFormat(getActivity()).format(modificationDateToValue.getTime()));
    }
}

From source file:at.jclehner.rxdroid.DrugListActivity.java

@TargetApi(11)
private void updateDateString() {
    if (mCurrentDate == null)
        return;// ww  w .j  a va  2s  .c o  m

    final SpannableString dateString = new SpannableString(
            DateFormat.getDateFormat(this).format(mCurrentDate.getTime()));

    if (isShowingCurrentDate())
        Util.applyStyle(dateString, new UnderlineSpan());

    Util.applyStyle(dateString, new RelativeSizeSpan(0.75f));
    getSupportActionBar().setSubtitle(dateString);
}

From source file:org.restcomm.app.qoslib.Utils.QosInfo.java

/**
 * Called Internally to initialize all of the current measurements for every type of connected newtork
 * This is like a snapshot of everything at this moment in time
 * The information comes from various sources and it mainly fetched from the database for this call, or from APIs such as WiFi
 *//*www .j a va  2s  . com*/
private void updateFromDB() {
    Cursor sig_cursor = null;
    Cursor cell_cursor = null;

    try {
        Uri signalUri = UriMatch.SIGNAL_STRENGTHS.getContentUri();
        Uri limitSignalUri = signalUri.buildUpon().appendQueryParameter("limit", "1").build();
        // sig_cursor = managedQuery(

        Provider dbProvider = ReportManager.getInstance(context.getApplicationContext()).getDBProvider();
        if (dbProvider == null) {
            return;
        }

        sig_cursor = dbProvider.query(UriMatch.SIGNAL_STRENGTHS.getContentUri(), null, null, null,
                Tables.TIMESTAMP_COLUMN_NAME + " DESC");

        sig_cursor.moveToFirst();

        Uri baseStationTable = (UriMatch.BASE_STATIONS
                .getContentUri()/*telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA
                                ? UriMatchOld.BASE_STATIONS_CDMA.getContentUri()
                                : UriMatchOld.BASE_STATIONS_GSM.getContentUri()*/
        );
        Uri limitBSUri = baseStationTable.buildUpon().appendQueryParameter("limit", "1").build();

        // Cursor cell_cursor = managedQuery(
        cell_cursor = dbProvider.query(limitBSUri, null, null, null, Tables.TIMESTAMP_COLUMN_NAME + " DESC");

        cell_cursor.moveToFirst();

        int LowIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_LOW);
        int MidIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_MID);
        int HighIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_HIGH);
        int CodeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CODE);
        int BandIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_BAND);
        int ChanIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CHAN);
        int netTypeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.NET_TYPE);
        String netType = cell_cursor.getString(netTypeIndex);
        int bsLow = cell_cursor.getInt(LowIndex);
        int bsMid = cell_cursor.getInt(MidIndex);
        int bsHigh = cell_cursor.getInt(HighIndex);
        int bsCode = cell_cursor.getInt(CodeIndex);
        int bsBand = cell_cursor.getInt(BandIndex);
        int bsChan = cell_cursor.getInt(ChanIndex);
        if (netType.equals("cdma")) {
            if (LowIndex != -1)
                BID = bsLow;
            if (MidIndex != -1)
                NID = bsMid;
            if (HighIndex != -1)
                SID = bsHigh;
        } else if (netType.equals("gsm")) {
            if (LowIndex != -1) {
                RNC = bsMid;
                CellID = cell_cursor.getInt(LowIndex);
            }
            // the network Id is kept 0 for gsm phones
            if (HighIndex != -1)
                LAC = bsHigh;
            if (bsCode > 0 && bsCode < 1000)
                PSC = bsCode;
            else
                PSC = 0;
            if (bsBand > 0)
                Band = bsBand;
            else
                Band = 0;
            if (bsChan > 0)
                Channel = bsChan;
            else
                Channel = 0;
        }

        if (sig_cursor.getCount() != 0) {
            int signalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL);
            int signal2GIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL2G);
            int rsrpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRP);
            int rsrqIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRQ);
            int lteSnrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SNR);
            int lteSignalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SIGNAL);
            int lteCqiIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_CQI);
            int ecioIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECI0);
            int ecnoIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECN0);
            int snrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SNR);
            int berIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.BER);
            int rscpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.RSCP);
            int tierIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.COVERAGE);
            Integer tier = sig_cursor.isNull(tierIndex) ? null : sig_cursor.getInt(tierIndex);
            Integer rssi = sig_cursor.isNull(signalIndex) ? null : sig_cursor.getInt(signalIndex);
            Integer rssi2G = sig_cursor.isNull(signal2GIndex) ? null : sig_cursor.getInt(signal2GIndex);
            Integer rsrp = sig_cursor.isNull(rsrpIndex) ? null : sig_cursor.getInt(rsrpIndex);
            Float lteSnr = (sig_cursor.isNull(lteSnrIndex) ? null : (float) sig_cursor.getInt(lteSnrIndex));
            Integer lteSignal = sig_cursor.isNull(lteSignalIndex) ? null : sig_cursor.getInt(lteSignalIndex);
            Integer lteCqi = sig_cursor.isNull(lteCqiIndex) ? null : sig_cursor.getInt(lteCqiIndex);
            Integer rsrq = sig_cursor.isNull(rsrqIndex) ? null : sig_cursor.getInt(rsrqIndex);
            Integer eci0 = sig_cursor.isNull(ecioIndex) ? null : sig_cursor.getInt(ecioIndex);
            Integer ecn0 = sig_cursor.isNull(ecnoIndex) ? null : sig_cursor.getInt(ecnoIndex);
            Integer snr = sig_cursor.isNull(snrIndex) ? null : sig_cursor.getInt(snrIndex);
            Integer ber = sig_cursor.isNull(berIndex) ? null : sig_cursor.getInt(berIndex);
            Integer rscp = sig_cursor.isNull(rscpIndex) ? null : sig_cursor.getInt(rscpIndex);

            if (eci0 != null && (netType.equals("cdma") || netType.equals("lte")) && eci0 <= -30)
                eci0 = (eci0 / 10);
            else if (ecn0 != null && ecn0 > 1 && ecn0 < 60 && netType.equals("gsm"))
                ecn0 = -(ecn0 / 2);
            else if (eci0 != null && eci0 > 1 && eci0 < 60 && netType.equals("gsm"))
                eci0 = -(eci0 / 2);

            // if (lteSnr != null && lteSnr > 1 && lteSnr < 500)
            // lteSnr = (lteSnr+5)/10;
            if (lteSignal != null && lteSignal > -120 && lteSignal < -20) // rssi == lteSignal)
            {
                LTE_RSSI = simpleValidate(lteSignal);
                RSSI = 0;
            } else if (rssi == null || rssi == -255)
                RSSI = 0;
            else if (rssi == -256)
                RSSI = -256;
            else {
                String name = "RSCP: ";
                int spacing = 15;
                if (netType.equals("gsm") && (tier == 3 || tier == 4)) {
                    RSCP = rssi;
                    RSSI = 0;
                } else {
                    RSSI = rssi;
                    RSCP = 0;
                }

                LTE_RSSI = 0;
            }
            if (netType.equals("cdma") && rssi2G != null && rssi2G < -30 && rssi2G >= -120)
                CDMA_RSSI = rssi2G;
            if (tier == 5) {
                if (lteSnr != null && lteSnr > -101)
                    lteSnr = lteSnr / 10;
                if (rsrq != null && rsrq > 0)
                    rsrq = -rsrq;
                LTE_RSRP = simpleValidate(rsrp);
                LTE_RSRQ = simpleValidate(rsrq);
                LTE_SNR = simpleValidate(lteSnr);
                LTE_CQI = simpleValidate(lteCqi);
                ECIO = simpleValidate(eci0);
                ECNO = simpleValidate(ecn0);
            }
            //nerdview.setValue(0, "RSCP", simpleValidate(rscp, "RSCP", "dBm"));
            //BER = simpleValidate(ber);
            SNR = simpleValidate(snr);

            if (rsrp != null && rsrp <= -10 && rsrp >= -140 && tier == 5) {
                LTEIdentity = ReportManager.getInstance(context.getApplicationContext()).getNeighbors();
            } else {
                LTEIdentity = null;
                Neighbors = ReportManager.getInstance(context.getApplicationContext()).getNeighbors();
            }
        }
        location = ReportManager.getInstance(context.getApplicationContext()).getLastKnownLocation();

        try {
            JSONObject serviceMode = PhoneState.getServiceMode();
            if (serviceMode != null && serviceMode.getLong("time") + 5000 > System.currentTimeMillis()) {
                if (serviceMode.has("rrc") && serviceMode.getString("rrc").length() > 1) {
                    RRC = serviceMode.getString("rrc");
                } else
                    RRC = null;
                if (serviceMode.has("band") && serviceMode.getString("band").length() > 0) {
                    Band = Integer.parseInt(serviceMode.getString("band"));
                }
                //else
                if (serviceMode.has("freq") && serviceMode.getString("freq").length() > 0) {
                    Band = Integer.parseInt(serviceMode.getString("freq"));
                } else
                    Band = 0;
                if (serviceMode.has("channel") && serviceMode.getString("channel").length() > 0) {
                    Channel = Integer.parseInt(serviceMode.getString("channel"));
                } else
                    Channel = 0;
            } else {
                RRC = null;
                Band = 0;
                Channel = 0;
            }

            TelephonyManager telephonyManager = (TelephonyManager) context
                    .getSystemService(Service.TELEPHONY_SERVICE);
            String carrier = telephonyManager.getNetworkOperatorName();
            String mcc = "0", mnc = "0";
            if (telephonyManager.getNetworkOperator() != null
                    && telephonyManager.getNetworkOperator().length() >= 4) {
                mcc = telephonyManager.getNetworkOperator().substring(0, 3);
                mnc = telephonyManager.getNetworkOperator().substring(3);
            }
            int networkType = telephonyManager.getNetworkType();
            int networkTier = PhoneState.getNetworkGeneration(networkType);
            String nettype = PhoneState.getNetworkName(telephonyManager.getNetworkType());
            String data = PhoneState.getNetworkName(telephonyManager.getNetworkType()) + " ";
            int dataState = telephonyManager.getDataState();
            if (dataState == TelephonyManager.DATA_CONNECTED) {
                String activity = getActivityName(telephonyManager.getDataActivity());
                data += activity;
            } else if (telephonyManager.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                String state = getStateName(telephonyManager.getDataState());
                data += state;
            }

            Data = data;
            Carrier = carrier;

            Date date = new Date(System.currentTimeMillis());
            final String dateStr = DateFormat.getDateFormat(context).format(date);
            final String timeStr = dateStr + "  " + DateFormat.getTimeFormat(context).format(date);

            Time = timeStr;

            MCC = Integer.parseInt(mcc);
            MNC = Integer.parseInt(mnc);

            // Tell the service we're watching the signal, so keep it updated
            Intent intent = new Intent(CommonIntentActionsOld.VIEWING_SIGNAL);
            context.sendBroadcast(intent);

            WifiInfo wifiinfo = getWifiInfo();
            WifiConfiguration wifiConfig = getWifiConfig();
            setWifi(wifiinfo, wifiConfig);

            // Instantiate only the relevant Network type
            if (netType.equals("cdma"))
                connectedNetwork = CDMAInfo = new CDMAInfo(this);
            else if (netType.equals("gsm") && networkTier < 3)
                connectedNetwork = GSMInfo = new GSMInfo(this);
            else if (netType.equals("gsm") && networkTier < 5)
                connectedNetwork = WCDMAInfo = new WCDMAInfo(this);
            if (networkTier == 5) // LTE
                connectedNetwork = LTEInfo = new LTEInfo(this);
            if (wifiConfig != null)
                connectedNetwork = WiFiInfo = new WIFIInfo(this); // The most relevant network ends up in NetworkInfo
        } catch (Exception e) {
        }

    } catch (Exception e) {
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "updateNerdViewFromDB",
                "exception querying signal data: " + e.getMessage());
    } finally {
        if (cell_cursor != null)
            cell_cursor.close();
        if (sig_cursor != null)
            sig_cursor.close();
    }
}

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * Show/hide, enable/disable send buttons.
 *///from ww  w.ja  v a2s.  c  o  m
private void setButtons() {
    if (prefsConnectorSpec != null && prefsSubConnectorSpec != null
            && prefsConnectorSpec.hasStatus(ConnectorSpec.STATUS_ENABLED)) {
        final boolean sFlashsms = prefsSubConnectorSpec.hasFeatures(SubConnectorSpec.FEATURE_FLASHSMS);
        final boolean sCustomsender = prefsSubConnectorSpec.hasFeatures(SubConnectorSpec.FEATURE_CUSTOMSENDER);
        final boolean sSendLater = prefsSubConnectorSpec.hasFeatures(SubConnectorSpec.FEATURE_SENDLATER);

        if (bShowExtras && (sFlashsms || sCustomsender || sSendLater)) {
            if (sFlashsms) {
                this.vFlashSMS.setVisibility(View.VISIBLE);
            } else {
                this.vFlashSMS.setVisibility(View.GONE);
            }
            if (sCustomsender) {
                this.vCustomSender.setVisibility(View.VISIBLE);
                this.vCustomSender.setChecked(!TextUtils.isEmpty(lastCustomSender));
            } else {
                this.vCustomSender.setVisibility(View.GONE);
                this.vCustomSender.setChecked(false);
            }
            if (sSendLater) {
                this.vSendLater.setVisibility(View.VISIBLE);
            } else {
                this.vSendLater.setVisibility(View.GONE);
            }
            this.findViewById(R.id.extraButtons).setVisibility(View.VISIBLE);
        } else {
            this.findViewById(R.id.extraButtons).setVisibility(View.GONE);
        }

        String t = prefsConnectorSpec.getName();
        if (prefsConnectorSpec.getSubConnectorCount() > 1) {
            t += " - " + prefsSubConnectorSpec.getName();
        }
        this.setTitle(t);
        String s = t;
        if (lastSendLater > 0L) {
            Calendar cal = Calendar.getInstance();
            cal.setTimeInMillis(lastSendLater);
            s += "\n@" + DateFormat.getDateFormat(this).format(cal.getTime());
            s += " " + DateFormat.getTimeFormat(this).format(cal.getTime());
            this.vSendLater.setChecked(true);
        } else {
            this.vSendLater.setChecked(false);
        }
        Log.d(TAG, "set backgroundtext: " + s);
        ((TextView) this.findViewById(R.id.text_connector)).setText(s);
    } else {
        this.setTitle(R.string.app_name);
        ((TextView) this.findViewById(R.id.text_connector)).setText("");
        if (CONNECTORS.size() > 0) {
            Toast.makeText(this, R.string.log_noselectedconnector, Toast.LENGTH_SHORT).show();
        }
        this.findViewById(R.id.extraButtons).setVisibility(View.GONE);
    }
}