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();
}
Aggregations