Android Open Source - Tacere Advanced Settings Fragment






From Project

Back to project page Tacere.

License

The source code is released under:

MIT License

If you think the Android project Tacere listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (c) 2014 Jonathan Nelson/* ww w .  j a  v  a2 s  .co m*/
 * Released under the BSD license.  For details see the COPYING file.
 */

package org.ciasaboark.tacere.activity.fragment;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.ciasaboark.tacere.R;
import org.ciasaboark.tacere.bug.CrashReportManager;
import org.ciasaboark.tacere.event.ringer.Intervals;
import org.ciasaboark.tacere.manager.AlarmManagerWrapper;
import org.ciasaboark.tacere.prefs.BetaPrefs;
import org.ciasaboark.tacere.prefs.Prefs;
import org.ciasaboark.tacere.service.RequestTypes;

public class AdvancedSettingsFragment extends android.support.v4.app.Fragment {
    public static final String TAG = "AdvancedSettingsFragment";
    private View rootView;
    private Context context;
    private Prefs prefs;

    public AdvancedSettingsFragment() {
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rootView = inflater.inflate(R.layout.fragment_advanced_settings, container, false);
        context = getActivity();
        if (context == null) {
            throw new IllegalStateException("Fragment " + TAG + " can not find its activity");
        }
        prefs = new Prefs(context);
        drawAllWidgets();

        return rootView;
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    public void drawAllWidgets() {
        drawFreeTimeWidgets();
        drawSilenceAllDayWidgets();
        drawEventBufferWidgets();
        drawLookaheadWidgets();
        drawQuickSilenceWidget();
        drawReportsWidget();
        drawBetaWidgets();
    }

    private void drawBetaWidgets() {
        LinearLayout betaSettingsBox = (LinearLayout) rootView.findViewById(R.id.beta_settings_box);
        final BetaPrefs betaPrefs = new BetaPrefs(getActivity());
        if (betaPrefs.isBetaPrefsUnlocked()) {
            betaSettingsBox.setVisibility(View.VISIBLE);
            final CheckBox useLargeDisplayCheckbox = (CheckBox) rootView.findViewById(R.id.beta_largedisplay_checkbox);
            final RelativeLayout useLargeDisplayBox = (RelativeLayout) rootView.findViewById(R.id.large_display_box);
            if (betaPrefs.getUseLargeDisplay()) {
                useLargeDisplayCheckbox.setChecked(true);
            }
            useLargeDisplayBox.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    useLargeDisplayCheckbox.performClick();
                    betaPrefs.setUseLargeDisplay(useLargeDisplayCheckbox.isChecked());
                }
            });

