List of usage examples for org.joda.time LocalDate now
public static LocalDate now()
ISOChronology
in the default time zone. From source file:com.prayer.Utils.java
License:Apache License
public static void init(Context c) { String newLang = Prefs.getLanguage(); int year = LocalDate.now().getYear(); if (year != Prefs.getLastCalSync()) { MainIntentService.startCalendarIntegration(c); }//from w w w. j a v a 2s.c o m Prefs.setLastCalSync(year); if (newLang == null) { return; } Locale locale = new Locale(newLang); Configuration config = new Configuration(); Locale.setDefault(locale); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { config.setLocale(locale); } else { config.locale = locale; } c.getResources().updateConfiguration(config, c.getResources().getDisplayMetrics()); }
From source file:com.prayer.vakit.fragments.MainFragment.java
License:Apache License
public void update() { if ((mTimes == null) || (mView == null)) { return; }/* w ww . java 2s . c o m*/ mTitle.setText(mTimes.getName()); LocalDate greg = LocalDate.now(); HicriDate hijr = new HicriDate(greg); String[] daytimes = { mTimes.getTime(greg, 0), mTimes.getTime(greg, 1), mTimes.getTime(greg, 2), mTimes.getTime(greg, 3), mTimes.getTime(greg, 4), mTimes.getTime(greg, 5) }; for (int i = 0; i < 6; i++) { TextView time = (TextView) mView.findViewById(ids[i]); time.setText(Utils.fixTimeForHTML(daytimes[i])); } }
From source file:com.prayer.vakit.fragments.MainFragment.java
License:Apache License
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.fix_time: Main.mTopSlider.animateOpen(); break; case R.id.notification: Fragment frag = getActivity().getSupportFragmentManager().findFragmentByTag("notPrefs"); if (frag == null) { getActivity().getSupportFragmentManager().beginTransaction() .add(R.id.fragContainer, NotificationPrefs.create(mTimes), "notPrefs").commit(); } else { getActivity().getSupportFragmentManager().beginTransaction().remove(frag).commit(); }//from w w w . j ava2s . c o m break; case R.id.share: String txt = getString(R.string.shareTimes, mTimes.getName()) + ":"; LocalDate date = LocalDate.now(); String[] times = { mTimes.getTime(date, 0), mTimes.getTime(date, 1), mTimes.getTime(date, 2), mTimes.getTime(date, 3), mTimes.getTime(date, 4), mTimes.getTime(date, 5) }; for (int i = 0; i < times.length; i++) { txt += "\n " + Vakit.getByIndex(i).getString() + ": " + times[i]; } 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); startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share))); } return super.onOptionsItemSelected(item); }
From source file:com.prayer.vakit.times.Times.java
License:Apache License
Collection<Alarm> getAlarms() { Collection<Alarm> alarms = new ArrayList<>(); LocalDate cal = LocalDate.now(); for (int ii = 0; ii <= 1/* next day */; ii++) { for (Vakit v : Vakit.values()) { if (isNotificationActive(v)) { if (v != Vakit.SABAH) { int vakit = v.ordinal(); if (vakit != 0) { vakit--;// w w w. ja v a 2s . c o m } long mills = getTimeCal(cal, vakit).toDateTime().getMillis(); if (System.currentTimeMillis() < mills) { Alarm a = new Alarm(); a.city = getID(); a.early = false; a.cuma = false; a.time = mills; a.vakit = v; a.dayOffset = ii; alarms.add(a); } } else { long mills; if (isAfterImsak()) { mills = getTimeCal(cal, 0).toDateTime().getMillis() + getSabahTime() * 60 * 1000; } else { mills = getTimeCal(cal, 1).toDateTime().getMillis() - getSabahTime() * 60 * 1000; } if (System.currentTimeMillis() < mills) { Alarm a = new Alarm(); a.city = getID(); a.cuma = false; a.early = false; a.time = mills; a.vakit = v; a.dayOffset = ii; alarms.add(a); } } } if (isEarlyNotificationActive(v)) { if (v != Vakit.SABAH) { int vakit = v.ordinal(); if (vakit != 0) { vakit--; } int early = getEarlyTime(v); long mills = getTimeCal(cal, vakit).toDateTime().getMillis() - early * 60 * 1000; if (System.currentTimeMillis() < mills) { Alarm a = new Alarm(); a.city = getID(); a.early = true; a.cuma = false; a.time = mills; a.vakit = v; a.dayOffset = ii; alarms.add(a); } } } } cal = cal.plusDays(1); } if (isCumaActive()) { int early = getCumaTime(); DateTime c = DateTime.now().withDayOfWeek(DateTimeConstants.FRIDAY); if ((c.getMillis() + 1000) < System.currentTimeMillis()) { c = c.plusWeeks(1); } long mills = getTimeCal(c.toLocalDate(), 2).toDateTime().getMillis(); mills -= early * 60 * 1000; if (System.currentTimeMillis() < mills) { Alarm a = new Alarm(); a.city = getID(); a.cuma = true; a.early = false; a.time = mills; a.vakit = Vakit.OGLE; a.dayOffset = 0; alarms.add(a); } } return alarms; }
From source file:com.prayer.vakit.times.Times.java
License:Apache License
public LocalDateTime getTimeCal(LocalDate date, int time) { if (date == null) { date = LocalDate.now(); }/* ww w .j a v a2 s . c o m*/ if ((time < 0) || (time > 5)) { while (time >= 6) { date = date.plusDays(1); time -= 6; } while (time <= -1) { date = date.minusDays(1); time += 6; } } LocalDateTime timeCal = date.toLocalDateTime(new LocalTime(getTime(date, time))); int h = timeCal.getHourOfDay(); if ((time >= 3) && (h < 5)) { timeCal = timeCal.plusDays(1); } return timeCal; }
From source file:com.prayer.vakit.times.Times.java
License:Apache License
public String getTime(LocalDate date, int time) { if (date == null) { date = LocalDate.now(); }//from w w w. ja va2 s. c o m if ((time < 0) || (time > 5)) { while (time >= 6) { date = date.plusDays(1); time -= 6; } while (time == -1) { date = date.minusDays(1); time += 6; } } String ret = adj(_getTime(date, time), time); return ret; }
From source file:com.prayer.vakit.WidgetProvider.java
License:Apache License
private static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int widgetId) { if (mDP == 0) { Resources r = context.getResources(); mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()); }/*ww w . j av a 2s.c om*/ 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_prayer); 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_prayer); 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) { 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); canvas.drawText(Vakit.getByIndex(0).getString(), w / 6, (int) (l * 3.2), paint); canvas.drawText(Vakit.GUNES.getString(), w / 6, (int) (l * 4.2), paint); canvas.drawText(Vakit.OGLE.getString(), w / 6, (int) (l * 5.2), paint); canvas.drawText(Vakit.IKINDI.getString(), w / 6, (int) (l * 6.2), paint); canvas.drawText(Vakit.AKSAM.getString(), w / 6, (int) (l * 7.2), paint); canvas.drawText(Vakit.YATSI.getString(), w / 6, (int) (l * 8.2), paint); paint.setTextAlign(Align.RIGHT); if (Prefs.use12H()) { for (int i = 0; i < daytimes.length; i++) { 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); } } else { for (int i = 0; i < daytimes.length; i++) { canvas.drawText(Utils.toArabicNrs(daytimes[i]), (w * 5) / 6, (int) (l * 3.2 + i * l), paint); } } 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")) { } } }
From source file:com.prayer.vakit.WidgetProviderClock.java
License:Apache License
public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int widgetId) { if (mDP == 0) { Resources r = context.getResources(); mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()); }//from w ww .j ava 2 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_prayer); 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_prayer); 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")) { } } }
From source file:com.prayer.vakit.WidgetProviderLong.java
License:Apache License
public static void updateAppWidget(Context context, 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 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", 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_prayer); 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_prayer); 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) { 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++) { canvas.drawText(vakits[i], (w * (1 + (2 * i))) / 12, y, paint); } paint.setTextSize((h * 2) / 9); if (Prefs.use12H()) { for (int i = 0; i < daytimes.length; i++) { 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); } } else { for (int i = 0; i < daytimes.length; i++) { canvas.drawText(Utils.toArabicNrs(daytimes[i]), (w * (1 + (2 * i))) / 12, h * 3 / 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")) { } } }
From source file:com.prayer.vakit.WidgetService.java
License:Apache License
public static void updateOngoing() { extractColors();/*from w ww . ja va 2 s . c om*/ NotificationManager nm = (NotificationManager) App.getContext() .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.getContext().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) }; Notification noti = null; boolean icon = Prefs.showOngoingIcon(); boolean number = Prefs.showOngoingNumber(); if (Prefs.getAlternativeOngoing()) { RemoteViews views = new RemoteViews(App.getContext().getPackageName(), R.layout.notification_layout_prayer); 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)); String PersianTime = String.valueOf(t.getNext()); Log.e("PersianTime", " " + PersianTime); 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.getContext()).setContent(views) .setContentIntent(Main.getPendingIntent(t)) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), R.drawable.ic_placeholder)) .setOngoing(true).build(); } else { noti = new NotificationCompat.Builder(App.getContext()).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.getContext().getString(R.string.leftText, Vakit.getByIndex(n - 1).getString(), left_part[n], t.getLeft().substring(0, 5)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { long left = t.getLeftMinutes(t.getNext()); noti = new Notification.InboxStyle( new Notification.Builder(App.getContext()) .setContentTitle(t.getName() + " (" + t.getSource() + ")").setContentText("") .setLargeIcon(mAbIcon) .setSmallIcon(icon ? (number ? Icon.createWithBitmap(getIconFromMinutes(left)) : Icon.createWithResource(App.getContext(), R.drawable.ic_abicon)) : Icon.createWithResource(App.getContext(), 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.getContext()) .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) { } } }