Android Open Source - turbo-editor Settings Fragment






From Project

Back to project page turbo-editor.

License

The source code is released under:

GNU General Public License

If you think the Android project turbo-editor 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 Vlad Mihalachi//from   w ww  .  ja  v  a  2  s.  c  om
 *
 * This file is part of Turbo Editor.
 *
 * Turbo Editor is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Turbo Editor is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package sharedcode.turboeditor.preferences;

import android.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.TextView;

import sharedcode.turboeditor.R;
import sharedcode.turboeditor.activity.MainActivity;
import sharedcode.turboeditor.dialogfragment.EncodingDialog;
import sharedcode.turboeditor.dialogfragment.NumberPickerDialog;
import sharedcode.turboeditor.util.ProCheckUtils;
import sharedcode.turboeditor.util.ViewUtils;
import sharedcode.turboeditor.views.DialogHelper;

import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged;
import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.ENCODING;
import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.FONT_SIZE;
import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.LINE_NUMERS;
import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.MONOSPACE;
import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.READ_ONLY;
import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.SYNTAX;
import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.TEXT_SUGGESTIONS;
import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.THEME_CHANGE;
import static sharedcode.turboeditor.util.EventBusEvents.APreferenceValueWasChanged.Type.WRAP_CONTENT;

public class SettingsFragment extends Fragment implements NumberPickerDialog.INumberPickerDialog, EncodingDialog.DialogListener {

    // Editor Variables
    private boolean sLineNumbers;
    private boolean sColorSyntax;
    private boolean sWrapContent;
    private boolean sUseMonospace;
    private boolean sReadOnly;

    private boolean sLightTheme;
    private boolean sSuggestions;
    private boolean sAutoSave;
    private boolean sIgnoreBackButton;
    private boolean sSplitText;
    private boolean sErrorReports;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sUseMonospace = PreferenceHelper.getUseMonospace(getActivity());
        sColorSyntax = PreferenceHelper.getSyntaxHighlight(getActivity());
        sWrapContent = PreferenceHelper.getWrapContent(getActivity());
        sLineNumbers = PreferenceHelper.getLineNumbers(getActivity());
        sReadOnly = PreferenceHelper.getReadOnly(getActivity());

        sLightTheme = PreferenceHelper.getLightTheme(getActivity());
        sSuggestions = PreferenceHelper.getSuggestionActive(getActivity());
        sAutoSave = PreferenceHelper.getAutoSave(getActivity());
        sIgnoreBackButton = PreferenceHelper.getIgnoreBackButton(getActivity());
        sSplitText = PreferenceHelper.getSplitText(getActivity());
        sErrorReports = PreferenceHelper.getSendErrorReports(getActivity());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Our custom layout
        final View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
        final SwitchCompat swLineNumbers, swSyntax, swWrapContent, swMonospace, swReadOnly;
        final SwitchCompat swLightTheme, swSuggestions, swAutoSave, swIgnoreBackButton, swSplitText, swErrorReports;
        
        swLineNumbers = (SwitchCompat) rootView.findViewById(R.id.switch_line_numbers);
        swSyntax = (SwitchCompat) rootView.findViewById(R.id.switch_syntax);
        swWrapContent = (SwitchCompat) rootView.findViewById(R.id.switch_wrap_content);
        swMonospace = (SwitchCompat) rootView.findViewById(R.id.switch_monospace);
        swReadOnly = (SwitchCompat) rootView.findViewById(R.id.switch_read_only);

        swLightTheme = (SwitchCompat) rootView.findViewById(R.id.switch_light_theme);
        swSuggestions = (SwitchCompat) rootView.findViewById(R.id.switch_suggestions_active);
        swAutoSave = (SwitchCompat) rootView.findViewById(R.id.switch_auto_save);
        swIgnoreBackButton = (SwitchCompat) rootView.findViewById(R.id.switch_ignore_backbutton);
        swSplitText = (SwitchCompat) rootView.findViewById(R.id.switch_page_system);
        swErrorReports = (SwitchCompat) rootView.findViewById(R.id.switch_send_error_reports);

        swLineNumbers.setChecked(sLineNumbers);
        swSyntax.setChecked(sColorSyntax);
        swWrapContent.setChecked(sWrapContent);
        swMonospace.setChecked(sUseMonospace);
        swReadOnly.setChecked(sReadOnly);

        swLightTheme.setChecked(sLightTheme);
        swSuggestions.setChecked(sSuggestions);
        swAutoSave.setChecked(sAutoSave);
        swIgnoreBackButton.setChecked(sIgnoreBackButton);
        swSplitText.setChecked(sSplitText);
        swErrorReports.setChecked(sErrorReports);

