diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-03-25 17:02:10 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-03-25 17:02:10 +0300 |
commit | 4268054637aa236109f492c8ef32d8dd17194298 (patch) | |
tree | 30d8eefb005dcb76db57029e6dfa84ec65322dd7 /app/src/main/java/it/niedermann/nextcloud/deck/ui/view | |
parent | ab2330fc9a7f7dd1cffa2640adab652cd20964ca (diff) |
Move all pure view into one package
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/view')
4 files changed, 267 insertions, 0 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ColorChooser.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ColorChooser.java new file mode 100644 index 000000000..fb61ab7bc --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ColorChooser.java @@ -0,0 +1,121 @@ +package it.niedermann.nextcloud.deck.ui.view; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; + +import androidx.annotation.Nullable; + +import com.skydoves.colorpickerview.ColorEnvelope; +import com.skydoves.colorpickerview.ColorPickerView; +import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener; +import com.skydoves.colorpickerview.sliders.BrightnessSlideBar; + +import it.niedermann.nextcloud.deck.R; +import it.niedermann.nextcloud.deck.databinding.WidgetColorChooserBinding; +import it.niedermann.nextcloud.deck.util.ViewUtil; + +public class ColorChooser extends LinearLayout { + + private WidgetColorChooserBinding binding; + + private Context context; + private String[] colors; + + private String selectedColor; + private String previouslySelectedColor; + private ImageView previouslySelectedImageView; + + private Boolean hasCustomColor = false; + private ColorPickerView customColorPicker; + private BrightnessSlideBar brightnessSlideBar; + private ImageView customColorChooser; + + public ColorChooser(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + this.context = context; + + TypedArray a = context.obtainStyledAttributes(attrs, + R.styleable.ColorChooser, 0, 0); + colors = getResources().getStringArray(a.getResourceId(R.styleable.ColorChooser_colors, 0)); + a.recycle(); + + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + binding = WidgetColorChooserBinding.inflate(inflater, this, true); + initDefaultColors(); + + customColorPicker = (ColorPickerView) findViewById(R.id.customColorPicker); + brightnessSlideBar = findViewById(R.id.brightnessSlide); + + customColorPicker.attachBrightnessSlider(brightnessSlideBar); + + customColorPicker.setColorListener(new ColorEnvelopeListener() { + @Override + public void onColorSelected(ColorEnvelope envelope, boolean fromUser) { + String customColor = "#" + envelope.getHexCode().substring(2); + selectedColor = customColor; + previouslySelectedColor = customColor; + //previouslySelectedColor = customColor; + customColorChooser.setImageDrawable(ViewUtil.getTintedImageView(context, R.drawable.circle_alpha_colorize_36dp, selectedColor)); + } + }); + } + + private void initDefaultColors() { + for (final String color : colors) { + ImageView image = new ImageView(getContext()); + image.setOnClickListener((imageView) -> { + if (previouslySelectedImageView != null) { // null when first selection + previouslySelectedImageView.setImageDrawable(ViewUtil.getTintedImageView(this.context, R.drawable.circle_grey600_36dp, previouslySelectedColor)); + } + image.setImageDrawable(ViewUtil.getTintedImageView(this.context, R.drawable.circle_alpha_check_36dp, color)); + selectedColor = color; + this.previouslySelectedColor = color; + this.previouslySelectedImageView = image; + }); + image.setImageDrawable(ViewUtil.getTintedImageView(this.context, R.drawable.circle_grey600_36dp, color)); + binding.colorPicker.addView(image); + } + } + + private void initCustomColorChooser() { + // initializes a final image icon for the custom color chooser and, if already set, + // will set the icon color to the custom color + customColorChooser = new ImageView(getContext()); + if (!hasCustomColor) { + customColorChooser.setImageDrawable(ViewUtil.getTintedImageView(this.context, R.drawable.circle_alpha_colorize_36dp, R.color.board_default_custom_color)); + } else { + customColorChooser.setImageDrawable(ViewUtil.getTintedImageView(this.context, R.drawable.circle_alpha_colorize_36dp, this.selectedColor)); + } + binding.colorPicker.addView(customColorChooser); + customColorChooser.setOnClickListener((View imageView) -> { + // when clicked sets the custom color wheel to be visible + customColorPicker.setVisibility(View.VISIBLE); + brightnessSlideBar.setVisibility(View.VISIBLE); + }); + } + + public void selectColor(String newColor) { + selectedColor = newColor; + for (int i = 0; i < colors.length; i++) { + if (colors[i].equals(newColor)) { + initCustomColorChooser(); // adds custom color picker, with default color + binding.colorPicker.getChildAt(i).performClick(); + return; + } + } + // if the board color is not found to be a default color, then a custom color is assumed and + // the custom color chooser is setup for this + hasCustomColor = true; + initCustomColorChooser(); // adds custom color picker, with custom color + } + + public String getSelectedColor() { + return this.selectedColor; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/EmptyContentView.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/EmptyContentView.java new file mode 100644 index 000000000..70fcb1ead --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/EmptyContentView.java @@ -0,0 +1,46 @@ +package it.niedermann.nextcloud.deck.ui.view; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.RelativeLayout; + +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; + +import it.niedermann.nextcloud.deck.R; +import it.niedermann.nextcloud.deck.databinding.WidgetEmptyContentViewBinding; + +public class EmptyContentView extends RelativeLayout { + + private static final int NO_DESCRIPTION = -1; + + private WidgetEmptyContentViewBinding binding; + + public EmptyContentView(@NonNull Context context, AttributeSet attrs) { + super(context, attrs); + + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + binding = WidgetEmptyContentViewBinding.inflate(inflater, this, true); + + TypedArray a = context.obtainStyledAttributes(attrs, + R.styleable.EmptyContentView, 0, 0); + + @StringRes int descriptionRes = a.getResourceId(R.styleable.EmptyContentView_description, NO_DESCRIPTION); + + binding.title.setText(getResources().getString(a.getResourceId(R.styleable.EmptyContentView_title, R.string.no_content))); + if (descriptionRes == NO_DESCRIPTION) { + binding.description.setVisibility(View.GONE); + } else { + binding.description.setText(getResources().getString(descriptionRes)); + } + binding.image.setImageResource(a.getResourceId(R.styleable.EmptyContentView_image, R.drawable.ic_app_logo)); + a.recycle(); + } + + public void hideDescription() { + binding.description.setVisibility(View.GONE); + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/SquareRelativeLayout.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/SquareRelativeLayout.java new file mode 100644 index 000000000..7f3649c94 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/SquareRelativeLayout.java @@ -0,0 +1,34 @@ +package it.niedermann.nextcloud.deck.ui.view; + +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; +import android.util.AttributeSet; +import android.widget.RelativeLayout; + +public class SquareRelativeLayout extends RelativeLayout { + + public SquareRelativeLayout(Context context) { + super(context); + } + + public SquareRelativeLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + // Set a square layout. + super.onMeasure(widthMeasureSpec, widthMeasureSpec); + } + +}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ToggleAutoCompleteTextView.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ToggleAutoCompleteTextView.java new file mode 100644 index 000000000..7958e9f29 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/view/ToggleAutoCompleteTextView.java @@ -0,0 +1,66 @@ +package it.niedermann.nextcloud.deck.ui.view; + +import android.content.Context; +import android.graphics.Rect; +import android.os.Build; +import android.util.AttributeSet; +import android.widget.AdapterView; + +import androidx.annotation.RequiresApi; +import androidx.appcompat.widget.AppCompatAutoCompleteTextView; + +/** + * This AutoCompleteTextView implementation closes the dropdown on each second click + */ +public class ToggleAutoCompleteTextView extends AppCompatAutoCompleteTextView { + + private boolean hideOnNextClick = false; + + public ToggleAutoCompleteTextView(Context context, AttributeSet attrs) { + super(context, attrs); + setOnClickListener((v) -> { + if (hideOnNextClick) { + dismissDropDown(); + } else { + performFiltering(getText(), 0); + showDropDown(); + } + hideOnNextClick = !hideOnNextClick; + }); + } + + @Override + public void setOnItemClickListener(AdapterView.OnItemClickListener l) { + super.setOnItemClickListener((parent, view, position, id) -> { + l.onItemClick(parent, view, position, id); + hideOnNextClick = false; + }); + } + + @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) + @Override + public void setOnDismissListener(OnDismissListener dismissListener) { + super.setOnDismissListener(() -> { + dismissListener.onDismiss(); + hideOnNextClick = true; + }); + } + + @Override + public boolean enoughToFilter() { + return true; + } + + @Override + protected void onFocusChanged(boolean focused, int direction, + Rect previouslyFocusedRect) { + super.onFocusChanged(focused, direction, previouslyFocusedRect); + if (focused && getAdapter() != null) { + hideOnNextClick = true; + performFiltering(getText(), 0); + showDropDown(); + } else { + hideOnNextClick = false; + } + } +} |