Java Code Examples for org.joda.time.LocalDate#now()

The following examples show how to use org.joda.time.LocalDate#now() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodaDocHead_validate_Test.java    From estatio with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    codaDocHead = new CodaDocHead("IT01", "FR-GEN", "123", (short)1, LocalDate.now(), LocalDate.now(), "2019/1", "books", "SHA256", "");
    codaDocHead.setLines(new TreeSet<>());

    line1 = new CodaDocLine();
    line1.setDocHead(codaDocHead);
    line1.setLineNum(1);

    line2 = new CodaDocLine();
    line2.setDocHead(codaDocHead);
    line2.setLineNum(2);

    codaDocHead.getLines().add(line1);
    codaDocHead.getLines().add(line2);
}
 
Example 2
Source File: FormatParser.java    From hangout with MIT License 6 votes vote down vote up
public static void main(String[] args) {
	LocalDate date = LocalDate.now();
	DateTimeFormatter fmt = DateTimeFormat.forPattern("d MMM, yyyy")
			.withLocale(Locale.ENGLISH);
	String str = date.toString(fmt);
	System.out.println(str);

	long a = DateTimeFormat.forPattern("dd MMM YYYY:HH:mm:ss")
			.withLocale(Locale.ENGLISH).parseMillis("13 May 2015:22:46:59");
	System.out.println(a);

	DateTime b = DateTimeFormat.forPattern("dd MMM YYYY:HH:mm:ss")
			.withLocale(Locale.forLanguageTag("en")).parseDateTime("13 May 2015:22:46:59");
	System.out.println(b);


	String input = "2015/05/06 10:31:20.427";
	FormatParser p = new FormatParser("YYYY/MM/dd HH:mm:ss.SSS", null, null);
	System.out.println(p.parse(input));

	input = "13 May 2015:22:46:59";
	p = new FormatParser("dd MMM YYYY:HH:mm:ss", null, "en");
	System.out.println(p.parse(input));
}
 
Example 3
Source File: SemerkandTimes.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
protected boolean sync() throws ExecutionException, InterruptedException {
    LocalDate date = LocalDate.now();
    String _id = getId();
    
    final int year = LocalDate.now().getYear();
    
    char type = _id.charAt(0);
    String id = _id.substring(1);
    List<Day> result = Ion.with(App.get())
            .load("http://semerkandtakvimi.semerkandmobile.com/salaattimes?year=" + year + "&" + (type == 'c' ? "cityId=" : "districtId=") + id)
            .userAgent(App.getUserAgent()).as(new TypeToken<List<Day>>() {
            }).get();
    for (Day d : result) {
        date = date.withDayOfYear(d.DayOfYear);
        setTime(date, Vakit.FAJR, d.Fajr);
        setTime(date, Vakit.SUN, d.Tulu);
        setTime(date, Vakit.DHUHR, d.Zuhr);
        setTime(date, Vakit.ASR, d.Asr);
        setTime(date, Vakit.MAGHRIB, d.Maghrib);
        setTime(date, Vakit.ISHAA, d.Isha);
    }
    return result.size() > 25;
}
 
Example 4
Source File: WebTimes.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@NonNull
public LocalDate getFirstSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;
    while (true) {
        String prefix = date.toString("yyyy-MM-dd") + "-";
        String[] times = {this.times.get(prefix + 0), this.times.get(prefix + 1), this.times.get(prefix + 2), this.times.get(prefix + 3),
                this.times.get(prefix + 4), this.times.get(prefix + 5)};
        for (String time : times) {
            if (time == null || time.contains("00:00") || i > this.times.size())
                return date.plusDays(1);
        }
        i++;
        date = date.minusDays(1);
    }
}
 
Example 5
Source File: SemerkandTimes.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
protected boolean sync() throws ExecutionException, InterruptedException {
    LocalDate date = LocalDate.now();
    String _id = getId();
    
    final int year = LocalDate.now().getYear();
    
    char type = _id.charAt(0);
    String id = _id.substring(1);
    List<Day> result = Ion.with(App.get())
            .load("http://semerkandtakvimi.semerkandmobile.com/salaattimes?year=" + year + "&" + (type == 'c' ? "cityId=" : "districtId=") + id)
            .userAgent(App.getUserAgent()).as(new TypeToken<List<Day>>() {
            }).get();
    for (Day d : result) {
        date = date.withDayOfYear(d.DayOfYear);
        setTime(date, Vakit.FAJR, d.Fajr);
        setTime(date, Vakit.SUN, d.Tulu);
        setTime(date, Vakit.DHUHR, d.Zuhr);
        setTime(date, Vakit.ASR, d.Asr);
        setTime(date, Vakit.MAGHRIB, d.Maghrib);
        setTime(date, Vakit.ISHAA, d.Isha);
    }
    return result.size() > 25;
}
 
