Exemplo n.º 1
0
/**
 * Helper class to format a due date to present it to the user.
 *
 * @author Arjun Naik <*****@*****.**>
 */
public class DueDateFormatter {
  /** The formatter we use for due dates other than today. */
  private final DateFormat mDateFormatter = DateFormat.getDateInstance(SimpleDateFormat.MEDIUM);

  /** The formatter we use for tasks that are due today. */
  private final DateFormat mTimeFormatter =
      SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);

  /** A context to load resource string. */
  private Context mContext;

  /** A helper to get the current date & time. */
  private Time mNow;

  public DueDateFormatter(Context context) {
    mContext = context;
    mNow = new Time();
  }

  /**
   * Format the given due date. The result depends on the current date and on the all-day flag of
   * the due date.
   *
   * <p>If the due date it today the format will contain "today" instead of the date. Allday dates
   * won't contain a time.
   *
   * @param dueDate The due date to format.
   * @return A string with the formatted due date.
   */
  public String format(Time dueDate) {
    mNow.clear(TimeZone.getDefault().getID());
    mNow.setToNow();

    if (!dueDate.allDay) {
      dueDate.switchTimezone(TimeZone.getDefault().getID());
    }

    // normalize time to ensure yearDay is set properly
    dueDate.normalize(false);

    if (dueDate.year == mNow.year && dueDate.yearDay == mNow.yearDay) {
      if (dueDate.allDay) {
        return mContext.getString(R.string.today);
      } else {
        return mContext.getString(R.string.today)
            + ", "
            + mTimeFormatter.format(new Date(dueDate.toMillis(false)));
      }
    } else {
      return mDateFormatter.format(new Date(dueDate.toMillis(false)));
    }
  }
}
  public static String formatDate(FldSimpleModel model, String format, Date date) {

    DateFormat dateFormat = null;
    if ((format != null) && (format.length() > 0)) {
      SimpleDateFormat simpleDateFormat = getSimpleDateFormat();
      simpleDateFormat.applyPattern(convertDatePattern(format));
      dateFormat = simpleDateFormat;
    } else {
      dateFormat =
          (model.getFldName().indexOf("DATE") > -1
              ? SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT)
              : SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT));
    }
    return dateFormat.format(date);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.history_detail_activity);

    mDb = HistoryDbHelper.getInstance(this).getWritableDatabase();
    mParentLayout = findViewById(R.id.entry_detail_layout);
    mDateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance();
    mTimeFormat = (SimpleDateFormat) SimpleDateFormat.getTimeInstance(DateFormat.SHORT);
    mDecimalFormat = new DecimalFormat("#0.00");

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      mEntryID = extras.getLong("HISTORY_ENTRY_ITEM_ID");
      new FetchHistoryEntry().execute(mEntryID);
    }
  }
Exemplo n.º 4
0
  // 显示时间信息处理
  public class MyTime extends TimerTask {
    RemoteViews remoteViews;
    AppWidgetManager appWidgetManager;
    ComponentName thisWidget;
    DateFormat format =
        SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());

    public MyTime(Context context, AppWidgetManager appWidgetManager) {
      this.appWidgetManager = appWidgetManager;
      remoteViews = new RemoteViews(context.getPackageName(), R.layout.weather_widget);
      thisWidget = new ComponentName(context, MyWidgetProvider.class);
    }

    @Override
    public void run() {
      remoteViews.setTextViewText(R.id.time, format.format(new Date()));
      appWidgetManager.updateAppWidget(thisWidget, remoteViews);
    }
  }
Exemplo n.º 5
0
 /**
  * Returns the date format pattern to be used, based on the date range.
  *
  * @param start the start date in milliseconds
  * @param end the end date in milliseconds
  * @return the date format
  */
 private DateFormat getDateFormat(double start, double end) {
   if (mDateFormat != null) {
     SimpleDateFormat format = null;
     try {
       format = new SimpleDateFormat(mDateFormat);
       return format;
     } catch (Exception e) {
       // do nothing here
     }
   }
   DateFormat format = SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM);
   double diff = end - start;
   if (diff > DAY && diff < 5 * DAY) {
     format = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT);
   } else if (diff < DAY) {
     format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM);
   }
   return format;
 }
