use of android.app.AlarmManager in project Slide by ccrama.
the class AutoCacheScheduler method start.
public void start(Context c) {
AlarmManager manager = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, Reddit.cachedData.getInt("hour", 0));
cal.set(Calendar.MINUTE, Reddit.cachedData.getInt("minute", 0));
if (cal.getTimeInMillis() < System.currentTimeMillis()) {
cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + 1);
}
manager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
use of android.app.AlarmManager in project Slide by ccrama.
the class NotificationJobScheduler method cancel.
public void cancel(Context c) {
AlarmManager manager = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
manager.cancel(pendingIntent);
}
use of android.app.AlarmManager in project Slide by ccrama.
the class StartOnBoot method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
/* Setting the alarm here */
Intent alarmIntent = new Intent(context, NotificationJobScheduler.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
int interval = 8000;
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);
}
}
use of android.app.AlarmManager in project Alarmio by TheAndroidMaster.
the class HomeFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_home, container, false);
viewPager = view.findViewById(R.id.viewPager);
tabLayout = view.findViewById(R.id.tabLayout);
timePager = view.findViewById(R.id.timePager);
bottomSheet = view.findViewById(R.id.bottomSheet);
timeIndicator = view.findViewById(R.id.pageIndicator);
background = view.findViewById(R.id.background);
overlay = view.findViewById(R.id.overlay);
menu = view.findViewById(R.id.fabsMenu);
stopwatchFab = view.findViewById(R.id.stopwatchFab);
timerFab = view.findViewById(R.id.timerFab);
alarmFab = view.findViewById(R.id.alarmFab);
menu.setMenuUpdateListener(this);
behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setHideable(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
private int statusBarHeight = -1;
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_COLLAPSED)
bottomSheet.setPadding(0, 0, 0, 0);
else if (newState == BottomSheetBehavior.STATE_EXPANDED) {
if (statusBarHeight < 0)
statusBarHeight = ConversionUtils.getStatusBarHeight(getContext());
bottomSheet.setPadding(0, statusBarHeight, 0, 0);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
if (statusBarHeight < 0)
statusBarHeight = ConversionUtils.getStatusBarHeight(getContext());
bottomSheet.setPadding(0, (int) (slideOffset * statusBarHeight), 0, 0);
}
});
}
pagerAdapter = new SimplePagerAdapter(getChildFragmentManager(), new AlarmsFragment(), new SettingsFragment());
viewPager.setAdapter(pagerAdapter);
tabLayout.setupWithViewPager(viewPager);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
if (tab.getPosition() > 0) {
shouldCollapseBack = behavior.getState() != BottomSheetBehavior.STATE_EXPANDED;
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
} else if (shouldCollapseBack) {
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
shouldCollapseBack = false;
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
Bundle args = new Bundle();
args.putString(ClockFragment.EXTRA_TIME_ZONE, TimeZone.getAvailableIDs()[0]);
ClockFragment fragment = new ClockFragment();
fragment.setArguments(args);
timeAdapter = new SimplePagerAdapter(getChildFragmentManager(), new ClockFragment(), fragment);
timePager.setAdapter(timeAdapter);
timeIndicator.setViewPager(timePager);
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
behavior.setPeekHeight(view.getMeasuredHeight() / 2);
view.findViewById(R.id.timeContainer).setLayoutParams(new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, view.getMeasuredHeight() / 2));
}
});
background.setImageDrawable(WallpaperManager.getInstance(getContext()).getFastDrawable());
colorPrimarySubscription = Aesthetic.get().colorPrimary().subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
bottomSheet.setBackgroundColor(integer);
overlay.setBackgroundColor(integer);
}
});
colorAccentSubscription = Aesthetic.get().colorAccent().subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
menu.getMenuButton().setBackgroundColor(integer);
stopwatchFab.setBackgroundColor(integer);
timerFab.setBackgroundColor(integer);
alarmFab.setBackgroundColor(integer);
}
});
textColorPrimarySubscription = Aesthetic.get().textColorPrimary().subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
stopwatchFab.setTitleTextColor(integer);
timerFab.setTitleTextColor(integer);
alarmFab.setTitleTextColor(integer);
}
});
stopwatchFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
menu.collapseImmediately();
getFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_in_up_sheet, R.anim.slide_out_up_sheet, R.anim.slide_in_down_sheet, R.anim.slide_out_down_sheet).replace(R.id.fragment, new StopwatchFragment()).addToBackStack(null).commit();
}
});
timerFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
viewPager.setCurrentItem(0, false);
new TimerDialog(getContext(), getFragmentManager()).show();
menu.collapse();
}
});
alarmFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
viewPager.setCurrentItem(0, false);
Calendar time = Calendar.getInstance();
new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
AlarmManager manager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
AlarmData alarm = getAlarmio().newAlarm();
alarm.time.set(Calendar.HOUR_OF_DAY, hourOfDay);
alarm.time.set(Calendar.MINUTE, minute);
alarm.setTime(getContext(), getAlarmio().getPrefs(), manager, alarm.time.getTimeInMillis());
alarm.setEnabled(getContext(), getAlarmio().getPrefs(), manager, true);
getAlarmio().onAlarmsChanged();
}
}, time.get(Calendar.HOUR_OF_DAY), time.get(Calendar.MINUTE), DateFormat.is24HourFormat(getContext())).show();
menu.collapse();
}
});
return view;
}
use of android.app.AlarmManager in project Alarmio by TheAndroidMaster.
the class AlarmReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Alarmio alarmio = (Alarmio) context.getApplicationContext();
AlarmData alarm = alarmio.getAlarms().get(intent.getIntExtra(EXTRA_ALARM_ID, 0));
if (alarm.isRepeat())
alarm.set(context, manager);
else
alarm.setEnabled(context, alarmio.getPrefs(), manager, false);
alarmio.onAlarmsChanged();
Intent ringer = new Intent(context, AlarmActivity.class);
ringer.putExtra(AlarmActivity.EXTRA_ALARM, alarm);
context.startActivity(ringer);
}
Aggregations