Example usage for org.joda.time LocalDate now

List of usage examples for org.joda.time LocalDate now

Introduction

In this page you can find the example usage for org.joda.time LocalDate now.

Prototype

public static LocalDate now() 

Source Link

Document

Obtains a LocalDate set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

@NonNull
public LocalDate getFirstSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;/*from   w  ww  . j a v  a  2s  .c  om*/
    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);
    }
}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

@NonNull
public LocalDate getLastSyncedDay() {
    LocalDate date = LocalDate.now();
    int i = 0;//from w  w w. j  a  va 2 s  . c  o  m
    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.minusDays(1);
        }
        i++;
        date = date.plusDays(1);
    }
}

From source file:com.metinkale.prayerapp.vakit.times.WebTimes.java

License:Apache License

private void cleanTimes() {
    Set<String> keys = new ArraySet<>();
    keys.addAll(times.keySet());//from  w  w w  .  ja  v a 2s  . c o m
    LocalDate date = LocalDate.now();
    int y = date.getYear();
    int m = date.getMonthOfYear();
    for (String key : keys) {
        int year = FastParser.parseInt(key.substring(0, 4));
        if (year < y)
            keys.remove(key);
        else if (year == y) {
            int month = FastParser.parseInt(key.substring(5, 7));
            if (month < m)
                keys.remove(key);
        }
    }

}

From source file:com.metinkale.prayerapp.vakit.WidgetProvider.java

License:Apache License

private static void updateAppWidget(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager,
        int widgetId) {

    if (mDP == 0) {
        Resources r = context.getResources();
        mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());
    }/*  w ww . j av a 2 s  . co  m*/

    Resources r = context.getResources();
    SharedPreferences widgets = context.getSharedPreferences("widgets", 0);

    int t = widgets.getInt(widgetId + "_theme", 0);
    int w = widgets.getInt(widgetId + "_width", 130);
    int h = widgets.getInt(widgetId + "_height", 160);

    w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, r.getDisplayMetrics());
    h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, r.getDisplayMetrics());

    float scaleX = (float) w / (float) 13;
    float scaleY = (float) h / (float) 16;
    float scale = Math.min(scaleY, scaleX);

    //Workaround for exception "RemoteViews for widget update exceeds maximum bitmap memory usage"
    //scale = WidgetProvider.correctScaleFactorIfNeeded(context, scale, 13, 16);

    w = (int) (13 * scale);
    h = (int) (16 * scale);

    if ((w <= 0) || (h <= 0)) {
        SharedPreferences.Editor edit = widgets.edit();
        edit.remove(widgetId + "_width");
        edit.remove(widgetId + "_height");
        edit.apply();
        updateAppWidget(context, appWidgetManager, widgetId);
        return;
    }

    Theme theme;
    switch (t) {
    case 0:
        theme = Theme.Light;
        break;
    case 1:
        theme = Theme.Dark;
        break;
    case 2:
        theme = Theme.LightTrans;
        break;
    case 3:
        theme = Theme.Trans;
        break;
    default:
        theme = Theme.Light;
    }
    Times times = null;
    long id = 0;
    try {
        id = widgets.getLong(widgetId + "", 0L);
    } catch (ClassCastException e) {
        widgets.edit().remove(widgetId + "").apply();
    }
    if (id != 0) {
        times = Times.getTimes(id);
    }
    if (times == null) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_city_removed);
        Intent i = new Intent(context, WidgetConfigure.class);
        i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
        remoteViews.setOnClickPendingIntent(R.id.image,
                PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT));
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
        return;
    }

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget);

    LocalDate date = LocalDate.now();
    String[] daytimes = { times.getTime(date, 0), times.getTime(date, 1), times.getTime(date, 2),
            times.getTime(date, 3), times.getTime(date, 4), times.getTime(date, 5) };

    int next = times.getNext();
    String left = times.getLeft(next, false);
    if (Prefs.getVakitIndicator().equals("next"))
        next++;

    remoteViews.setOnClickPendingIntent(R.id.widget, Main.getPendingIntent(times));

    Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bmp);
    canvas.scale(0.99f, 0.99f, w / 2, h / 2);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);

    paint.setStyle(Style.FILL);
    paint.setColor(theme.bgcolor);
    canvas.drawRect(0, 0, w, h, paint);

    paint.setColor(theme.textcolor);
    paint.setStyle(Style.FILL_AND_STROKE);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);

    double l = h / 10;
    paint.setTextSize((int) l);
    paint.setTextAlign(Align.CENTER);
    canvas.drawText(times.getName(), w / 2, (int) (l * 1.8), paint);

    paint.setTextSize((int) ((l * 8) / 10));

    if (next != 0 && !Prefs.showAltWidgetHightlight()) {
        paint.setColor(theme.hovercolor);
        canvas.drawRect(0, (int) (l * (next + 1.42)), w, (int) (l * (next + 2.42)), paint);
    }
    paint.setColor(theme.textcolor);

    paint.setTextAlign(Align.LEFT);
    for (int i = 0; i < 6; i++) {
        if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
            paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC));
        }
        canvas.drawText(Vakit.getByIndex(i).getString(), w / 6, (int) (l * (3.2 + i)), paint);
        if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
            paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
        }
    }
    paint.setTextAlign(Align.RIGHT);
    if (Prefs.use12H()) {
        for (int i = 0; i < daytimes.length; i++) {
            if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
                paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC));
            }
            String time = Utils.fixTime(daytimes[i]);
            String suffix = time.substring(time.indexOf(" ") + 1);
            time = time.substring(0, time.indexOf(" "));
            paint.setTextSize((int) ((l * 8) / 10));
            canvas.drawText(time, ((w * 5) / 6) - paint.measureText("A"), (int) (l * 3.2 + i * l), paint);
            paint.setTextSize((int) ((l * 4) / 10));
            canvas.drawText(suffix, ((w * 5) / 6) + (paint.measureText(time) / 4), (int) (l * 3 + i * l),
                    paint);
            if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
                paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
            }
        }
    } else {
        for (int i = 0; i < daytimes.length; i++) {
            if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
                paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC));
            }
            canvas.drawText(Utils.toArabicNrs(daytimes[i]), (w * 5) / 6, (int) (l * 3.2 + i * l), paint);
            if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
                paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
            }
        }
    }
    paint.setTextSize((int) l);
    paint.setTextAlign(Align.CENTER);
    canvas.drawText(left, w / 2, (int) (l * 9.5), paint);

    paint.setStyle(Style.STROKE);
    float stroke = mDP;
    paint.setStrokeWidth(stroke);
    paint.setColor(theme.strokecolor);
    canvas.drawRect(0, 0, w, h, paint);

    remoteViews.setImageViewBitmap(R.id.widget, bmp);

    try {
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            Crashlytics.logException(e);
        }
    }

}