Exemplo n.º 6
0
  @Override
  public void onStart(Intent intent, int startId) {
    Log.d(MODULE, "onStart:enter");
    RemoteViews updateViews = new RemoteViews(this.getPackageName(), R.layout.widget);
    Date date = new Date();
    DateFormat format =
        SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());

    updateViews.setTextViewText(R.id.time, format.format(date));

    ComponentName thisWidget = new ComponentName(this, MedAppWidget.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    manager.updateAppWidget(thisWidget, updateViews);
    synchronized (lock) {
      if (!thread_running) {
        thread_running = true;
        new Thread(this).start();
      }
    }
    Log.d(MODULE, "onStart:exit");
  }
Exemplo n.º 7
0
  public void run() {
    Log.d(MODULE, "run:enter");

    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    //		ContentResolver resolve = getContentResolver();

    RemoteViews updateViews = null;

    updateViews = MedAppWidget.buildUpdate(this);

    // Draw the updated time
    //		RemoteViews updateViews = new RemoteViews(this.getPackageName(), R.layout.widget_loading);
    Date date = new Date();
    DateFormat format =
        SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());

    updateViews.setTextViewText(R.id.time, format.format(date));

    ComponentName thisWidget = new ComponentName(this, MedAppWidget.class);
    manager.updateAppWidget(thisWidget, updateViews);

    // Schedule our next update
    Time time = new Time();
    time.set(System.currentTimeMillis() + UPDATE_INTERVAL);
    time.second = 0;
    long nextUpdate = time.toMillis(false);

    Intent updateIntent = new Intent(ACTION_UPDATE_ALL);
    updateIntent.setClass(this, UpdateService.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, updateIntent, 0);

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdate, pendingIntent);

    thread_running = false;
    stopSelf();
    Log.d(MODULE, "run:exit");
  }
Exemplo n.º 8
0
 @Override
 protected DateFormat initialValue() {
   return SimpleDateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
 }