Example 6
Source File: CityFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
private boolean updateTimes() {
    LocalDate greg = LocalDate.now();

    boolean hasTimes = false;
    for (int i = 0; i < 6; i++) {

        TextView time = mPrayerTimes[i];
        time.setText(LocaleUtils.formatTimeForHTML(mTimes.getTime(greg, i).toLocalTime()));
        if (!time.getText().equals("00:00")) {
            hasTimes = true;
        }
    }

    if (!hasTimes) {
        mHandler.postDelayed(this::updateTimes, 1000);
    }

    return hasTimes;
}
 
Example 7
Source File: JodaSampleActivity.java    From joda-time-android with Apache License 2.0 5 votes vote down vote up
private void sampleIsToday() {
    List<String> text = new ArrayList<String>();
    LocalDate today = LocalDate.now();
    text.add("Today: " + DateUtils.isToday(today));
    text.add("Tomorrow: " + DateUtils.isToday(today.plusDays(1)));
    text.add("Yesterday: " + DateUtils.isToday(today.minusDays(1)));
    addSample("DateUtils.isToday()", text);
}
 
Example 8
Source File: DilbertPreferences.java    From Simple-Dilbert with Apache License 2.0 5 votes vote down vote up
/**
 * Returns saved date for specific widget id
 *
 * @param appWidgetId id of widget
 * @return Date which is saved or todays day if there is no such
 */
public LocalDate getDateForWidgetId(int appWidgetId) {
    String savedDate = preferences.getString("widget_" + appWidgetId, null);
    if (savedDate == null || isWidgetAlwaysShowLatest())
        return LocalDate.now();
    else
        return LocalDate.parse(savedDate, DATE_FORMATTER);
}
 
Example 9
Source File: ImsakiyeFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public ImsakiyeAdapter(Context context) {
    LocalDate now = LocalDate.now();
    today = now.getDayOfMonth();
    date = now.withDayOfMonth(1);
    daysInMonth = date.dayOfMonth().getMaximumValue();


    inflater = LayoutInflater.from(context);
}
 
Example 10
Source File: JodaSampleActivity.java    From joda-time-android with Apache License 2.0 5 votes vote down vote up
private void sampleLocalDate() {
    List<String> text = new ArrayList<String>();
    LocalDate now = LocalDate.now();
    text.add("Now: " + now);
    text.add("Now + 2 days: " + now.plusDays(2));
    text.add("Now + 3 months: " + now.plusMonths(3));
    addSample("LocalDate", text);
}
 
Example 11
Source File: QiblaTimeView.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public QiblaTimeView(@NonNull Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mKaabe = context.getResources().getDrawable(R.drawable.kaabe, null);
    } else {
        mKaabe = context.getResources().getDrawable(R.drawable.kaabe);
    }

    int blue = getResources().getColor(R.color.colorPrimary);

    mTrianglePaint.setColor(blue);
    mTrianglePaint.setStyle(Paint.Style.FILL);
    mBackgroundPaint.setColor(Color.WHITE);
    mBackgroundPaint.setStyle(Paint.Style.FILL);
    mOuterStrokePaint.setColor(blue);
    mOuterStrokePaint.setStyle(Paint.Style.STROKE);
    mCenterPaint.setColor(blue);
    mCenterPaint.setStyle(Paint.Style.FILL);
    mNightPaint.setColor(Color.BLACK);
    mNightPaint.setAlpha(150);
    mNightPaint.setStyle(Paint.Style.FILL);
    mYellowPaint.setColor(Color.YELLOW);
    mYellowPaint.setStyle(Paint.Style.STROKE);
    mTextPaint.setColor(Color.WHITE);
    mSunPaint.setColor(Color.YELLOW);
    mSunPaint.setStyle(Paint.Style.FILL);


    LocalDate date = LocalDate.now();
    mPrayTimes.setDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
}
 
