Search in sources :

Example 1 with MFBDialog

use of me.zeeroooo.materialfb.ui.MFBDialog in project MaterialFBook by ZeeRooo.

the class MoreAndCreditsFragment method onPreferenceClick.

@Override
public boolean onPreferenceClick(Preference preference) {
    switch(preference.getKey()) {
        case "changelog":
            final AlertDialog changelog = new MFBDialog(getActivity()).create();
            changelog.setTitle(getResources().getString(R.string.changelog));
            changelog.setMessage(Html.fromHtml(getResources().getString(R.string.changelog_list)));
            changelog.setCancelable(false);
            changelog.setButton(DialogInterface.BUTTON_POSITIVE, getText(android.R.string.ok), (dialogInterface, i) -> changelog.dismiss());
            changelog.show();
            return true;
    }
    return false;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) MFBDialog(me.zeeroooo.materialfb.ui.MFBDialog)

Example 2 with MFBDialog

use of me.zeeroooo.materialfb.ui.MFBDialog in project MaterialFBook by ZeeRooo.

the class NotificationsSettingsFragment method onPreferenceClick.

@Override
public boolean onPreferenceClick(Preference preference) {
    switch(preference.getKey()) {
        case "notification_channel_shortcut":
            startActivity(new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).putExtra(Settings.EXTRA_APP_PACKAGE, getActivity().getPackageName()));
            break;
        case "ringtone":
        case "ringtone_msg":
            new MFBRingtoneDialog(getActivity(), sharedPreferences, preference.getKey()).show();
            break;
        case "BlackList":
            AlertDialog blacklistDialog = new MFBDialog(getActivity()).create();
            blacklistDialog.setTitle(R.string.blacklist_title);
            final View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.chip_input, null);
            final Cursor cursor = DBHelper.getReadableDatabase().rawQuery("SELECT BL FROM mfb_table", null);
            while (cursor.moveToNext()) {
                if (cursor.getString(0) != null)
                    addRemovableChip(cursor.getString(0), rootView);
            }
            final AutoCompleteTextView autoCompleteTextView = rootView.findViewById(R.id.preloadedTags);
            autoCompleteTextView.setAdapter(new ArrayAdapter<>(rootView.getContext(), android.R.layout.simple_dropdown_item_1line));
            autoCompleteTextView.setOnItemClickListener((parent, view, position, id) -> {
                addRemovableChip((String) parent.getItemAtPosition(position), rootView);
                autoCompleteTextView.setText("");
            });
            autoCompleteTextView.setOnEditorActionListener((v, actionId, event) -> {
                if ((actionId == EditorInfo.IME_ACTION_DONE)) {
                    addRemovableChip(v.getText().toString(), rootView);
                    autoCompleteTextView.setText("");
                    return true;
                } else
                    return false;
            });
            blacklistDialog.setButton(DialogInterface.BUTTON_POSITIVE, getText(android.R.string.ok), (dialog, which) -> {
                for (int position = 0; position < blacklist.size(); position++) {
                    DBHelper.addData(null, null, blacklist.get(position));
                }
                blacklist.clear();
                if (!cursor.isClosed()) {
                    cursor.close();
                }
            });
            blacklistDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getText(android.R.string.cancel), (dialog, which) -> {
                blacklistDialog.dismiss();
                blacklist.clear();
                if (!cursor.isClosed()) {
                    cursor.close();
                }
            });
            blacklistDialog.setView(rootView);
            blacklistDialog.show();
            return true;
    }
    return false;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) MFBDialog(me.zeeroooo.materialfb.ui.MFBDialog) MFBRingtoneDialog(me.zeeroooo.materialfb.ui.MFBRingtoneDialog) Intent(android.content.Intent) Cursor(android.database.Cursor) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 3 with MFBDialog

use of me.zeeroooo.materialfb.ui.MFBDialog in project MaterialFBook by ZeeRooo.

the class SettingsFragment method onPreferenceClick.