        TextView fontSizeView, encodingView, donateView, extraOptionsView;
        fontSizeView = (TextView) rootView.findViewById(R.id.drawer_button_font_size);
        encodingView = (TextView) rootView.findViewById(R.id.drawer_button_encoding);
        extraOptionsView = (TextView) rootView.findViewById(R.id.drawer_button_extra_options);
        donateView = (TextView) rootView.findViewById(R.id.drawer_button_go_pro);

        if(ProCheckUtils.isPro(getActivity(), false))
            ViewUtils.setVisible(donateView, false);

        swLineNumbers.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceHelper.setLineNumbers(getActivity(), isChecked);
                ((MainActivity) getActivity()).onEvent(new APreferenceValueWasChanged(LINE_NUMERS));
            }
        });

        swSyntax.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                sColorSyntax = isChecked;
                PreferenceHelper.setSyntaxHighlight(getActivity(), isChecked);
                ((MainActivity) getActivity()).onEvent(new APreferenceValueWasChanged(SYNTAX));

            }
        });

        swWrapContent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceHelper.setWrapContent(getActivity(), isChecked);
                ((MainActivity) getActivity()).onEvent(new APreferenceValueWasChanged(WRAP_CONTENT));
            }
        });

        swMonospace.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                sUseMonospace = isChecked;
                PreferenceHelper.setUseMonospace(getActivity(), isChecked);
                ((MainActivity) getActivity()).onEvent(new APreferenceValueWasChanged(MONOSPACE));

            }
        });

        swReadOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceHelper.setReadOnly(getActivity(), isChecked);
                ((MainActivity) getActivity()).onEvent(new APreferenceValueWasChanged(READ_ONLY));
            }
        });

        fontSizeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int fontMax = 36;
                int fontCurrent = //(int) (mEditor.getTextSize() / scaledDensity);
                        //fontMax / 2;
                        PreferenceHelper.getFontSize(getActivity());
                NumberPickerDialog dialogFrag = NumberPickerDialog.newInstance(NumberPickerDialog
                        .Actions
                        .FontSize, 1, fontCurrent, fontMax);
                dialogFrag.setTargetFragment(SettingsFragment.this, 0);
                dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
            }
        });

        encodingView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EncodingDialog dialogFrag = EncodingDialog.newInstance();
                dialogFrag.setTargetFragment(SettingsFragment.this, 0);
                dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
            }
        });

        extraOptionsView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View otherOptions = rootView.findViewById(R.id.other_options);
                boolean isVisible = otherOptions.getVisibility() == View.VISIBLE;
                ViewUtils.setVisible(otherOptions, !isVisible);
            }
        });

        donateView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogHelper.showDonateDialog(getActivity());
            }
        });

        swLightTheme.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceHelper.setLightTheme(getActivity(), isChecked);
                ((MainActivity) getActivity()).onEvent(new APreferenceValueWasChanged(THEME_CHANGE));
            }
        });

        swSuggestions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceHelper.setSuggestionsActive(getActivity(), isChecked);
                ((MainActivity) getActivity()).onEvent(new APreferenceValueWasChanged(TEXT_SUGGESTIONS));
            }
        });

        swAutoSave.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceHelper.setAutoSave(getActivity(), isChecked);
            }
        });

        swIgnoreBackButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceHelper.setIgnoreBackButton(getActivity(), isChecked);
            }
        });

        swSplitText.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceHelper.setSplitText(getActivity(), isChecked);
            }
        });

        swErrorReports.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                PreferenceHelper.setSendErrorReport(getActivity(), isChecked);
            }
        });

        return rootView;
    }

    @Override
    public void onNumberPickerDialogDismissed(NumberPickerDialog.Actions action, int value) {
        PreferenceHelper.setFontSize(getActivity(), value);
        ((MainActivity) getActivity()).onEvent(new APreferenceValueWasChanged(FONT_SIZE));

    }

    @Override
    public void onEncodingSelected(String result) {
        PreferenceHelper.setEncoding(getActivity(), result);
        ((MainActivity) getActivity()).onEvent(new APreferenceValueWasChanged(ENCODING));
    }
}




Java Source Code List

