use of james.alarmio.dialogs.TimerDialog 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);
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 {
setClockFragments();
if (shouldCollapseBack) {
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
shouldCollapseBack = false;
}
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
setClockFragments();
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));
}
});
colorPrimarySubscription = Aesthetic.Companion.get().colorPrimary().subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
bottomSheet.setBackgroundColor(integer);
overlay.setBackgroundColor(integer);
}
});
colorAccentSubscription = Aesthetic.Companion.get().colorAccent().subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
menu.setMenuButtonColor(integer);
int color = ContextCompat.getColor(getContext(), getAlarmio().getActivityTheme() == Alarmio.THEME_AMOLED ? R.color.textColorPrimary : R.color.textColorPrimaryNight);
menu.getMenuButton().setColorFilter(color);
stopwatchFab.setColorFilter(color);
timerFab.setColorFilter(color);
alarmFab.setColorFilter(color);
stopwatchFab.setBackgroundColor(integer);
timerFab.setBackgroundColor(integer);
alarmFab.setBackgroundColor(integer);
}
});
textColorPrimarySubscription = Aesthetic.Companion.get().textColorPrimary().subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
stopwatchFab.setTitleTextColor(integer);
timerFab.setTitleTextColor(integer);
alarmFab.setTitleTextColor(integer);
}
});
textColorPrimaryInverseSubscription = Aesthetic.Companion.get().textColorPrimaryInverse().subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
alarmFab.setTitleBackgroundColor(integer);
stopwatchFab.setTitleBackgroundColor(integer);
timerFab.setTitleBackgroundColor(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) {
new TimerDialog(getContext(), getFragmentManager()).show();
menu.collapse();
}
});
alarmFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new AestheticTimeSheetPickerDialog(view.getContext()).setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {
@Override
public void onSelect(PickerDialog<LinearTimePickerView> dialog, LinearTimePickerView view) {
AlarmManager manager = (AlarmManager) view.getContext().getSystemService(Context.ALARM_SERVICE);
AlarmData alarm = getAlarmio().newAlarm();
alarm.time.set(Calendar.HOUR_OF_DAY, view.getHourOfDay());
alarm.time.set(Calendar.MINUTE, view.getMinute());
alarm.setEnabled(getContext(), manager, true);
getAlarmio().onAlarmsChanged();
}
@Override
public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
}
}).show();
menu.collapse();
}
});
menu.setMenuListener(new FABsMenuListener() {
@Override
public void onMenuExpanded(FABsMenu fabsMenu) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.FOREGROUND_SERVICE) != PackageManager.PERMISSION_GRANTED)
requestPermissions(new String[] { Manifest.permission.FOREGROUND_SERVICE }, 0);
else
fabsMenu.collapseImmediately();
}
}
});
return view;
}
Aggregations