Example 12
Source File: CalcTimeConfDialogFragment.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
void updateTimes() {
    LocalDate today = LocalDate.now();
    ((TextView) mView.findViewById(R.id.fajr)).setText(LocaleUtils.formatTime(mCalcTime.getTime(today, Vakit.FAJR.ordinal()).toLocalTime()));
    ((TextView) mView.findViewById(R.id.sun)).setText(LocaleUtils.formatTime(mCalcTime.getTime(today, Vakit.SUN.ordinal()).toLocalTime()));
    ((TextView) mView.findViewById(R.id.dhuhr)).setText(LocaleUtils.formatTime(mCalcTime.getTime(today, Vakit.DHUHR.ordinal()).toLocalTime()));
    ((TextView) mView.findViewById(R.id.asr)).setText(LocaleUtils.formatTime(mCalcTime.getTime(today, Vakit.ASR.ordinal()).toLocalTime()));
    ((TextView) mView.findViewById(R.id.maghrib)).setText(LocaleUtils.formatTime(mCalcTime.getTime(today, Vakit.MAGHRIB.ordinal()).toLocalTime()));
    ((TextView) mView.findViewById(R.id.ishaa)).setText(LocaleUtils.formatTime(mCalcTime.getTime(today, Vakit.ISHAA.ordinal()).toLocalTime()));

    if (mCalcTime.getAsrType() == CalcTimes.AsrType.Both) {
        ((TextView) mView.findViewById(R.id.asr)).setText(String.format("%s / %s", LocaleUtils.formatTime(mCalcTime.getTime(today, Vakit.ASR.ordinal()).toLocalTime()), LocaleUtils.formatTime(mCalcTime.getAsrThaniTime(today).toLocalTime())));
    }
}
 
Example 13
Source File: StatsGetTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testGetStartAndEndDates()
{
    LocalDate currentDate = LocalDate.now();
    Pair<LocalDate, LocalDate> dates = StatsGet.getStartAndEndDates(null, null);
    assertNull(dates);
    
    String test1 = "2014-05-01";
    String test2 = "2015-06-30";
    dates = StatsGet.getStartAndEndDates(test1, null);
    assertNotNull(dates);
    assertEquals(2014, dates.getFirst().getYear());
    assertEquals(5, dates.getFirst().getMonthOfYear());
    assertEquals(1, dates.getFirst().getDayOfMonth());
    assertEquals(currentDate, dates.getSecond());
    
    dates = StatsGet.getStartAndEndDates(null, test2);
    assertNull(dates);
    
    dates = StatsGet.getStartAndEndDates(test1, test2);
    assertNotNull(dates);
    assertEquals(2014, dates.getFirst().getYear());
    assertEquals(5, dates.getFirst().getMonthOfYear());
    assertEquals(1, dates.getFirst().getDayOfMonth());
    assertNotNull(dates);
    assertEquals(2015, dates.getSecond().getYear());
    assertEquals(6, dates.getSecond().getMonthOfYear());
    assertEquals(30, dates.getSecond().getDayOfMonth());
}
 
Example 14
Source File: DilbertPreferences.java    From Simple-Dilbert with Apache License 2.0 5 votes vote down vote up
/**
 * Validates selected date and filters ot future dates and dates before Dilbert started
 *
 * @param selDate Date user selected
 * @return LocalDate date which is correct
 */
private static LocalDate validateDate(LocalDate selDate) {
    if (selDate.isAfter(LocalDate.now())) {
        selDate = LocalDate.now();
    }
    if (selDate.isBefore(DilbertPreferences.getFirstStripDate())) {
        selDate = DilbertPreferences.getFirstStripDate();
    }
    return selDate;
}
 
Example 15
Source File: DateRange.java    From adwords-alerting with Apache License 2.0 4 votes vote down vote up
/**
 * Parse DateRange in ReportDefinitionDateRangeType enum format.
 */
