/**
 * This file was auto-generated by the Titanium Module SDK helper for Android
 * Appcelerator Titanium Mobile
 * Copyright (c) 2016 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 *
 */
package ti.touchid;

import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.CancellationSignal;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollFunction;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.kroll.KrollProxy;

import java.lang.Override;
import java.util.HashMap;

import android.app.Activity;

@Kroll.module(name="Touchid", id="ti.touchid")
public class TouchidModule extends KrollModule
{
	public static final int PERMISSION_CODE_FINGERPRINT = 99;



	@Kroll.constant public static final int SUCCESS = 0;
	@Kroll.constant public static final int SERVICE_MISSING = 1;
	@Kroll.constant public static final int SERVICE_VERSION_UPDATE_REQUIRED = 2;
	@Kroll.constant public static final int SERVICE_DISABLED = 3;
	@Kroll.constant public static final int SERVICE_INVALID = 9;


	protected FingerPrintHelper mfingerprintHelper;

	public TouchidModule()
	{
		super();
		Activity activity = TiApplication.getAppRootOrCurrentActivity();
		if (Build.VERSION.SDK_INT >= 23) {
			mfingerprintHelper = new FingerPrintHelper();
		}
	}

	@Kroll.method
	public boolean hasFingerprintPermissions() {
		if (Build.VERSION.SDK_INT < 23) {
			return true;
		}
		Activity currentActivity  = TiApplication.getInstance().getCurrentActivity();
		if (currentActivity.checkSelfPermission(Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED) {
			return true;
		}
		return false;
	}

	@Kroll.method
	public void requestFingerprintPermissions(@Kroll.argument(optional=true)KrollFunction permissionCallback) {
		if (hasFingerprintPermissions()) {
			return;
		}

		String[] permissions = new String[]{Manifest.permission.USE_FINGERPRINT};
		//TiBaseActivity.registerPermissionRequestCallback(PERMISSION_CODE_FINGERPRINT,permissionCallback, getKrollObject());

		Activity currentActivity = TiApplication.getInstance().getCurrentActivity();
		currentActivity.requestPermissions(permissions, PERMISSION_CODE_FINGERPRINT);
	}

	@Kroll.method
	public void authenticate(String reason, @Kroll.argument(optional=true)KrollFunction permissionCallback) {
		mfingerprintHelper.startListening(permissionCallback, getKrollObject());
	}

	@Kroll.method
	public HashMap deviceCanAuthenticate() {
		if (Build.VERSION.SDK_INT >= 23) {
			return mfingerprintHelper.deviceCanAuthenticate();
		}
		KrollDict response = new KrollDict();
		response.put("canAuthenticate", false);
		response.put("error", "Device is running with API < 23");
		return response;
	}

	@Kroll.method
	public boolean isSupported() {
		return mfingerprintHelper.isDeviceSupported();
	}

	@Override
	public void onPause(Activity activity) {
		super(activity);
		if (mfingerprintHelper != null) {
			mfingerprintHelper.stopListening();
		}
	}


}


@@ -3184,17 +3184,18 @@
 d();%0A%09%7D%0A
+%09
 %0A
-
 %09@Overri
@@ -3246,16 +3246,24 @@
 %0A%09%09super
+.onPause
 (activit
@@ -3265,16 +3265,17 @@
 tivity);
+%09
 %0A%09%09if (m
@@ -3338,24 +3338,25 @@
 istening();%0A
-
 %09%09%7D
+%09
 %0A%09%7D%0A%0A%0A%7D%0A%0A

Fix typo