            final CheckBox disableNotificationsCheckbox = (CheckBox) rootView.findViewById(R.id.beta_notifications_checkbox);
            final RelativeLayout disableNotificationsBox = (RelativeLayout) rootView.findViewById(R.id.disable_notifications_box);
            if (betaPrefs.getDisableNotifications()) {
                disableNotificationsCheckbox.setChecked(true);
            }
            disableNotificationsBox.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    disableNotificationsCheckbox.performClick();
                    betaPrefs.setDisableNotifications(disableNotificationsCheckbox.isChecked());
                    AlarmManagerWrapper alarmManagerWrapper = new AlarmManagerWrapper(getActivity());
                    alarmManagerWrapper.scheduleImmediateAlarm(RequestTypes.NORMAL);
//                    if (disableNotificationsCheckbox.isChecked()) {
//                        NotificationManagerWrapper notificationManagerWrapper = new NotificationManagerWrapper(context);
//                        notificationManagerWrapper.cancelAllNotifications();
//                    }
                }
            });

            final CheckBox disableVibrationCheckbox = (CheckBox) rootView.findViewById(R.id.beta_vibration_checkbox);
            final RelativeLayout disableVibrationBox = (RelativeLayout) rootView.findViewById(R.id.disable_vibration_box);
            if (betaPrefs.getDisableVibration()) {
                disableVibrationCheckbox.setChecked(true);
            }
            disableVibrationBox.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    disableVibrationCheckbox.performClick();
                    betaPrefs.setDisableVibration(disableVibrationCheckbox.isChecked());
                }
            });

        } else {
            betaSettingsBox.setVisibility(View.GONE);
        }
    }

    private void drawFreeTimeWidgets() {
        RelativeLayout freeTimeBox = (RelativeLayout) rootView.findViewById(R.id.advanced_settings_freetime_box);
        freeTimeBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                prefs.setSilenceFreeTimeEvents(!prefs.shouldAvailableEventsSilence());
                drawFreeTimeWidgets();
            }
        });

        // the silence free time state toggle
        CheckBox freeCB = (CheckBox) rootView.findViewById(R.id.silenceFreeTimeCheckBox);
        TextView freeTV = (TextView) rootView.findViewById(R.id.silenceFreeTimeDescription);
        if (prefs.shouldAvailableEventsSilence()) {
            freeCB.setChecked(true);
            freeTV.setText(R.string.advanced_settings_section_events_available_enabled);
        } else {
            freeCB.setChecked(false);
            freeTV.setText(R.string.advanced_settings_section_events_available_disabled);
        }
    }

    private void drawSilenceAllDayWidgets() {
        RelativeLayout allDayBox = (RelativeLayout) rootView.findViewById(R.id.advanced_settings_allday_box);
        allDayBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                prefs.setSilenceAllDayEvents(!prefs.shouldAllDayEventsSilence());
                drawSilenceAllDayWidgets();
            }
        });

        // the silence all day state toggle
        CheckBox dayCB = (CheckBox) rootView.findViewById(R.id.silenceAllDayCheckBox);
        TextView dayTV = (TextView) rootView.findViewById(R.id.silenceAllDayDescription);
        if (prefs.shouldAllDayEventsSilence()) {
            dayCB.setChecked(true);
            dayTV.setText(R.string.advanced_settings_section_events_all_day_enabled);
        } else {
            dayCB.setChecked(false);
            dayTV.setText(R.string.advanced_settings_section_events_all_day_disabled);
        }
    }

    private void drawEventBufferWidgets() {
        LinearLayout bufferBox = (LinearLayout) rootView.findViewById(R.id.advanced_settings_buffer_box);
        bufferBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(
                        new ContextThemeWrapper(context, R.style.Dialog)
                );
                builder.setTitle("Buffer Minutes");
                final NumberPicker number = new NumberPicker(context);
                String[] nums = new String[32];

                for (int i = 0; i < nums.length; i++) {
                    nums[i] = Integer.toString(i);
                }

                number.setMinValue(1);
                number.setMaxValue(nums.length - 1);
                number.setWrapSelectorWheel(false);
                number.setDisplayedValues(nums);
                number.setValue(prefs.getBufferMinutes() + 1);

                builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        prefs.setBufferMinutes(number.getValue() - 1);
                        drawEventBufferWidgets();
                    }
                });

                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Do nothing
                    }
                });

                builder.setView(number);

                AlertDialog dialog = builder.show();
            }
        });

        // the event buffer button
        TextView bufferTV = (TextView) rootView.findViewById(R.id.bufferMinutesDescription);
        String bufferText = getResources().getString(R.string.advanced_settings_section_intervals_buffer_duration);
        bufferTV.setText(String.format(bufferText, prefs.getBufferMinutes()));
    }

    private void drawLookaheadWidgets() {
        LinearLayout lookaheadBox = (LinearLayout) rootView.findViewById(R.id.advanced_settings_lookahead_box);
        lookaheadBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String[] intervals = Intervals.names();
                AlertDialog.Builder builder = new AlertDialog.Builder(
                        new ContextThemeWrapper(context, R.style.Dialog)
                );
                builder.setTitle(R.string.advanced_settings_section_intervals_lookahead);

                builder.setSingleChoiceItems(intervals, -1, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        String intervalString = intervals[i];
                        int intervalValue = Intervals.getIntForStringValue(intervalString);
                        Intervals interval = Intervals.getTypeForInt(intervalValue);

                        prefs.setLookaheadDays(interval);
                        drawLookaheadWidgets();
                    }
                });

                builder.setNeutralButton(R.string.close, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        //do nothing
                    }
                });

                AlertDialog dialog = builder.show();
            }
        });

        // the lookahead interval button
        TextView lookaheadTV = (TextView) rootView.findViewById(R.id.lookaheadDaysDescription);
        String lookaheadText = getResources().getString(R.string.advanced_settings_section_intervals_lookahead_duration);
        lookaheadTV.setText(String.format(lookaheadText, prefs.getLookaheadDays().injectString));
    }

    private void drawReportsWidget() {
        final CheckBox sendReportsCheckbox = (CheckBox) rootView.findViewById(R.id.advanced_settings_reports_checkbox);
        final CrashReportManager crashReportManager = new CrashReportManager(getActivity());

        sendReportsCheckbox.setChecked(crashReportManager.isReportsEnabled());
        TextView sendReportsDescription = (TextView) rootView.findViewById(R.id.advanced_settings_reports_description);
        sendReportsDescription.setText(crashReportManager.isReportsDisabled() ?
                R.string.advanced_settings_section_reports_description_disabled :
                R.string.advanced_settings_section_reports_description_enabled);
        RelativeLayout reportsBox = (RelativeLayout) rootView.findViewById(R.id.advanced_settings_reports_box);
        reportsBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendReportsCheckbox.performClick();
                boolean willSendReports = sendReportsCheckbox.isChecked();
                crashReportManager.setReportsEnabled(willSendReports);
                drawReportsWidget();
            }
        });
    }

    private void drawQuickSilenceWidget() {
        LinearLayout quicksilenceBox = (LinearLayout) rootView.findViewById(R.id.advanced_settings_quicksilence_box);
        quicksilenceBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LayoutInflater inflater = LayoutInflater.from(v.getContext());
                View dialogView = inflater.inflate(R.layout.dialog_quicksilent, null);
                final AlertDialog.Builder builder = new AlertDialog.Builder(
                        new ContextThemeWrapper(context, R.style.Dialog)
                );
                builder.setTitle(R.string.notification_quicksilence_title);
                builder.setView(dialogView);

                final NumberPicker hourP = (NumberPicker) dialogView.findViewById(R.id.hourPicker);
                final NumberPicker minP = (NumberPicker) dialogView.findViewById(R.id.minutePicker);

                String[] hours = new String[25];
                String[] minutes = new String[59];

                for (int i = 0; i < hours.length; i++) {
                    hours[i] = Integer.toString(i);
                }

                int i = 0;
                while (i < minutes.length) {
                    minutes[i] = Integer.toString(++i);
                }


                hourP.setMinValue(1);
                hourP.setMaxValue(hours.length - 1);
                hourP.setWrapSelectorWheel(false);
                hourP.setDisplayedValues(hours);
                hourP.setValue(prefs.getQuickSilenceHours() + 1);

                minP.setMinValue(1);
                minP.setMaxValue(minutes.length - 1);
                minP.setWrapSelectorWheel(false);
                minP.setDisplayedValues(minutes);
                minP.setValue(prefs.getQuicksilenceMinutes());

                builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        prefs.setQuickSilenceHours(hourP.getValue() - 1);
                        prefs.setQuicksilenceMinutes(minP.getValue());
                        drawQuickSilenceWidget();
                    }
                });

                builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        //do nothing
                    }
                });

                AlertDialog dialog = builder.show();
            }
        });

        //the quick silence button
        TextView quickTV = (TextView) rootView.findViewById(R.id.quickSilenceDescription);
        String quicksilenceText = getResources().getString(R.string.advanced_settings_section_interval_quicksilence_duration);
        String hrs = "";
        if (prefs.getQuickSilenceHours() > 0) {
            hrs = String.valueOf(prefs.getQuickSilenceHours()) + " " + getString(R.string.hours_lower) + " ";
        }
        quickTV.setText(String.format(quicksilenceText, hrs, prefs.getQuicksilenceMinutes()));
    }
}




