List of usage examples for android.text.format Time getCurrentTimezone
public static String getCurrentTimezone()
From source file:fr.inria.ucn.collectors.SysStateCollector.java
/** * /*from w w w .j a v a 2s . co m*/ * @param c * @param ts * @param change */ @SuppressLint("NewApi") public void run(Context c, long ts, boolean change) { try { JSONObject data = new JSONObject(); data.put("on_screen_state_change", change); // this collection run was triggered by screen state change data.put("hostname", Helpers.getSystemProperty("net.hostname", "unknown hostname")); data.put("current_timezone", Time.getCurrentTimezone()); // general memory state ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); MemoryInfo mi = new MemoryInfo(); am.getMemoryInfo(mi); JSONObject mem = new JSONObject(); mem.put("available", mi.availMem); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { mem.put("total", mi.totalMem); } mem.put("is_low", mi.lowMemory); data.put("memory", mem); // screen state PowerManager pm = (PowerManager) c.getSystemService(Context.POWER_SERVICE); data.put("screen_on", pm.isScreenOn()); // battery state IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); Intent battery = c.registerReceiver(null, ifilter); int level = battery.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = battery.getIntExtra(BatteryManager.EXTRA_SCALE, -1); float pct = (float) (100.0 * level) / scale; int status = battery.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL); int chargePlug = battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; JSONObject batt = new JSONObject(); batt.put("level", level); batt.put("scale", scale); batt.put("pct", pct); batt.put("is_charging", isCharging); batt.put("usb_charge", usbCharge); batt.put("ac_charge", acCharge); data.put("battery", batt); // some proc stats data.put("cpu", getCpuStat()); data.put("loadavg", getLoadStat()); data.put("uptime", getUptimeStat()); // audio state data.put("audio", getAudioState(c)); // done Helpers.sendResultObj(c, "system_state", ts, data); } catch (JSONException jex) { Log.w(Constants.LOGTAG, "failed to create json object", jex); } }
From source file:uk.org.openseizuredetector.SdData.java
public SdData() { simpleSpec = new int[10]; dataTime = new Time(Time.getCurrentTimezone()); }
From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java
/** * Gets validity of ticket with time {@code t} in minutes. */// w w w . j a va 2 s. co m public static int getValidityMinutes(Time t) { if (t == null) { return -1; } final Time now = new Time(); now.setToNow(); now.switchTimezone(Time.getCurrentTimezone()); return (int) Math.ceil((t.toMillis(true) - now.toMillis(true)) / 1000d / 60d); }
From source file:com.andexert.calendarlistview.library.SimpleMonthView.java
public SimpleMonthView(Context context, TypedArray typedArray) { super(context); Resources resources = context.getResources(); mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); today = new Time(Time.getCurrentTimezone()); today.setToNow();/*from ww w. j ava 2s. com*/ mDayOfWeekTypeface = resources.getString(R.string.sans_serif); mCurrentDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorCurrentDay, resources.getColor(R.color.to_day)); mMonthTextColor = typedArray.getColor(R.styleable.DayPickerView_colorMonthName, resources.getColor(R.color.normal_day)); mDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorDayName, resources.getColor(R.color.normal_day)); mDayNumColor = typedArray.getColor(R.styleable.DayPickerView_colorNormalDay, resources.getColor(R.color.normal_day)); mPreviousDayColor = typedArray.getColor(R.styleable.DayPickerView_colorPreviousDay, resources.getColor(R.color.normal_day)); mSelectedDaysColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayBackground, resources.getColor(R.color.selected_day_background)); mMonthTitleBGColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayText, resources.getColor(R.color.selected_day_text)); mIsShowMonthDay = typedArray.getBoolean(R.styleable.DayPickerView_showMonthDay, true); mDrawRect = typedArray.getBoolean(R.styleable.DayPickerView_drawRoundRect, false); mStringBuilder = new StringBuilder(50); MINI_DAY_NUMBER_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDay, resources.getDimensionPixelSize(R.dimen.text_size_day)); MONTH_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeMonth, resources.getDimensionPixelSize(R.dimen.text_size_month)); MONTH_DAY_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDayName, resources.getDimensionPixelSize(R.dimen.text_size_day_name)); MONTH_HEADER_SIZE = typedArray.getDimensionPixelOffset(R.styleable.DayPickerView_headerMonthHeight, resources.getDimensionPixelOffset( mIsShowMonthDay ? R.dimen.header_month_height_showWeek : R.dimen.header_month_height)); DAY_SELECTED_CIRCLE_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_selectedDayRadius, resources.getDimensionPixelOffset(R.dimen.selected_day_radius)); mRowHeight = ((typedArray.getDimensionPixelSize(R.styleable.DayPickerView_calendarHeight, resources.getDimensionPixelOffset(R.dimen.calendar_height)) - MONTH_HEADER_SIZE) / 6); isPrevDayEnabled = typedArray.getBoolean(R.styleable.DayPickerView_enablePreviousDay, true); initView(); }
From source file:uk.org.openseizuredetector.client.SdClientService.java
/** * onStartCommand - start regular download of status data from the server. *//*from ww w.ja v a 2 s . c o m*/ @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.v(TAG, "SdClientService service starting"); // Update preferences. Log.v(TAG, "calling updatePrefs()"); updatePrefs(); // Display a notification icon in the status bar of the phone to // show the service is running. Log.v(TAG, "showing Notification"); showNotification(); // Start timer to check status of pebble regularly. mStatusTime = new Time(Time.getCurrentTimezone()); mStatusTime.setToNow(); if (statusTimer == null) { Log.v(TAG, "onCreate(): starting status timer"); statusTimer = new Timer(); statusTimer.schedule(new TimerTask() { @Override public void run() { getSdData(); } }, 0, mDataUpdatePeriod); } else { Log.v(TAG, "onCreate(): status timer already running."); } // Apply the wake-lock to prevent CPU sleeping (very battery intensive!) if (mWakeLock != null) { mWakeLock.acquire(); Log.v(TAG, "Applied Wake Lock to prevent device sleeping"); } else { Log.d(TAG, "mmm...mWakeLock is null, so not aquiring lock. This shouldn't happen!"); } return START_STICKY; }
From source file:com.xandy.calendar.month.SimpleDayPickerFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mContext = activity;//from w w w.j a v a 2 s .c o m String tz = Time.getCurrentTimezone(); ViewConfiguration viewConfig = ViewConfiguration.get(activity); mMinimumFlingVelocity = viewConfig.getScaledMinimumFlingVelocity(); // Ensure we're in the correct time zone mSelectedDay.switchTimezone(tz); mSelectedDay.normalize(true); mFirstDayOfMonth.timezone = tz; mFirstDayOfMonth.normalize(true); mFirstVisibleDay.timezone = tz; mFirstVisibleDay.normalize(true); mTempTime.timezone = tz; Resources res = activity.getResources(); mSaturdayColor = res.getColor(R.color.month_saturday); mSundayColor = res.getColor(R.color.month_sunday); mDayNameColor = res.getColor(R.color.month_day_names_color); // Adjust sizes for screen density if (mScale == 0) { mScale = activity.getResources().getDisplayMetrics().density; if (mScale != 1) { WEEK_MIN_VISIBLE_HEIGHT *= mScale; BOTTOM_BUFFER *= mScale; LIST_TOP_OFFSET *= mScale; } } setUpAdapter(); setListAdapter(mAdapter); }
From source file:com.android.calendar.month.SimpleDayPickerFragment.java
@Override public void onAttach(Activity activity) { super.onAttach(activity); mContext = activity;/*from w w w . j a va 2 s.c o m*/ String tz = Time.getCurrentTimezone(); ViewConfiguration viewConfig = ViewConfiguration.get(activity); mMinimumFlingVelocity = viewConfig.getScaledMinimumFlingVelocity(); // Ensure we're in the correct time zone mSelectedDay.switchTimezone(tz); mSelectedDay.normalize(true); mFirstDayOfMonth.timezone = tz; mFirstDayOfMonth.normalize(true); mFirstVisibleDay.timezone = tz; mFirstVisibleDay.normalize(true); mTempTime.timezone = tz; Resources res = activity.getResources(); mSaturdayColor = res.getColor(R.color.month_saturday); mSundayColor = res.getColor(R.color.month_sunday); mFridayColor = res.getColor(R.color.month_friday); mDayNameColor = res.getColor(R.color.month_day_names_color); // Adjust sizes for screen density if (mScale == 0) { mScale = activity.getResources().getDisplayMetrics().density; if (mScale != 1) { WEEK_MIN_VISIBLE_HEIGHT *= mScale; BOTTOM_BUFFER *= mScale; LIST_TOP_OFFSET *= mScale; } } setUpAdapter(); setListAdapter(mAdapter); }
From source file:uk.org.openseizuredetector.SdServer.java
/** * onStartCommand - start the web server and the message loop for * communications with other processes./* ww w .j a v a 2s . com*/ */ @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.v(TAG, "onStartCommand() - SdServer service starting"); // Update preferences. Log.v(TAG, "onStartCommand() - calling updatePrefs()"); updatePrefs(); // Display a notification icon in the status bar of the phone to // show the service is running. Log.v(TAG, "showing Notification"); showNotification(); // Record last time we sent an SMS so we can limit rate of SMS // sending to one per minute. mSMSTime = new Time(Time.getCurrentTimezone()); // Start receiving data from the pebble watch startPebbleServer(); // Start timer to check status of pebble regularly. mPebbleStatusTime = new Time(Time.getCurrentTimezone()); //getPebbleStatus(); if (statusTimer == null) { Log.v(TAG, "onCreate(): starting status timer"); statusTimer = new Timer(); statusTimer.schedule(new TimerTask() { @Override public void run() { getPebbleStatus(); } }, 0, 1000); } else { Log.v(TAG, "onCreate(): status timer already running."); } // Start timer to retrieve pebble settings regularly. getPebbleSdSettings(); if (settingsTimer == null) { Log.v(TAG, "onCreate(): starting settings timer"); settingsTimer = new Timer(); settingsTimer.schedule(new TimerTask() { @Override public void run() { getPebbleSdSettings(); } }, 0, 1000 * 60); } else { Log.v(TAG, "onCreate(): settings timer already running."); } // Start timer to log data regularly.. if (dataLogTimer == null) { Log.v(TAG, "onCreate(): starting dataLog timer"); dataLogTimer = new Timer(); dataLogTimer.schedule(new TimerTask() { @Override public void run() { logData(); } }, 0, 1000 * 60); } else { Log.v(TAG, "onCreate(): dataLog timer already running."); } // Start the web server startWebServer(); // Apply the wake-lock to prevent CPU sleeping (very battery intensive!) if (mWakeLock != null) { mWakeLock.acquire(); Log.v(TAG, "Applied Wake Lock to prevent device sleeping"); } else { Log.d(TAG, "mmm...mWakeLock is null, so not aquiring lock. This shouldn't happen!"); } return START_STICKY; }
From source file:com.android.calendar.alerts.AlarmScheduler.java
/** * Queries for all the reminders of the events in the instancesCursor, and schedules * the alarm for the next upcoming reminder. *//* w w w.j a v a2 s .c om*/ private static void queryNextReminderAndSchedule(Cursor instancesCursor, Context context, ContentResolver contentResolver, AlarmManagerInterface alarmManager, int batchSize, long currentMillis) { if (AlertService.DEBUG) { int eventCount = instancesCursor.getCount(); if (eventCount == 0) { Log.d(TAG, "No events found starting within 1 week."); } else { Log.d(TAG, "Query result count for events starting within 1 week: " + eventCount); } } // Put query results of all events starting within some interval into map of event ID to // local start time. Map<Integer, List<Long>> eventMap = new HashMap<Integer, List<Long>>(); Time timeObj = new Time(); long nextAlarmTime = Long.MAX_VALUE; int nextAlarmEventId = 0; instancesCursor.moveToPosition(-1); while (!instancesCursor.isAfterLast()) { int index = 0; eventMap.clear(); StringBuilder eventIdsForQuery = new StringBuilder(); eventIdsForQuery.append('('); while (index++ < batchSize && instancesCursor.moveToNext()) { int eventId = instancesCursor.getInt(INSTANCES_INDEX_EVENTID); long begin = instancesCursor.getLong(INSTANCES_INDEX_BEGIN); boolean allday = instancesCursor.getInt(INSTANCES_INDEX_ALL_DAY) != 0; long localStartTime; if (allday) { // Adjust allday to local time. localStartTime = Utils.convertAlldayUtcToLocal(timeObj, begin, Time.getCurrentTimezone()); } else { localStartTime = begin; } List<Long> startTimes = eventMap.get(eventId); if (startTimes == null) { startTimes = new ArrayList<Long>(); eventMap.put(eventId, startTimes); eventIdsForQuery.append(eventId); eventIdsForQuery.append(","); } startTimes.add(localStartTime); // Log for debugging. if (Log.isLoggable(TAG, Log.DEBUG)) { timeObj.set(localStartTime); StringBuilder msg = new StringBuilder(); msg.append("Events cursor result -- eventId:").append(eventId); msg.append(", allDay:").append(allday); msg.append(", start:").append(localStartTime); msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")"); Log.d(TAG, msg.toString()); } } if (eventIdsForQuery.charAt(eventIdsForQuery.length() - 1) == ',') { eventIdsForQuery.deleteCharAt(eventIdsForQuery.length() - 1); } eventIdsForQuery.append(')'); // Query the reminders table for the events found. Cursor cursor = null; try { cursor = contentResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION, REMINDERS_WHERE + eventIdsForQuery, null, null); // Process the reminders query results to find the next reminder time. cursor.moveToPosition(-1); while (cursor.moveToNext()) { int eventId = cursor.getInt(REMINDERS_INDEX_EVENT_ID); int reminderMinutes = cursor.getInt(REMINDERS_INDEX_MINUTES); List<Long> startTimes = eventMap.get(eventId); if (startTimes != null) { for (Long startTime : startTimes) { long alarmTime = startTime - reminderMinutes * DateUtils.MINUTE_IN_MILLIS; if (alarmTime > currentMillis && alarmTime < nextAlarmTime) { nextAlarmTime = alarmTime; nextAlarmEventId = eventId; } if (Log.isLoggable(TAG, Log.DEBUG)) { timeObj.set(alarmTime); StringBuilder msg = new StringBuilder(); msg.append("Reminders cursor result -- eventId:").append(eventId); msg.append(", startTime:").append(startTime); msg.append(", minutes:").append(reminderMinutes); msg.append(", alarmTime:").append(alarmTime); msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")"); Log.d(TAG, msg.toString()); } } } } } finally { if (cursor != null) { cursor.close(); } } } // Schedule the alarm for the next reminder time. if (nextAlarmTime < Long.MAX_VALUE) { scheduleAlarm(context, nextAlarmEventId, nextAlarmTime, currentMillis, alarmManager); } }
From source file:mad.codeforcommunity.CalendarView.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.monthI: //returns to the current month Time today = new Time(Time.getCurrentTimezone()); Intent intent = new Intent(this, CalendarView.class); intent.putExtra("date", today.year + "-" + today.month + "-" + today.monthDay); startActivityForResult(intent, 1); break;//from w w w .j a va 2 s.c om case R.id.dayI: setContentView(findViewById(R.layout.calendar_item)); //returns to the current date loadEventView(findViewById(R.layout.calendar_item)); break; case R.id.createI: //go to webpage to create new event //setContentView(R.layout.create_layout); Intent createInt = new Intent(this, CreateEvent.class); startActivity(createInt); break; case R.id.refreshI: //refresh the calendar refreshCalendar(); break; } return true; }