Giter Club home page Giter Club logo

pinentryview's Introduction

PinEntryView

About

A PIN entry view widget for Android with support for Android 5 Material Theme features via the AppCompat v7 support library.

Uses a hidden EditText to handle input, hence behaves much in the same was as an EditText on the screen and supports similar features.

Demo

The demo app running the latest release build is also available on Google Play:

Get it on Google Play

Change log

  • 1.0.6 - Added pinInputType attribute to allow changing the input type, fixed #7
  • 1.0.5 - Added setText and clearText methods, updated build to API 22
  • 1.0.4 - Changed attribute name accentColor to pinAccentColor to avoid conflicts with other libraries
  • 1.0.3 - Fixed #2, gravity of digits now correctly displayed
  • 1.0.2 - Add support for elevation on the digits in Lollipop
  • 1.0.1 - Minor fixes
  • 1.0.0 - Initial release

Download

Gradle

Add the following to your build.gradle:

compile 'me.philio:pinentryview:1.0.6'

Or for latest snapshot:

compile 'me.philio:pinentryview:1.1.0-SNAPSHOT'

Styling

Attributes

  • numDigits - The number of digits in the PIN, default 4.
  • digitWidth - The width of the digit view, default 50dp.
  • digitHeight - The heigh of the digit view, default 50dp.
  • digitSpacing - The distance between the digit views, default 20dp.
  • digitBackground - A resource to use for the digit views, supports drawables or colours and can be used with a custom selector as an alternative to using the built in accent support (by setting the accentColor as transparent). Defaults to android:windowBackground from the current theme.
  • digitTextSize - The size of the text in the digit view, default 15sp.
  • digitTextColor - The colour of the text in the digit view, defaults to android:textColorPrimary from the current theme.
  • digitElevation - Set the elevation of the digit views, API 21+ only, default 0dp.
  • mask - A character to use as a mask for the entered PIN value, can be set to an empty string to show typed numbers, default *.
  • pinAccentColor - The colour of the accent to use to highlight the view when it's in focus, defaults to android:colorAccent from the current theme.
  • accentWidth - The width of the accent highlight, default 3dp.
  • accentType - Defines the behaviour of the accent, default none, options:
    • none - disabled
    • all - highlights each separate digit view
    • character - highlights a single digit view to represent the position of the cursor
  • accentRequiresFocus - show accent only when focused, default true
  • pinInputType - Set the input type, default number, options:
    • text - full keyboard, any available character allowed
    • number - numeric keyboard, only numbers allowed

License

Copyright 2014-2015 Phil Bayfield

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 distributed under the License is distributed on an "AS IS" BASIS, 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.

pinentryview's People

Contributors

cdrussell avatar fideas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pinentryview's Issues

Visible Cursor for edittext

Hi,
I have to show cursor in editext. i have made setCursorVisible (true) but it isnt showing cursor.
Also i have tried to remove line SetCursorVisible because edittext have default cursor visible but still not shown.

No way to effectively disable the view

.setFocusable(false)
.setFocusableInTouchMode(false)
.setEnabled(false)
.setClickable(false)

All of these methods, during my test, keep me able to compile the PinEntryView.

Regards.

Query for digitSpacing

Hi..I have been using this library and its amazing. All i wanted to ask is that I have the need to show the pass code boxes in pairs of 2 i.e. like 12 34 56/ So after two boxes i need a space and then again the 2 boxes should come. Since we only have a single digitSpacing attribute right now, can you please advise how we can achieve this?

Change inputType

I would want to be able to change the inputType of the text and not only have numbers in my pins.

Wrong gravity with match_parent width on Android 4.x

When you set android:layout_width attribute of PinEntryView to match_parent, it will render fine centered on Lollipop but will be aligned to left on Android 4.x.
As a sideeffect, when you type into the view, you cannot see mask symbols.
Easily reproducible on PinEntryView DEMO app.

We got exception when onRestoreInstanceState has been called

Stack:

Caused by java.lang.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1022)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:615)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:611)
at android.text.Selection.setSelection(Selection.java:123)
at android.text.Selection.setSelection(Selection.java:134)
at android.widget.EditText.setSelection(EditText.java:128)
at me.philio.pinentry.PinEntryView.onRestoreInstanceState(PinEntryView.java:226)

Custom Accent Shape

Hello, how do i add custom accent shape in PinEntryView? i have set custom background for digits but not able to find any attribute to change the custom accent shape.