@Override
public boolean onPreferenceClick(Preference preference) {
    switch(preference.getKey()) {
        case "notifications_settings":
            getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.content_frame, new NotificationsSettingsFragment()).commit();
            return true;
        case "navigation_menu_settings":
            getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.content_frame, new NavigationMenuFragment()).commit();
            return true;
        case "more_and_credits":
            getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.content_frame, new MoreAndCreditsFragment()).commit();
            return true;
        case "location_enabled":
            ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 1);
            return true;
        case "save_data":
        case "notif":
            setScheduler();
            return true;
        case "color_picker":
            final AlertDialog mfbColorPickerDialog = new MFBDialog(getActivity()).create();
            final TextView previewTextView = new TextView(getActivity());
            previewTextView.setTextAppearance(getActivity(), R.style.MaterialAlertDialog_MaterialComponents_Title_Text);
            previewTextView.setTextSize(22.0f);
            previewTextView.setText(R.string.color_picker_title);
            previewTextView.setPadding(24, 21, 24, 21);
            previewTextView.setBackgroundColor(Color.BLACK);
            mfbColorPickerDialog.setCustomTitle(previewTextView);
            final View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_color_picker, null);
            final EditText hexColorInput = rootView.findViewById(R.id.color_picker_hex);
            final Slider sliderRed = rootView.findViewById(R.id.color_picker_red_slider), sliderGreen = rootView.findViewById(R.id.color_picker_green_slider), sliderBlue = rootView.findViewById(R.id.color_picker_blue_slider);
            sliderRed.addOnChangeListener((slider, value, fromUser) -> {
                red = (int) value;
                setColor(previewTextView, hexColorInput);
            });
            sliderGreen.addOnChangeListener((slider, value, fromUser) -> {
                green = (int) value;
                setColor(previewTextView, hexColorInput);
            });
            sliderBlue.addOnChangeListener((slider, value, fromUser) -> {
                blue = (int) value;
                setColor(previewTextView, hexColorInput);
            });
            hexColorInput.setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
            hexColorInput.setOnEditorActionListener((textView, i, keyEvent) -> {
                colorPrimary = Color.parseColor("#" + textView.getText().toString().replace("#", ""));
                previewTextView.setBackgroundColor(colorPrimary);
                red = Color.red(colorPrimary);
                green = Color.green(colorPrimary);
                blue = Color.blue(colorPrimary);
                sliderRed.setValue(red);
                sliderGreen.setValue(green);
                sliderBlue.setValue(blue);
                return true;
            });
            final SwitchMaterial switchMaterial = rootView.findViewById(R.id.color_picker_dark_mode);
            switchMaterial.setOnCheckedChangeListener((compoundButton, b) -> {
                switchMaterial.getThumbDrawable().setColorFilter(b ? MFB.colorAccent : Color.parseColor("#ECECEC"), PorterDuff.Mode.SRC_ATOP);
                switchMaterial.getTrackDrawable().setColorFilter(b ? MFB.colorPrimaryDark : Color.parseColor("#B9B9B9"), PorterDuff.Mode.SRC_ATOP);
            });
            mfbColorPickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(android.R.string.cancel), (dialogInterface, i) -> mfbColorPickerDialog.dismiss());
            mfbColorPickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok), (dialogInterface, i) -> {
                mfbColorPickerDialog.dismiss();
                colorPrimary = Color.rgb(red, green, blue);
                int colorAccent;
                if (// it's too bright
                ColorUtils.calculateLuminance(colorPrimary) > 0.8 || (ColorUtils.calculateLuminance(MFB.colorPrimary) < 0.5 && switchMaterial.isChecked()))
                    colorAccent = Color.BLACK;
                else if (// it's too dark
                ColorUtils.calculateLuminance(colorPrimary) < 0.01 && switchMaterial.isChecked())
                    colorAccent = Color.WHITE;
                else
                    colorAccent = colorLighter(colorPrimary);
                mPreferences.edit().putInt("colorPrimary", colorPrimary).apply();
                mPreferences.edit().putInt("colorPrimaryDark", colorDarker(colorPrimary)).apply();
                mPreferences.edit().putInt("colorAccent", colorAccent).apply();
                mPreferences.edit().putBoolean("darkMode", switchMaterial.isChecked()).apply();
                getActivity().recreate();
            // CookingAToast.cooking(getActivity(), getString(R.string.required_restart), Color.WHITE, colorPrimary, R.drawable.ic_error, true).show();
            });
            mfbColorPickerDialog.setView(rootView);
            mfbColorPickerDialog.show();
            return true;
        default:
            return false;
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) EditText(android.widget.EditText) InputFilter(android.text.InputFilter) Slider(com.google.android.material.slider.Slider) View(android.view.View) TextView(android.widget.TextView) MFBDialog(me.zeeroooo.materialfb.ui.MFBDialog) SwitchMaterial(com.google.android.material.switchmaterial.SwitchMaterial) TextView(android.widget.TextView)

Aggregations

AlertDialog (androidx.appcompat.app.AlertDialog)3 MFBDialog (me.zeeroooo.materialfb.ui.MFBDialog)3 View (android.view.View)2 Intent (android.content.Intent)1 Cursor (android.database.Cursor)1 InputFilter (android.text.InputFilter)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 EditText (android.widget.EditText)1 TextView (android.widget.TextView)1 Slider (com.google.android.material.slider.Slider)1 SwitchMaterial (com.google.android.material.switchmaterial.SwitchMaterial)1 MFBRingtoneDialog (me.zeeroooo.materialfb.ui.MFBRingtoneDialog)1