private static DateRange parseEnumFormat(String dateRange) {
  ReportDefinitionDateRangeType dateRangeType;
  try {
    dateRangeType = ReportDefinitionDateRangeType.valueOf(dateRange);
  } catch (IllegalArgumentException e) {
    throw new IllegalArgumentException("Unknown DateRange type: " + dateRange);
  }

  LocalDate today = LocalDate.now();
  LocalDate startDate;
  LocalDate endDate;
  switch (dateRangeType) {
    case TODAY:
      startDate = endDate = today;
      break;
    case YESTERDAY:
      startDate = endDate = today.minusDays(1);
      break;
    case LAST_7_DAYS:
      startDate = today.minusDays(7);
      endDate = today.minusDays(1);
      break;
    case LAST_WEEK:
      LocalDate.Property lastWeekProp = today.minusWeeks(1).dayOfWeek();
      startDate = lastWeekProp.withMinimumValue();
      endDate = lastWeekProp.withMaximumValue();
      break;
    case THIS_MONTH:
      LocalDate.Property thisMonthProp = today.dayOfMonth();
      startDate = thisMonthProp.withMinimumValue();
      endDate = thisMonthProp.withMaximumValue();
      break;
    case LAST_MONTH:
      LocalDate.Property lastMonthProp = today.minusMonths(1).dayOfMonth();
      startDate = lastMonthProp.withMinimumValue();
      endDate = lastMonthProp.withMaximumValue();
      break;
    case LAST_14_DAYS:
      startDate = today.minusDays(14);
      endDate = today.minusDays(1);
      break;
    case LAST_30_DAYS:
      startDate = today.minusDays(30);
      endDate = today.minusDays(1);
      break;
    case THIS_WEEK_SUN_TODAY:
      // Joda-Time uses the ISO standard Monday to Sunday week.
      startDate = today.minusWeeks(1).dayOfWeek().withMaximumValue();
      endDate = today;
      break;
    case THIS_WEEK_MON_TODAY:
      startDate = today.dayOfWeek().withMinimumValue();
      endDate = today;
      break;
    case LAST_WEEK_SUN_SAT:
      startDate = today.minusWeeks(2).dayOfWeek().withMaximumValue();
      endDate = today.minusWeeks(1).dayOfWeek().withMaximumValue().minusDays(1);
      break;
      // Don't support the following enums
    case LAST_BUSINESS_WEEK:
    case ALL_TIME:
    case CUSTOM_DATE:
    default:
      throw new IllegalArgumentException("Unsupported DateRange type: " + dateRange);
  }

  return new DateRange(startDate, endDate);
}
 
Example 16
Source File: LegionBoardParser.java    From substitution-schedule-parser with Mozilla Public License 2.0 4 votes vote down vote up
void parseLegionBoard(SubstitutionSchedule substitutionSchedule, JSONArray changes, JSONArray courses,
                         JSONArray teachers) throws IOException, JSONException {
       if (changes == null) {
		return;
	}
	// Link course IDs to their names
	HashMap<String, String> coursesHashMap = null;
	if (courses != null) {
		coursesHashMap = new HashMap<>();
		for (int i = 0; i < courses.length(); i++) {
			JSONObject course = courses.getJSONObject(i);
			coursesHashMap.put(course.getString("id"), course.getString("name"));
		}
	}
	// Link teacher IDs to their names
	HashMap<String, String> teachersHashMap = null;
	if (teachers != null) {
		teachersHashMap = new HashMap<>();
		for (int i = 0; i < teachers.length(); i++) {
			JSONObject teacher = teachers.getJSONObject(i);
			teachersHashMap.put(teacher.getString("id"), teacher.getString("name"));
		}
	}
	// Add changes to SubstitutionSchedule
	LocalDate currentDate = LocalDate.now();
	SubstitutionScheduleDay substitutionScheduleDay = new SubstitutionScheduleDay();
	substitutionScheduleDay.setDate(currentDate);
	for (int i = 0; i < changes.length(); i++) {
		final JSONObject change = changes.getJSONObject(i);
		final Substitution substitution = getSubstitution(change, coursesHashMap, teachersHashMap);
		final LocalDate startingDate = new LocalDate(change.getString("startingDate"));
		final LocalDate endingDate = new LocalDate(change.getString("endingDate"));
		// Handle multi-day changes
		if (!startingDate.isEqual(endingDate)) {
			if (!substitutionScheduleDay.getSubstitutions().isEmpty()) {
				substitutionSchedule.addDay(substitutionScheduleDay);
			}
			for (int k = 0; k < 8; k++) {
				final LocalDate date = LocalDate.now().plusDays(k);
				if ((date.isAfter(startingDate) || date.isEqual(startingDate)) &&
					(date.isBefore(endingDate) || date.isEqual(endingDate))) {
					substitutionScheduleDay = new SubstitutionScheduleDay();
					substitutionScheduleDay.setDate(date);
					substitutionScheduleDay.addSubstitution(substitution);
					substitutionSchedule.addDay(substitutionScheduleDay);
                       currentDate = date;
                   }
			}
			continue;
		}
		// If starting date of change does not equal date of SubstitutionScheduleDay
		if (!startingDate.isEqual(currentDate)) {
			if (!substitutionScheduleDay.getSubstitutions().isEmpty()) {
				substitutionSchedule.addDay(substitutionScheduleDay);
			}
			substitutionScheduleDay = new SubstitutionScheduleDay();
			substitutionScheduleDay.setDate(startingDate);
               currentDate = startingDate;
           }
		substitutionScheduleDay.addSubstitution(substitution);
	}
	substitutionSchedule.addDay(substitutionScheduleDay);
}
 