From source file:com.metinkale.prayerapp.vakit.WidgetProviderClock.java

License:Apache License

public static void updateAppWidget(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager,
        int widgetId) {

    if (mDP == 0) {
        Resources r = context.getResources();
        mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());
    }//from  w w w  .  j a v  a2  s . co  m

    Resources r = context.getResources();
    SharedPreferences widgets = context.getSharedPreferences("widgets", 0);

    int w = widgets.getInt(widgetId + "_width", 500);
    int h = widgets.getInt(widgetId + "_height", 200);

    w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, r.getDisplayMetrics());
    h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, r.getDisplayMetrics());

    float scaleX = (float) w / (float) 5;
    float scaleY = (float) h / (float) 2;
    float scale = Math.min(scaleY, scaleX);

    w = (int) (5 * scale);
    h = (int) (2 * scale);

    if ((w <= 0) || (h <= 0)) {
        SharedPreferences.Editor edit = widgets.edit();
        edit.remove(widgetId + "_width");
        edit.remove(widgetId + "_height");
        edit.apply();
        updateAppWidget(context, appWidgetManager, widgetId);
        return;
    }

    Times times = null;
    long id = 0;
    try {
        id = widgets.getLong(widgetId + "", 0L);
    } catch (ClassCastException e) {
        widgets.edit().remove(widgetId + "").apply();
    }
    if (id != 0) {
        times = Times.getTimes(id);
    }
    if (times == null) {
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_city_removed);
        Intent i = new Intent(context, WidgetConfigureClock.class);
        i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
        remoteViews.setOnClickPendingIntent(R.id.image,
                PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT));
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
        return;
    }

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget_clock);

    remoteViews.setOnClickPendingIntent(R.id.abovePart,
            PendingIntent.getActivity(context, (int) System.currentTimeMillis(),
                    new Intent(AlarmClock.ACTION_SHOW_ALARMS), PendingIntent.FLAG_UPDATE_CURRENT));
    remoteViews.setOnClickPendingIntent(R.id.belowPart, Main.getPendingIntent(times));

    Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
    builder.appendPath("time");
    builder.appendPath(Long.toString(System.currentTimeMillis()));
    Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
    remoteViews.setOnClickPendingIntent(R.id.center, PendingIntent.getActivity(context,
            (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT));

    int next = times.getNext();
    int last = next - 1;

    Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bmp);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);

    paint.setStyle(Style.FILL_AND_STROKE);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);
    paint.setShadowLayer(2, 2, 2, 0xFF555555);
    paint.setTextAlign(Align.CENTER);
    paint.setColor(Color.WHITE);

    LocalTime ltime = LocalTime.now();

    paint.setTextSize(h * 0.55f);
    String time = ltime.toString("HH:mm");
    if (Prefs.use12H()) {
        time = Utils.fixTime(time);
        String suffix = time.substring(time.indexOf(" ") + 1);
        time = time.substring(0, time.indexOf(" "));
        canvas.drawText(time, (w / 2) - (paint.measureText(suffix) / 4), h * 0.4f, paint);
        paint.setTextSize(h * 0.275f);
        canvas.drawText(suffix, (w / 2) + paint.measureText(time), h * 0.2f, paint);
    } else {
        canvas.drawText(Utils.toArabicNrs(time), w / 2, h * 0.4f, paint);
    }

    LocalDate date = LocalDate.now();
    String greg = Utils.format(date);
    String hicri = Utils.format(new HicriDate(date));

    paint.setTextSize(h * 0.12f);
    float m = paint.measureText(greg + "  " + hicri);
    if (m > (w * 0.8f)) {
        paint.setTextSize((h * 0.12f * w * 0.8f) / m);
    }

    paint.setTextAlign(Align.LEFT);
    canvas.drawText(greg, w * .1f, h * 0.55f, paint);
    paint.setTextAlign(Align.RIGHT);
    canvas.drawText(hicri, w * .9f, h * 0.55f, paint);
    remoteViews.setImageViewBitmap(R.id.widget, bmp);

    canvas.drawRect(w * 0.1f, h * 0.6f, w * 0.9f, h * 0.63f, paint);

    if (times.isKerahat()) {
        paint.setColor(0xffbf3f5b);
    } else {
        paint.setColor(Theme.Light.strokecolor);
    }
    canvas.drawRect(w * 0.1f, h * 0.6f, (w * 0.1f) + (w * 0.8f * times.getPassedPart()), h * 0.63f, paint);

    paint.setColor(Color.WHITE);
    paint.setTextSize(h * 0.2f);
    paint.setTextAlign(Align.LEFT);
    if (Prefs.use12H()) {
        String l = Utils.fixTime(times.getTime(last));
        String s = l.substring(l.indexOf(" ") + 1);
        l = l.substring(0, l.indexOf(" "));
        canvas.drawText(l, w * 0.1f, h * 0.82f, paint);
        paint.setTextSize(h * 0.1f);
        canvas.drawText(s, (w * 0.1f) + (2 * paint.measureText(l)), h * 0.72f, paint);

    } else {
        canvas.drawText(Utils.fixTime(times.getTime(last)), w * 0.1f, h * 0.82f, paint);

    }
    paint.setTextSize(h * 0.12f);
    canvas.drawText(Vakit.getByIndex(last).getString(), w * 0.1f, h * 0.95f, paint);

    paint.setColor(Color.WHITE);
    paint.setTextSize(h * 0.2f);
    paint.setTextAlign(Align.RIGHT);
    if (Prefs.use12H()) {
        String l = Utils.fixTime(times.getTime(next));
        String s = l.substring(l.indexOf(" ") + 1);
        l = l.substring(0, l.indexOf(" "));
        canvas.drawText(l, (w * 0.9f) - (paint.measureText(s) / 2), h * 0.82f, paint);
        paint.setTextSize(h * 0.1f);
        canvas.drawText(s, w * 0.9f, h * 0.72f, paint);

    } else {
        canvas.drawText(Utils.fixTime(times.getTime(next)), w * 0.9f, h * 0.82f, paint);
    }
    paint.setTextSize(h * 0.12f);
    canvas.drawText(Vakit.getByIndex(next).getString(), w * 0.9f, h * 0.95f, paint);

    paint.setColor(Color.WHITE);
    paint.setTextSize(h * 0.25f);
    paint.setTextAlign(Align.CENTER);
    paint.setFakeBoldText(true);
    canvas.drawText(times.getLeft(next, false), w * 0.5f, h * 0.9f, paint);
    paint.setFakeBoldText(false);
    try {
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            Crashlytics.logException(e);
        }
    }
}