Exemplo n.º 9
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    System.out.println("Capture-Image doPost[jm]");
    HttpSession session = request.getSession(false);
    String cPath = request.getContextPath();
    int id = Integer.parseInt(request.getParameter("CI_id"));
    String mun = request.getParameter("CI_mun");
    int user_role = Integer.parseInt(request.getParameter("CI_user_role"));

    BASE64Decoder decoder = new BASE64Decoder(); // 1st step of decoding base64 string
    System.out.println("request.getParameter:" + request.getParameter("capture_image"));
    String regex[] = request.getParameter("capture_image").split("base64,");
    String imageInString = regex[1];
    byte[] imageInByte =
        decoder.decodeBuffer(imageInString); // 2nd step and end of decoding base64 string
    ByteArrayInputStream in = new ByteArrayInputStream(imageInByte);
    BufferedImage img = ImageIO.read(in);

    BufferedImage scaledImg = Scalr.resize(img, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, 250);
    ByteArrayOutputStream outputstream = new ByteArrayOutputStream();
    ImageIO.write(scaledImg, "jpeg", outputstream);
    outputstream.flush();
    byte[] finalImageInByte = outputstream.toByteArray();
    outputstream.close();

    try {

      UserDAO dao = new UserDAO();

      Calendar calendar = Calendar.getInstance();
      DateFormat timeInstance = SimpleDateFormat.getTimeInstance();
      SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");

      String date = format.format(calendar.getTime());
      // System.out.println("date:"+day);
      String time = timeInstance.format(Calendar.getInstance().getTime());

      // uploadPhoto.uploadProvPhoto(imageInByte, false); //uploading image to database
      // boolean ret = uploadPhoto.uploadMunPhoto(imageInByte, mun, fname, lname, false);
      dao.upload_capture_photo(finalImageInByte, false, id, user_role);
      // if(ret){
      // dao.add_logs(false, date, time, "Municipal user from "+mun_name+" named "+lname+",
      // "+fname+" change its photo by Provincial Link");
      // }
      String rfname = dao.getFname(user_role, id);
      String rlname = dao.getLname(user_role, id);
      /*for logs (ge set ug 1 para makuha ang pangan ug apelyido sa admin o provlink)*/
      String logs_fname = dao.getUser2Fname(1);
      String logs_lname = dao.getUser2Lname(1);
      if (user_role == 2) {
        dao.add_logs(
            false,
            date,
            time,
            "Municipal Link user named "
                + rlname
                + ", "
                + rfname
                + " change its photo by "
                + logs_fname
                + " "
                + logs_lname);
      } else if (user_role == 4) {
        dao.add_logs(
            false,
            date,
            time,
            "BookKeeper user named "
                + rlname
                + ", "
                + rfname
                + " change its photo by "
                + logs_fname
                + " "
                + logs_lname);
      } else if (user_role == 5) {
        dao.add_logs(
            false,
            date,
            time,
            "Verifier user named "
                + rlname
                + ", "
                + rfname
                + " change its photo by "
                + logs_fname
                + " "
                + logs_lname);
      } else if (user_role == 6) {
        dao.add_logs(
            false,
            date,
            time,
            "Grievance Officer user named "
                + rlname
                + ", "
                + rfname
                + " change its photo by "
                + logs_fname
                + " "
                + logs_lname);
      } else if (user_role == 7) {
        dao.add_logs(
            false,
            date,
            time,
            "Social Worker user named "
                + rlname
                + ", "
                + rfname
                + " change its photo by "
                + logs_fname
                + " "
                + logs_lname);
      }
    } catch (Exception e) {

      e.printStackTrace();
    }
    response.sendRedirect(cPath + "/Add_user?id=" + id + "&mun=" + mun + "&user_role=" + user_role);
  }
Exemplo n.º 10
0
/**
 * Definition of the by-completed grouping.
 *
 * <p>TODO: refactor!
 *
 * <p>TODO: refactor!
 *
 * <p>TODO: also, don't forget to refactor! The plan is to provide some kind of GroupingDescriptior
 * that provides the {@link ExpandableGroupDescriptorAdapter}, a name and a set of filters. Also it
 * should take care of persisting and restoring the open groups, selected filters ...
 *
 * @author Marten Gajda <*****@*****.**>
 */
public interface ByCompleted {
  /** A {@link ViewDescriptor} that knows how to present the tasks in the task list. */
  public final ViewDescriptor TASK_VIEW_DESCRIPTOR =
      new ViewDescriptor() {
        /** We use this to get the current time. */
        private Time mNow;

        /** The formatter we use for due dates other than today. */
        private final DateFormat mDateFormatter =
            DateFormat.getDateInstance(SimpleDateFormat.MEDIUM);

        /** The formatter we use for tasks that are due today. */
        private final DateFormat mTimeFormatter =
            SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);

