Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add props and change layout modal android #291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public void isSupported(final Callback reactErrorCallback, final Callback reactS

int result = isFingerprintAuthAvailable();
if (result == FingerprintAuthConstants.IS_SUPPORTED) {
// TODO: once this package supports Android's Face Unlock,
// implement a method to find out which type of biometry
// (not just fingerprint) is actually supported
reactSuccessCallback.invoke("Fingerprint");
reactSuccessCallback.invoke("Is supported.");
} else {
reactErrorCallback.invoke("Not supported.", result);
}
Expand Down
43 changes: 37 additions & 6 deletions android/src/main/java/com/rnfingerprint/FingerprintDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.graphics.Color;
import android.widget.LinearLayout;
import android.graphics.drawable.Drawable;
import android.graphics.PorterDuff;

import com.facebook.react.bridge.ReadableMap;

Expand All @@ -25,11 +29,15 @@ public class FingerprintDialog extends DialogFragment implements FingerprintHand
private ImageView mFingerprintImage;
private TextView mFingerprintSensorDescription;
private TextView mFingerprintError;
private View mLine;
private LinearLayout mfingerprint_container;

private String authReason;
private int imageColor = 0;
private int imageErrorColor = 0;
private String dialogTitle = "";
private String textColor = "#333333";
private String lineColor = "#2782E5";
private String backgroundColor = "#ffffff";
private String cancelText = "";
private String sensorDescription = "";
private String sensorErrorDescription = "";
Expand All @@ -45,7 +53,7 @@ public void onAttach(Context context) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Material_Light_Dialog);
setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialogStyle);
setCancelable(false);
}

Expand All @@ -67,6 +75,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
this.mFingerprintError = (TextView) v.findViewById(R.id.fingerprint_error);
this.mFingerprintError.setText(this.errorText);

this.mfingerprint_container = (LinearLayout) v.findViewById(R.id.fingerprint_container);
this.mLine = (View) v.findViewById(R.id.line_division);

final Button mCancelButton = (Button) v.findViewById(R.id.cancel_button);
mCancelButton.setText(this.cancelText);
mCancelButton.setOnClickListener(new View.OnClickListener() {
Expand All @@ -76,7 +87,20 @@ public void onClick(View view) {
}
});

getDialog().setTitle(this.dialogTitle);
try{
Drawable backgroundModal = mfingerprint_container.getBackground();
backgroundModal.setColorFilter(Color.parseColor(this.backgroundColor), PorterDuff.Mode.SRC_IN);

mLine.setBackgroundColor(Color.parseColor(this.lineColor));

mCancelButton.setTextColor(Color.parseColor(this.textColor));
mFingerprintError.setTextColor(Color.parseColor(this.textColor));
mFingerprintDescription.setTextColor(Color.parseColor(this.textColor));
mFingerprintSensorDescription.setTextColor(Color.parseColor(this.textColor));
}catch (Exception e){

}

getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode != KeyEvent.KEYCODE_BACK || mFingerprintHandler == null) {
Expand Down Expand Up @@ -130,8 +154,16 @@ public void setAuthConfig(final ReadableMap config) {
return;
}

if (config.hasKey("title")) {
this.dialogTitle = config.getString("title");
if (config.hasKey("textColor")) {
this.textColor = config.getString("textColor");
}

if (config.hasKey("backgroundColor")) {
this.backgroundColor = config.getString("backgroundColor");
}

if (config.hasKey("lineColor")) {
this.lineColor = config.getString("lineColor");
}

if (config.hasKey("cancelText")) {
Expand Down Expand Up @@ -172,7 +204,6 @@ public void onAuthenticated() {

@Override
public void onError(String errorString, int errorCode) {
this.mFingerprintError.setText(errorString);
this.mFingerprintImage.setColorFilter(this.imageErrorColor);
this.mFingerprintSensorDescription.setText(this.sensorErrorDescription);
}
Expand Down
5 changes: 5 additions & 0 deletions android/src/main/res/layout/background_rounded.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/shape">
<solid android:color="#FFFFFF"/>
<corners android:radius="10dp"/> />
</shape>
82 changes: 46 additions & 36 deletions android/src/main/res/layout/fingerprint_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,85 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@layout/background_rounded"
android:weightSum="1">

<!-- https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.btn3al2l2 appCompat works if app is srcCompat 7 activity-->
<!-- app:srcCompat="@drawable/ic_fp_40px" -->

<TextView
android:id="@+id/fingerprint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="10dp"
android:gravity="left"
android:text="TextView"
android:textColor="#696969"
android:textSize="17dp" />


<LinearLayout
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="25dp"
android:paddingRight="20dp"
android:paddingTop="25dp">
android:padding="8dp"
android:orientation="vertical">

<ImageView
android:layout_marginTop="5dp"
android:id="@+id/fingerprint_icon"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_marginLeft="25dp"
android:gravity="left"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:src="@drawable/ic_fp_40px" />

<TextView
android:id="@+id/fingerprint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:gravity="center_horizontal"
android:text="TextView"
android:textColor="#333333"
android:textSize="17dp" />


<TextView
android:id="@+id/fingerprint_sensor_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:gravity="left|center_vertical"
android:textAlignment="center"
android:gravity="center_horizontal"
android:text="Touch sensor"
android:textColor="#696969"
android:textColor="#333333"
android:textSize="15dp" />
</LinearLayout>


<TextView
android:id="@+id/fingerprint_error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="TextView"
android:textColor="#F00"
android:textAlignment="center"
android:gravity="center_horizontal"
android:textColor="#333333"
android:textSize="15dp" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">

<View
android:id="@+id/line_division"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#2782E5"/>

<Button
android:id="@+id/cancel_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:gravity="center"
android:padding="0dp"
android:layout_marginBottom="1dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:paddingRight="15dp"
android:paddingLeft="15dp"
android:layout_marginEnd="10dp"
android:background="#fff"
android:text="Cancel"
android:textColor="#696969" />
android:textColor="#333333" />

</LinearLayout>

</LinearLayout>
9 changes: 9 additions & 0 deletions android/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


<resources>

<style name="MyDialogStyle" parent="@android:style/Theme.Material.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
</style>

</resources>