From 3e2c34c3bd4882f7ad445da294e24b147b6cfa75 Mon Sep 17 00:00:00 2001 From: Floens Date: Tue, 26 Aug 2014 00:03:19 +0200 Subject: [PATCH] Remote float label --- .../floatlabel/FloatLabelEditText.java | 233 ------------------ .../chan/ui/fragment/ReplyFragment.java | 31 ++- .../src/main/res/anim/slide_from_bottom.xml | 12 - .../app/src/main/res/anim/slide_to_bottom.xml | 12 - .../main/res/layout/floatlabel_edittext.xml | 20 -- .../app/src/main/res/layout/reply_input.xml | 27 +- Clover/app/src/main/res/values/attrs.xml | 12 - 7 files changed, 24 insertions(+), 323 deletions(-) delete mode 100644 Clover/app/src/main/java/com/micromobs/android/floatlabel/FloatLabelEditText.java delete mode 100644 Clover/app/src/main/res/anim/slide_from_bottom.xml delete mode 100644 Clover/app/src/main/res/anim/slide_to_bottom.xml delete mode 100644 Clover/app/src/main/res/layout/floatlabel_edittext.xml diff --git a/Clover/app/src/main/java/com/micromobs/android/floatlabel/FloatLabelEditText.java b/Clover/app/src/main/java/com/micromobs/android/floatlabel/FloatLabelEditText.java deleted file mode 100644 index 676b2ccf..00000000 --- a/Clover/app/src/main/java/com/micromobs/android/floatlabel/FloatLabelEditText.java +++ /dev/null @@ -1,233 +0,0 @@ -package com.micromobs.android.floatlabel; - -import org.floens.chan.R; - -import android.animation.ArgbEvaluator; -import android.animation.ValueAnimator; -import android.annotation.TargetApi; -import android.content.Context; -import android.content.res.TypedArray; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.util.TypedValue; -import android.view.LayoutInflater; -import android.view.View; -import android.view.WindowManager; -import android.view.animation.AnimationUtils; -import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.TextView; - -@TargetApi(11) -public class FloatLabelEditText extends LinearLayout { - - private int mFocusedColor, mUnFocusedColor, mFitScreenWidth; - private final int mCurrentApiVersion = android.os.Build.VERSION.SDK_INT; - private float mTextSizeInSp; - private String mHintText, mEditText; - - private AttributeSet mAttrs; - private final Context mContext; - private EditText mEditTextView; - private TextView mFloatingLabel; - - // ----------------------------------------------------------------------- - // default constructors - - public FloatLabelEditText(Context context) { - super(context); - mContext = context; - initializeView(); - } - - public FloatLabelEditText(Context context, AttributeSet attrs) { - super(context, attrs); - mContext = context; - mAttrs = attrs; - initializeView(); - } - - public FloatLabelEditText(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - mContext = context; - mAttrs = attrs; - initializeView(); - } - - // ----------------------------------------------------------------------- - // public interface - - public EditText getEditText() { - return mEditTextView; - } - - public String getText() { - if (getEditTextString() != null && - getEditTextString().toString() != null && - getEditTextString().toString().length() > 0) { - return getEditTextString().toString(); - } - return ""; - } - - // ----------------------------------------------------------------------- - // private helpers - - private void initializeView() { - - if (mContext == null) return; - - LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - mInflater.inflate(R.layout.floatlabel_edittext, this, true); - - mFloatingLabel = (TextView) findViewById(R.id.floating_label_hint); - mEditTextView = (EditText) findViewById(R.id.floating_label_edit_text); - - getAttributesFromXmlAndStoreLocally(); - setupEditTextView(); - setupFloatingLabel(); - } - - private void getAttributesFromXmlAndStoreLocally() { - TypedArray attributesFromXmlLayout = mContext.obtainStyledAttributes(mAttrs, R.styleable.FloatLabelEditText ); - if (attributesFromXmlLayout == null) return; - - mHintText = attributesFromXmlLayout.getString(R.styleable.FloatLabelEditText_hint); - mEditText = attributesFromXmlLayout.getString(R.styleable.FloatLabelEditText_text); - mTextSizeInSp = getScaledFontSize(attributesFromXmlLayout.getDimensionPixelSize(R.styleable.FloatLabelEditText_textSize, (int) mEditTextView.getTextSize())); - mFocusedColor = attributesFromXmlLayout.getColor(R.styleable.FloatLabelEditText_textColorHintFocused, android.R.color.black); - mUnFocusedColor = attributesFromXmlLayout.getColor(R.styleable.FloatLabelEditText_textColorHintUnFocused, android.R.color.darker_gray); - mFitScreenWidth = attributesFromXmlLayout.getInt(R.styleable.FloatLabelEditText_fitScreenWidth, 0); - - attributesFromXmlLayout.recycle(); - } - - private void setupEditTextView() { - mEditTextView.setHint(mHintText); - mEditTextView.setHintTextColor(mUnFocusedColor); - mEditTextView.setText(mEditText); - mEditTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSizeInSp); - mEditTextView.addTextChangedListener(getTextWatcher()); - - if (mFitScreenWidth > 0) { - mEditTextView.setWidth(getSpecialWidth()); - } - - if (mCurrentApiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) { - mEditTextView.setOnFocusChangeListener(getFocusChangeListener()); - } - } - - private void setupFloatingLabel() { - mFloatingLabel.setText(mHintText); - mFloatingLabel.setTextColor(mUnFocusedColor); - mFloatingLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float) (mTextSizeInSp / 1.3)); - - mFloatingLabel.setPadding(mEditTextView.getPaddingLeft(), 0, 0, 0); - - if (getText().length() > 0) { - showFloatingLabel(); - } - } - - private TextWatcher getTextWatcher() { - return new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) {} - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) {} - - @Override - public void afterTextChanged(Editable s) { - if (s.length() > 0 && mFloatingLabel.getVisibility() == INVISIBLE) { - showFloatingLabel(); - } else if (s.length() == 0 && mFloatingLabel.getVisibility() == VISIBLE) { - hideFloatingLabel(); - } - } - }; - } - - private void showFloatingLabel() { - mFloatingLabel.setVisibility(VISIBLE); - mFloatingLabel.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.slide_from_bottom)); - } - - private void hideFloatingLabel() { - mFloatingLabel.setVisibility(INVISIBLE); - mFloatingLabel.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.slide_to_bottom)); - } - - private OnFocusChangeListener getFocusChangeListener() { - return new OnFocusChangeListener() { - - ValueAnimator mFocusToUnfocusAnimation, mUnfocusToFocusAnimation; - - @Override - public void onFocusChange(View v, boolean hasFocus) { - ValueAnimator lColorAnimation; - - if (hasFocus) { - lColorAnimation = getFocusToUnfocusAnimation(); - } else { - lColorAnimation = getUnfocusToFocusAnimation(); - } - - lColorAnimation.setDuration(700); - lColorAnimation.start(); - } - - private ValueAnimator getFocusToUnfocusAnimation() { - if (mFocusToUnfocusAnimation == null) { - mFocusToUnfocusAnimation = getFocusAnimation(mUnFocusedColor, mFocusedColor); - } - return mFocusToUnfocusAnimation; - } - - private ValueAnimator getUnfocusToFocusAnimation() { - if (mUnfocusToFocusAnimation == null) { - mUnfocusToFocusAnimation = getFocusAnimation(mFocusedColor, mUnFocusedColor); - } - return mUnfocusToFocusAnimation; - } - }; - } - - private ValueAnimator getFocusAnimation(int fromColor, int toColor) { - ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor); - colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator animator) { - mFloatingLabel.setTextColor((Integer) animator.getAnimatedValue()); - } - }); - return colorAnimation; - } - - private Editable getEditTextString() { - return mEditTextView.getText(); - } - - private float getScaledFontSize(float fontSizeFromAttributes) { - float scaledDensity = getContext().getResources().getDisplayMetrics().scaledDensity; - return fontSizeFromAttributes/scaledDensity; - } - - @SuppressWarnings({ "deprecation", "unused" }) - private int getSpecialWidth() { - float screenWidth = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth(); - int prevWidth = mEditTextView.getWidth(); - - switch (mFitScreenWidth) { - case 2: - return (int) Math.round(screenWidth * 0.5); - default: - return Math.round(screenWidth); - } - } - - - -} diff --git a/Clover/app/src/main/java/org/floens/chan/ui/fragment/ReplyFragment.java b/Clover/app/src/main/java/org/floens/chan/ui/fragment/ReplyFragment.java index 7eb40f38..5610a01c 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/fragment/ReplyFragment.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/fragment/ReplyFragment.java @@ -49,7 +49,6 @@ import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.NetworkImageView; import com.android.volley.toolbox.StringRequest; -import com.micromobs.android.floatlabel.FloatLabelEditText; import org.floens.chan.ChanApplication; import org.floens.chan.R; @@ -88,9 +87,9 @@ public class ReplyFragment extends DialogFragment { private Button fileButton; private Button fileDeleteButton; private Button submitButton; - private FloatLabelEditText nameView; - private FloatLabelEditText emailView; - private FloatLabelEditText subjectView; + private EditText nameView; + private EditText emailView; + private EditText subjectView; private EditText commentView; private EditText fileNameView; private LoadView imageViewContainer; @@ -164,9 +163,9 @@ public class ReplyFragment extends DialogFragment { draft.email = ChanPreferences.getDefaultEmail(); } - nameView.getEditText().setText(draft.name); - emailView.getEditText().setText(draft.email); - subjectView.getEditText().setText(draft.subject); + nameView.setText(draft.name); + emailView.setText(draft.email); + subjectView.setText(draft.subject); commentView.setText(draft.comment); // To the end of the comment Selection.setSelection(commentView.getText(), commentView.getText().length()); @@ -196,9 +195,9 @@ public class ReplyFragment extends DialogFragment { ReplyManager replyManager = ChanApplication.getReplyManager(); if (shouldSaveDraft) { - draft.name = nameView.getText(); - draft.email = emailView.getText(); - draft.subject = subjectView.getText(); + draft.name = nameView.getText().toString(); + draft.email = emailView.getText().toString(); + draft.subject = subjectView.getText().toString(); draft.comment = commentView.getText().toString(); if (fileNameView != null) { @@ -228,9 +227,9 @@ public class ReplyFragment extends DialogFragment { container = inflater.inflate(R.layout.reply_view, null); flipper = (ViewFlipper) container.findViewById(R.id.reply_flipper); - nameView = (FloatLabelEditText) container.findViewById(R.id.reply_name); - emailView = (FloatLabelEditText) container.findViewById(R.id.reply_email); - subjectView = (FloatLabelEditText) container.findViewById(R.id.reply_subject); + nameView = (EditText) container.findViewById(R.id.reply_name); + emailView = (EditText) container.findViewById(R.id.reply_email); + subjectView = (EditText) container.findViewById(R.id.reply_subject); commentView = (EditText) container.findViewById(R.id.reply_comment); commentView.requestFocus(); @@ -469,9 +468,9 @@ public class ReplyFragment extends DialogFragment { responseContainer.setView(null); - draft.name = nameView.getText(); - draft.email = emailView.getText(); - draft.subject = subjectView.getText(); + draft.name = nameView.getText().toString(); + draft.email = emailView.getText().toString(); + draft.subject = subjectView.getText().toString(); draft.comment = commentView.getText().toString(); draft.captchaChallenge = captchaChallenge; draft.captchaResponse = captchaInput.getText().toString(); diff --git a/Clover/app/src/main/res/anim/slide_from_bottom.xml b/Clover/app/src/main/res/anim/slide_from_bottom.xml deleted file mode 100644 index 552753ac..00000000 --- a/Clover/app/src/main/res/anim/slide_from_bottom.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - diff --git a/Clover/app/src/main/res/anim/slide_to_bottom.xml b/Clover/app/src/main/res/anim/slide_to_bottom.xml deleted file mode 100644 index 48d25795..00000000 --- a/Clover/app/src/main/res/anim/slide_to_bottom.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Clover/app/src/main/res/layout/floatlabel_edittext.xml b/Clover/app/src/main/res/layout/floatlabel_edittext.xml deleted file mode 100644 index 133dadec..00000000 --- a/Clover/app/src/main/res/layout/floatlabel_edittext.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Clover/app/src/main/res/layout/reply_input.xml b/Clover/app/src/main/res/layout/reply_input.xml index 7fbbf9e1..746e5b06 100644 --- a/Clover/app/src/main/res/layout/reply_input.xml +++ b/Clover/app/src/main/res/layout/reply_input.xml @@ -25,35 +25,26 @@ along with this program. If not, see . android:layout_height="wrap_content" android:orientation="vertical"> - + android:hint="@string/reply_name" + android:textSize="16sp"/> - + android:hint="@string/reply_subject" + android:textSize="16sp"/> - + android:hint="@string/reply_email" + android:textSize="16sp"/> . --> - - - - - - - - - - - -