Java Source Code List

.EventInstanceTest.java
com.viewpagerindicator.BuildConfig.java
com.viewpagerindicator.BuildConfig.java
com.viewpagerindicator.CirclePageIndicator.java
com.viewpagerindicator.IconPageIndicator.java
com.viewpagerindicator.IconPagerAdapter.java
com.viewpagerindicator.IcsLinearLayout.java
com.viewpagerindicator.LinePageIndicator.java
com.viewpagerindicator.PageIndicator.java
com.viewpagerindicator.TabPageIndicator.java
com.viewpagerindicator.TitlePageIndicator.java
com.viewpagerindicator.UnderlinePageIndicator.java
org.ciasaboark.tacere.ApplicationTest.java
org.ciasaboark.tacere.Tacere.java
org.ciasaboark.tacere.activity.AboutActivity.java
org.ciasaboark.tacere.activity.AboutLicenseActivity.java
org.ciasaboark.tacere.activity.AdvancedSettingsActivity.java
org.ciasaboark.tacere.activity.BetaReleaseActivity.java
org.ciasaboark.tacere.activity.BetaSettingsActivity.java
org.ciasaboark.tacere.activity.BugReportActivity.java
org.ciasaboark.tacere.activity.DonationActivityTest.java
org.ciasaboark.tacere.activity.LicenseCheckWrapper.java
org.ciasaboark.tacere.activity.MainActivity.java
org.ciasaboark.tacere.activity.ProUpgradeActivity.java
org.ciasaboark.tacere.activity.SelectCalendarsActivity.java
org.ciasaboark.tacere.activity.SettingsActivity.java
org.ciasaboark.tacere.activity.ShowUpdatesActivity.java
org.ciasaboark.tacere.activity.TutorialActivity.java
org.ciasaboark.tacere.activity.fragment.AdvancedSettingsFragment.java
org.ciasaboark.tacere.activity.fragment.BetaSettingsFragment.java
org.ciasaboark.tacere.activity.fragment.EventDetailsFragment.java
org.ciasaboark.tacere.activity.fragment.MainSettingsFragment.java
org.ciasaboark.tacere.activity.fragment.SelectCalendarsFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialCrashReporterFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialEndFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialEventListFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialProVersionFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialRingerPriorityFragment.java
org.ciasaboark.tacere.activity.fragment.TutorialWelcomeFragment.java
org.ciasaboark.tacere.adapter.EventCursorAdapter.java
org.ciasaboark.tacere.billing.Authenticator.java
org.ciasaboark.tacere.billing.google.Base64DecoderException.java
org.ciasaboark.tacere.billing.google.Base64.java
org.ciasaboark.tacere.billing.google.IabException.java
org.ciasaboark.tacere.billing.google.IabHelper.java
org.ciasaboark.tacere.billing.google.IabResult.java
org.ciasaboark.tacere.billing.google.Inventory.java
org.ciasaboark.tacere.billing.google.Purchase.java
org.ciasaboark.tacere.billing.google.Security.java
org.ciasaboark.tacere.billing.google.SkuDetails.java
org.ciasaboark.tacere.bug.CrashReportManager.java
org.ciasaboark.tacere.converter.DateConverterTest.java
org.ciasaboark.tacere.converter.DateConverter.java
org.ciasaboark.tacere.converter.TimeConverter.java
org.ciasaboark.tacere.database.Columns.java
org.ciasaboark.tacere.database.DataSetManager.java
org.ciasaboark.tacere.database.DatabaseInterface.java
org.ciasaboark.tacere.database.EventDatabaseOpenHelper.java
org.ciasaboark.tacere.database.NoSuchEventInstanceException.java
org.ciasaboark.tacere.database.TooltipManager.java
org.ciasaboark.tacere.event.Calendar.java
org.ciasaboark.tacere.event.EventInstance.java
org.ciasaboark.tacere.event.EventManager.java
org.ciasaboark.tacere.event.ringer.Intervals.java
org.ciasaboark.tacere.event.ringer.RingerSource.java
org.ciasaboark.tacere.event.ringer.RingerType.java
org.ciasaboark.tacere.key.ApplicationTest.java
org.ciasaboark.tacere.key.MainActivity.java
org.ciasaboark.tacere.manager.AlarmManagerWrapper.java
org.ciasaboark.tacere.manager.NotificationManagerWrapper.java
org.ciasaboark.tacere.manager.RingerStateManager.java
org.ciasaboark.tacere.manager.ServiceStateManager.java
org.ciasaboark.tacere.manager.VolumesManager.java
org.ciasaboark.tacere.notifier.WidgetNotifier.java
org.ciasaboark.tacere.prefs.BetaPrefs.java
org.ciasaboark.tacere.prefs.DefaultPrefs.java
org.ciasaboark.tacere.prefs.PrefsTest.java
org.ciasaboark.tacere.prefs.Prefs.java
org.ciasaboark.tacere.prefs.Updates.java
org.ciasaboark.tacere.receiver.BootCompletedReceiver.java
org.ciasaboark.tacere.receiver.ProviderChangedReceiver.java
org.ciasaboark.tacere.service.EventSilencerService.java
org.ciasaboark.tacere.service.ExtendEventService.java
org.ciasaboark.tacere.service.ExtendQuicksilenceService.java
org.ciasaboark.tacere.service.RequestTypes.java
org.ciasaboark.tacere.service.ResetEventServiceTest.java
org.ciasaboark.tacere.service.ResetEventService.java
org.ciasaboark.tacere.service.SkipEventService.java
org.ciasaboark.tacere.versioning.Versioning.java
org.ciasaboark.tacere.view.EventListItem.java
org.ciasaboark.tacere.widget.ActiveEventWidgetProvider.java
org.ciasaboark.tacere.widget.EventListWidgetProvider.java
org.ciasaboark.tacere.widget.QuickSilenceTinyWidgetProvider.java
org.ciasaboark.tacere.widget.QuickSilenceWidgetProvider.java
org.ciasaboark.tacere.widget.activity.WidgetPopupRinger.java
org.ciasaboark.tacere.widget.adapter.WidgetEventListAdapter.java
org.ciasaboark.tacere.widget.service.WidgetService.java