Search in sources :

Example 1 with SimplePagerAdapter

use of james.alarmio.adapters.SimplePagerAdapter 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 2 with SimplePagerAdapter

use of james.alarmio.adapters.SimplePagerAdapter in project Alarmio by TheAndroidMaster.

the class SoundChooserDialog method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.dialog_sound_chooser, container, false);
    view.setBackgroundColor(colorWindowBackground);
    TabLayout tabLayout = view.findViewById(R.id.tabLayout);
    ViewPager viewPager = view.findViewById(R.id.viewPager);
    AlarmSoundChooserFragment alarmFragment = new AlarmSoundChooserFragment();
    RingtoneSoundChooserFragment ringtoneFragment = new RingtoneSoundChooserFragment();
    RadioSoundChooserFragment radioFragment = new RadioSoundChooserFragment();
    alarmFragment.setListener(this);
    ringtoneFragment.setListener(this);
    radioFragment.setListener(this);
    viewPager.setAdapter(new SimplePagerAdapter(getChildFragmentManager(), alarmFragment, ringtoneFragment, radioFragment));
    tabLayout.setupWithViewPager(viewPager);
    return view;
}
Also used : RadioSoundChooserFragment(james.alarmio.fragments.RadioSoundChooserFragment) TabLayout(android.support.design.widget.TabLayout) AlarmSoundChooserFragment(james.alarmio.fragments.AlarmSoundChooserFragment) SimplePagerAdapter(james.alarmio.adapters.SimplePagerAdapter) ViewPager(android.support.v4.view.ViewPager) RingtoneSoundChooserFragment(james.alarmio.fragments.RingtoneSoundChooserFragment) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)2 TabLayout (android.support.design.widget.TabLayout)2 SimplePagerAdapter (james.alarmio.adapters.SimplePagerAdapter)2 AlarmManager (android.app.AlarmManager)1 TimePickerDialog (android.app.TimePickerDialog)1 Bundle (android.os.Bundle)1 BottomSheetBehavior (android.support.design.widget.BottomSheetBehavior)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 ImageView (android.widget.ImageView)1 TimePicker (android.widget.TimePicker)1 Consumer (io.reactivex.functions.Consumer)1 AlarmData (james.alarmio.data.AlarmData)1 TimerDialog (james.alarmio.dialogs.TimerDialog)1 AlarmSoundChooserFragment (james.alarmio.fragments.AlarmSoundChooserFragment)1 RadioSoundChooserFragment (james.alarmio.fragments.RadioSoundChooserFragment)1 RingtoneSoundChooserFragment (james.alarmio.fragments.RingtoneSoundChooserFragment)1 PageIndicatorView (james.alarmio.views.PageIndicatorView)1 Calendar (java.util.Calendar)1