Search in sources :

Example 1 with BorderCircleView

use of com.moro.mtweaks.views.BorderCircleView in project MTweaks-KernelAdiutorMOD by morogoku.

the class SettingsFragment method colorDialog.

private void colorDialog(int selection) {
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    int padding = (int) getResources().getDimension(R.dimen.dialog_padding);
    linearLayout.setPadding(padding, padding, padding, padding);
    final List<BorderCircleView> circles = new ArrayList<>();
    LinearLayout subView = null;
    for (int i = 0; i < BorderCircleView.sAccentColors.size(); i++) {
        if (subView == null || i % 5 == 0) {
            subView = new LinearLayout(getActivity());
            subView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            linearLayout.addView(subView);
        }
        BorderCircleView circle = new BorderCircleView(getActivity());
        circle.setChecked(i == selection);
        circle.setBackgroundColor(ContextCompat.getColor(getActivity(), BorderCircleView.sAccentColors.keyAt(i)));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1);
        int margin = (int) getResources().getDimension(R.dimen.color_dialog_margin);
        params.setMargins(margin, margin, margin, margin);
        circle.setLayoutParams(params);
        circle.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                for (BorderCircleView borderCircleView : circles) {
                    if (v == borderCircleView) {
                        borderCircleView.setChecked(true);
                        mColorSelection = circles.indexOf(borderCircleView);
                    } else {
                        borderCircleView.setChecked(false);
                    }
                }
            }
        });
        circles.add(circle);
        subView.addView(circle);
    }
    new Dialog(getActivity()).setView(linearLayout).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (mColorSelection >= 0) {
                Prefs.saveString(KEY_ACCENT_COLOR, BorderCircleView.sAccentColors.valueAt(mColorSelection), getActivity());
            }
            getActivity().finish();
            Intent intent = new Intent(getActivity(), MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    }).setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            mColorSelection = -1;
        }
    }).show();
}
Also used : DialogInterface(android.content.DialogInterface) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) Intent(android.content.Intent) MainActivity(com.moro.mtweaks.activities.MainActivity) View(android.view.View) BorderCircleView(com.moro.mtweaks.views.BorderCircleView) Dialog(com.moro.mtweaks.views.dialog.Dialog) ProgressDialog(android.app.ProgressDialog) AlertDialog(android.support.v7.app.AlertDialog) BorderCircleView(com.moro.mtweaks.views.BorderCircleView) LinearLayout(android.widget.LinearLayout)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 LinearLayout (android.widget.LinearLayout)1 MainActivity (com.moro.mtweaks.activities.MainActivity)1 BorderCircleView (com.moro.mtweaks.views.BorderCircleView)1 Dialog (com.moro.mtweaks.views.dialog.Dialog)1 ArrayList (java.util.ArrayList)1