How to change mask in code.

I implemented this library and it works perfectly.
Btw I want to add feature "show/hide pin"

So my guess is I need to change mask string in code.

How can I do this?
Thanks.

Change Typeface

How can I change digit typeface? I use Calligraphy library but not working.

Attribute name conflict with another library

There is conflict when I try to use this library with com.android.support:appcompat-v7 library as both are using same attribute names.
Gradle report following error:
Attribute "accentColor" has already been defined

Please consider using your custom and possibly unique prefix for all custom attributes. The comonly used standard is to use first characters of your library name:
accentColor -> pev_accentColor
accentWidth -> pev_accentWidth
etc.

Add ImeOption to the library interface

I need to change the button on the screen keyboard. TextView has this property it just need to be exported.
To your convenience, I have open a pull request with the appropriate change.

Always show the keyboard

When user press back the keyboard will be hide.
I want to finish() when user press back.
I tried to override some medthods

  1. https://stackoverflow.com/questions/11965961/android-custom-edittext-and-back-button-override
    this way will cause runtime error cannot cast your object to my object
    pinEntryView = (LockEditText) findViewById(R.id.pinView);

Here is my obj
public class LockEditText extends PinEntryView {
/* Must use this constructor in order for the layout files to instantiate the class properly */
public LockEditText(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
}

@OverRide
public boolean onKeyPreIme (int keyCode, KeyEvent event)
{
// Return true if I handle the event:
// In my case i want the keyboard to not be dismissible so i simply return true
// Other people might want to handle the event differently
System.out.println("onKeyPreIme " +event);
return true;
}

}

Gravity of DigitalTextViews not working (pin input is not being centered in the DigitTextView)

Something is going wrong in either onMeasure or onLayout of this custom view that is causing the DigitViews to not get their "setGravity(Gravity.CENTER)" set properly. It is honoring the center horizontal, but not the center vertical, which leads me to believe that the error is either with onMeasure or onLayout. I fixed this by converting the custom view to a FrameLayout, which didnt require overriding onMeasure or onLayout, and gave it children of the EditText (which fills the entire parent) and a LinearLayout that is set to horizontal orientation, and adds the children dynamically. I can help with that part of the code if you want, it is a pretty big change though.

Idea: method to clear entered PIN

When user enters the PIN wrong the app may want to clear the field and allow him to try it again.
Is it possible to do it with current API? If not is it possible to add such option?

Supporting different screen densities

First of all, I want to say I love the ease of use and the nice material design effect customizing this view offers. But I have noticed some issues when testing with a wide range of devices as the views seem to either become smaller or bigger (in this case some some boxes are not visible on the screen). Is there a work around for this ?

Instrumentation tests

How can I do instrumentation tests using for instance Espresso and hamcrest view matchers if the PinEntry view does not support any input?

Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: ((is displayed on the screen to the user) and (supports input methods or is assignable from class: class android.widget.SearchView)) Target view: "PinEntryView{id=2131427464, res-name=pin_entry, visibility=VISIBLE, width=570, height=120, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=207.0, y=154.0, child-count=5}" at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:138)

Attribute name collisions

Other libraries have similarly named attributes e.g. "mask" which for some reason need to be unique, and so make it impossible to include this library when there's a name collision.

Ui issue

is it possible to change view like 2 row and 3 column
image22222

Gravity of DigitalTextViews not working (pin input is not being centered in the DigitTextView)

Something is going wrong in either onMeasure or onLayout of this custom view that is causing the DigitViews to not get their "setGravity(Gravity.CENTER)" set properly. It is honoring the center horizontal, but not the center vertical, which leads me to believe that the error is either with onMeasure or onLayout. I fixed this by converting the custom view to a FrameLayout, which didnt require overriding onMeasure or onLayout, and gave it children of the EditText (which fills the entire parent) and a LinearLayout that is set to horizontal orientation, and adds the children dynamically. I can help with that part of the code if you want, it is a pretty big change though.

focus

