Code Monkey home page Code Monkey logo

showhidepasswordedittext's Issues

Image causes text to be off-center

If you have two text fields one on top of the other with one being a regular EditText field and the other of this custom type and both have a gravity of center; then the text will not line up once the show/hide image appears.

set tint of icon based on theme

Would be cool if showhidepasswordedittextview would automatically read the theme colorAccent and set the icon tint accordingly.

cannot change font of password hint

If you want to change the font form the default monaspace font that is auto set my android when you when set the inputtype to password. There's a SO post about it here. An easy fix (albeit API16+) should be android:fontFamily="sans-serif" however this doesn't work with showhidepasswordedittext.

Custom Typefaces overwritten

A typeface which is set using setTypeface(Typeface) is overwritten when tapping the icon. This is caused by the call to setInputType() in togglePasswordVisibility(). Instead of calling setInputType() it would be better to use setTransformationMethod() like this:

private void togglePasswordVisibility() {
    // Store the selection
    int selectionStart = this.getSelectionStart();
    int selectionEnd = this.getSelectionEnd();

    // Set transformation method to show/hide password
    if (isShowingPassword) {
        setTransformationMethod(new PasswordTransformationMethod());
    } else {
        setTransformationMethod(null);
    }

    // Restore selection
    this.setSelection(selectionStart, selectionEnd);

    // Toggle flag and show indicator
    isShowingPassword = !isShowingPassword;
    showPasswordVisibilityIndicator(true);
}

Benefits:

  • InputType is preserved
  • Typeface is preserved

Tested on API 23

Idea to improve "clickability" using dead drawablePadding space

I've experimented some hard times clicking when the drawable is small. One simple but not elegant solution is to use bigger drawables or include empty margins in the drawable.

I think that checking only for inner X border is smart, but could be even better by adding some extra space.
My first simple approach was to add an offset to the border. I used a relative value, but it could be done with an absolute value too:

private static double boundsXExtension = 1.5f; //It could be an xml attribute
// Then inside onTouchEvent()
 if ((leftToRight && (x >= (this.getRight() - (int)(boundsXExtension*bounds.width())))) ||
                    (!leftToRight &&  (x <= (this.getLeft() + (int)(boundsXExtension*bounds.width()))))){

Then i came up with a probably more elegant solution; which is taking advantage of the "drawablePadding" attribute. Its pixel value is accesible via getCompoundDrawablePadding(). This solution feels quite nice since it is adding some user value to an empty space that i guess everyone is using!

if ((leftToRight && (x >= (this.getRight() - (bounds.width()+getCompoundDrawablePadding())))) ||
                    (!leftToRight &&  (x <= (this.getLeft() + (bounds.width()+getCompoundDrawablePadding())))))

Drawable-Left image vanishes after clicking on edit text

<com.scottyab.showhidepasswordedittext.ShowHidePasswordEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:id="@+id/password_editText"
        android:hint="Type your Password"
        android:drawableLeft="@drawable/key"
        android:drawablePadding="15dp" />

The Left-Drawable image vanishes after we start typing in the edit text

allow setting of text instead of an icon

Show/Hide text is less mental strain to understand and can be localised.

  • Add two new attributes show_text and hide_text and corresponding java methods.
  • If text set then use this in preference over drawable

Suggestion: treat the text as a drawable create inner class that extends Drawable. This way it can just be handled as a drawable and the logic of the view can stay the same (not if text do this). If possible get the typeface from the edittext in case a custom font has been set.

not working with android.support.design.widget.TextInputLayout

it is not working with
<android.support.design.widget.TextInputLayout
android:id="@+id/login_input_layout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.scottyab.showhidepasswordedittext.ShowHidePasswordEditText
android:id="@+id/simplePassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@android:color/white"
android:inputType="textEmailAddress"
android:gravity="left"
android:textColor="#000"
android:hint="Password" />

    </android.support.design.widget.TextInputLayout>

device-2016-11-04-171630

Strange behavior when using layout_centerHorizontal

I've noticed the icon would not work if I set android:layout_centerHorizontal=true in the ShowHidePasswordEditText view, but I also observed that it would work (and apparently that's only way) if I swipe the icon from left to right.

PS: I'm using RelativeLayout, I don't know if this makes any difference.

Edit: I forgot to mention that I'm also using api 24.

Remove "android:label" from manifest

Hi.

The library should not have android:label="@string/app_name" in the manifest because it will force the app that uses the library to use the replace attribute.

Error when using this library:

Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@label value=(@string/app_name) from AndroidManifest.xml:35:9-46
    is also present at [com.github.scottyab:showhidepasswordedittext:0.3] AndroidManifest.xml:11:18-50 value=(@string/app_name).
    Suggestion: add 'tools:replace="android:label"' to <application> element at AndroidManifest.xml:31:5-82:19 to override. 

Only show symbol when edittext has focus

Hi,

I'd really like to have the option to only show the icon when the edit text has focus. If this is something you'd be interested in adding, I'm happy to submit a pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.