        @Override
        public void populateView(
            View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags) {
          TextView title = (TextView) view.findViewById(android.R.id.title);
          if (title != null) {
            String text = cursor.getString(5);
            title.setText(text);
          }

          Integer status = cursor.getInt(11);

          TextView dueDateField = (TextView) view.findViewById(R.id.task_due_date);
          if (dueDateField != null) {
            Time dueDate = Common.DUE_ADAPTER.get(cursor);

            if (dueDate != null) {
              if (mNow == null) {
                mNow = new Time();
              }
              mNow.clear(TimeZone.getDefault().getID());
              mNow.setToNow();

              if (status == null || status < Tasks.STATUS_COMPLETED) {

                dueDateField.setText(makeDueDate(dueDate));

                // highlight overdue dates & times
                if (dueDate.before(mNow)) {
                  dueDateField.setTextColor(Color.RED);
                } else {
                  dueDateField.setTextColor(Color.argb(255, 0x80, 0x80, 0x80));
                }
              } else {
                Long completed = cursor.getLong(12);
                if (completed != null) {
                  Time complTime = new Time(Time.TIMEZONE_UTC);
                  complTime.set(completed);

                  dueDateField.setText(makeDueDate(complTime));

                  // highlight if the task has been completed after the due date
                  if (dueDate.after(complTime)) {
                    dueDateField.setTextColor(Color.RED);
                  } else {
                    dueDateField.setTextColor(Color.argb(255, 0x80, 0x80, 0x80));
                  }
                } else {
                  // TODO: what do we show then there is no completed date?
                }
              }
            } else {
              dueDateField.setText("");
            }
          }

          View colorbar = view.findViewById(R.id.colorbar);
          if (colorbar != null) {
            colorbar.setBackgroundColor(cursor.getInt(6));
          }
        }

        @Override
        public int getView() {
          return R.layout.task_list_element;
        }

        /**
         * Get the due date to show. It returns just a time for tasks that are due today and a date
         * otherwise.
         *
         * @param due The due date to format.
         * @return A String with the formatted date.
         */
        private String makeDueDate(Time due) {
          if (!due.allDay) {
            due.switchTimezone(TimeZone.getDefault().getID());
          }

          if (due.year == mNow.year && due.yearDay == mNow.yearDay) {
            return mTimeFormatter.format(new Date(due.toMillis(false)));
          } else {
            return mDateFormatter.format(new Date(due.toMillis(false)));
          }
        }
      };

  /** A {@link ViewDescriptor} that knows how to present due date groups. */
  public final ViewDescriptor GROUP_VIEW_DESCRIPTOR =
      new ViewDescriptor() {

        @Override
        public void populateView(
            View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags) {
          TextView title = (TextView) view.findViewById(android.R.id.title);
          if (title != null) {
            title.setText(getTitle(cursor, view.getContext()));
          }
        }

        @Override
        public int getView() {
          return R.layout.task_list_group;
        }

        /**
         * Return the title of a due date group.
         *
         * @param cursor A {@link Cursor} pointing to the current group.
         * @return A {@link String} with the group name.
         */
        private String getTitle(Cursor cursor, Context context) {
          int type = cursor.getInt(cursor.getColumnIndex(CompletedFlagCursorFactory.STATUS_TYPE));
          if (type == CompletedFlagCursorFactory.STATUS_TYPE_COMPLETED) {
            return context.getString(R.string.status_completed);
          }
          if (type == CompletedFlagCursorFactory.STATUS_TYPE_INCOMPLETE) {
            return context.getString(R.string.status_incomplete);
          }
          return "";
        }
      };

  /** A descriptor that knows how to load elements in a due date group. */
  public static final ExpandableChildDescriptor CHILD_DESCRIPTOR =
      new ExpandableChildDescriptor(
              Instances.CONTENT_URI,
              Common.INSTANCE_PROJECTION,
              Instances.VISIBLE
                  + "=1 and "
                  + Instances.STATUS
                  + ">=? and "
                  + Instances.STATUS
                  + "<=?",
              Instances.DEFAULT_SORT_ORDER,
              1,
              2)
          .setViewDescriptor(TASK_VIEW_DESCRIPTOR);

  /** A descriptor for the "grouped by due date" view. */
  public static final ExpandableGroupDescriptor GROUP_DESCRIPTOR =
      new ExpandableGroupDescriptor(
              new CompletedFlagCursorLoaderFactory(CompletedFlagCursorFactory.DEFAULT_PROJECTION),
              CHILD_DESCRIPTOR)
          .setViewDescriptor(GROUP_VIEW_DESCRIPTOR);
}