Browse Source

add animations for markdown button expand/collapse, prevent edittext from going full screen on landscape

pull/61/merge
Thodoris1999 6 years ago
parent
commit
bcfdcbe6cd
  1. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java
  2. 104
      app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java

6
app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java

@ -90,7 +90,7 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
layoutManager.setReverseLayout(true); layoutManager.setReverseLayout(true);
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
recyclerView.setOnTouchListener((view, motionEvent) -> { recyclerView.setOnTouchListener((view, motionEvent) -> {
editorView.setMarkdownVisible(false); editorView.hideMarkdown();
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0); imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0);
return false; return false;
@ -117,9 +117,9 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
.execute(shoutbox.getSendShoutUrl(), editorView.getText().toString(), shoutbox.getSc(), .execute(shoutbox.getSendShoutUrl(), editorView.getText().toString(), shoutbox.getSc(),
shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl()); shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl());
}); });
editorView.setMarkdownVisible(false); editorView.hideMarkdown();
editorView.setOnTouchListener((view, motionEvent) -> { editorView.setOnTouchListener((view, motionEvent) -> {
editorView.setMarkdownVisible(true); editorView.showMarkdown();
return false; return false;
}); });
editorView.setMarkdownVisible(false); editorView.setMarkdownVisible(false);

104
app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.editorview; package gr.thmmy.mthmmy.editorview;
import android.animation.Animator;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -12,6 +13,8 @@ import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@ -27,12 +30,14 @@ import java.util.Objects;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageButton; import androidx.appcompat.widget.AppCompatImageButton;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
public class EditorView extends LinearLayout { public class EditorView extends LinearLayout {
private static final int ANIMATION_DURATION = 100;
private SparseArray<String> colors = new SparseArray<>(); private SparseArray<String> colors = new SparseArray<>();
private TextInputLayout edittextWrapper; private TextInputLayout edittextWrapper;
@ -40,6 +45,7 @@ public class EditorView extends LinearLayout {
private AppCompatImageButton emojiButton; private AppCompatImageButton emojiButton;
private AppCompatImageButton submitButton; private AppCompatImageButton submitButton;
private EmojiKeyboard.EmojiKeyboardOwner emojiKeyboardOwner; private EmojiKeyboard.EmojiKeyboardOwner emojiKeyboardOwner;
private RecyclerView formatButtonsRecyclerview;
public EditorView(Context context) { public EditorView(Context context) {
super(context); super(context);
@ -61,8 +67,14 @@ public class EditorView extends LinearLayout {
LayoutInflater.from(context).inflate(R.layout.editor_view, this, true); LayoutInflater.from(context).inflate(R.layout.editor_view, this, true);
setOrientation(VERTICAL); setOrientation(VERTICAL);
formatButtonsRecyclerview = findViewById(R.id.buttons_recyclerview);
edittextWrapper = findViewById(R.id.editor_edittext_wrapper); edittextWrapper = findViewById(R.id.editor_edittext_wrapper);
editText = findViewById(R.id.editor_edittext); editText = findViewById(R.id.editor_edittext);
editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
editText.setOnTouchListener((v, event) -> {
if (emojiKeyboardOwner.isEmojiKeyboardVisible()) return true;
return false;
});
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EditorView, 0, 0); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.EditorView, 0, 0);
try { try {
@ -79,11 +91,6 @@ public class EditorView extends LinearLayout {
emojiButton = findViewById(R.id.emoji_keyboard_button); emojiButton = findViewById(R.id.emoji_keyboard_button);
editText.setOnTouchListener((v, event) -> {
if (emojiKeyboardOwner.isEmojiKeyboardVisible()) return true;
return false;
});
colors.append(R.id.black, "black"); colors.append(R.id.black, "black");
colors.append(R.id.red, "red"); colors.append(R.id.red, "red");
colors.append(R.id.yellow, "yellow"); colors.append(R.id.yellow, "yellow");
@ -99,7 +106,6 @@ public class EditorView extends LinearLayout {
colors.append(R.id.maroon, "maroon"); colors.append(R.id.maroon, "maroon");
colors.append(R.id.lime_green, "limegreen"); colors.append(R.id.lime_green, "limegreen");
RecyclerView formatButtonsRecyclerview = findViewById(R.id.buttons_recyclerview);
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
float itemWidth = getResources().getDimension(R.dimen.editor_format_button_size) + float itemWidth = getResources().getDimension(R.dimen.editor_format_button_size) +
getResources().getDimension(R.dimen.editor_format_button_margin_between); getResources().getDimension(R.dimen.editor_format_button_margin_between);
@ -277,14 +283,90 @@ public class EditorView extends LinearLayout {
} }
public void setMarkdownVisible(boolean visible) { public void setMarkdownVisible(boolean visible) {
findViewById(R.id.buttons_recyclerview).setVisibility(visible ? VISIBLE : GONE); formatButtonsRecyclerview.setVisibility(visible ? VISIBLE : GONE);
} }
public void showMarkdownOnfocus() { public void showMarkdownOnfocus() {
edittextWrapper.setOnClickListener(view -> setMarkdownVisible(true)); edittextWrapper.setOnClickListener(view -> {
editText.setOnClickListener(view -> setMarkdownVisible(true)); showMarkdown();
edittextWrapper.setOnFocusChangeListener((view, b) -> setMarkdownVisible(b)); });
editText.setOnFocusChangeListener((view, b) -> setMarkdownVisible(b)); editText.setOnClickListener(view -> {
showMarkdown();
});
edittextWrapper.setOnFocusChangeListener((view, b) -> {
if (b) showMarkdown();
else hideMarkdown();
});
editText.setOnFocusChangeListener((view, b) -> {
if (b) showMarkdown();
else hideMarkdown();
});
}
/**
* Animates the hiding of the markdown options.
*
*/
public void hideMarkdown() {
if (formatButtonsRecyclerview.getVisibility() == GONE) return;
ViewPropertyAnimator animator = formatButtonsRecyclerview.animate()
.translationY(formatButtonsRecyclerview.getHeight())
.setInterpolator(new FastOutSlowInInterpolator())
.setDuration(ANIMATION_DURATION);
animator.setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
formatButtonsRecyclerview.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
animator.start();
}
/**
* Animates the showing of the markdown options.
*
*/
public void showMarkdown() {
if (formatButtonsRecyclerview.getVisibility() == VISIBLE) return;
ViewPropertyAnimator animator = formatButtonsRecyclerview.animate()
.translationY(0)
.setInterpolator(new FastOutSlowInInterpolator())
.setDuration(ANIMATION_DURATION);
animator.setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
formatButtonsRecyclerview.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
animator.start();
} }
public TextInputEditText getEditText() { public TextInputEditText getEditText() {

Loading…
Cancel
Save