From source file:com.metinkale.prayerapp.vakit.WidgetProviderLong.java

License:Apache License

public static void updateAppWidget(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager,
        int widgetId) {

    if (mDP == 0) {
        Resources r = context.getResources();
        mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics());
    }//  w w  w  .  j av  a  2s.c o m

    Resources r = context.getResources();
    SharedPreferences widgets = context.getSharedPreferences("widgets", 0);

    int t = widgets.getInt(widgetId + "_theme", 0);
    int w = widgets.getInt(widgetId + "_width", 300);
    int h = widgets.getInt(widgetId + "_height", 60);

    w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, r.getDisplayMetrics());
    h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, r.getDisplayMetrics());

    float scaleX = (float) w / (float) 20;
    float scaleY = (float) h / (float) 5;
    float scale = Math.min(scaleY, scaleX);

    w = (int) (20 * scale);
    h = (int) (5 * scale);

    if ((w <= 0) || (h <= 0)) {
        if (!widgets.contains(widgetId + "_width") && !widgets.contains(widgetId + "_height")) {
            return;
        }
        SharedPreferences.Editor edit = widgets.edit();
        edit.remove(widgetId + "_width");
        edit.remove(widgetId + "_height");
        edit.apply();
        updateAppWidget(context, appWidgetManager, widgetId);
        return;
    }

    Theme theme;
    switch (t) {
    case 0:
        theme = Theme.Light;
        break;
    case 1:
        theme = Theme.Dark;
        break;
    case 2:
        theme = Theme.LightTrans;
        break;
    case 3:
        theme = Theme.Trans;
        break;
    default:
        theme = Theme.Light;
        break;
    }

    Times times = null;
    long id = 0;
    try {
        id = widgets.getLong(widgetId + "", 0L);
    } catch (ClassCastException e) {
        widgets.edit().remove(widgetId + "").apply();
    }
    if (id != 0) {
        times = Times.getTimes(id);
    }
    if (times == null) {

        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_city_removed);
        Intent i = new Intent(context, WidgetConfigure.class);
        i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
        remoteViews.setOnClickPendingIntent(R.id.image,
                PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT));
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
        return;
    }

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget);

    LocalDate date = LocalDate.now();
    String[] daytimes = { times.getTime(date, 0), times.getTime(date, 1), times.getTime(date, 2),
            times.getTime(date, 3), times.getTime(date, 4), times.getTime(date, 5) };

    int next = times.getNext();
    String left = times.getLeft(next, false);
    if (Prefs.getVakitIndicator().equals("next"))
        next++;

    remoteViews.setOnClickPendingIntent(R.id.widget, Main.getPendingIntent(times));

    Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(bmp);
    canvas.scale(0.99f, 0.99f, w / 2, h / 2);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setDither(true);
    paint.setFilterBitmap(true);

    paint.setStyle(Style.FILL);
    paint.setColor(theme.bgcolor);
    canvas.drawRect(0, 0, w, h, paint);

    paint.setStyle(Style.FILL_AND_STROKE);
    paint.setAntiAlias(true);
    paint.setSubpixelText(true);

    paint.setColor(theme.hovercolor);
    if (next != 0 && !Prefs.showAltWidgetHightlight()) {
        canvas.drawRect((w * (next - 1)) / 6, h * 3 / 9, w * next / 6, h, paint);
    }
    float s = paint.getStrokeWidth();
    float dip = (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) ? 2f : 3f;
    paint.setStrokeWidth(dip * mDP);
    canvas.drawLine(0, (h * 3) / 9, w, h * 3 / 9, paint);
    // canvas.drawRect(0, 0, w, h * 3 / 9, paint);
    paint.setStrokeWidth(s);

    paint.setColor(theme.textcolor);

    paint.setTextAlign(Align.LEFT);
    paint.setTextSize(h / 4);
    canvas.drawText(" " + times.getName(), 0, h / 4, paint);

    paint.setTextAlign(Align.RIGHT);
    canvas.drawText(left + " ", w, h / 4, paint);

    paint.setTextSize(h / 5);
    paint.setTextAlign(Align.CENTER);
    int y = (h * 6) / 7;
    if (Prefs.use12H()) {
        y += h / 14;
    }

    boolean fits = true;
    String[] vakits = { Vakit.getByIndex(0).getString(), Vakit.GUNES.getString(), Vakit.OGLE.getString(),
            Vakit.IKINDI.getString(), Vakit.AKSAM.getString(), Vakit.YATSI.getString() };
    do {
        if (!fits) {
            paint.setTextSize((float) (paint.getTextSize() * 0.95));
        }
        fits = true;
        for (String v : vakits) {
            if ((paint.measureText(v) > (w / 6)) && (w > 5)) {
                fits = false;
            }
        }
    } while (!fits);

    for (int i = 0; i < vakits.length; i++) {
        if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
            paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC));
        }
        canvas.drawText(vakits[i], (w * (1 + (2 * i))) / 12, y, paint);
        if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
            paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
        }
    }

    paint.setTextSize((h * 2) / 9);
    if (Prefs.use12H()) {
        for (int i = 0; i < daytimes.length; i++) {
            if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
                paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC));
            }
            String time = Utils.fixTime(daytimes[i]);
            String suffix = time.substring(time.indexOf(" ") + 1);
            time = time.substring(0, time.indexOf(" "));
            paint.setTextSize((h * 2) / 9);
            canvas.drawText(time, (w * (1 + (2 * i))) / 12, h * 6 / 10, paint);
            paint.setTextSize(h / 9);
            canvas.drawText(suffix, (w * (1 + (2 * i))) / 12, h * 7 / 10, paint);
            if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
                paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
            }
        }
    } else {
        for (int i = 0; i < daytimes.length; i++) {
            if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
                paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC));
            }
            canvas.drawText(Utils.toArabicNrs(daytimes[i]), (w * (1 + (2 * i))) / 12, h * 3 / 5, paint);
            if (i == next - 1 && Prefs.showAltWidgetHightlight()) {
                paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
            }
        }
    }

    paint.setStyle(Style.STROKE);
    float stroke = mDP;
    paint.setStrokeWidth(stroke);
    paint.setColor(theme.strokecolor);
    canvas.drawRect(0, 0, w, h, paint);

    remoteViews.setImageViewBitmap(R.id.widget, bmp);

    try {
        appWidgetManager.updateAppWidget(widgetId, remoteViews);
    } catch (RuntimeException e) {
        if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) {
            Crashlytics.logException(e);
        }
    }
}

