Search in sources :

Example 91 with AlarmManager

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);
}
Also used : Calendar(java.util.Calendar) AlarmManager(android.app.AlarmManager)

Example 92 with AlarmManager

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);
}
Also used : AlarmManager(android.app.AlarmManager)

Example 93 with AlarmManager

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);
    }
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 94 with AlarmManager

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;
}
Also used : TimePicker(android.widget.TimePicker) SimplePagerAdapter(james.alarmio.adapters.SimplePagerAdapter) BottomSheetBehavior(android.support.design.widget.BottomSheetBehavior) Consumer(io.reactivex.functions.Consumer) TabLayout(android.support.design.widget.TabLayout) ViewTreeObserver(android.view.ViewTreeObserver) TimerDialog(james.alarmio.dialogs.TimerDialog) Bundle(android.os.Bundle) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) ImageView(android.widget.ImageView) View(android.view.View) PageIndicatorView(james.alarmio.views.PageIndicatorView) AlarmManager(android.app.AlarmManager) AlarmData(james.alarmio.data.AlarmData) Nullable(android.support.annotation.Nullable)

Example 95 with AlarmManager

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);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) Alarmio(james.alarmio.Alarmio) AlarmData(james.alarmio.data.AlarmData)

Aggregations

AlarmManager (android.app.AlarmManager)471 PendingIntent (android.app.PendingIntent)349 Intent (android.content.Intent)323 Calendar (java.util.Calendar)75 SuppressLint (android.annotation.SuppressLint)24 Date (java.util.Date)24 Context (android.content.Context)22 SharedPreferences (android.content.SharedPreferences)20 SimpleDateFormat (java.text.SimpleDateFormat)18 Test (org.junit.Test)17 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)13 Config (org.robolectric.annotation.Config)13 Handler (android.os.Handler)11 HashMap (java.util.HashMap)11 PowerManager (android.os.PowerManager)10 File (java.io.File)10 Map (java.util.Map)10 Activity (android.app.Activity)9 ShadowAlarmManager (org.robolectric.shadows.ShadowAlarmManager)9 TargetApi (android.annotation.TargetApi)8