Search in sources :

Example 1 with SunriseView

use of james.alarmio.views.SunriseView in project Alarmio by TheAndroidMaster.

the class SettingsFragment2 method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_settings, container, false);
    themeSpinner = view.findViewById(R.id.themeSpinner);
    sunriseAutoSwitch = view.findViewById(R.id.sunriseAutoSwitch);
    sunriseLayout = view.findViewById(R.id.sunriseLayout);
    sunriseTextView = view.findViewById(R.id.sunriseTextView);
    sunsetTextView = view.findViewById(R.id.sunsetTextView);
    sunriseView = view.findViewById(R.id.sunriseView);
    timeZoneAddView = view.findViewById(R.id.addTimeZone);
    timeZonesView = view.findViewById(R.id.timeZones);
    defaultRingtoneView = view.findViewById(R.id.defaultRingtone);
    defaultRingtoneTextView = view.findViewById(R.id.defaultRingtoneName);
    sleepReminderView = view.findViewById(R.id.sleepReminderSwitch);
    sleepReminderTimeView = view.findViewById(R.id.sleepReminderTime);
    sleepReminderTimeTextView = view.findViewById(R.id.sleepReminderTimeDesc);
    prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    themeSpinner.setAdapter(ArrayAdapter.createFromResource(getContext(), R.array.array_themes, R.layout.support_simple_spinner_dropdown_item));
    int theme = getAlarmio().getActivityTheme();
    themeSpinner.setSelection(theme);
    sunriseAutoSwitch.setVisibility(theme == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
    sunriseLayout.setVisibility(theme == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
    themeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            PreferenceData.THEME.setValue(getContext(), i);
            sunriseAutoSwitch.setVisibility(i == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
            sunriseLayout.setVisibility(i == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
            getAlarmio().onActivityResume();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    sunriseAutoSwitch.setChecked(getAlarmio().isDayAuto());
    sunriseAutoSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            PreferenceData.DAY_AUTO.setValue(getContext(), b);
            if (b && ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, 954);
                sunriseAutoSwitch.setChecked(false);
            } else {
                sunriseView.invalidate();
                onSunriseChanged(getAlarmio().getDayStart(), getAlarmio().getDayEnd());
            }
            getAlarmio().onActivityResume();
        }
    });
    sunriseView.setListener(this);
    onSunriseChanged(getAlarmio().getDayStart(), getAlarmio().getDayEnd());
    sunriseTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
                    int dayEnd = getAlarmio().getDayEnd();
                    if (hourOfDay < dayEnd) {
                        PreferenceData.DAY_START.setValue(getContext(), hourOfDay);
                        sunriseView.invalidate();
                        onSunriseChanged(hourOfDay, dayEnd);
                        getAlarmio().onActivityResume();
                    }
                }
            }, getAlarmio().getDayStart(), 0, DateFormat.is24HourFormat(getContext())).show();
        }
    });
    sunsetTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
                    int dayStart = getAlarmio().getDayStart();
                    if (hourOfDay > dayStart) {
                        PreferenceData.DAY_END.setValue(getContext(), hourOfDay);
                        sunriseView.invalidate();
                        onSunriseChanged(dayStart, hourOfDay);
                        getAlarmio().onActivityResume();
                    }
                }
            }, getAlarmio().getDayEnd(), 0, DateFormat.is24HourFormat(getContext())).show();
        }
    });
    if (PreferenceData.SLEEP_REMINDER.getValue(getContext())) {
        sleepReminderView.setChecked(true);
        sleepReminderTimeView.setVisibility(View.VISIBLE);
    } else {
        sleepReminderView.setChecked(false);
        sleepReminderTimeView.setVisibility(View.GONE);
    }
    sleepReminderView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            PreferenceData.SLEEP_REMINDER.setValue(getContext(), b);
            sleepReminderTimeView.setVisibility(b ? View.VISIBLE : View.GONE);
        }
    });
    colorAccentSubscription = Aesthetic.get().colorAccent().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            colorAccent = integer;
            invalidate();
        }
    });
    colorForegroundSubscription = Aesthetic.get().colorCardViewBackground().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            colorForeground = integer;
            invalidate();
        }
    });
    textColorPrimarySubscription = Aesthetic.get().textColorPrimary().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            textColorPrimary = integer;
            invalidate();
        }
    });
    textColorSecondarySubscription = Aesthetic.get().textColorSecondary().subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            textColorSecondary = integer;
            invalidate();
        }
    });
    return view;
}
Also used : TimePicker(android.widget.TimePicker) TimePickerDialog(android.app.TimePickerDialog) View(android.view.View) SunriseView(james.alarmio.views.SunriseView) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Consumer(io.reactivex.functions.Consumer) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) Nullable(android.support.annotation.Nullable)

Aggregations

TimePickerDialog (android.app.TimePickerDialog)1 Nullable (android.support.annotation.Nullable)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CompoundButton (android.widget.CompoundButton)1 TextView (android.widget.TextView)1 TimePicker (android.widget.TimePicker)1 Consumer (io.reactivex.functions.Consumer)1 SunriseView (james.alarmio.views.SunriseView)1