com.faizmalkani.floatingactionbutton.BuildConfig.java
com.faizmalkani.floatingactionbutton.BuildConfig.java
com.faizmalkani.floatingactionbutton.DirectionScrollListener.java
com.faizmalkani.floatingactionbutton.FloatingActionButton.java
com.maskyn.fileeditor.AdsHelper.java
com.maskyn.fileeditor.ApplicationTest.java
com.maskyn.fileeditor.HomeActivity.java
com.maskyn.fileeditorpro.ApplicationTest.java
com.maskyn.fileeditorpro.HomeActivity.java
org.sufficientlysecure.rootcommands.Mount.java
org.sufficientlysecure.rootcommands.Remounter.java
org.sufficientlysecure.rootcommands.RootCommands.java
org.sufficientlysecure.rootcommands.Shell.java
org.sufficientlysecure.rootcommands.SystemCommands.java
org.sufficientlysecure.rootcommands.Toolbox.java
org.sufficientlysecure.rootcommands.command.Command.java
org.sufficientlysecure.rootcommands.command.ExecutableCommand.java
org.sufficientlysecure.rootcommands.command.SimpleCommand.java
org.sufficientlysecure.rootcommands.command.SimpleExecutableCommand.java
org.sufficientlysecure.rootcommands.util.BrokenBusyboxException.java
org.sufficientlysecure.rootcommands.util.Log.java
org.sufficientlysecure.rootcommands.util.RootAccessDeniedException.java
org.sufficientlysecure.rootcommands.util.UnsupportedArchitectureException.java
org.sufficientlysecure.rootcommands.util.Utils.java
sharedcode.turboeditor.ApplicationTest.java
sharedcode.turboeditor.activity.MainActivity.java
sharedcode.turboeditor.activity.SelectFileActivity.java
sharedcode.turboeditor.adapter.AdapterDetailedList.java
sharedcode.turboeditor.adapter.AdapterDrawer.java
sharedcode.turboeditor.adapter.AdapterTwoItem.java
sharedcode.turboeditor.application.MyApp.java
sharedcode.turboeditor.dialogfragment.AboutDialog.java
sharedcode.turboeditor.dialogfragment.ChangelogDialog.java
sharedcode.turboeditor.dialogfragment.EditTextDialog.java
sharedcode.turboeditor.dialogfragment.EncodingDialog.java
sharedcode.turboeditor.dialogfragment.FileInfoDialog.java
sharedcode.turboeditor.dialogfragment.FindTextDialog.java
sharedcode.turboeditor.dialogfragment.NewFileDetailsDialog.java
sharedcode.turboeditor.dialogfragment.NumberPickerDialog.java
sharedcode.turboeditor.dialogfragment.SaveFileDialog.java
sharedcode.turboeditor.iab.DonationAdapter.java
sharedcode.turboeditor.iab.DonationFragment.java
sharedcode.turboeditor.iab.DonationItems.java
sharedcode.turboeditor.iab.Donation.java
sharedcode.turboeditor.iab.utils.Base64DecoderException.java
sharedcode.turboeditor.iab.utils.Base64.java
sharedcode.turboeditor.iab.utils.IabException.java
sharedcode.turboeditor.iab.utils.IabHelper.java
sharedcode.turboeditor.iab.utils.IabResult.java
sharedcode.turboeditor.iab.utils.Inventory.java
sharedcode.turboeditor.iab.utils.Purchase.java
sharedcode.turboeditor.iab.utils.Security.java
sharedcode.turboeditor.iab.utils.SkuDetails.java
sharedcode.turboeditor.preferences.PreferenceHelper.java
sharedcode.turboeditor.preferences.SettingsFragment.java
sharedcode.turboeditor.root.LinuxShell.java
sharedcode.turboeditor.root.RootUtils.java
sharedcode.turboeditor.task.SaveFileTask.java
sharedcode.turboeditor.texteditor.EditTextPadding.java
sharedcode.turboeditor.texteditor.FileUtils.java
sharedcode.turboeditor.texteditor.LineUtils.java
sharedcode.turboeditor.texteditor.PageSystemButtons.java
sharedcode.turboeditor.texteditor.PageSystem.java
sharedcode.turboeditor.texteditor.Patterns.java
sharedcode.turboeditor.texteditor.SearchResult.java
sharedcode.turboeditor.util.AccessStorageApi.java
sharedcode.turboeditor.util.AlphanumComparator.java
sharedcode.turboeditor.util.AnimationUtils.java
sharedcode.turboeditor.util.AppInfoHelper.java
sharedcode.turboeditor.util.Build.java
sharedcode.turboeditor.util.Device.java
sharedcode.turboeditor.util.EventBusEvents.java
sharedcode.turboeditor.util.IHomeActivity.java
sharedcode.turboeditor.util.MimeTypes.java
sharedcode.turboeditor.util.PixelDipConverter.java
sharedcode.turboeditor.util.ProCheckUtils.java
sharedcode.turboeditor.util.ThemeUtils.java
sharedcode.turboeditor.util.ToastUtils.java
sharedcode.turboeditor.util.ViewUtils.java
sharedcode.turboeditor.util.systemui.SystemUiHelperImplHC.java
sharedcode.turboeditor.util.systemui.SystemUiHelperImplICS.java
sharedcode.turboeditor.util.systemui.SystemUiHelperImplJB.java
sharedcode.turboeditor.util.systemui.SystemUiHelperImplKK.java
sharedcode.turboeditor.util.systemui.SystemUiHelper.java
sharedcode.turboeditor.views.CustomDrawerLayout.java
sharedcode.turboeditor.views.DialogHelper.java
sharedcode.turboeditor.views.GoodScrollView.java