Example 17
Source File: CityFragment.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    if (mTimes == null) return super.onOptionsItemSelected(item);
    int i1 = item.getItemId();
    if (i1 == R.id.notification) {
        Fragment frag = getActivity().getSupportFragmentManager().findFragmentByTag("notPrefs");
        if (frag == null) {
            ((TimesFragment) getParentFragment()).setFooterText("", false);
            ((BaseActivity.MainFragment) getParentFragment()).moveToFrag(AlarmsFragment.create(mTimes));
        } else {
            ((TimesFragment) getParentFragment()).setFooterText(getString(R.string.monthly), true);
            ((BaseActivity.MainFragment) getParentFragment()).back();
        }

        //AppRatingDialog.addToOpenedMenus("notPrefs");

    } else if (i1 == R.id.export) {
        if (mTimes instanceof WebTimes) {
            ((WebTimes) mTimes).syncAsync();
        }
        ExportController.export(getActivity(), mTimes);
    } else if (i1 == R.id.refresh) {
        if (mTimes instanceof WebTimes) {
            ((WebTimes) mTimes).syncAsync();
        }

    } else if (i1 == R.id.share) {
        StringBuilder txt = new StringBuilder(getString(R.string.shareTimes, mTimes.getName()) + ":");
        LocalDate date = LocalDate.now();

        for (Vakit v : Vakit.values()) {
            txt.append("\n   ").append(v.getString()).append(": ").append(LocaleUtils.formatTime(mTimes.getTime(date, v.ordinal()).toLocalTime()));
        }

        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.appName));
        sharingIntent.putExtra(Intent.EXTRA_TEXT, txt.toString());
        startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share)));
    }
    return super.onOptionsItemSelected(item);
}
 
Example 18
Source File: MiBandToolsReceiver.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Times times = null;
    for (Times t : Times.getTimes()) {
        if (times == null) {
            times = t;
        } else if (t.isOngoingNotificationActive() && !times.isOngoingNotificationActive()) {
            times = t;
        }
        // short choose first city, or if existent, first with ongoing notifications
    }

    if (times == null) return;

    String title = times.getName() + " - " + context.getString(R.string.appName);
    LocalDate date = LocalDate.now();
    StringBuilder builder = new StringBuilder().append("$^");
    int marker = times.getCurrentTime();
    if (Preferences.VAKIT_INDICATOR_TYPE.get().equals("next"))
        marker = marker + 1;
    for (Vakit v : Vakit.values()) {
        if (v.ordinal() == marker)
            builder.append(v.getString().charAt(0)).append(" :-").append(LocaleUtils.formatTime(times.getTime(date, v.ordinal()).toLocalTime())).append("-$^");
        else
            builder.append(v.getString().charAt(0)).append(" : ").append(LocaleUtils.formatTime(times.getTime(date, v.ordinal()).toLocalTime())).append("$^");
    }
    builder.append("$^");
    builder.append("- ").append(LocaleUtils.formatPeriod(new Period(LocalDateTime.now(), times.getTime(date, times.getNextTime())), false)).append(" -");

    Notification noti = new NotificationCompat.Builder(context, getMiBandChannel(context))
            .setContentTitle(title)
            .setContentText(builder.toString())
            .setSmallIcon(R.drawable.ic_placeholder)
            .build();

    NotificationManager notMan = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    notMan.notify("MIBAND", 0, noti);

    new Handler().postDelayed(() -> notMan.cancel("MIBAND", 0), 3000);

}
 