From source file:com.metinkale.prayerapp.vakit.WidgetService.java

License:Apache License

public static void updateOngoing() {
    extractColors();//from   w  w w . j a v a2  s  .c  o m
    NotificationManager nm = (NotificationManager) App.get().getSystemService(Context.NOTIFICATION_SERVICE);

    for (int i = mOngoing.size() - 1; i >= 0; i--) {
        long id = mOngoing.get(i);
        Times t = Times.getTimes(id);

        if ((t == null) || !t.isOngoingNotificationActive()) {
            nm.cancel(id + "", NotIds.ONGOING);
            mOngoing.remove(i);
        }
    }
    List<Long> ids = Times.getIds();
    for (long id : ids) {

        Times t = Times.getTimes(id);

        if ((t != null) && t.isOngoingNotificationActive() && !mOngoing.contains(id)) {
            mOngoing.add(id);
        }
    }

    LocalDate cal = LocalDate.now();
    String[] left_part = App.get().getResources().getStringArray(R.array.lefttext_part);
    for (long id : mOngoing) {

        Times t = Times.getTimes(id);

        String[] dt = { t.getTime(cal, 0), t.getTime(cal, 1), t.getTime(cal, 2), t.getTime(cal, 3),
                t.getTime(cal, 4), t.getTime(cal, 5) };
        boolean icon = Prefs.showOngoingIcon();
        boolean number = Prefs.showOngoingNumber();
        Crashlytics.setBool("showIcon", icon);
        Crashlytics.setBool("showNumber", number);

        Notification noti;
        if (Prefs.getAlternativeOngoing()) {
            RemoteViews views = new RemoteViews(App.get().getPackageName(), R.layout.notification_layout);

            int[] timeIds = { R.id.time0, R.id.time1, R.id.time2, R.id.time3, R.id.time4, R.id.time5 };
            int[] vakitIds = { R.id.imsak, R.id.gunes, R.id.ogle, R.id.ikindi, R.id.aksam, R.id.yatsi };

            int next = t.getNext();
            if (Prefs.getVakitIndicator().equals("next"))
                next++;
            for (int i = 0; i < dt.length; i++) {
                if ((next - 1) == i) {
                    views.setTextViewText(timeIds[i],
                            Html.fromHtml("<strong><em>" + Utils.fixTime(dt[i]) + "</em></strong>"));
                } else {
                    views.setTextViewText(timeIds[i], Utils.fixTime(dt[i]));
                }
            }

            for (int i = 0; i < dt.length; i++) {
                if ((next - 1) == i) {
                    views.setTextViewText(vakitIds[i],
                            Html.fromHtml("<strong><em>" + Vakit.getByIndex(i).getString() + "</em></strong>"));
                } else {
                    views.setTextViewText(vakitIds[i], Vakit.getByIndex(i).getString());
                }
            }

            views.setTextViewText(R.id.time, t.getLeft(t.getNext(), false));
            views.setTextViewText(R.id.city, t.getName());

            views.setTextColor(R.id.imsak, COLOR_1ST);
            views.setTextColor(R.id.gunes, COLOR_1ST);
            views.setTextColor(R.id.ogle, COLOR_1ST);
            views.setTextColor(R.id.ikindi, COLOR_1ST);
            views.setTextColor(R.id.aksam, COLOR_1ST);
            views.setTextColor(R.id.yatsi, COLOR_1ST);

            views.setTextColor(R.id.time0, COLOR_1ST);
            views.setTextColor(R.id.time1, COLOR_1ST);
            views.setTextColor(R.id.time2, COLOR_1ST);
            views.setTextColor(R.id.time3, COLOR_1ST);
            views.setTextColor(R.id.time4, COLOR_1ST);
            views.setTextColor(R.id.time5, COLOR_1ST);

            views.setTextColor(R.id.time, COLOR_1ST);
            views.setTextColor(R.id.city, COLOR_1ST);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                long left = t.getLeftMinutes(t.getNext());
                noti = new Notification.Builder(App.get()).setContent(views)
                        .setContentIntent(Main.getPendingIntent(t))
                        .setSmallIcon(icon
                                ? (number ? Icon.createWithBitmap(getIconFromMinutes(left))
                                        : Icon.createWithResource(App.get(), R.drawable.ic_abicon))
                                : Icon.createWithResource(App.get(), R.drawable.ic_placeholder))
                        .setOngoing(true).build();
            } else {
                noti = new NotificationCompat.Builder(App.get()).setContent(views)
                        .setContentIntent(Main.getPendingIntent(t))
                        .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder).setOngoing(true)
                        .build();
            }
        } else {
            int n = t.getNext();
            String sum = App.get().getString(R.string.leftText, Vakit.getByIndex(n - 1).getString(),
                    left_part[n], t.getLeft().substring(0, 5));

            if (mAbIcon == null) {
                mAbIcon = ((BitmapDrawable) App.get().getResources().getDrawable(R.drawable.ic_abicon))
                        .getBitmap();
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                long left = t.getLeftMinutes(t.getNext());
                noti = new Notification.InboxStyle(new Notification.Builder(App.get())
                        .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("")
                        .setLargeIcon(mAbIcon)
                        .setSmallIcon(icon
                                ? (number ? Icon.createWithBitmap(getIconFromMinutes(left))
                                        : Icon.createWithResource(App.get(), R.drawable.ic_abicon))
                                : Icon.createWithResource(App.get(), R.drawable.ic_placeholder))
                        .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)).setOngoing(true))
                                .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0]))
                                .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1]))
                                .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2]))
                                .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3]))
                                .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4]))
                                .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5]))
                                .setSummaryText("").build();
            } else {
                noti = new NotificationCompat.InboxStyle(new NotificationCompat.Builder(App.get())
                        .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("")
                        .setLargeIcon(mAbIcon)
                        .setSmallIcon(icon ? R.drawable.ic_abicon : R.drawable.ic_placeholder)
                        .setContentInfo(sum).setContentIntent(Main.getPendingIntent(t)).setOngoing(true))
                                .addLine(Vakit.getByIndex(0).getString() + ": " + Utils.fixTime(dt[0]))
                                .addLine(Vakit.GUNES.getString() + ": " + Utils.fixTime(dt[1]))
                                .addLine(Vakit.OGLE.getString() + ": " + Utils.fixTime(dt[2]))
                                .addLine(Vakit.IKINDI.getString() + ": " + Utils.fixTime(dt[3]))
                                .addLine(Vakit.AKSAM.getString() + ": " + Utils.fixTime(dt[4]))
                                .addLine(Vakit.YATSI.getString() + ": " + Utils.fixTime(dt[5]))
                                .setSummaryText("").build();
            }

        }

        if (Build.VERSION.SDK_INT >= 16) {
            noti.priority = Notification.PRIORITY_LOW;
        }
        noti.when = icon ? System.currentTimeMillis() : 0;
        try {
            nm.notify(id + "", NotIds.ONGOING, noti);
        } catch (Exception e) {
            Crashlytics.logException(e);
        }

    }

}

