--- /dev/null
+/*
+ * Copyright © 2019 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe 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 terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.ui.profiles;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+import net.ktnx.mobileledger.utils.Colors;
+
+import androidx.appcompat.widget.AppCompatTextView;
+
+public class MoLeColoredTextView extends AppCompatTextView {
+ public MoLeColoredTextView(Context context) {
+ super(context);
+ }
+ public MoLeColoredTextView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+ public MoLeColoredTextView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+ @Override
+ public void setText(CharSequence text, BufferType type) {
+ super.setText(text, type);
+ int deg = (text == null || text.equals("")) ? -1 : Integer.valueOf(String.valueOf(text));
+ if (deg == -1) deg = Colors.DEFAULT_HUE_DEG;
+ setBackgroundColor(Colors.getPrimaryColorForHue(deg));
+ }
+}
import android.app.Activity;
import android.content.Context;
-import android.os.Build;
+import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import net.ktnx.mobileledger.ui.activity.ProfileDetailActivity;
import net.ktnx.mobileledger.utils.Colors;
-import org.jetbrains.annotations.NotNull;
-
import java.util.List;
import androidx.annotation.ColorInt;
passwordLayout = rootView.findViewById(R.id.password_layout);
colorSpinner = rootView.findViewById(R.id.colorSpinner);
- ArrayAdapter<CharSequence> adapter = ColorListAdapter
- .createFromResource(rootView.getContext(), R.array.profile_colors,
- R.layout.color_selector_item);
-// Log.d("profiles", String.format("color count: %s", adapter.getCount()));
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ ColorListAdapter adapter =
+ new ColorListAdapter(rootView.getContext(), R.layout.color_selector_item);
+ adapter.add(-1);
+ for (int i = 0; i < 360; i += 15) adapter.add(i);
+ Log.d("profiles", String.format("color count: %s", adapter.getCount()));
+// adapter.setDropDownViewResource(R.layout.color_selector_item);
colorSpinner.setAdapter(adapter);
colorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final int primaryColor;
- final int degrees =
- Integer.valueOf((String) (parent.getAdapter().getItem(position)));
+ final int degrees = (Integer) parent.getAdapter().getItem(position);
if (degrees < 0) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- if (getActivity() != null) primaryColor = getResources()
- .getColor(R.color.colorPrimary, getActivity().getTheme());
- else primaryColor = Colors.getPrimaryColorForHue(Colors.DEFAULT_HUE_DEG);
- }
- else {
- primaryColor = getResources().getColor(R.color.colorPrimary);
- }
+ primaryColor = Colors.getPrimaryColorForHue(Colors.DEFAULT_HUE_DEG);
}
else primaryColor = Colors.getPrimaryColorForHue(degrees);
return valid;
}
- private class ColorListAdapter extends ArrayAdapter<String> {
+ private class ColorListAdapter extends ArrayAdapter<Integer> {
public ColorListAdapter(@NonNull Context context, int resource) {
super(context, resource);
}
public ColorListAdapter(@NonNull Context context, int resource, int textViewResourceId) {
super(context, resource, textViewResourceId);
}
- public ColorListAdapter(@NonNull Context context, int resource, @NonNull String[] objects) {
+ public ColorListAdapter(@NonNull Context context, int resource,
+ @NonNull Integer[] objects) {
super(context, resource, objects);
}
public ColorListAdapter(@NonNull Context context, int resource, int textViewResourceId,
- @NonNull String[] objects) {
+ @NonNull Integer[] objects) {
super(context, resource, textViewResourceId, objects);
}
public ColorListAdapter(@NonNull Context context, int resource,
- @NonNull List<String> objects) {
+ @NonNull List<Integer> objects) {
super(context, resource, objects);
}
public ColorListAdapter(@NonNull Context context, int resource, int textViewResourceId,
- @NonNull List<String> objects) {
+ @NonNull List<Integer> objects) {
super(context, resource, textViewResourceId, objects);
}
- @NotNull
@Override
- public View getView(int position, View convertView, @NotNull ViewGroup parent) {
- String hueStr = getItem(position);
- int hue = (hueStr == null) ? -1 : Integer.valueOf(hueStr);
+ public @NonNull
+ View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
+ Integer hueDeg = getItem(position);
+ int hue = ((hueDeg == null) || (hueDeg == -1)) ? Colors.DEFAULT_HUE_DEG : hueDeg;
@ColorInt int primaryColor = Colors.getPrimaryColorForHue(hue);
View view = convertView;
if (convertView == null) {
- view = getLayoutInflater().inflate(R.layout.color_selector_item, parent);
+ view = getLayoutInflater().inflate(R.layout.color_selector_item, null);
}
- view.setBackgroundColor(primaryColor);
+ view.setBackground(new ColorDrawable(primaryColor));
return view;
}
}