Example 19
Source File: IGMGTimes.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
protected boolean sync() throws ExecutionException, InterruptedException {
    String path = getId().replace("nix", "-1");
    String[] a = path.split("_");
    int id = Integer.parseInt(a[0]);
    if (id <= 0 && a.length > 1)
        id = Integer.parseInt(a[1]);

    LocalDate ldate = LocalDate.now();
    int rY = ldate.getYear();
    int Y = rY;
    int m = ldate.getMonthOfYear();

    int i = 0;
    for (int M = m; (M <= (m + 2)) && (rY == Y); M++) {
        if (M == 13) {
            M = 1;
            Y++;
        }
        String result = Ion.with(App.get())
                .load("POST", "https://www.igmg.org/wp-content/themes/igmg/include/gebetskalender_ajax_api.php")
                .userAgent(App.getUserAgent())
                .setTimeout(3000)
                .setBodyParameter("show_ajax_variable", "" + id)
                .setBodyParameter("show_month", "" + (M - 1))
                .asString()
                .get();

        result = result.substring(result.indexOf("<div class='zeiten'>") + 20);
        String[] zeiten = result.split("</div><div class='zeiten'>");
        for (String zeit : zeiten) {
            if (zeit.contains("turkish")) {
                continue;
            }
            String tarih = extractLine(zeit.substring(zeit.indexOf("tarih")));
            String imsak = extractLine(zeit.substring(zeit.indexOf("imsak")));
            String gunes = extractLine(zeit.substring(zeit.indexOf("gunes")));
            String ogle = extractLine(zeit.substring(zeit.indexOf("ogle")));
            String ikindi = extractLine(zeit.substring(zeit.indexOf("ikindi")));
            String aksam = extractLine(zeit.substring(zeit.indexOf("aksam")));
            String yatsi = extractLine(zeit.substring(zeit.indexOf("yatsi")));

            int _d = Integer.parseInt(tarih.substring(0, 2));
            int _m = Integer.parseInt(tarih.substring(3, 5));
            int _y = Integer.parseInt(tarih.substring(6, 10));
            try {
                LocalDate localDate = new LocalDate(_y, _m, _d);
                setTime(localDate, Vakit.FAJR, imsak);
                setTime(localDate, Vakit.SUN, gunes);
                setTime(localDate, Vakit.DHUHR, ogle);
                setTime(localDate, Vakit.ASR, ikindi);
                setTime(localDate, Vakit.MAGHRIB, aksam);
                setTime(localDate, Vakit.ISHAA, yatsi);
                i++;
            } catch (IllegalFieldValueException ignore) {
            }
        }


    }


    return i > 25;
}
 
Example 20
Source File: MiBandToolsReceiver.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    Times times = null;
    for (Times t : Times.getTimes()) {
        if (times == null) {
            times = t;
        } else if (t.isOngoingNotificationActive() && !times.isOngoingNotificationActive()) {
            times = t;
        }
        // short choose first city, or if existent, first with ongoing notifications
    }

    if (times == null) return;

    String title = times.getName() + " - " + context.getString(R.string.appName);
    LocalDate date = LocalDate.now();
    StringBuilder builder = new StringBuilder().append("$^");
    int marker = times.getCurrentTime();
    if (Preferences.VAKIT_INDICATOR_TYPE.get().equals("next"))
        marker = marker + 1;
    for (Vakit v : Vakit.values()) {
        if (v.ordinal() == marker)
            builder.append(v.getString().charAt(0)).append(" :-").append(LocaleUtils.formatTime(times.getTime(date, v.ordinal()).toLocalTime())).append("-$^");
        else
            builder.append(v.getString().charAt(0)).append(" : ").append(LocaleUtils.formatTime(times.getTime(date, v.ordinal()).toLocalTime())).append("$^");
    }
    builder.append("$^");
    builder.append("- ").append(LocaleUtils.formatPeriod(new Period(LocalDateTime.now(), times.getTime(date, times.getNextTime())), false)).append(" -");

    Notification noti = new NotificationCompat.Builder(context, getMiBandChannel(context))
            .setContentTitle(title)
            .setContentText(builder.toString())
            .setSmallIcon(R.drawable.ic_placeholder)
            .build();

    NotificationManager notMan = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    notMan.notify("MIBAND", 0, noti);

    new Handler().postDelayed(() -> notMan.cancel("MIBAND", 0), 3000);

}