List of usage examples for android.text.format Time set
public void set(Time that)
From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java
public static void addAlarm(Context context, Lecture lecture, int alarmTimesIndex) { int[] alarm_times = { 0, 5, 10, 15, 30, 45, 60 }; long when;//from w ww. j av a 2 s . c o m Time time; long startTime; long startTimeInSeconds = lecture.dateUTC; if (startTimeInSeconds > 0) { when = startTimeInSeconds; startTime = startTimeInSeconds; time = new Time(); } else { time = lecture.getTime(); startTime = time.normalize(true); when = time.normalize(true); } long alarmTimeDiffInSeconds = alarm_times[alarmTimesIndex] * 60 * 1000; when -= alarmTimeDiffInSeconds; // DEBUG // when = System.currentTimeMillis() + (30 * 1000); time.set(when); MyApp.LogDebug("addAlarm", "Alarm time: " + time.format("%Y-%m-%dT%H:%M:%S%z") + ", in seconds: " + when); Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(BundleKeys.ALARM_LECTURE_ID, lecture.lecture_id); intent.putExtra(BundleKeys.ALARM_DAY, lecture.day); intent.putExtra(BundleKeys.ALARM_TITLE, lecture.title); intent.putExtra(BundleKeys.ALARM_START_TIME, startTime); intent.setAction(AlarmReceiver.ALARM_LECTURE); intent.setData(Uri.parse("alarm://" + lecture.lecture_id)); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingintent = PendingIntent.getBroadcast(context, Integer.parseInt(lecture.lecture_id), intent, 0); // Cancel any existing alarms for this lecture alarmManager.cancel(pendingintent); // Set new alarm alarmManager.set(AlarmManager.RTC_WAKEUP, when, pendingintent); int alarmTimeInMin = alarm_times[alarmTimesIndex]; // write to DB AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(context); SQLiteDatabase db = alarmDB.getWritableDatabase(); // delete any previous alarms of this lecture try { db.beginTransaction(); db.delete(AlarmsTable.NAME, AlarmsTable.Columns.EVENT_ID + "=?", new String[] { lecture.lecture_id }); ContentValues values = new ContentValues(); values.put(AlarmsTable.Columns.EVENT_ID, Integer.parseInt(lecture.lecture_id)); values.put(AlarmsTable.Columns.EVENT_TITLE, lecture.title); values.put(AlarmsTable.Columns.ALARM_TIME_IN_MIN, alarmTimeInMin); values.put(AlarmsTable.Columns.TIME, when); DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); values.put(AlarmsTable.Columns.TIME_TEXT, df.format(new Date(when))); values.put(AlarmsTable.Columns.DISPLAY_TIME, startTime); values.put(AlarmsTable.Columns.DAY, lecture.day); db.insert(AlarmsTable.NAME, null, values); db.setTransactionSuccessful(); } catch (SQLException e) { } finally { db.endTransaction(); db.close(); } lecture.has_alarm = true; }
From source file:com.nextgis.firereporter.ReporterService.java
public void ScheduleNextUpdate(Context context, long nMinTimeBetweenSend, boolean bEnergyEconomy) { if (context == null) return;/*from w ww.j a v a 2 s. c o m*/ Intent intent = new Intent(ReporterService.ACTION_START); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // The update frequency should often be user configurable. This is not. long currentTimeMillis = System.currentTimeMillis(); long nextUpdateTimeMillis = currentTimeMillis + nMinTimeBetweenSend; Time nextUpdateTime = new Time(); nextUpdateTime.set(nextUpdateTimeMillis); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (bEnergyEconomy) alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent); else alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdateTimeMillis, pendingIntent); }
From source file:pro.jariz.reisplanner.fragments.PlannerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); thisView = inflater.inflate(R.layout.fragment_planner, container, false); final SlidingFragmentActivity context = (SlidingFragmentActivity) this.getActivity(); //make sure we've got some actionbar buttons setHasOptionsMenu(true);/* w w w. j a v a 2 s . c om*/ //context.getSupportMenuInflater(). CheckBox extra = (CheckBox) thisView.findViewById(R.id.extraOptions); extra.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { LinearLayout time = (LinearLayout) thisView.findViewById(R.id.time); LinearLayout date = (LinearLayout) thisView.findViewById(R.id.date); if (isChecked) { time.setVisibility(View.VISIBLE); date.setVisibility(View.VISIBLE); Animation anim = AnimationUtils.loadAnimation(context, R.anim.fadein); time.startAnimation(anim); date.startAnimation(anim); } else { time.setVisibility(View.GONE); date.setVisibility(View.GONE); //Animation anim = AnimationUtils.loadAnimation(context, R.anim.fadeout); //time.startAnimation(anim); //date.startAnimation(anim); } } }); context.getSupportActionBar().setTitle("Planner"); Time time = new Time(); time.setToNow(); Integer lastCacheTime = DB.getLastCacheTime("stations"); Time difference = new Time(); difference.set(time.toMillis(true) - lastCacheTime); //no stations present or cache is outdated? refresh. if (DB.getStationCount() == 0 || (lastCacheTime != 0 && difference.monthDay >= 10)) { Crouton.showText(context, getResources().getString(R.string.updating_station_list), CroutonStyles.infoStyle); new NSTask(this).execute(NSTask.TYPE_STATIONS); } else { //cache time! new NSTask(this).execute(NSTask.TYPE_STATIONS_DB); } return thisView; }
From source file:com.granita.tasks.notification.NotificationActionIntentService.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) @Override//from w w w .jav a 2s . co m protected void onHandleIntent(Intent intent) { mAuthority = getString(R.string.org_dmfs_tasks_authority); final String action = intent.getAction(); final Context context = this; if (intent.hasExtra(EXTRA_NOTIFICATION_ID)) { Uri taskUri = intent.getData(); int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.cancel(notificationId); if (ACTION_COMPLETE.equals(action)) { markCompleted(taskUri); } else if (intent.hasExtra(EXTRA_TASK_DUE) && intent.hasExtra(EXTRA_TIMEZONE)) { long due = intent.getLongExtra(EXTRA_TASK_DUE, -1); String tz = intent.getStringExtra(EXTRA_TIMEZONE); boolean allDay = intent.getBooleanExtra(EXTRA_ALLDAY, false); if (ACTION_DELAY_1H.equals(action)) { Time time = new Time(tz); time.set(due); time.allDay = false; time.hour++; time.normalize(true); delayTask(taskUri, time); } else if (ACTION_DELAY_1D.equals(action)) { if (tz == null) { tz = "UTC"; } Time time = new Time(tz); time.set(due); time.allDay = allDay; time.monthDay++; time.normalize(true); delayTask(taskUri, time); } } } else if (intent.hasExtra(NotificationActionUtils.EXTRA_NOTIFICATION_ACTION)) { /* * Grab the alarm from the intent. Since the remote AlarmManagerService fills in the Intent to add some extra data, it must unparcel the * NotificationAction object. It throws a ClassNotFoundException when unparcelling. To avoid this, do the marshalling ourselves. */ final NotificationAction notificationAction; final byte[] data = intent.getByteArrayExtra(NotificationActionUtils.EXTRA_NOTIFICATION_ACTION); if (data != null) { final Parcel in = Parcel.obtain(); in.unmarshall(data, 0, data.length); in.setDataPosition(0); notificationAction = NotificationAction.CREATOR.createFromParcel(in, NotificationAction.class.getClassLoader()); } else { return; } if (NotificationActionUtils.ACTION_UNDO.equals(action)) { NotificationActionUtils.cancelUndoTimeout(context, notificationAction); NotificationActionUtils.cancelUndoNotification(context, notificationAction); resendNotification(notificationAction); } else if (ACTION_COMPLETE.equals(action)) { // All we need to do is switch to an Undo notification NotificationActionUtils.createUndoNotification(context, notificationAction); NotificationActionUtils.registerUndoTimeout(this, notificationAction); } else { if (NotificationActionUtils.ACTION_UNDO_TIMEOUT.equals(action) || NotificationActionUtils.ACTION_DESTRUCT.equals(action)) { // Process the action NotificationActionUtils.cancelUndoTimeout(this, notificationAction); NotificationActionUtils.processUndoNotification(this, notificationAction); processDesctructiveNotification(notificationAction); } } } }
From source file:com.android.calendar.year.YearViewPagerFragment.java
public YearViewPagerFragment(long timeMillis) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timeMillis); Time gTime = new Time(); gTime.set(timeMillis); mCurrentJalaliYear = Jalali.gregorianToJalali(gTime).year; // check//from w w w . j a va 2 s. c om if (mCurrentJalaliYear < EPOCH_TIME_YEAR_START || mCurrentJalaliYear > EPOCH_TIME_YEAR_END) { mCurrentJalaliYear = EPOCH_TIME_YEAR_START; } // mCurrentMonth = calendar.get(Calendar.MONTH); }
From source file:com.android.calendar.SearchActivity.java
private void initFragments(long timeMillis, String query) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); AgendaFragment searchResultsFragment = new AgendaFragment(timeMillis, true); ft.replace(R.id.search_results, searchResultsFragment); mController.registerEventHandler(R.id.search_results, searchResultsFragment); ft.commit();/* w w w. j a va 2 s . com*/ Time t = new Time(); t.set(timeMillis); search(query, t); }
From source file:com.election.US.basicsyncadapter.EntryListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mAdapter = new SimpleCursorAdapter(getActivity(), // Current context android.R.layout.simple_list_item_activated_2, // Layout for individual rows null, // Cursor FROM_COLUMNS, // Cursor columns to use TO_FIELDS, // Layout fields to use 0 // No flags );//from ww w. j av a2 s . com mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int i) { if (i == COLUMN_PUBLISHED) { // Convert timestamp to human-readable date Time t = new Time(); t.set(cursor.getLong(i)); ((TextView) view).setText(t.format("%Y-%m-%d %H:%M")); return true; } else { // Let SimpleCursorAdapter handle other fields automatically return false; } } }); setListAdapter(mAdapter); setEmptyText(getText(R.string.loading)); getLoaderManager().initLoader(0, null, this); }
From source file:com.xandy.calendar.SearchActivity.java
private void initFragments(long timeMillis, String query) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); AgendaFragment searchResultsFragment = new AgendaFragment(timeMillis, true); ft.replace(R.id.search_results, searchResultsFragment); mController.registerEventHandler(R.id.search_results, searchResultsFragment); ft.commit();/* www.j a v a2s . c om*/ Time t = new Time(); t.set(timeMillis); search(query, t); }
From source file:securityantennas.viwer.android.mogaworks.securityantenna.FeedListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); int loader_id = getArguments().getInt(ARG_SECTION_NUMBER); mAdapter = new SimpleCursorAdapter(getActivity(), // Current context android.R.layout.simple_list_item_activated_2, // Layout for individual rows null, // Cursor FROM_COLUMNS, // Cursor columns to use TO_FIELDS, // Layout fields to use 0 // No flags );/*from ww w . j ava 2 s . c o m*/ mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int i) { if (i == COLUMN_PUBLISHED) { // Convert timestamp to human-readable date Time t = new Time(); t.set(cursor.getLong(i)); ((TextView) view).setText(t.format("%Y-%m-%d %H:%M")); return true; } else { // Let SimpleCursorAdapter handle other fields automatically return false; } } }); setListAdapter(mAdapter); setEmptyText(getText(R.string.loading)); getLoaderManager().initLoader(loader_id, null, this); }
From source file:com.example.android.basicsyncadapter.FeedListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mListView = (ListView) view.findViewById(R.id.list_view); mEmpty = view.findViewById(R.id.empty); mAdapter = new SimpleCursorAdapter(getActivity(), // Current context R.layout.list_item, // Layout for individual rows null, // Cursor new String[] { // Cursor columns to use FeedContract.Entry.COLUMN_NAME_TITLE, FeedContract.Entry.COLUMN_NAME_PUBLISHED }, new int[] { // Layout fields to use R.id.title, R.id.date }, 0 // No flags );// w ww.ja v a 2s.c o m mAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int i) { if (i == COLUMN_PUBLISHED) { // Convert timestamp to human-readable date Time t = new Time(); t.set(cursor.getLong(i)); ((TextView) view).setText(t.format("%Y-%m-%d %H:%M")); return true; } else { // Let SimpleCursorAdapter handle other fields automatically return false; } } }); mListView.setAdapter(mAdapter); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Load an article in the default browser when selected by the user. // Get a URI for the selected item, then start an Activity that displays the URI. Any // Activity that filters for ACTION_VIEW and a URI can accept this. In most cases, this will // be a browser. // Get the item at the selected position, in the form of a Cursor. Cursor c = (Cursor) mAdapter.getItem(position); // Get the link to the article represented by the item. String articleUrlString = c.getString(COLUMN_URL_STRING); if (articleUrlString == null) { Log.e(TAG, "Attempt to launch entry with null link"); return; } Log.i(TAG, "Opening URL: " + articleUrlString); // Get a Uri object for the URL string Uri articleURL = Uri.parse(articleUrlString); Intent i = new Intent(Intent.ACTION_VIEW, articleURL); startActivity(i); } }); getLoaderManager().initLoader(0, null, this); }