Ejemplo n.º 1
0
public class UniqueId {
  private static String latestTimeStamp = MyUtils.getTimeStamp();
  private static int timeStampCounter = 0;

  private static synchronized void setLatestTimeStamp(String timeStamp) {
    if (!UniqueId.latestTimeStamp.equals(timeStamp)) {
      UniqueId.latestTimeStamp = timeStamp;
    }
  }

  private static synchronized int getTimeStampCounter() {
    return UniqueId.timeStampCounter;
  }

  private static synchronized void updateTimeStampCounter(String timeStamp) {
    if (timeStamp.equals(latestTimeStamp)) {
      timeStampCounter++;
    } else {
      timeStampCounter = 0;
      setLatestTimeStamp(timeStamp);
    }
  }

  public static synchronized String getUniqueID() {
    String timeStamp = MyUtils.getTimeStamp();
    String id = getTimeStampCounter() + timeStamp;
    updateTimeStampCounter(timeStamp);
    return id;
  }
}
Ejemplo n.º 2
0
 /**
  * �� ����ת��Ϊָ�����ȵ������ַ���
  *
  * @param value
  * @param retLength
  * @return
  */
 public static String getChangeIntLength(String value, int retLength) {
   String ret = value;
   if (!MyUtils.isNull(value)) {
     int intValue = Integer.valueOf(value);
     char[] cc = new char[retLength];
     for (int i = 0; i < retLength; i++) {
       cc[i] = '0';
     }
     DecimalFormat df = new DecimalFormat(new String(cc));
     ret = df.format(intValue);
   }
   return ret;
 }
Ejemplo n.º 3
0
  public static void setAlarm(Context context, int noteId, long when) {
    Intent intent = new Intent(context, ReminderService.class);
    intent.putExtra(Constants.EXTRA_NOTE_ID, noteId);

    PendingIntent pendingIntent =
        PendingIntent.getService(
            context,
            noteId, // use contentBase's id, cuz it is unique and it used later for canceling alarms
            intent,
            PendingIntent
                .FLAG_CANCEL_CURRENT); // FLAG_CANCEL_CURRENT, cuz when updating reminders' date it
    // must cancel previous intent

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (MyUtils.isPreApi19()) {
      // its pre19 and AlarmManager#set() is interpreted as exact time
      setAlarmPre19(alarmManager, when, pendingIntent);
    } else {
      // its API 19 or greater and AlarmManager#set() is NOT interpreted as exact time, use
      // #setExact()
      setAlarm19(alarmManager, when, pendingIntent);
    }
  }
Ejemplo n.º 4
0
  public static void main(String[] args) {

    LogFactory.setLogger(LogType.SIMPLE);
    MyUtils firstTest = new MyUtils(LogType.SIMPLE);

    firstTest.getInt("125");
    System.out.println("----------------------------------------");
    firstTest.getInt("tweehonderd");
    System.out.println("----------------------------------------");

    LogFactory.setLogger(LogType.FANCY);
    MyUtils secondTest = new MyUtils(LogType.FANCY);

    secondTest.getInt("driehonderden5");
    System.out.println("----------------------------------------");
    secondTest.getInt("400");
    System.out.println("----------------------------------------");
  }
Ejemplo n.º 5
0
 public BarView(Context context, AttributeSet attrs) {
   super(context, attrs);
   bgPaint = new Paint();
   bgPaint.setAntiAlias(true);
   bgPaint.setColor(BACKGROUND_COLOR);
   fgPaint = new Paint(bgPaint);
   fgPaint.setColor(FOREGROUND_COLOR);
   rect = new Rect();
   topMargin = MyUtils.dip2px(context, 5);
   int textSize = MyUtils.sp2px(context, 15);
   barWidth = MyUtils.dip2px(context, 22);
   MINI_BAR_WIDTH = MyUtils.dip2px(context, 22);
   BAR_SIDE_MARGIN = MyUtils.dip2px(context, 22);
   TEXT_TOP_MARGIN = MyUtils.dip2px(context, 5);
   textPaint = new Paint();
   textPaint.setAntiAlias(true);
   textPaint.setColor(TEXT_COLOR);
   textPaint.setTextSize(textSize);
   textPaint.setTextAlign(Paint.Align.CENTER);
   percentList = new ArrayList<Float>();
 }
Ejemplo n.º 6
0
 public static synchronized String getUniqueID() {
   String timeStamp = MyUtils.getTimeStamp();
   String id = getTimeStampCounter() + timeStamp;
   updateTimeStampCounter(timeStamp);
   return id;
 }
Ejemplo n.º 7
0
 public static void main(String[] args) {
   LogFactory.setLogger(LogType.FANCY);
   MyUtils.getInt("666");
 }
  /** Refresh the list with the items in the Mobile Service Table */
  private void refreshItemsFromTable() {

    // Get the items that weren't marked as completed and add them in the
    // adapter

    final ProgressDialog progress;
    progress =
        ProgressDialog.show(
            this, "", getResources().getString(R.string.appointments_loading), true);

    SharedPreferences prefs = getSharedPreferences(SHAREDPREFFILE, Context.MODE_PRIVATE);
    Boolean tmpSync = prefs.getBoolean(SYNCACTIVATED, true);

    // final String calendarPrimaryId = MyUtils.getCalendarId(getContentResolver());

    String tmpCalendarPrimaryId = prefs.getString(CALENDARID, "");

    if (tmpSync) {
      if (tmpCalendarPrimaryId.isEmpty()) {
        tmpCalendarPrimaryId = MyUtils.getCalendarId(getContentResolver());

        if (tmpCalendarPrimaryId.isEmpty()) {
          createAndShowDialog(
              getResources().getString(R.string.no_calendar_found),
              getResources().getString(R.string.warning));
          Editor editor = prefs.edit();
          editor.putBoolean(SYNCACTIVATED, false);
          editor.commit();

          tmpSync = false;
        } else {
          Editor editor = prefs.edit();
          editor.putString(CALENDARID, tmpCalendarPrimaryId);
          editor.commit();
        }
      }
    }

    final Boolean sync = tmpSync;

    final Activity currentActivity = this;

    final String calendarPrimaryId = tmpCalendarPrimaryId;

    AppointmentListFragment tmpFragment =
        ((AppointmentListFragment)
            getSupportFragmentManager().findFragmentById(R.id.appointment_list));

    if (tmpFragment == null || tmpFragment.getAdapter() == null) {
      return;
    }

    ArrayAdapter<MemberAppointments> tmpadapter = tmpFragment.getAdapter();

    tmpadapter.clear();
    // DataContent.ClearData();
    Map tmpcalEntries = MyUtils.getStoredAppointments(currentActivity);

    Iterator it = tmpcalEntries.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pair = (Map.Entry) it.next();
      // System.out.println(pair.getKey() + " = " + pair.getValue());
      tmpadapter.add((MemberAppointments) pair.getValue());
    }

    tmpadapter.notifyDataSetChanged();

    AppointmentListFragment taskFragment =
        ((AppointmentListFragment)
            getSupportFragmentManager().findFragmentById(R.id.appointment_list));

    LoadingTask task =
        new LoadingTask(
            this,
            mAppointmentTable,
            mNotificationAppointmentId,
            calendarPrimaryId,
            progress,
            sync,
            getContentResolver(),
            taskFragment,
            getResources());

    task.execute();
  }