Add sign in scene
This commit is contained in:
1 parent
3c3dd4a7e2
commit
08d0794fe8
15 files changed
+495
-47
No files matched your search
@@ -27,6 +27,11 @@ public class EhHttpHelper extends HttpHelper {
|
||||
|
||||
private static final Pool<EhHttpHelper> sPool = new Pool<>(10);
|
||||
|
||||
private static String[] EHENTAI_DOMAIN = {
|
||||
"exhentai.org",
|
||||
"e-hentai.org"
|
||||
};
|
||||
|
||||
public static @NonNull EhHttpHelper obtain() {
|
||||
EhHttpHelper ehh = sPool.obtain();
|
||||
if (ehh == null) {
|
||||
|
||||
@@ -29,16 +29,19 @@ import android.widget.AdapterView;
|
||||
import com.hippo.content.VectorContext;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene;
|
||||
import com.hippo.ehviewer.ui.scene.SignInScene;
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.ehviewer.widget.DrawerLeftPanel;
|
||||
import com.hippo.ehviewer.widget.StatusBarLayout;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.SimpleCurtain;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.scene.StageLayout;
|
||||
import com.hippo.widget.DrawerListView;
|
||||
|
||||
public class ContentActivity extends StageActivity
|
||||
implements StatusBarLayout.OnGetFitPaddingBottomListener {
|
||||
public final class ContentActivity extends StageActivity
|
||||
implements StatusBarLayout.OnGetFitPaddingBottomListener,
|
||||
DrawerLeftPanel.Helper {
|
||||
|
||||
public static final int DRAWER_LIST_NONE = -1;
|
||||
public static final int DRAWER_LIST_HOMEPAGE = 0;
|
||||
@@ -92,6 +95,7 @@ public class ContentActivity extends StageActivity
|
||||
return Config.getShowApplicationStats();
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -108,6 +112,10 @@ public class ContentActivity extends StageActivity
|
||||
|
||||
mStatusBarLayout.setOnGetFitPaddingBottomListener(this);
|
||||
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
|
||||
|
||||
mDrawerLeftPanel.setHelper(this);
|
||||
|
||||
// Drawer
|
||||
Drawable[] drawerListDrawables = new Drawable[] {
|
||||
mResources.getDrawable(R.drawable.ic_drawer_list_home),
|
||||
@@ -171,4 +179,15 @@ public class ContentActivity extends StageActivity
|
||||
public void onGetFitPaddingBottom(int b) {
|
||||
setFitPaddingBottom(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickSignIn() {
|
||||
mDrawerLayout.closeDrawers();
|
||||
startScene(SignInScene.class, null, new SimpleCurtain(SimpleCurtain.DIRECTION_BOTTOM));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickSignOut() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ import java.util.List;
|
||||
// TODO remeber the data in ContentHelper after screen dirction change
|
||||
// TODO Must refresh when change source
|
||||
// TODO disable click action when animating
|
||||
public class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
View.OnClickListener, FabLayout.OnCancelListener,
|
||||
SearchLayout.SearhLayoutHelper {
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.effect.ripple.RippleSalon;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.scene.Scene;
|
||||
|
||||
public class SignInScene extends Scene {
|
||||
|
||||
private View mMainView;
|
||||
private TextView mSignUp;
|
||||
private TextView mSignIn;
|
||||
|
||||
@Override
|
||||
public int getLaunchMode() {
|
||||
return LAUNCH_MODE_SINGLE_TOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.scene_sign_in);
|
||||
|
||||
mMainView = findViewById(R.id.sigin_in_main);
|
||||
mSignUp = (TextView) mMainView.findViewById(R.id.sign_up);
|
||||
mSignIn = (TextView) mMainView.findViewById(R.id.sign_in);
|
||||
|
||||
RippleSalon.addRipple(mSignUp, false);
|
||||
RippleSalon.addRipple(mSignIn, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onGetFitPaddingBottom(int b) {
|
||||
mMainView.setPadding(mMainView.getPaddingLeft(),
|
||||
mMainView.getPaddingTop(),
|
||||
mMainView.getPaddingRight(), b);
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,10 @@ public final class Config {
|
||||
private static final String KEY_EH_SOURCE = "eh_source";
|
||||
private static final int DEFAULT_EH_SOURCE = BuildConfig.DEBUG ?
|
||||
EhClient.SOURCE_LOFI : EhClient.SOURCE_G;
|
||||
private static final String KEY_IPD_MEMBER_ID = "ipb_member_id";
|
||||
private static final String DEFAULT_IPD_MEMBER_ID = null;
|
||||
private static final String KEY_IPD_PASS_HASH = "ipb_pass_hash";
|
||||
private static final String DEFAULT_IPD_PASS_HASH = null;
|
||||
|
||||
public static int getEhSource() {
|
||||
int value = getInt(KEY_EH_SOURCE, DEFAULT_EH_SOURCE);
|
||||
@@ -97,6 +101,24 @@ public final class Config {
|
||||
Messenger.getInstance().notify(Constants.MESSENGER_ID_EH_SOURCE, value);
|
||||
}
|
||||
|
||||
public static String getIpdNumberId() {
|
||||
return getString(KEY_IPD_MEMBER_ID, DEFAULT_IPD_MEMBER_ID);
|
||||
}
|
||||
|
||||
public static void putIpdMemberId(String value) {
|
||||
putString(KEY_IPD_MEMBER_ID, value);
|
||||
}
|
||||
|
||||
public static String getIpdPassHash() {
|
||||
return getString(KEY_IPD_PASS_HASH, DEFAULT_IPD_PASS_HASH);
|
||||
}
|
||||
|
||||
public static void putIpdPassHash(String value) {
|
||||
putString(KEY_IPD_PASS_HASH, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****** Advance ******/
|
||||
|
||||
private static final String KEY_SHOW_APPLICATION_STATS = "show_application_stats";
|
||||
|
||||
@@ -65,6 +65,8 @@ public class DrawerLeftPanel extends LinearLayout {
|
||||
|
||||
private boolean mSignIn;
|
||||
|
||||
private Helper mHelper;
|
||||
|
||||
private Messenger.Receiver mMessengerReceiver = new Messenger.Receiver() {
|
||||
@Override
|
||||
public void onReceive(int id, Object obj) {
|
||||
@@ -117,20 +119,37 @@ public class DrawerLeftPanel extends LinearLayout {
|
||||
mDrawerListView = (DrawerListView) getChildAt(1);
|
||||
|
||||
RippleSalon.addRipple(mAction, false);
|
||||
|
||||
mAvatar.setImageURI(DEFAULT_AVATAR_URI);
|
||||
mUsename.setText("");
|
||||
mAction.setText(mContext.getString(R.string.signin));
|
||||
mAction.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mHelper != null) {
|
||||
if (mSignIn) {
|
||||
mHelper.onClickSignOut();
|
||||
} else {
|
||||
mHelper.onClickSignIn();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mSuperUserPanelHeight = mSuperUserPanel.getLayoutParams().height;
|
||||
mUserPanelOriginalPaddingTop = mUserPanel.getPaddingTop();
|
||||
mDrawerListViewOriginalPaddingBottom = mDrawerListView.getPaddingBottom();
|
||||
|
||||
// TODO
|
||||
mAvatar.setImageURI(DEFAULT_AVATAR_URI);
|
||||
mUsename.setText("");
|
||||
mAction.setText(mContext.getString(R.string.signin));
|
||||
}
|
||||
|
||||
public DrawerListView getDrawerListView() {
|
||||
return mDrawerListView;
|
||||
}
|
||||
|
||||
public void setHelper(Helper helper) {
|
||||
mHelper = helper;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
@@ -217,4 +236,9 @@ public class DrawerLeftPanel extends LinearLayout {
|
||||
|
||||
return super.fitSystemWindows(insets);
|
||||
}
|
||||
|
||||
public interface Helper {
|
||||
void onClickSignIn();
|
||||
void onClickSignOut();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.hippo.scene;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.PropertyValuesHolder;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
import com.hippo.animation.SimpleAnimatorListener;
|
||||
import com.hippo.util.AnimationUtils;
|
||||
import com.hippo.util.AssertUtils;
|
||||
import com.hippo.util.ViewUtils;
|
||||
|
||||
public class SimpleCurtain extends Curtain {
|
||||
|
||||
private static long ANIMATE_TIME = 300L;
|
||||
|
||||
public static final int DIRECTION_LEFT = 0;
|
||||
public static final int DIRECTION_TOP = 1;
|
||||
public static final int DIRECTION_RIGHT = 2;
|
||||
public static final int DIRECTION_BOTTOM = 3;
|
||||
|
||||
private int mDirection;
|
||||
|
||||
private Animator mAnimator;
|
||||
|
||||
public SimpleCurtain(int direction) {
|
||||
mDirection = direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(@NonNull final Scene enter, @NonNull final Scene exit) {
|
||||
final View enterSceneView = enter.getSceneView();
|
||||
AssertUtils.assertNotNull("Enter scene view must not be null.", enterSceneView);
|
||||
|
||||
ViewUtils.setVisibility(enterSceneView, View.INVISIBLE);
|
||||
|
||||
enterSceneView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
ViewUtils.removeOnGlobalLayoutListener(enterSceneView.getViewTreeObserver(), this);
|
||||
|
||||
int width = enterSceneView.getWidth();
|
||||
int height = enterSceneView.getHeight();
|
||||
float translationX = 0f;
|
||||
float translationY = 0f;
|
||||
switch (mDirection) {
|
||||
case DIRECTION_LEFT:
|
||||
translationX = -width;
|
||||
break;
|
||||
case DIRECTION_TOP:
|
||||
translationY = -height;
|
||||
break;
|
||||
case DIRECTION_RIGHT:
|
||||
translationX = width;
|
||||
break;
|
||||
default:
|
||||
case DIRECTION_BOTTOM:
|
||||
translationY = height;
|
||||
break;
|
||||
}
|
||||
PropertyValuesHolder pvh;
|
||||
if (translationX != 0f) {
|
||||
pvh = PropertyValuesHolder.ofFloat("translationX", translationX, 0f);
|
||||
} else {
|
||||
pvh = PropertyValuesHolder.ofFloat("translationY", translationY, 0f);
|
||||
}
|
||||
Animator animator = ObjectAnimator.ofPropertyValuesHolder(enterSceneView, pvh);
|
||||
animator.setDuration(ANIMATE_TIME);
|
||||
animator.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
|
||||
animator.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
ViewUtils.setVisibility(enterSceneView, View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation, boolean canceled) {
|
||||
super.onAnimationEnd(animation, canceled);
|
||||
dispatchOpenFinished(enter, exit);
|
||||
hideSceneOnOpen(exit);
|
||||
mAnimator = null;
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
mAnimator = animator;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(@NonNull final Scene enter, @NonNull final Scene exit) {
|
||||
showSceneOnClose(enter);
|
||||
|
||||
final View exitSceneView = exit.getSceneView();
|
||||
AssertUtils.assertNotNull("Exit scene view must not be null.", exitSceneView);
|
||||
|
||||
int width = exitSceneView.getWidth();
|
||||
int height = exitSceneView.getHeight();
|
||||
float translationX = 0f;
|
||||
float translationY = 0f;
|
||||
switch (mDirection) {
|
||||
case DIRECTION_LEFT:
|
||||
translationX = -width;
|
||||
break;
|
||||
case DIRECTION_TOP:
|
||||
translationY = -height;
|
||||
break;
|
||||
case DIRECTION_RIGHT:
|
||||
translationX = width;
|
||||
break;
|
||||
default:
|
||||
case DIRECTION_BOTTOM:
|
||||
translationY = height;
|
||||
break;
|
||||
}
|
||||
PropertyValuesHolder pvh;
|
||||
if (translationX != 0f) {
|
||||
pvh = PropertyValuesHolder.ofFloat("translationX", 0f, translationX);
|
||||
} else {
|
||||
pvh = PropertyValuesHolder.ofFloat("translationY", 0f, translationY);
|
||||
}
|
||||
Animator animator = ObjectAnimator.ofPropertyValuesHolder(exitSceneView, pvh);
|
||||
animator.setDuration(ANIMATE_TIME);
|
||||
animator.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR);
|
||||
animator.addListener(new SimpleAnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation, boolean canceled) {
|
||||
super.onAnimationEnd(animation, canceled);
|
||||
dispatchCloseFinished(enter, exit);
|
||||
mAnimator = null;
|
||||
}
|
||||
});
|
||||
animator.start();
|
||||
mAnimator = animator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endAnimation() {
|
||||
if (mAnimator != null) {
|
||||
mAnimator.end();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInAnimation() {
|
||||
return mAnimator != null;
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,12 @@ import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.PropertyValuesHolder;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.view.animation.FastOutLinearInInterpolator;
|
||||
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
import com.hippo.animation.ArgbEvaluator;
|
||||
import com.hippo.animation.SimpleAnimatorListener;
|
||||
import com.hippo.util.AnimationUtils;
|
||||
import com.hippo.util.AssertUtils;
|
||||
import com.hippo.util.ViewUtils;
|
||||
|
||||
@@ -38,9 +36,6 @@ public class SimpleDialogCurtain extends Curtain {
|
||||
|
||||
private static long ANIMATE_TIME = 300L;
|
||||
|
||||
private final static Interpolator FAST_OUT_LINEAR_IN_INTERPOLATOR = new FastOutLinearInInterpolator();
|
||||
private final static Interpolator LINEAR_OUT_SLOW_IN_INTERPOLATOR = new LinearOutSlowInInterpolator();
|
||||
|
||||
private int mStartX;
|
||||
private int mStartY;
|
||||
|
||||
@@ -69,7 +64,7 @@ public class SimpleDialogCurtain extends Curtain {
|
||||
ObjectAnimator colorAnim = ObjectAnimator.ofInt(enter, "backgroundColor", bgColor);
|
||||
colorAnim.setEvaluator(ArgbEvaluator.getInstance());
|
||||
colorAnim.setDuration(ANIMATE_TIME);
|
||||
colorAnim.setInterpolator(LINEAR_OUT_SLOW_IN_INTERPOLATOR);
|
||||
colorAnim.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
|
||||
animatorCollection.add(colorAnim);
|
||||
|
||||
final View mFrame = enterDialog.getFrame();
|
||||
@@ -111,7 +106,7 @@ public class SimpleDialogCurtain extends Curtain {
|
||||
PropertyValuesHolder bottomPvh = PropertyValuesHolder.ofInt("drawBottom", startBottom, endBottom);
|
||||
ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(mFrame, leftPvh, topPvh, rightPvh, bottomPvh);
|
||||
anim.setDuration(ANIMATE_TIME);
|
||||
anim.setInterpolator(LINEAR_OUT_SLOW_IN_INTERPOLATOR);
|
||||
anim.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
|
||||
|
||||
animatorCollection.add(anim);
|
||||
|
||||
@@ -147,7 +142,7 @@ public class SimpleDialogCurtain extends Curtain {
|
||||
colorAnim.setEvaluator(ArgbEvaluator.getInstance());
|
||||
colorAnim.setDuration(ANIMATE_TIME);
|
||||
animatorCollection.add(colorAnim);
|
||||
colorAnim.setInterpolator(FAST_OUT_LINEAR_IN_INTERPOLATOR);
|
||||
colorAnim.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR);
|
||||
|
||||
final View mFrame = exitDialog.getFrame();
|
||||
AssertUtils.assertNotNull("Frame view must not be null.", mFrame);
|
||||
@@ -180,7 +175,7 @@ public class SimpleDialogCurtain extends Curtain {
|
||||
PropertyValuesHolder bottomPvh = PropertyValuesHolder.ofInt("drawBottom", startBottom, endBottom);
|
||||
ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(mFrame, leftPvh, topPvh, rightPvh, bottomPvh);
|
||||
anim.setDuration(ANIMATE_TIME);
|
||||
anim.setInterpolator(FAST_OUT_LINEAR_IN_INTERPOLATOR);
|
||||
anim.setInterpolator(AnimationUtils.SLOW_FAST_INTERPOLATOR);
|
||||
|
||||
animatorCollection.add(anim);
|
||||
|
||||
|
||||
@@ -82,10 +82,19 @@ public abstract class StageActivity extends StatsActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public void startScene(@NonNull Class sceneClass) {
|
||||
sSceneManager.startScene(sceneClass, null, null);
|
||||
}
|
||||
|
||||
public void startScene(@NonNull Class sceneClass, @Nullable Announcer announcer) {
|
||||
sSceneManager.startScene(sceneClass, announcer, null);
|
||||
}
|
||||
|
||||
public void startScene(@NonNull Class sceneClass, @Nullable Announcer announcer,
|
||||
@Nullable Curtain curtain) {
|
||||
sSceneManager.startScene(sceneClass, announcer, curtain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start new Activity for result to listener
|
||||
*
|
||||
|
||||
@@ -22,13 +22,15 @@ import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -52,10 +54,11 @@ public class FloatLabelEditText extends FrameLayout {
|
||||
};
|
||||
|
||||
private TextView mLabel;
|
||||
private PrefixEditText mEditText;
|
||||
private EditText mEditText;
|
||||
|
||||
private Trigger mTrigger = Trigger.TEXT;
|
||||
|
||||
// Text for hint text view
|
||||
private CharSequence mHint;
|
||||
|
||||
public FloatLabelEditText(Context context, AttributeSet attrs) {
|
||||
@@ -70,39 +73,43 @@ public class FloatLabelEditText extends FrameLayout {
|
||||
|
||||
private void init(Context context, AttributeSet attrs) {
|
||||
mLabel = new TextView(context);
|
||||
mLabel.setVisibility(View.INVISIBLE);
|
||||
addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
|
||||
PrefixEditText attrCollector = new PrefixEditText(context, attrs);
|
||||
mEditText = (PrefixEditText) LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.widget_float_label_edit_text, this, false);
|
||||
final LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
|
||||
lp.gravity = Gravity.BOTTOM;
|
||||
lp.topMargin = (int) mLabel.getTextSize();
|
||||
addView(mEditText, lp);
|
||||
|
||||
// Collect attr
|
||||
mHint = attrCollector.getHint();
|
||||
mEditText.setInputType(attrCollector.getInputType());
|
||||
|
||||
final TypedArray a = context
|
||||
.obtainStyledAttributes(attrs, R.styleable.FloatLabelEditText);
|
||||
mLabel.setTextAppearance(context,
|
||||
a.getResourceId(R.styleable.FloatLabelEditText_labelAppearance,
|
||||
android.R.style.TextAppearance_Small));
|
||||
CharSequence labelHint = a.getText(R.styleable.FloatLabelEditText_labelHint);
|
||||
if (labelHint == null) {
|
||||
labelHint = mHint;
|
||||
}
|
||||
mLabel.setText(labelHint);
|
||||
mHint = a.getText(R.styleable.FloatLabelEditText_labelHint);
|
||||
mLabel.setText(mHint);
|
||||
final int index = a.getInt(R.styleable.FloatLabelEditText_trigger, -1);
|
||||
if (index >= 0) {
|
||||
setTrigger(sTriggerArray[index]);
|
||||
}
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
mLabel.setVisibility(View.INVISIBLE);
|
||||
@Override
|
||||
public final void addView(@NonNull View child, int index, ViewGroup.LayoutParams params) {
|
||||
if (child instanceof EditText) {
|
||||
setEditText((EditText) child);
|
||||
|
||||
mEditText.setHint(mHint);
|
||||
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) params;
|
||||
lp.gravity = Gravity.BOTTOM;
|
||||
lp.topMargin = (int) mLabel.getTextSize();
|
||||
}
|
||||
|
||||
// Carry on adding the View...
|
||||
super.addView(child, index, params);
|
||||
}
|
||||
|
||||
private void setEditText(EditText editText) {
|
||||
// If we already have an EditText, throw an exception
|
||||
if (mEditText != null) {
|
||||
throw new IllegalArgumentException("We already have an EditText, can only have one");
|
||||
}
|
||||
mEditText = editText;
|
||||
|
||||
// Add a TextWatcher so that we know when the text input has changed
|
||||
mEditText.addTextChangedListener(mTextWatcher);
|
||||
@@ -111,6 +118,11 @@ public class FloatLabelEditText extends FrameLayout {
|
||||
// Allows the use of a ColorStateList for the text color on the label
|
||||
mEditText.setOnFocusChangeListener(mOnFocusChangeListener);
|
||||
|
||||
// If we do not have a valid hint, try and retrieve it from the EditText
|
||||
if (TextUtils.isEmpty(mHint)) {
|
||||
setHint(mEditText.getHint());
|
||||
}
|
||||
|
||||
// Align with label and edittext
|
||||
mLabel.setPadding(mEditText.getPaddingLeft(), 0, 0, 0);
|
||||
}
|
||||
@@ -119,6 +131,11 @@ public class FloatLabelEditText extends FrameLayout {
|
||||
mTrigger = trigger;
|
||||
}
|
||||
|
||||
public void setHint(CharSequence hint) {
|
||||
mHint = hint;
|
||||
mLabel.setText(hint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the label using an animation
|
||||
*/
|
||||
@@ -179,14 +196,6 @@ public class FloatLabelEditText extends FrameLayout {
|
||||
return mEditText.getText();
|
||||
}
|
||||
|
||||
public void setPrefix(int resId) {
|
||||
mEditText.setPrefix(resId);
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
mEditText.setPrefix(prefix);
|
||||
}
|
||||
|
||||
private TextWatcher mTextWatcher = new TextWatcher() {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user