Android Open Source - TaskButler Toast Maker






From Project

Back to project page TaskButler.

License

The source code is released under:

GNU General Public License

If you think the Android project TaskButler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * ToastMaker.java/*w ww .j a  v a2  s . c o m*/
 *
 * Copyright 2012 Jonathan Hasenzahl, James Celona, Dhimitraq Jorgji
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.worcester.cs499summer2012.task;

import java.util.Calendar;
import java.util.GregorianCalendar;

import android.content.Context;
import android.text.format.DateFormat;
import android.widget.Toast;

/**
 * Helper class that provides methods to build Strings used in Toast notifications
 * in various activities.
 * @author Jon
 *
 */
public class ToastMaker {
  
  /**
   * Generates a string that can be used to inform the user the next time a
   * repeating task is due.
   * @param context The context of the calling activity.
   * @param resId The resource ID of the prefix string
   * @param cal A Calendar set to the time of the next due date.
   * @return a String for a Toast notification
   */
  public static String getRepeatMessage(Context context, int resId, Calendar cal) {
    Calendar current_date = GregorianCalendar.getInstance();
    StringBuilder message = new StringBuilder();
    message.append(context.getString(resId));
    
    if (cal.get(Calendar.YEAR) > current_date.get(Calendar.YEAR)) {
      // Due date is in a future year
      message.append(DateFormat.format(" MMMM d, yyyy'.'", cal));
    } else if (cal.get(Calendar.DAY_OF_YEAR) - current_date.get(Calendar.DAY_OF_YEAR) > 6) {
      // Due date is more than a week away
      message.append(DateFormat.format(" MMMM d'.'", cal));
    } else if (cal.get(Calendar.DAY_OF_YEAR) > current_date.get(Calendar.DAY_OF_YEAR)) {
      // Due date is after today
      message.append(DateFormat.format(" EEEE 'at' h:mmaa'.'", cal));
    } else {
      // Due date is today
      message.append(DateFormat.format(" 'today at' h:mmaa'.'", cal));
    }
    
    return message.toString();
  }
  
  /**
   * Displays a Toast notification for a short duration.
   * @param context
   * @param resId
   */
  public static void toast(Context context, int resId) {
    Toast.makeText(context, resId, Toast.LENGTH_SHORT).show();
  }
  
  /**
   * Displays a Toast notification for a short duration.
   * @param context
   * @param resId
   */
  public static void toast(Context context, String message) {
    Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
  }

}




Java Source Code List

edu.worcester.cs499summer2012.activity.AddTaskActivity.java
edu.worcester.cs499summer2012.activity.BaseTaskActivity.java
edu.worcester.cs499summer2012.activity.CustomSortActivity.java
edu.worcester.cs499summer2012.activity.EditCategoriesActivity.java
edu.worcester.cs499summer2012.activity.EditTaskActivity.java
edu.worcester.cs499summer2012.activity.MainActivity.java
edu.worcester.cs499summer2012.activity.SettingsActivity.java
edu.worcester.cs499summer2012.activity.ViewTaskActivity.java
edu.worcester.cs499summer2012.adapter.CategoryListAdapter.java
edu.worcester.cs499summer2012.adapter.ComparatorListAdapter.java
edu.worcester.cs499summer2012.adapter.PriorityListAdapter.java
edu.worcester.cs499summer2012.adapter.TaskListAdapter.java
edu.worcester.cs499summer2012.comparator.TaskAutoComparator.java
edu.worcester.cs499summer2012.comparator.TaskCategoryComparator.java
edu.worcester.cs499summer2012.comparator.TaskCompletionComparator.java
edu.worcester.cs499summer2012.comparator.TaskDateCreatedComparator.java
edu.worcester.cs499summer2012.comparator.TaskDateDueComparator.java
edu.worcester.cs499summer2012.comparator.TaskDateModifiedComparator.java
edu.worcester.cs499summer2012.comparator.TaskNameComparator.java
edu.worcester.cs499summer2012.comparator.TaskPriorityComparator.java
edu.worcester.cs499summer2012.database.DatabaseHandler.java
edu.worcester.cs499summer2012.database.TasksDataSource.java
edu.worcester.cs499summer2012.service.NotificationHelper.java
edu.worcester.cs499summer2012.service.OnAlarmReceiver.java
edu.worcester.cs499summer2012.service.OnBootReceiver.java
edu.worcester.cs499summer2012.service.TaskAlarm.java
edu.worcester.cs499summer2012.service.TaskButlerService.java
edu.worcester.cs499summer2012.service.TaskButlerWidgetProvider.java
edu.worcester.cs499summer2012.service.WakefulIntentService.java
edu.worcester.cs499summer2012.task.BackupManager.java
edu.worcester.cs499summer2012.task.Category.java
edu.worcester.cs499summer2012.task.Comparator.java
edu.worcester.cs499summer2012.task.Task.java
edu.worcester.cs499summer2012.task.ToastMaker.java