<commit_before>package com.karakuri.lib.pincodeview;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Selection;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.KeyListener;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.karakuri.lib.pincodeview.PinKeyListener.Type;

/**
 * A widget for displaying a pin code entry field.
 */
public class PinCodeView extends LinearLayout {
	private static final String TAG = "PinCodeView";

	private static final int DEFAULT_PIN_LENGTH = 4;

	/* values matching enum for R.styleable.PinCodeView_inputType */
	public static final int INPUT_TYPE_NUMERIC = 1;
	public static final int INPUT_TYPE_ALPHA = 2;
	public static final int INPUT_TYPE_ALPHA_NUMERIC = 3;

	private TextView mPinText;
	private int mPinLength;

	private int mInputType;
	private int mImeOptions;
	private int mImeActionId;
	private CharSequence mImeActionLabel;

	public PinCodeView(Context context) {
		super(context);
	}

	public PinCodeView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context, attrs, R.attr.pinCodeViewStyle);
	}

	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public PinCodeView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context, attrs, defStyle);
	}

	private void init(Context context, AttributeSet attrs, int defStyle) {
		Log.d(TAG, "[init]");

		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PinCodeView, defStyle, 0);
		try {
			final int N = a.getIndexCount();
			for (int i = 0; i < N; i++) {
				int attr = a.getIndex(i);

				switch (attr) {
				case R.styleable.PinCodeView_pinLength:
					mPinLength = a.getInt(attr, DEFAULT_PIN_LENGTH);
					break;
				case R.styleable.PinCodeView_inputType:
					mInputType = a.getInt(attr, INPUT_TYPE_NUMERIC);
					break;
				case R.styleable.PinCodeView_android_imeOptions:
					mImeOptions = a.getInt(attr, EditorInfo.IME_ACTION_UNSPECIFIED);
					break;
				case R.styleable.PinCodeView_android_imeActionLabel:
					mImeActionLabel = a.getText(attr);
					break;
				case R.styleable.PinCodeView_android_imeActionId:
					mImeActionId = a.getInt(attr, 0);
					break;
				}
			}
		} finally {
			a.recycle();
		}

		// try to prevent the IME from going full screen in landscape
		mImeOptions |= EditorInfo.IME_FLAG_NO_FULLSCREEN;

		mPinText = new TextView(context);
		mPinText.addTextChangedListener(mPinTextWatcher);

		mPinText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mPinLength) }); // temp
		mPinText.setImeOptions(mImeOptions); // temp
		mPinText.setImeActionLabel(mImeActionLabel, mImeActionId); // temp

		setInputType(mInputType);

		setClickable(true);
		setFocusableInTouchMode(true);
	}

	private TextWatcher mPinTextWatcher = new TextWatcher() {

		@Override
		public void onTextChanged(CharSequence s, int start, int before, int count) {}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

		@Override
		public void afterTextChanged(Editable s) {
			Log.d(TAG, String.format("[afterTextChanged] s = \"%s\"", s));
		}
	};

	public void setPinLength(int newLength) {
		mPinLength = newLength;
	}

	public int getPinLength() {
		return mPinLength;
	}

	public CharSequence getPin() {
		return mPinText.getText();
	}

	public void setInputType(int inputType) {
		PinKeyListener input;
		switch (inputType) {
		case INPUT_TYPE_NUMERIC:
			input = PinKeyListener.getInstance(Type.NUMERIC);
			break;
		case INPUT_TYPE_ALPHA:
			input = PinKeyListener.getInstance(Type.ALPHA);
			break;
		case INPUT_TYPE_ALPHA_NUMERIC:
			input = PinKeyListener.getInstance(Type.ALPHA_NUMERIC);
			break;
		default:
			throw new IllegalArgumentException("inputType must be one of "
					+ "INPUT_TYPE_NUMERIC, INPUT_TYPE_ALPHA, or INPUT_TYPE_ALPHA_NUMERIC");
		}

		mInputType = input.getInputType();
		mPinText.setKeyListener(input);

		InputMethodManager imm =
				(InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
		if (imm != null) imm.restartInput(this);
	}

	public int getInputType() {
		return mInputType;
	}

	public void setImeOptions(int options) {

	}

	public int getImeOptions() {
		return mImeOptions;
	}

	public void setImeActionLabel(CharSequence label, int actionId) {

	}

	public CharSequence getImeActionLabel() {
		return mImeActionLabel;
	}

	public int getImeActionId() {
		return mImeActionId;
	}
<commit_msg>- Implement setMaxPinLength() and setImeOptions()<commit_after>package com.karakuri.lib.pincodeview;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Selection;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.KeyListener;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.karakuri.lib.pincodeview.PinKeyListener.Type;

/**
 * A widget for displaying a pin code entry field.
 */
public class PinCodeView extends LinearLayout {
	private static final String TAG = "PinCodeView";

	private static final int DEFAULT_PIN_LENGTH = 4;

	/* values matching enum for R.styleable.PinCodeView_inputType */
	public static final int INPUT_TYPE_NUMERIC = 1;
	public static final int INPUT_TYPE_ALPHA = 2;
	public static final int INPUT_TYPE_ALPHA_NUMERIC = 3;

	private TextView mPinText;
	private int mMaxPinLength;

	private int mInputType;
	private int mImeOptions;
	private int mImeActionId;
	private CharSequence mImeActionLabel;

	public PinCodeView(Context context) {
		super(context);
	}

	public PinCodeView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context, attrs, R.attr.pinCodeViewStyle);
	}

	@TargetApi(Build.VERSION_CODES.HONEYCOMB)
	public PinCodeView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context, attrs, defStyle);
	}

	private void init(Context context, AttributeSet attrs, int defStyle) {
		Log.d(TAG, "[init]");
		
		int maxPinLength = DEFAULT_PIN_LENGTH;
		
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PinCodeView, defStyle, 0);
		try {
			final int N = a.getIndexCount();
			for (int i = 0; i < N; i++) {
				int attr = a.getIndex(i);

				switch (attr) {
				case R.styleable.PinCodeView_pinLength:
					maxPinLength = a.getInt(attr, maxPinLength);
					break;
				case R.styleable.PinCodeView_inputType:
					mInputType = a.getInt(attr, INPUT_TYPE_NUMERIC);
					break;
				case R.styleable.PinCodeView_android_imeOptions:
					mImeOptions = a.getInt(attr, mImeOptions);
					break;
				case R.styleable.PinCodeView_android_imeActionLabel:
					mImeActionLabel = a.getText(attr);
					break;
				case R.styleable.PinCodeView_android_imeActionId:
					mImeActionId = a.getInt(attr, 0);
					break;
				}
			}
		} finally {
			a.recycle();
		}

		mPinText = new TextView(context);
		mPinText.addTextChangedListener(mPinTextWatcher);

		setMaxPinLength(maxPinLength);
		setImeOptions(mImeOptions);
		setInputType(mInputType);

		setClickable(true);
		setFocusableInTouchMode(true);
	}

	private TextWatcher mPinTextWatcher = new TextWatcher() {

		@Override
		public void onTextChanged(CharSequence s, int start, int before, int count) {}

		@Override
		public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

		@Override
		public void afterTextChanged(Editable s) {
			Log.d(TAG, String.format("[afterTextChanged] s = \"%s\"", s));
		}
	};

	public void setMaxPinLength(int newLength) {
		if (mMaxPinLength != newLength) {
			mMaxPinLength = newLength;			
			mPinText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(newLength) });
			
			CharSequence text = mPinText.getText();
			if (text != null && text.length() > newLength) {
				mPinText.setText(text.subSequence(0, newLength));
				Selection.setSelection(mPinText.getEditableText(), newLength);
			}
		}
	}

	public int getMaxPinLength() {
		return mMaxPinLength;
	}

	public CharSequence getPin() {
		return mPinText.getText();
	}

	public void setInputType(int inputType) {
		PinKeyListener input;
		switch (inputType) {
		case INPUT_TYPE_NUMERIC:
			input = PinKeyListener.getInstance(Type.NUMERIC);
			break;
		case INPUT_TYPE_ALPHA:
			input = PinKeyListener.getInstance(Type.ALPHA);
			break;
		case INPUT_TYPE_ALPHA_NUMERIC:
			input = PinKeyListener.getInstance(Type.ALPHA_NUMERIC);
			break;
		default:
			throw new IllegalArgumentException("inputType must be one of "
					+ "INPUT_TYPE_NUMERIC, INPUT_TYPE_ALPHA, or INPUT_TYPE_ALPHA_NUMERIC");
		}

		mInputType = input.getInputType();
		mPinText.setKeyListener(input);

		InputMethodManager imm =
				(InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
		if (imm != null) imm.restartInput(this);
	}

	public int getInputType() {
		return mInputType;
	}

	public void setImeOptions(int options) {
		// try to prevent the IME from going full screen in landscape
		mImeOptions = options |= EditorInfo.IME_FLAG_NO_FULLSCREEN;
	}

	public int getImeOptions() {
		return mImeOptions;
	}

	public void setImeActionLabel(CharSequence label, int actionId) {

	}

	public CharSequence getImeActionLabel() {
		return mImeActionLabel;
	}

	public int getImeActionId() {
		return mImeActionId;
	}

{'fraction_non_alphanumeric': 0.09731477851822815, 'fraction_numerical': 0.0014700117600940808, 'mean_word_length': 4.701117318435754, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2361592', 'n_tokens_mistral': 3714, 'n_tokens_neox': 3342, 'n_words': 747}