From source file:com.mycollab.core.utils.DateTimeUtils.java

License:Open Source License

public static String getPrettyDurationValue(Date date, Locale locale) {
    Period period = new Period(new LocalDate(date), LocalDate.now());
    PeriodFormatter formatter = PeriodFormat.wordBased(locale);
    return formatter.print(period);
}

From source file:com.planyourexchange.fragments.result.ResultCalculations.java

License:Open Source License

public void setNumberOfWeeks(Integer numberOfWeeks) {
    this.numberOfWeeks = new BigDecimal(numberOfWeeks);
    LocalDate localDate = LocalDate.now();
    Months months = Months.monthsBetween(localDate, localDate.plusWeeks(numberOfWeeks));
    this.months = new BigDecimal(months.getMonths());
}

From source file:com.prayer.MainIntentService.java

License:Apache License

private void handleCalendarIntegration() {
    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
        Prefs.setCalendar("-1");
        return;/*from   w  w w.ja  v a  2 s  . c om*/
    }
    Context context = App.getContext();
    try {
        ContentResolver cr = context.getContentResolver();

        cr.delete(CalendarContract.Events.CONTENT_URI,
                CalendarContract.Events.DESCRIPTION + "=\"com.metinkale.prayer\"", null);

        String id = Prefs.getCalendar();

        if ("-1".equals(id) || (Prefs.getLanguage() == null)) {
            return;
        }
        int year = LocalDate.now().getYear();
        Collection<int[]> days = new ArrayList<>();
        days.addAll(HicriDate.getHolydays(year));
        days.addAll(HicriDate.getHolydays(year + 1));

        int i = 0;
        ContentValues[] events = new ContentValues[days.size()];
        for (int[] date : days) {
            ContentValues event = new ContentValues();

            event.put(CalendarContract.Events.CALENDAR_ID, id);
            event.put(CalendarContract.Events.TITLE, Utils.getHolyday(date[HicriDate.DAY] - 1));
            event.put(CalendarContract.Events.DESCRIPTION, "com.metinkale.prayer");

            ReadableInstant cal = new DateTime(date[HicriDate.GY], date[HicriDate.GM], date[HicriDate.GD], 0, 0,
                    0);

            long dtstart = cal.getMillis();
            long dtend = dtstart + DateUtils.DAY_IN_MILLIS;

            event.put(CalendarContract.Events.DTSTART, dtstart + TimeZone.getDefault().getOffset(dtstart));
            event.put(CalendarContract.Events.DTEND, dtend + TimeZone.getDefault().getOffset(dtend));
            event.put(CalendarContract.Events.EVENT_TIMEZONE, Time.TIMEZONE_UTC);
            event.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED);
            event.put(CalendarContract.Events.ALL_DAY, 1);

            events[i] = event;
            i++;
        }
        cr.bulkInsert(CalendarContract.Events.CONTENT_URI, events);
    } catch (Exception e) {
        Prefs.setCalendar("-1");

    }
}