List of usage examples for java.util TimeZone getDisplayName
public final String getDisplayName()
From source file:com.edgenius.wiki.gwt.server.SecurityControllerImpl.java
public UserModel checkLogin(JsInfoModel jsModel) { User user = WikiUtil.getUser();/* ww w . ja v a 2s .co m*/ UserModel userModel = UserUtil.copyUserToModel(null, user); if (user.isAnonymous() || user.getSetting().getTimeZone() == null) { //jsModel.timezoneOffset format is hour.minutes, such as 6.30 TimeZone timezone = TimeZoneUtil.guessTimeZone(jsModel.timezoneOffset); HttpSession session = WebUtil.getRequest().getSession(); session.setAttribute(Constants.TIMEZONE, timezone); log.info("User timezone is set to {} with timezone offset {}", timezone.getDisplayName(), jsModel.timezoneOffset); } return userModel; }
From source file:com.rareventure.gps2.reviewer.map.OsmMapGpsTrailerReviewerMapActivity.java
private void initSasPanel() { ListView sasPanelList = (ListView) findViewById(R.id.sas_grid); sasPanelList.setOnItemClickListener(new OnItemClickListener() { private static final int MIN_TR_TIMESPAN_SEC = Util.SECONDS_IN_DAY; private static final int TR_TIMESPAN_MULTIPLIER = 3; @Override/*from ww w . ja va 2 s .c o m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //note that getTimeRange reuses the same tr instance, so we have to be careful // when we call it twice TimeRange tr = gpsTrailerOverlay.sas.getTimeRange(position - 1); int currStartSec = tr.startTimeSec; int currEndSec = tr.endTimeSec; //co: we just want the time inside the box // int timeSpan; // // if(tr.fullRangeEndSec - tr.fullRangeStartSec < MIN_TR_TIMESPAN_SEC / TR_TIMESPAN_MULTIPLIER) // { // timeSpan = MIN_TR_TIMESPAN_SEC; // } // else // { // timeSpan = (tr.fullRangeEndSec - tr.fullRangeStartSec) * TR_TIMESPAN_MULTIPLIER; // } // // int currStartSec = (int) Math.max(- timeSpan /2 + (tr.endTimeSec/2 + tr.startTimeSec/2), getStartTimeMs()/1000); // int currEndSec = (int) Math.min(timeSpan /2 + (tr.endTimeSec/2 + tr.startTimeSec/2), getEndTimeMs()/1000); // // if(position > 0) // { // TimeRange prevTr = gpsTrailerOverlay.sas.getTimeRange(position-1); // currStartSec = Math.max(prevTr.endTimeSec, currStartSec); // } // // if(position < gpsTrailerOverlay.sas.getTimeRangeCount() - 1) // { // TimeRange nextTr = gpsTrailerOverlay.sas.getTimeRange(position+1); // currEndSec = Math.min(nextTr.startTimeSec, currEndSec); // } // if (currEndSec - currStartSec < timeView.getMinSelectableTimeSec()) { currEndSec = currStartSec + timeView.getMinSelectableTimeSec(); } setStartAndEndTimeSec(currStartSec, currEndSec); updateTimeViewTime(); } }); sasPanelList.setAdapter(new ListAdapter() { @Override public void unregisterDataSetObserver(DataSetObserver observer) { gpsTrailerOverlay.sas.unregisterDataSetObserver(observer); } @Override public void registerDataSetObserver(DataSetObserver observer) { gpsTrailerOverlay.sas.registerDataSetObserver(observer); } @Override public boolean isEmpty() { return gpsTrailerOverlay.sas.isEmpty(); } @Override public boolean hasStableIds() { return false; //because we might merge timeviews } @Override public int getViewTypeCount() { return 2; } public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { // Log.d(GTG.TAG,"SASPanel: Creating new view"); if (position == 0) convertView = getLayoutInflater().inflate(R.layout.selected_area_info_top_row, null); else convertView = getLayoutInflater().inflate(R.layout.selected_area_info_row, null); } // else // Log.d(GTG.TAG,"SASPanel: Reusing view"); if (position == 0) { ((TextView) convertView.findViewById(R.id.totalTime)) .setText(Util.convertMsToText(gpsTrailerOverlay.sas.getTotalTimeSecs() * 1000l)); ((TextView) convertView.findViewById(R.id.totalDist)).setText(MapScaleWidget .calcLabelForLength(gpsTrailerOverlay.sas.getTotalDistM(), GTG.prefs.useMetric)); ((TextView) convertView.findViewById(R.id.timesInArea)) .setText(String.valueOf(gpsTrailerOverlay.sas.getTimesInArea())); ((TextView) convertView.findViewById(R.id.timesInArea)) .setText(String.valueOf(gpsTrailerOverlay.sas.getTimesInArea())); TimeZone tz = gpsTrailerOverlay.sas.timeZone; if (tz == null || tz.hasSameRules(Util.getCurrTimeZone())) { convertView.findViewById(R.id.timeZoneTableRow).setVisibility(View.GONE); } else { convertView.findViewById(R.id.timeZoneTableRow).setVisibility(View.VISIBLE); ((TextView) convertView.findViewById(R.id.timezone)).setText(tz.getDisplayName()); } return convertView; } TimeRange tr = gpsTrailerOverlay.sas.getTimeRange(position - 1); timeAndDateSdf.setTimeZone(gpsTrailerOverlay.sas.timeZone); String startText = timeAndDateSdf.format(new Date(tr.startTimeSec * 1000l)); String endText = timeAndDateSdf.format(new Date(tr.endTimeSec * 1000l)); ((TextView) convertView.findViewById(R.id.startTime)).setText(startText); ((TextView) convertView.findViewById(R.id.endTime)).setText(endText); String distText; if (tr.dist == -1) distText = "--"; else { distText = MapScaleWidget.calcLabelForLength(tr.dist, GTG.prefs.useMetric); } ((TextView) convertView.findViewById(R.id.distance)).setText(distText); //this fixes a bug where sometimes if the last row is deleted and readded, it isn't //layedout again, causing the date/times to be cut off convertView.requestLayout(); // ((TextView)convertView.findViewById(R.id.timeLength)).setText("a certain amount of time"); return convertView; } @Override public int getItemViewType(int position) { if (position == 0) return 0; return 1; } @Override public long getItemId(int position) { if (position == 0) return Long.MIN_VALUE; TimeRange tr = gpsTrailerOverlay.sas.getTimeRange(position - 1); return tr.fullRangeStartSec; } @Override public Object getItem(int position) { if (position == 0) return null; return gpsTrailerOverlay.sas.getTimeRange(position - 1); } @Override public int getCount() { int count = gpsTrailerOverlay.sas.getTimeRangeCount(); // Log.d(GTG.TAG,"item count is "+count); if (count >= 1) return count + 1; return 0; } @Override public boolean isEnabled(int position) { if (position == 0) return false; return true; } @Override public boolean areAllItemsEnabled() { return false; } }); }
From source file:com.appsimobile.appsii.timezonepicker.TimeZoneData.java
private HashSet<String> loadTzsInZoneTab(Context context) { HashSet<String> processedTimeZones = new HashSet<>(); AssetManager am = context.getAssets(); InputStream is = null;/*from ww w. j av a2 s . com*/ /* * The 'backward' file contain mappings between new and old time zone * ids. We will explicitly ignore the old ones. */ try { is = am.open("backward"); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { // Skip comment lines if (!line.startsWith("#") && line.length() > 0) { // 0: "Link" // 1: New tz id // Last: Old tz id String[] fields = line.split("\t+"); String newTzId = fields[1]; String oldTzId = fields[fields.length - 1]; final TimeZone tz = TimeZone.getTimeZone(newTzId); if (tz == null) { Log.e(TAG, "Timezone not found: " + newTzId); continue; } processedTimeZones.add(oldTzId); if (DEBUG) { Log.e(TAG, "# Dropping identical time zone from backward: " + oldTzId); } // Remember the cooler/newer time zone id if (mDefaultTimeZoneId != null && mDefaultTimeZoneId.equals(oldTzId)) { mAlternateDefaultTimeZoneId = newTzId; } } } } catch (IOException ex) { Log.e(TAG, "Failed to read 'backward' file."); } finally { try { if (is != null) { is.close(); } } catch (IOException ignored) { } } /* * zone.tab contains a list of time zones and country code. They are * "sorted first by country, then an order within the country that (1) * makes some geographical sense, and (2) puts the most populous zones * first, where that does not contradict (1)." */ try { String lang = Locale.getDefault().getLanguage(); is = am.open("zone.tab"); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { if (!line.startsWith("#")) { // Skip comment lines // 0: country code // 1: coordinates // 2: time zone id // 3: comments final String[] fields = line.split("\t"); final String timeZoneId = fields[2]; final String countryCode = fields[0]; final TimeZone tz = TimeZone.getTimeZone(timeZoneId); if (tz == null) { Log.e(TAG, "Timezone not found: " + timeZoneId); continue; } /* * Dropping non-GMT tzs without a country code. They are not * really needed and they are dups but missing proper * country codes. e.g. WET CET MST7MDT PST8PDT Asia/Khandyga * Asia/Ust-Nera EST */ if (countryCode == null && !timeZoneId.startsWith("Etc/GMT")) { processedTimeZones.add(timeZoneId); continue; } // Remember the mapping between the country code and display // name String country = mCountryCodeToNameMap.get(countryCode); if (country == null) { country = getCountryNames(lang, countryCode); mCountryCodeToNameMap.put(countryCode, country); } // TODO Don't like this here but need to get the country of // the default tz. // Find the country of the default tz if (mDefaultTimeZoneId != null && mDefaultTimeZoneCountry == null && timeZoneId.equals(mAlternateDefaultTimeZoneId)) { mDefaultTimeZoneCountry = country; TimeZone defaultTz = TimeZone.getTimeZone(mDefaultTimeZoneId); if (defaultTz != null) { mDefaultTimeZoneInfo = new TimeZoneInfo(defaultTz, country); int tzToOverride = getIdenticalTimeZoneInTheCountry(mDefaultTimeZoneInfo); if (tzToOverride == -1) { if (DEBUG) { Log.e(TAG, "Adding default time zone: " + mDefaultTimeZoneInfo.toString()); } mTimeZones.add(mDefaultTimeZoneInfo); } else { mTimeZones.add(tzToOverride, mDefaultTimeZoneInfo); if (DEBUG) { TimeZoneInfo tzInfoToOverride = mTimeZones.get(tzToOverride); String tzIdToOverride = tzInfoToOverride.mTzId; Log.e(TAG, "Replaced by default tz: " + tzInfoToOverride.toString()); Log.e(TAG, "Adding default time zone: " + mDefaultTimeZoneInfo.toString()); } } } } // Add to the list of time zones if the time zone is unique // in the given country. TimeZoneInfo timeZoneInfo = new TimeZoneInfo(tz, country); int identicalTzIdx = getIdenticalTimeZoneInTheCountry(timeZoneInfo); if (identicalTzIdx == -1) { if (DEBUG) { Log.e(TAG, "# Adding time zone: " + timeZoneId + " ## " + tz.getDisplayName()); } mTimeZones.add(timeZoneInfo); } else { if (DEBUG) { Log.e(TAG, "# Dropping identical time zone: " + timeZoneId + " ## " + tz.getDisplayName()); } } processedTimeZones.add(timeZoneId); } } } catch (IOException ex) { Log.e(TAG, "Failed to read 'zone.tab'."); } finally { try { if (is != null) { is.close(); } } catch (IOException ignored) { } } return processedTimeZones; }
From source file:org.cgiar.ccafs.marlo.action.BaseAction.java
public String getTimeZone() { TimeZone timeZone = TimeZone.getDefault(); String display = timeZone.getDisplayName(); return display; }