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;
}
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;
}
Aggregations