<commit_before>package com.garethevans.church.opensongtablet;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class PopUpEditStickyFragment extends DialogFragment {

    static PopUpEditStickyFragment newInstance() {
        PopUpEditStickyFragment frag;
        frag = new PopUpEditStickyFragment();
        return frag;
    }

    public interface MyInterface {
        void loadSong();
        void pageButtonAlpha(String s);
    }

    private MyInterface mListener;

    private TextView stickyNotesWidth_TextView, stickyNotesOpacity_TextView;
    private EditText editStickyText;
    private Preferences preferences;
    private StorageAccess storageAccess;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        mListener = (MyInterface) context;
    }

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

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        if (savedInstanceState != null) {
            this.dismiss();
        }
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (getDialog()!=null) {
            getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
            getDialog().setCanceledOnTouchOutside(true);
        }
        View V = inflater.inflate(R.layout.popup_editsticky, container, false);

        TextView title = V.findViewById(R.id.dialogtitle);
        title.setText(getString(R.string.stickynotes_edit));
        final FloatingActionButton closeMe = V.findViewById(R.id.closeMe);
        closeMe.setOnClickListener(view -> {
            CustomAnimations.animateFAB(closeMe,getContext());
            closeMe.setEnabled(false);
            dismiss();
        });
        final FloatingActionButton saveMe = V.findViewById(R.id.saveMe);
        saveMe.setOnClickListener(view -> {
            CustomAnimations.animateFAB(saveMe,getContext());
            saveMe.setEnabled(false);
            doSave();
        });

        preferences = new Preferences();
        storageAccess = new StorageAccess();

        // Initialise the views
        editStickyText = V.findViewById(R.id.editStickyText);
        SeekBar stickyNotesWidth_SeekBar = V.findViewById(R.id.stickyNotesWidth_SeekBar);
        stickyNotesWidth_TextView = V.findViewById(R.id.stickyNotesWidth_TextView);
        SeekBar stickyNotesOpacity_SeekBar = V.findViewById(R.id.stickyNotesOpacity_SeekBar);
        stickyNotesOpacity_TextView = V.findViewById(R.id.stickyNotesOpacity_TextView);
        SwitchCompat stickyTextSize = V.findViewById(R.id.stickyTextSize);

        // Set the text if it exists
        editStickyText.setText(StaticVariables.mNotes);
        int sw = preferences.getMyPreferenceInt(getContext(),"stickyWidth",400);
        String s = ""+sw;
        stickyNotesWidth_TextView.setText(s);
        stickyNotesWidth_SeekBar.setProgress(sw-200);
        int val = (int) (preferences.getMyPreferenceFloat(getContext(),"stickyOpacity",0.8f) * 10) - 2;
        stickyNotesOpacity_SeekBar.setProgress(val);
        s =  ((int) (preferences.getMyPreferenceFloat(getContext(),"stickyOpacity",0.8f)*100)) + "%";
        stickyNotesOpacity_TextView.setText(s);
        // Set the switch up based on preferences
        stickyTextSize.setChecked(preferences.getMyPreferenceBoolean(getContext(),"stickyLargeFont",true));

        stickyTextSize.setOnCheckedChangeListener((compoundButton, b) -> preferences.setMyPreferenceBoolean(getContext(),"stickyLargeFont",b));

        stickyNotesWidth_SeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                String s = ""+(i+200);
                stickyNotesWidth_TextView.setText(s);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                int i = seekBar.getProgress() + 200;
                preferences.setMyPreferenceInt(getContext(),"stickyWidth",i);
            }
        });
        stickyNotesOpacity_SeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                i = (int)((i+2.0f)/10.0f);
                String s =  (i*100) + "%";
                stickyNotesOpacity_TextView.setText(s);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                float i = (int)((seekBar.getProgress()+2.0f)/10.0f);
                preferences.setMyPreferenceFloat(getContext(),"stickyOpacity",i);
            }
        });
        PopUpSizeAndAlpha.decoratePopUp(getActivity(),getDialog(), preferences);

        return V;
    }

    private void doSave() {
        StaticVariables.mNotes = editStickyText.getText().toString();
        // Save the file
        PopUpEditSongFragment.prepareSongXML();

        if (FullscreenActivity.isPDF || FullscreenActivity.isImage) {<commit_msg>Fix sticky note alpha resetting to 0 or 1<commit_after>package com.garethevans.church.opensongtablet;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class PopUpEditStickyFragment extends DialogFragment {

    static PopUpEditStickyFragment newInstance() {
        PopUpEditStickyFragment frag;
        frag = new PopUpEditStickyFragment();
        return frag;
    }

    public interface MyInterface {
        void loadSong();
        void pageButtonAlpha(String s);
    }

    private MyInterface mListener;

    private TextView stickyNotesWidth_TextView, stickyNotesOpacity_TextView;
    private EditText editStickyText;
    private Preferences preferences;
    private StorageAccess storageAccess;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        mListener = (MyInterface) context;
    }

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

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        if (savedInstanceState != null) {
            this.dismiss();
        }
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (getDialog()!=null) {
            getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
            getDialog().setCanceledOnTouchOutside(true);
        }
        View V = inflater.inflate(R.layout.popup_editsticky, container, false);

        TextView title = V.findViewById(R.id.dialogtitle);
        title.setText(getString(R.string.stickynotes_edit));
        final FloatingActionButton closeMe = V.findViewById(R.id.closeMe);
        closeMe.setOnClickListener(view -> {
            CustomAnimations.animateFAB(closeMe,getContext());
            closeMe.setEnabled(false);
            dismiss();
        });
        final FloatingActionButton saveMe = V.findViewById(R.id.saveMe);
        saveMe.setOnClickListener(view -> {
            CustomAnimations.animateFAB(saveMe,getContext());
            saveMe.setEnabled(false);
            doSave();
        });

        preferences = new Preferences();
        storageAccess = new StorageAccess();

        // Initialise the views
        editStickyText = V.findViewById(R.id.editStickyText);
        SeekBar stickyNotesWidth_SeekBar = V.findViewById(R.id.stickyNotesWidth_SeekBar);
        stickyNotesWidth_TextView = V.findViewById(R.id.stickyNotesWidth_TextView);
        SeekBar stickyNotesOpacity_SeekBar = V.findViewById(R.id.stickyNotesOpacity_SeekBar);
        stickyNotesOpacity_TextView = V.findViewById(R.id.stickyNotesOpacity_TextView);
        SwitchCompat stickyTextSize = V.findViewById(R.id.stickyTextSize);

        // Set the text if it exists
        editStickyText.setText(StaticVariables.mNotes);
        int sw = preferences.getMyPreferenceInt(getContext(),"stickyWidth",400);
        String s = ""+sw;
        stickyNotesWidth_TextView.setText(s);
        stickyNotesWidth_SeekBar.setProgress(sw-200);
        int val = (int) (preferences.getMyPreferenceFloat(getContext(),"stickyOpacity",0.8f) * 10) - 2;
        stickyNotesOpacity_SeekBar.setProgress(val);
        s =  ((int) (preferences.getMyPreferenceFloat(getContext(),"stickyOpacity",0.8f)*100)) + "%";
        stickyNotesOpacity_TextView.setText(s);
        // Set the switch up based on preferences
        stickyTextSize.setChecked(preferences.getMyPreferenceBoolean(getContext(),"stickyLargeFont",true));

        stickyTextSize.setOnCheckedChangeListener((compoundButton, b) -> preferences.setMyPreferenceBoolean(getContext(),"stickyLargeFont",b));

        stickyNotesWidth_SeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                String s = ""+(i+200);
                stickyNotesWidth_TextView.setText(s);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                int i = seekBar.getProgress() + 200;
                preferences.setMyPreferenceInt(getContext(),"stickyWidth",i);
            }
        });
        stickyNotesOpacity_SeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                i = (int)((i+2.0f)*10.0f);
                String s =  i + "%";
                stickyNotesOpacity_TextView.setText(s);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                float f = (seekBar.getProgress()+2.0f)/10.0f;
                Log.d("d","f="+f);
                preferences.setMyPreferenceFloat(getContext(),"stickyOpacity",f);
            }
        });
        PopUpSizeAndAlpha.decoratePopUp(getActivity(),getDialog(), preferences);

        return V;
    }

    private void doSave() {
        StaticVariables.mNotes = editStickyText.getText().toString();
        // Save the file
        PopUpEditSongFragment.prepareSongXML();

        if (FullscreenActivity.isPDF || FullscreenActivity.isImage) {
{'fraction_non_alphanumeric': 0.09640287769784173, 'fraction_numerical': 0.005840033855268726, 'mean_word_length': 2.869024230517354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3406898', 'n_tokens_mistral': 3424, 'n_tokens_neox': 3237, 'n_words': 557}