I want to open keyboard on activity created automatically, how to achieve that? i have tried
1).requestFocus()
2) `InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(pinEntryView, InputMethodManager.SHOW_IMPLICIT);``

Clearing PinEntryView

Is it possible to programmatically clear PinEntryView? I know there is clearText method, but it clears only text, not View. I would like to clear whole view if user sets wrong PIN. After that "cursor" should be at the beginning.

Android Studio rendering problems

Hi, I'm having issues using the visual rendering library of Android Studio (1.5.1).

Here is the stack trace:

java.lang.NumberFormatException: Color value '/home/manjaro/Android/Sdk/platforms/android-23/data/res/color/primary_text_material_light.xml' must start with #
    at com.android.layoutlib.bridge.impl.ResourceHelper.getColor(ResourceHelper.java:79)
    at android.content.res.BridgeResources.getColor(BridgeResources.java:181)
    at android.content.res.Resources.getColor(Resources.java:936)
    at me.philio.pinentry.PinEntryView.<init>(PinEntryView.java:144)
    at me.philio.pinentry.PinEntryView.<init>(PinEntryView.java:103)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:458)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:170)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:103)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:168)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:247)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:171)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:223)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510)
    at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:888)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498)
    at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72)
    at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610)
    at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607)
    at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:362)
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607)
    at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629)
    at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:480)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
    at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

To reproduce, simply download the sample, import the project in Android Studio, open the file PinEntryView/demo/src/main/res/layout/activity_main.xml and click on the Design tab, next to the Text tab.

The project builds fine, however, but this is sad we can't enjoy the visual editor.

P.S.: I don't know if the problem is with this library or Android Studio, though, but anyway, here it is.

Add inputtype numberPassword

In order to help users created harder password, we want to set the inputtype to numberpassword. This will show a keyboard with letters underneath the numbers so that users can create passwords with 'words ' as well

Idea: OnPinEnteredListener

Common scenario that the submit action is done automatically when user enters last digit of PIN. But currently the only option os to add a TextWatcher and check the length of entered PIN. This logic may be included inside the component that will provide just simple callback called only in case full PIN has been entered.

Setting digitBackground loses accent support

When configuring digitBackground, for example, to app:digitBackground="@android:color/white the pin accent colour doesn't show, even when set explicitly using
app:accentType="character"
app:pinAccentColor="@color/colorAccent"

Any thoughts?

add new pinInputType

In our products, there is such a demand:

We need support to enter numbers and letters

Limit is 0-9, a-z, A-Z

No unicode character

so I realized this demand.

I think we should add to this project

setOnPinEnteredListener

I'm currently trying to put a setOnPinEnteredListener on my app so it calls a webservice to validate the password but unfortunately it is not recognized.

here is what I have:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.ggs.managerroom.MainActivity;
import com.mycomapany.myapp.R;
import me.philio.pinentry.PinEntryView;

public class PasswordFragment extends Fragment {
    private PinEntryView pinEntryView;


@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        loadControls();

        pinEntryView.setOnPinEnteredListener(new PinEntryView.OnPinEnteredListener() {
           @Override
            public void onPinEntered(String pin) {
                Toast.makeText(getActivity(), "Pin entered: " + pin, Toast.LENGTH_LONG).show();
            }
        });
    }

    protected void loadControls() {
        MainActivity activity;
        activity = (MainActivity) getActivity();
       pinEntryView = (PinEntryView)activity.findViewById(R.id.pin_entry);
    }
....
}

Any help on what I might be doing wrong?

here is a image to see what my problem is:

https://gyazo.com/8396ff4586e70d2822510b22565ca8a2

Text size issue between platforms

The digitTextSize attribute sets the digit text size to a much bigger value than the one in the input on Android 7.
The cause might be digitView.setTextSize(digitTextSize); in the addViews() method, as digitTextSize is a dimension in PX and not passing the unit to setTextSize defaults it to COMPLEX_UNIT_SP. So the size defined in SP is converted to PX, then the resulting "n PX" is treated as "n SP".
For some odd reason on Android 7.1.2 it defaults to something else so the text is very small.

* chars don't show up on the nexus 4

Trying to figure out what's happening here, any idea what area to look in?

Also, when touching the first character the white square box get about 2 pixels shaved off their bottoms. So for only seen either of these issues on a nexus 4, galaxy line seems fine.

java.lang.NoSuchFieldError: No static field colorAccent

Hello,

I am using the version 1.0.6 and I am getting the error "Caused by: java.lang.NoSuchFieldError: No static field colorAccent of type I in class Lme/philio/pinentry/R$attr; or its superclasses (declaration of 'me.philio.pinentry.R$attr' appears in something.apk"

Is this because in your PinEntryView.java class you are still using:

theme.resolveAttribute(attr.colorAccent, accentColor, true);

instead of pinAccentColor?

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.