List of usage examples for android.text.format DateFormat getTimeFormat
public static java.text.DateFormat getTimeFormat(Context context)
From source file:org.tigase.mobile.chat.ChatHistoryFragment.java
private void showMessageDetails(final long id) { Cursor cc = null;/*from w ww .jav a 2s. c om*/ final java.text.DateFormat df = DateFormat.getDateFormat(getActivity()); final java.text.DateFormat tf = DateFormat.getTimeFormat(getActivity()); try { cc = getChatEntry(id); Dialog alertDialog = new Dialog(getActivity()); alertDialog.setContentView(R.layout.chat_item_details_dialog); alertDialog.setCancelable(true); alertDialog.setCanceledOnTouchOutside(true); alertDialog.setTitle("Message details"); TextView msgDetSender = (TextView) alertDialog.findViewById(R.id.msgDetSender); msgDetSender.setText(cc.getString(cc.getColumnIndex(ChatTableMetaData.FIELD_JID))); Date timestamp = new Date(cc.getLong(cc.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP))); TextView msgDetReceived = (TextView) alertDialog.findViewById(R.id.msgDetReceived); msgDetReceived.setText(df.format(timestamp) + " " + tf.format(timestamp)); final int state = cc.getInt(cc.getColumnIndex(ChatTableMetaData.FIELD_STATE)); TextView msgDetState = (TextView) alertDialog.findViewById(R.id.msgDetState); switch (state) { case ChatTableMetaData.STATE_INCOMING: msgDetState.setText("Received"); break; case ChatTableMetaData.STATE_OUT_SENT: msgDetState.setText("Sent"); break; case ChatTableMetaData.STATE_OUT_NOT_SENT: msgDetState.setText("Not sent"); break; default: msgDetState.setText("?"); break; } alertDialog.show(); } finally { if (cc != null && !cc.isClosed()) cc.close(); } }
From source file:org.adblockplus.android.Preferences.java
/** * Constructs and updates subscription status text. * * @param text//from www. ja v a 2s. c om * status message * @param time * time of last change */ private void setSubscriptionStatus(final String text, final long time) { final ListPreference subscriptionList = (ListPreference) findPreference( getString(R.string.pref_subscription)); final CharSequence summary = subscriptionList.getEntry(); final StringBuilder builder = new StringBuilder(); if (summary != null) { builder.append(summary); if (StringUtils.isNotEmpty(text)) { builder.append(" ("); final int id = getResources().getIdentifier(text, "string", getPackageName()); if (id > 0) builder.append(getString(id, text)); else builder.append(text); if (time > 0) { builder.append(": "); final Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(time); final Date date = calendar.getTime(); builder.append(DateFormat.getDateFormat(this).format(date)); builder.append(" "); builder.append(DateFormat.getTimeFormat(this).format(date)); } builder.append(")"); } subscriptionSummary = builder.toString(); subscriptionList.setSummary(subscriptionSummary); } }
From source file:com.sweetiepiggy.raspberrybusmalaysia.SubmitTripActivity.java
private void submit() { final String sched_time = format_time(mData.sched_time); final String depart_time = format_time(mData.depart_time); final String arrival_time = format_time(mData.arrival_time); final String agent = ((AutoCompleteTextView) findViewById(R.id.agent_entry)).getText().toString(); final String operator = ((AutoCompleteTextView) findViewById(R.id.operator_entry)).getText().toString(); final String from_station = ((AutoCompleteTextView) findViewById(R.id.from_station_entry)).getText() .toString();//w w w . j a v a 2s . c o m final String to_station = ((AutoCompleteTextView) findViewById(R.id.to_station_entry)).getText().toString(); final String safety = Integer.toString((int) ((RatingBar) findViewById(R.id.safety_bar)).getRating()); final String comfort = Integer.toString((int) ((RatingBar) findViewById(R.id.comfort_bar)).getRating()); final String overall = Integer.toString((int) ((RatingBar) findViewById(R.id.overall_bar)).getRating()); final String comment = ((EditText) findViewById(R.id.comment_entry)).getText().toString(); String disp_sched = DateFormat.getTimeFormat(getApplicationContext()).format(mData.sched_time.getTime()); String trip_time = format_time( (mData.arrival_time.getTimeInMillis() - mData.sched_time.getTimeInMillis()) / 1000); String delay = format_time_min( (mData.depart_time.getTimeInMillis() - mData.sched_time.getTimeInMillis()) / 1000); String info = getResources().getString(R.string.sched_time) + ": " + disp_sched + "\n" + getResources().getString(R.string.trip_time) + ": " + trip_time + "\n" + getResources().getString(R.string.delay) + ": " + delay; AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(R.string.confirm_submit); alert.setMessage(info); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String msg = format_email(agent, operator, from_station, to_station, sched_time, depart_time, arrival_time, safety, comfort, overall, comment); new PostTask(getApplicationContext(), msg).execute(); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alert.show(); }
From source file:com.bluros.updater.UpdatesSettings.java
private void showSysInfo() { // Build the message Date lastCheck = new Date(mPrefs.getLong(Constants.LAST_UPDATE_CHECK_PREF, 0)); String date = DateFormat.getLongDateFormat(this).format(lastCheck); String time = DateFormat.getTimeFormat(this).format(lastCheck); String cmReleaseType = Constants.CM_RELEASETYPE_NIGHTLY; int updateType = Utils.getUpdateType(); if (updateType == Constants.UPDATE_TYPE_SNAPSHOT) { cmReleaseType = Constants.CM_RELEASETYPE_SNAPSHOT; }/*from w w w. j ava 2 s . c om*/ String message = getString(R.string.sysinfo_device) + " " + Utils.getDeviceType() + "\n\n" + getString(R.string.sysinfo_running) + " " + Utils.getInstalledVersion() + "\n\n" + getString(R.string.sysinfo_update_channel) + " " + cmReleaseType + "\n\n" + getString(R.string.sysinfo_last_check) + " " + date + " " + time; AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.menu_system_info) .setMessage(message).setPositiveButton(R.string.dialog_ok, null); AlertDialog dialog = builder.create(); dialog.show(); TextView messageView = (TextView) dialog.findViewById(android.R.id.message); messageView.setTextAppearance(this, android.R.style.TextAppearance_DeviceDefault_Small); }
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 */// w ww. j av a2 s. c om 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 w w w.j a 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); } }
From source file:org.videolan.vlc.gui.video.VideoPlayerActivity.java
/** * update the overlay/*from w ww. ja va2 s . c o m*/ */ private int setOverlayProgress() { if (mLibVLC == null) { return 0; } int time = (int) mLibVLC.getTime(); int length = (int) mLibVLC.getLength(); // Update all view elements mControls.setSeekable(length > 0); mSeekbar.setMax(length); mSeekbar.setProgress(time); mSysTime.setText(DateFormat.getTimeFormat(this).format(new Date(System.currentTimeMillis()))); mTime.setText(Util.millisToString(time)); mLength.setText(mDisplayRemainingTime && length > 0 ? "- " + Util.millisToString(length - time) : Util.millisToString(length)); return time; }
From source file:com.tct.mail.ui.ConversationListFragment.java
private String getElapseTime(long time) { long now = System.currentTimeMillis(); long elapseTime = now - time; String displayTime;//w w w .ja va2s .c om if (elapseTime < 0) { // abnormal time, this may occur when user change system time to a wrong time displayTime = (String) DateUtils.getRelativeTimeSpanString(mActivity.getActivityContext(), time); } else if (elapseTime < DateUtils.DAY_IN_MILLIS) { //within one day displayTime = (String) DateUtils.getRelativeTimeSpanString(mActivity.getActivityContext(), time); displayTime = mActivity.getActivityContext().getString(R.string.conversation_time_elapse_today) + ", " + displayTime; } else { //beyond one day java.text.DateFormat timeFormat = DateFormat.getTimeFormat(mActivity.getActivityContext()); Date date = new Date(time); String dateText = DateUtils.formatDateTime(mActivity.getActivityContext(), time, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH); displayTime = dateText + ", " + timeFormat.format(date); } return displayTime; }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void updateTvData() { if (!TvDataUpdateService.IS_RUNNING) { Cursor test = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null, TvBrowserContentProvider.CHANNEL_KEY_SELECTION + "=1", null, null); if (test.getCount() > 0) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); RelativeLayout dataDownload = (RelativeLayout) getLayoutInflater() .inflate(R.layout.dialog_data_update_selection, getParentViewGroup(), false); final Spinner days = (Spinner) dataDownload .findViewById(R.id.dialog_data_update_selection_download_days); final CheckBox pictures = (CheckBox) dataDownload .findViewById(R.id.dialog_data_update_selection_download_picture); final Spinner autoUpdate = (Spinner) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type); final Spinner frequency = (Spinner) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_frequency); final CheckBox onlyWiFi = (CheckBox) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type_connection); final TextView timeLabel = (TextView) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time_label); final TextView time = (TextView) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time); time.setTextColor(onlyWiFi.getTextColors()); String currentDownloadDays = PrefUtils.getStringValue(R.string.DAYS_TO_DOWNLOAD, R.string.days_to_download_default); final String[] possibleDownloadDays = getResources().getStringArray(R.array.download_days); for (int i = 0; i < possibleDownloadDays.length; i++) { if (currentDownloadDays.equals(possibleDownloadDays[i])) { days.setSelection(i); break; }//from w w w . ja va 2 s . com } pictures.setChecked( PrefUtils.getBooleanValue(R.string.LOAD_PICTURE_DATA, R.bool.load_picture_data_default)); String currentAutoUpdateValue = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_TYPE, R.string.pref_auto_update_type_default); String currentAutoUpdateFrequency = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_FREQUENCY, R.string.pref_auto_update_frequency_default); if (currentAutoUpdateValue.equals("0")) { frequency.setEnabled(false); onlyWiFi.setEnabled(false); timeLabel.setEnabled(false); time.setEnabled(false); frequency.setVisibility(View.GONE); onlyWiFi.setVisibility(View.GONE); timeLabel.setVisibility(View.GONE); time.setVisibility(View.GONE); } else if (currentAutoUpdateValue.equals("1")) { autoUpdate.setSelection(1); timeLabel.setEnabled(false); time.setEnabled(false); timeLabel.setVisibility(View.GONE); time.setVisibility(View.GONE); } else if (currentAutoUpdateValue.equals("2")) { autoUpdate.setSelection(2); } final String[] autoFrequencyPossibleValues = getResources() .getStringArray(R.array.pref_auto_update_frequency_values); for (int i = 0; i < autoFrequencyPossibleValues.length; i++) { if (autoFrequencyPossibleValues[i].equals(currentAutoUpdateFrequency)) { frequency.setSelection(i); break; } } onlyWiFi.setChecked(PrefUtils.getBooleanValue(R.string.PREF_AUTO_UPDATE_ONLY_WIFI, R.bool.pref_auto_update_only_wifi_default)); final AtomicInteger currentAutoUpdateTime = new AtomicInteger(PrefUtils.getIntValue( R.string.PREF_AUTO_UPDATE_START_TIME, R.integer.pref_auto_update_start_time_default)); Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60); now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime())); autoUpdate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { frequency.setEnabled(position != 0); onlyWiFi.setEnabled(position != 0); if (position != 0) { frequency.setVisibility(View.VISIBLE); onlyWiFi.setVisibility(View.VISIBLE); } else { frequency.setVisibility(View.GONE); onlyWiFi.setVisibility(View.GONE); } timeLabel.setEnabled(position == 2); time.setEnabled(position == 2); if (position == 2) { timeLabel.setVisibility(View.VISIBLE); time.setVisibility(View.VISIBLE); } else { timeLabel.setVisibility(View.GONE); time.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder b2 = new AlertDialog.Builder(TvBrowser.this); LinearLayout timeSelection = (LinearLayout) getLayoutInflater().inflate( R.layout.dialog_data_update_selection_auto_update_time, getParentViewGroup(), false); final TimePicker timePick = (TimePicker) timeSelection .findViewById(R.id.dialog_data_update_selection_auto_update_selection_time); timePick.setIs24HourView(DateFormat.is24HourFormat(TvBrowser.this)); timePick.setCurrentHour(currentAutoUpdateTime.get() / 60); timePick.setCurrentMinute(currentAutoUpdateTime.get() % 60); b2.setView(timeSelection); b2.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { currentAutoUpdateTime .set(timePick.getCurrentHour() * 60 + timePick.getCurrentMinute()); Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60); now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime())); } }); b2.setNegativeButton(android.R.string.cancel, null); b2.show(); } }; time.setOnClickListener(onClickListener); timeLabel.setOnClickListener(onClickListener); builder.setTitle(R.string.download_data); builder.setView(dataDownload); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String value = possibleDownloadDays[days.getSelectedItemPosition()]; Editor settings = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit(); if (PrefUtils.getStringValueAsInt(R.string.PREF_AUTO_UPDATE_RANGE, R.string.pref_auto_update_range_default) < Integer.parseInt(value)) { settings.putString(getString(R.string.PREF_AUTO_UPDATE_RANGE), value); } settings.putString(getString(R.string.DAYS_TO_DOWNLOAD), value); settings.putBoolean(getString(R.string.LOAD_PICTURE_DATA), pictures.isChecked()); settings.putString(getString(R.string.PREF_AUTO_UPDATE_TYPE), String.valueOf(autoUpdate.getSelectedItemPosition())); if (autoUpdate.getSelectedItemPosition() == 1 || autoUpdate.getSelectedItemPosition() == 2) { settings.putString(getString(R.string.PREF_AUTO_UPDATE_FREQUENCY), autoFrequencyPossibleValues[frequency.getSelectedItemPosition()]); settings.putBoolean(getString(R.string.PREF_AUTO_UPDATE_ONLY_WIFI), onlyWiFi.isChecked()); if (autoUpdate.getSelectedItemPosition() == 2) { settings.putInt(getString(R.string.PREF_AUTO_UPDATE_START_TIME), currentAutoUpdateTime.get()); } } settings.commit(); IOUtils.handleDataUpdatePreferences(TvBrowser.this); Intent startDownload = new Intent(TvBrowser.this, TvDataUpdateService.class); startDownload.putExtra(TvDataUpdateService.TYPE, TvDataUpdateService.TV_DATA_TYPE); startDownload.putExtra(getResources().getString(R.string.DAYS_TO_DOWNLOAD), Integer.parseInt(value)); startService(startDownload); updateProgressIcon(true); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } else { Cursor test2 = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null, null, null, null); boolean loadAgain = test2.getCount() < 1; test2.close(); selectChannels(loadAgain); } test.close(); } }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void showAbout() { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); RelativeLayout about = (RelativeLayout) getLayoutInflater().inflate(R.layout.about, getParentViewGroup(), false);/* w w w .j a va 2s. c om*/ try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); TextView version = (TextView) about.findViewById(R.id.version); version.setText(pInfo.versionName); } catch (NameNotFoundException e) { e.printStackTrace(); } ((TextView) about.findViewById(R.id.license)) .setText(Html.fromHtml(getResources().getString(R.string.license))); TextView androidVersion = (TextView) about.findViewById(R.id.android_version); androidVersion.setText(Build.VERSION.RELEASE); TextView lastUpdate = (TextView) about.findViewById(R.id.data_update); lastUpdate.setText(DateFormat.getLongDateFormat(TvBrowser.this) .format(new Date(PrefUtils.getLongValue(R.string.LAST_DATA_UPDATE, 0)))); TextView nextUpdate = (TextView) about.findViewById(R.id.next_data_update); switch (Integer.parseInt( PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_TYPE, R.string.pref_auto_update_type_default))) { case 0: nextUpdate.setText(R.string.next_data_update_manually); break; case 1: nextUpdate.setText(R.string.next_data_update_connection); break; case 2: { Date date = new Date(PrefUtils.getLongValue(R.string.AUTO_UPDATE_CURRENT_START_TIME, 0)); nextUpdate.setText(DateFormat.getMediumDateFormat(TvBrowser.this).format(date) + " " + DateFormat.getTimeFormat(TvBrowser.this).format(date)); } break; } ((TextView) about.findViewById(R.id.rundate_value)) .setText(DateFormat.getLongDateFormat(getApplicationContext()).format(mRundate.getTime())); builder.setTitle(R.string.action_about); builder.setView(about); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.show(); }