MobbSign Cordova: Customize UI
Introduction
Mobbsign allows the customization of the user interface, making it a flexible product that can fits in any application indenpendently of its look & feel.
Customize Sign Document UI
When the method MobbSignAPI.signDocument
is called, a document screen appears by default. This screen can be customized using the following method:
MobbSignAPI.setSignDocumentInterface(uiClass, onSuccess, onFailure);
Where the arguments are:
uiClass
is the class name of the new screen.onSuccess
is a callback which will be called if the UI has been set correctly.onFailure
is a callback which will be called if some error happens.
The uiClass
should refer to Android or iOS native classes. Check the documentation of the native SDKs for more details about how to build these classes:
Instructions
To implement your own interface, you need to follow the instructions:
- Due to MobbSign Cordova is a wrapper for Android and Native MobbSign, read Getting Started of Android SDK.
- According to this and only after initialization, you can use our
PreferencesManager
to configure the license.
- According to this and only after initialization, you can use our
String license = preferencesManager.getPreference(PreferencesManager.LICENSE_KEY);
mobbSignView.configureLicense(license, new LicenseStatusListener() {
@Override
public void onLicenseStatusChecked(Date licenseValidTo, MobbSignLicenseResult licenseResult) {
Log.d(LOG_TAG, "LicenseResult " + licenseResult.toString());
}
});
NSString *license = [self.preferencesManager getPreference:LICENSE_KEY];
[self.mobbSignView configureLicense:license status:^(MobbSignLicenseResult result, NSDate *expirationDate) {
NSLog(@"LicenseResult: %ld", (long)result);
}];
- After that, you must configure the encription key.
Security.addProvider(new BouncyCastleProvider());
PEMParser reader = new PEMParser(new InputStreamReader(this.getAssets().open("<your file key>.key")));
Object obj;
PublicKey publicKey = null;
while (((obj = reader.readObject()) != null) && (publicKey == null)) {
if (obj instanceof SubjectPublicKeyInfo) {
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
publicKey = converter.getPublicKey((SubjectPublicKeyInfo) obj);
} else {
if (obj instanceof PublicKey) {
publicKey = (PublicKey) obj;
}
}
}
if (publicKey != null) {
mobbSignView.setEncryptionKey(publicKey);
return true;
}
NSString* keyPath = [[NSBundle mainBundle] pathForResource:@"<your file key>" ofType:@"key"];
[self.mobbSignView setEncryptionKey:keyPath];
NOTE: Whitout license and encription key, you will see the document loaded, but you can't sign the document. You will receive an error.
- In this moment, you must be able to load the document. We use the preference with the key
PreferencesManager.B64_FILE_KEY
to save the document due to his size.
String encodedFile = preferencesManager.getPreference(PreferencesManager.B64_FILE_KEY);
byte[] bytes = Base64.decode(encodedFile, Base64.DEFAULT);
InputStream document = new ByteArrayInputStream(bytes);
mobbSignView.loadPDFDocument(document, "documentTitle");
NSString *encodedFile = [self.preferencesManager getPreference:B64_FILE_KEY];
NSData *documentData = [[NSData alloc] initWithBase64EncodedString:encodedFile options:NSDataBase64DecodingIgnoreUnknownCharacters];
[self.mobbSignView loadPDFDocumentFromData:documentData name:@"documentTitle"];
- If you want to use the listeners of the signing documents process, you must set the listener on
mobbSignView
object and launch the specific event using theMobbSignEventsManager
class.
mobbSignView.setOnDocumentShownListener((editable) -> {
eventsManager.sendOnDocumentShownEvent(editable);
});
mobbSignView.setOnDocumentSignedListener((document, encryptedSignatureData, signatureBitmap, signaturePage, signatureCoord) -> {
eventsManager.sendOnDocumentSignedEvent(document, encryptedSignatureData, signatureBitmap, signaturePage, signatureCoord);
});
mobbSignView.setOnSignatureAcquiredListener(() -> {
eventsManager.sendOnSignatureAcquiredEvent();
});
mobbSignView.setOnSignatureDeletedListener(() -> {
eventsManager.sendOnSignatureDeletedEvent();
});
mobbSignView.setOnBackButtonPressedListener(() -> {
eventsManager.sendOnBackButtonPressedEvent();
});
mobbSignView.setOnSignButtonPressedListener(() -> {
eventsManager.sendOnSignButtonPressedEvent();
});
mobbSignView.setOnProcessEndListener(bytes -> {
eventsManager.sendOnProcessEndEvent();
});
mobbSignView.setOnErrorOccurredListener((errorCode, hashMap) -> {
String message;
switch (errorCode) {
case MobbSignResultCodes.ERROR_VISUALIZING_DOCUMENT:
message = getResources().getString(R.string.msg_error_visualizing_document);
break;
case MobbSignResultCodes.ERROR_STAMPING_SIGNATURE:
message = getResources().getString(R.string.msg_error_stamping_signature);
break;
case MobbSignResultCodes.ERROR_SAVING_FORM_FIELDS:
message = getResources().getString(R.string.msg_error_saving_form_fields);
break;
case MobbSignResultCodes.ERROR_DOCUMENT_IS_NOT_COMPLETELY_FILLED:
message = getResources().getString(R.string.msg_error_document_is_not_completely_filled);
break;
case MobbSignResultCodes.ERROR_LICENSE_INVALID:
message = getResources().getString(R.string.msg_error_license_invalid);
break;
case MobbSignResultCodes.ERROR_MANDATORY_PARAMS:
message = getResources().getString(R.string.msg_error_mandatory_params);
break;
case MobbSignResultCodes.ERROR_SIGNATURE_NOT_VERIFIED:
message = getResources().getString(R.string.msg_error_signature_not_verified);
break;
case MobbSignResultCodes.ERROR_CUSTOMIZATION_PROPERTY:
message = getResources().getString(R.string.msg_error_customization_property);
break;
case MobbSignResultCodes.ERROR_VERIFYING_SIGNATURE:
message = getResources().getString(R.string.msg_error_verifying_signature);
break;
case MobbSignResultCodes.ERROR_VERIFICATION_MODULE_NOT_PRESENT:
message = getResources().getString(R.string.msg_error_verification_module_not_present);
break;
case MobbSignResultCodes.ERROR_CANNOT_SIGN_EDITABLE_DOCUMENT:
message = getResources().getString(R.string.msg_error_cannot_sign_editable_document);
break;
case MobbSignResultCodes.ERROR_TIMESTAMP:
message = null;
break;
case MobbSignResultCodes.ERROR_STAMPING_SIGNATURE_DATA:
message = getResources().getString(R.string.msg_error_stamping_signatute_data);
break;
default:
message = getResources().getString(R.string.error_unexpected);
break;
}
eventsManager.sendOnErrorOccurredEvent(errorCode, message);
});
[self.mobbSignView setOnDocumentShown:^(BOOL editable) {
[self.eventsManager sendOnDocumentShownEvent:editable];
}];
[self.mobbSignView setOnDocumentSigned:^(NSData *document, NSData *encryptedSignatureData, UIImage *signatureBitmap, NSInteger signaturePage, CGRect signatureCoord) {
[self.eventsManager sendOnDocumentSignedEvent:document encryptedSignatureData:encryptedSignatureData signatureBitmap:signatureBitmap signaturePage:signaturePage signatureCoord:signatureCoord];
}];
[self.mobbSignView setOnSignatureAcquised:^{
[self.eventsManager sendOnSignatureAcquiredEvent];
}];
[self.mobbSignView setOnSignatureDeleted:^{
[self.eventsManager sendOnSignatureDeletedEvent];
}];
[self.mobbSignView setOnBackButtonPressed:^{
[self.eventsManager sendOnBackButtonPressedEvent];
}];
[self.mobbSignView setOnSignButtonPressed:^{
[self.eventsManager sendOnSignButtonPressedEvent];
}];
[self.mobbSignView setOnProcessEnd:^(NSData *signedDocument) {
[self.eventsManager sendOnProcessEndEvent];
}];
[self.mobbSignView setOnErrorOccurred:^(int errorCode, NSDictionary *errorDetail) {
[self.eventsManager sendOnErrorOccurredEvent:[NSNumber numberWithInt:errorCode] detail:errorDetail];
}];
Examples
SignDocumentInterfaceDefault
package com.mobbeel.mobbsign.interfaces;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.mobbeel.mobbsign.cordovaplugindemo.R;
import com.mobbeel.mobbsign.events.MobbSignEventsManager;
import com.mobbeel.mobbsign.license.LicenseStatusListener;
import com.mobbeel.mobbsign.license.MobbSignLicenseResult;
import com.mobbeel.mobbsign.utils.PreferencesManager;
import com.mobbeel.mobbsign.view.MobbSignCustomizationProperties;
import com.mobbeel.mobbsign.view.MobbSignResultCodes;
import com.mobbeel.mobbsign.view.MobbSignView;
import org.spongycastle.asn1.x509.SubjectPublicKeyInfo;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.openssl.PEMParser;
import org.spongycastle.openssl.jcajce.JcaPEMKeyConverter;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.PublicKey;
import java.security.Security;
import java.util.Date;
public class SignDocumentInterfaceDefault extends Activity {
private PreferencesManager preferencesManager;
private MobbSignEventsManager eventsManager;
private static final String LOG_TAG = "[MobbSignCordova]";
// topBar buttons
private Button btnSign;
private Button btnSave;
// bottomBar buttons
private ImageButton btnZoomIn;
private ImageButton btnZoomOut;
private ImageButton btnPagePrev;
private ImageButton btnPageNext;
private MobbSignView mobbSignView = null;
private RelativeLayout rlMobbSignView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferencesManager = new PreferencesManager(this);
eventsManager = new MobbSignEventsManager(this);
initMobbSignView();
}
private void setupUserConfigurations() {
btnZoomOut = findViewById(R.id.btnZoomOut);
btnZoomIn = findViewById(R.id.btnZoomIn);
btnPagePrev = findViewById(R.id.btnPagePrev);
btnPageNext = findViewById(R.id.btnPageNext);
btnSign = findViewById(R.id.btnSign);
btnSave = findViewById(R.id.btnSave);
}
private void initMobbSignView() {
setContentView(R.layout.mobbsignview);
Bundle customizationBundle = createCustomization();
mobbSignView = new MobbSignView(this, customizationBundle);
rlMobbSignView = findViewById(R.id.mobbsignview);
rlMobbSignView.addView(mobbSignView);
setupUserConfigurations();
setListeners();
configureLicense();
configureEncryptionKey();
loadPDFDocument();
}
private Bundle createCustomization() {
Bundle customizationBundle = new Bundle();
customizationBundle.putBoolean(MobbSignCustomizationProperties.TOPBAR_SHOWING, false);
customizationBundle.putBoolean(MobbSignCustomizationProperties.BOTTOMBAR_SHOWING, false);
customizationBundle.putBoolean(MobbSignCustomizationProperties.PROGRESS_BAR_SHOWING, false);
customizationBundle.putBoolean(MobbSignCustomizationProperties.ALLOW_SIGN_AFTER_TSA_ERROR, true);
return customizationBundle;
}
private void configureTopBar() {
if (mobbSignView.isEditable()) {
btnSave.setVisibility(View.VISIBLE);
btnSign.setVisibility(View.GONE);
} else {
btnSign.setEnabled(true);
btnSign.setVisibility(View.VISIBLE);
btnSave.setVisibility(View.GONE);
}
if (btnSign != null) {
btnSign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(SignDocumentInterfaceDefault.this, getString(R.string.msg_sign_now), Toast.LENGTH_SHORT).show();
switchBottomBar(false);
btnSign.setVisibility(View.GONE);
mobbSignView.signDocument();
}
});
}
if (btnSave != null) {
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnSave.setEnabled(false);
new StampDocumentTask().execute();
}
});
}
}
private void configureBottomBar() {
int pageCount = mobbSignView.getPageCount();
if (btnZoomIn != null) {
btnZoomIn.setEnabled(true);
btnZoomIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnZoomOut.setEnabled(true);
if (!mobbSignView.zoomIn()) {
btnZoomIn.setEnabled(false);
}
}
});
}
if (btnZoomOut != null) {
btnZoomOut.setEnabled(false);
btnZoomOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnZoomIn.setEnabled(true);
if (!mobbSignView.zoomOut()) {
btnZoomOut.setEnabled(false);
}
}
});
}
if (btnPagePrev != null) {
btnPagePrev.setEnabled(false);
btnPagePrev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mobbSignView.goToPreviousPage();
checkPageButtons();
}
});
}
if (btnPageNext != null) {
btnPageNext.setEnabled(pageCount > 1);
btnPageNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mobbSignView.goToNextPage();
checkPageButtons();
}
});
}
}
private void checkPageButtons() {
int pageCount = mobbSignView.getPageCount();
btnPagePrev.setEnabled(mobbSignView.getCurrentPage() != 1);
btnPageNext.setEnabled(mobbSignView.getCurrentPage() != pageCount);
}
private class StampDocumentTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
return null;
}
@Override
protected void onPostExecute(Void params) {
mobbSignView.stampDocument();
}
}
private void switchBottomBar(boolean value) {
if (btnZoomOut != null) {
btnZoomOut.setEnabled(value);
if (value) {
btnZoomOut.setEnabled(mobbSignView.getZoomLevel() > 1.0);
}
}
if (btnZoomIn != null) {
btnZoomIn.setEnabled(value);
if (value) {
btnZoomIn.setEnabled(!(mobbSignView.getZoomLevel() > 2.7));
}
}
if (btnPagePrev != null) {
btnPagePrev.setEnabled(value);
if (value) {
btnPagePrev.setEnabled(mobbSignView.getCurrentPage() != 1);
}
}
if (btnPageNext != null) {
btnPageNext.setEnabled(value);
if (value) {
btnPageNext.setEnabled(mobbSignView.getCurrentPage() != mobbSignView.getPageCount());
}
}
}
private void setListeners() {
mobbSignView.setOnDocumentShownListener((editable) -> {
configureTopBar();
configureBottomBar();
eventsManager.sendOnDocumentShownEvent(editable);
});
mobbSignView.setOnDocumentSignedListener((document, encryptedSignatureData, signatureBitmap, signaturePage, signatureCoord) -> {
mobbSignView.endProcess();
eventsManager.sendOnDocumentSignedEvent(document, encryptedSignatureData, signatureBitmap, signaturePage, signatureCoord);
});
mobbSignView.setOnSignatureAcquiredListener(() -> {
btnSign.setVisibility(View.GONE);
btnSave.setVisibility(View.VISIBLE);
eventsManager.sendOnSignatureAcquiredEvent();
});
mobbSignView.setOnSignatureDeletedListener(() -> {
eventsManager.sendOnSignatureDeletedEvent();
});
mobbSignView.setOnBackButtonPressedListener(() -> {
eventsManager.sendOnBackButtonPressedEvent();
});
mobbSignView.setOnSignButtonPressedListener(() -> {
eventsManager.sendOnSignButtonPressedEvent();
});
mobbSignView.setOnProcessEndListener(bytes -> {
eventsManager.sendOnProcessEndEvent();
});
mobbSignView.setOnErrorOccurredListener((errorCode, hashMap) -> {
String message;
switch (errorCode) {
case MobbSignResultCodes.ERROR_VISUALIZING_DOCUMENT:
message = getResources().getString(R.string.msg_error_visualizing_document);
break;
case MobbSignResultCodes.ERROR_STAMPING_SIGNATURE:
message = getResources().getString(R.string.msg_error_stamping_signature);
break;
case MobbSignResultCodes.ERROR_SAVING_FORM_FIELDS:
message = getResources().getString(R.string.msg_error_saving_form_fields);
break;
case MobbSignResultCodes.ERROR_DOCUMENT_IS_NOT_COMPLETELY_FILLED:
message = getResources().getString(R.string.msg_error_document_is_not_completely_filled);
break;
case MobbSignResultCodes.ERROR_LICENSE_INVALID:
message = getResources().getString(R.string.msg_error_license_invalid);
break;
case MobbSignResultCodes.ERROR_MANDATORY_PARAMS:
message = getResources().getString(R.string.msg_error_mandatory_params);
break;
case MobbSignResultCodes.ERROR_SIGNATURE_NOT_VERIFIED:
message = getResources().getString(R.string.msg_error_signature_not_verified);
break;
case MobbSignResultCodes.ERROR_CUSTOMIZATION_PROPERTY:
message = getResources().getString(R.string.msg_error_customization_property);
break;
case MobbSignResultCodes.ERROR_VERIFYING_SIGNATURE:
message = getResources().getString(R.string.msg_error_verifying_signature);
break;
case MobbSignResultCodes.ERROR_VERIFICATION_MODULE_NOT_PRESENT:
message = getResources().getString(R.string.msg_error_verification_module_not_present);
break;
case MobbSignResultCodes.ERROR_CANNOT_SIGN_EDITABLE_DOCUMENT:
message = getResources().getString(R.string.msg_error_cannot_sign_editable_document);
break;
case MobbSignResultCodes.ERROR_TIMESTAMP:
message = null;
Toast.makeText(SignDocumentInterfaceDefault.this, getResources().getString(R.string.msg_error_timestamp), Toast.LENGTH_LONG).show();
break;
case MobbSignResultCodes.ERROR_STAMPING_SIGNATURE_DATA:
message = getResources().getString(R.string.msg_error_stamping_signatute_data);
break;
default:
message = getResources().getString(R.string.error_unexpected);
break;
}
btnSave.setEnabled(true);
eventsManager.sendOnErrorOccurredEvent(errorCode, message);
});
}
private void configureLicense() {
String license = preferencesManager.getPreference(PreferencesManager.LICENSE_KEY);
mobbSignView.configureLicense(license, new LicenseStatusListener() {
@Override
public void onLicenseStatusChecked(Date licenseValidTo, MobbSignLicenseResult licenseResult) {
Log.d(LOG_TAG, "LicenseResult " + licenseResult.toString());
}
});
}
private boolean configureEncryptionKey() {
try {
Security.addProvider(new BouncyCastleProvider());
PEMParser reader = new PEMParser(new InputStreamReader(this.getAssets().open("mobbsign.key")));
Object obj;
PublicKey publicKey = null;
while (((obj = reader.readObject()) != null) && (publicKey == null)) {
if (obj instanceof SubjectPublicKeyInfo) {
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
publicKey = converter.getPublicKey((SubjectPublicKeyInfo) obj);
} else {
if (obj instanceof PublicKey) {
publicKey = (PublicKey) obj;
}
}
}
if (publicKey != null) {
mobbSignView.setEncryptionKey(publicKey);
return true;
}
Log.e(LOG_TAG, "Cannot find public key in the file");
return false;
} catch (IOException e) {
Log.e(LOG_TAG, "Cannot access public key file");
return false;
}
}
private void loadPDFDocument(){
String encodedFile = preferencesManager.getPreference(PreferencesManager.B64_FILE_KEY);
byte[] bytes2 = Base64.decode(encodedFile, Base64.DEFAULT);
InputStream toLoad = new ByteArrayInputStream(bytes2);
mobbSignView.loadPDFDocument(toLoad, "documentTitle");
}
@Override
protected void onPause() {
super.onPause();
if (mobbSignView != null) {
mobbSignView.pause();
}
}
@Override
protected void onResume() {
super.onResume();
if (mobbSignView != null) {
mobbSignView.resume();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mobbSignView != null) {
mobbSignView.destroy();
mobbSignView = null;
}
}
@Override
public void onLowMemory() {
super.onLowMemory();
if (mobbSignView != null) {
mobbSignView.purgeMemory();
}
}
}
#import "SignDocumentInterfaceDefault.h"
#import <MobbSignSDK/MobbSignView.h>
#import <MobbSignSDK/MobbSignCustomizationProperties.h>
#import "PreferencesManager.h"
#import "UIView+Toast.h"
#import "MobbSignEventsManager.h"
#define LOG_TAG @"[MobbSignCordova]"
#define logCurrentMethod() NSLog(@"%@ %@", LOG_TAG, NSStringFromSelector(_cmd))
@interface SignDocumentInterfaceDefault ()
@property (nonatomic, strong) MobbSignView* mobbSignView;
@property (weak, nonatomic) IBOutlet UIView *content;
@property (weak, nonatomic) IBOutlet UIButton *saveButton;
@property (weak, nonatomic) IBOutlet UIButton *signButton;
@property (weak, nonatomic) IBOutlet UIButton *discardButton;
@property (weak, nonatomic) IBOutlet UIButton *confirmButton;
@property (weak, nonatomic) IBOutlet UIButton *zoomOutButton;
@property (weak, nonatomic) IBOutlet UIButton *prevPageButton;
@property (weak, nonatomic) IBOutlet UIButton *nextPageButton;
@property (weak, nonatomic) IBOutlet UIButton *zoomInButton;
@property (strong, nonatomic) PreferencesManager *preferencesManager;
@property (strong, nonatomic) MobbSignEventsManager *eventsManager;
@end
@implementation SignDocumentInterfaceDefault
#pragma mark - View Controller methods
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.preferencesManager = [[PreferencesManager alloc] init];
self.eventsManager = [[MobbSignEventsManager alloc] init];
[self initMobbSignView];
}
- (void)initMobbSignView {
logCurrentMethod();
_mobbSignView = [[MobbSignView alloc] initWithFrame:[self.content bounds] customizationDictionary:[self createCustomization]];
[self.content addSubview:_mobbSignView];
[self configureLicense];
[self configureEncryptionKey];
[self setListeners];
[self configureTopBar];
[self configureBottomBar];
[self loadPDFDocument];
}
- (void)configureLicense {
NSString *license = [self.preferencesManager getPreference:LICENSE_KEY];
[self.mobbSignView configureLicense:license status:^(MobbSignLicenseResult result, NSDate *expirationDate) {
logCurrentMethod();
}];
}
- (void)configureEncryptionKey {
NSString* keyPath = [[NSBundle mainBundle] pathForResource:@"development-public" ofType:@"key"];
[self.mobbSignView setEncryptionKey:keyPath];
}
- (void)loadPDFDocument {
NSData *documentData = [[NSData alloc] initWithBase64EncodedString:[self.preferencesManager getPreference:B64_FILE_KEY] options:NSDataBase64DecodingIgnoreUnknownCharacters];
[self.mobbSignView loadPDFDocumentFromData:documentData name:@"document to sign"];
}
- (NSMutableDictionary*)createCustomization {
NSMutableDictionary * customDict = [[NSMutableDictionary alloc] init];
[customDict setObject:[NSNumber numberWithBool:NO] forKey:kMobbSign_TOPBAR_SHOWING];
[customDict setObject:[NSNumber numberWithBool:NO] forKey:kMobbSign_BOTTOMBAR_SHOWING];
[customDict setObject:[NSNumber numberWithBool:YES] forKey:kMobbSign_ALLOW_SIGN_AFTER_TSA_ERROR];
return customDict;
}
- (void)setListeners {
[self.mobbSignView setOnDocumentShown:^(BOOL editable) {
logCurrentMethod();
[self.eventsManager sendOnDocumentShownEvent:editable];
}];
[self.mobbSignView setOnDocumentSigned:^(NSData *document, NSData *encryptedSignatureData, UIImage *signatureBitmap, NSInteger signaturePage, CGRect signatureCoord) {
logCurrentMethod();
[self.eventsManager sendOnDocumentSignedEvent:document encryptedSignatureData:encryptedSignatureData signatureBitmap:signatureBitmap signaturePage:signaturePage signatureCoord:signatureCoord];
}];
[self.mobbSignView setOnSignatureAcquised:^{
logCurrentMethod();
[self.eventsManager sendOnSignatureAcquiredEvent];
}];
[self.mobbSignView setOnSignatureDeleted:^{
logCurrentMethod();
[self.eventsManager sendOnSignatureDeletedEvent];
}];
[self.mobbSignView setOnBackButtonPressed:^{
logCurrentMethod();
[self.eventsManager sendOnBackButtonPressedEvent];
}];
[self.mobbSignView setOnSignButtonPressed:^{
logCurrentMethod();
[self.eventsManager sendOnSignButtonPressedEvent];
}];
[self.mobbSignView setOnProcessEnd:^(NSData *signedDocument) {
logCurrentMethod();
[self.eventsManager sendOnProcessEndEvent];
}];
[self.mobbSignView setOnErrorOccurred:^(int errorCode, NSDictionary *errorDetail) {
logCurrentMethod();
[self.eventsManager sendOnErrorOccurredEvent:[NSNumber numberWithInt:errorCode] detail:errorDetail];
}];
}
- (void) configureTopBar {
[self enableTopBarButtons:true save:false confirm:false discard:false];
}
- (void) configureBottomBar {
UIImage *prevImage = [UIImage imageNamed:@"MobbSignSDK.bundle/previous.png"];
[self.prevPageButton setImage:prevImage forState:UIControlStateNormal];
UIImage *nextImage = [UIImage imageNamed:@"MobbSignSDK.bundle/next.png"];
[self.nextPageButton setImage:nextImage forState:UIControlStateNormal];
UIImage *zoomInImage = [UIImage imageNamed:@"MobbSignSDK.bundle/zoomin.png"];
[self.zoomInButton setImage:zoomInImage forState:UIControlStateNormal];
UIImage *zoomOutImage = [UIImage imageNamed:@"MobbSignSDK.bundle/zoomout.png"];
[self.zoomOutButton setImage:zoomOutImage forState:UIControlStateNormal];
[self enableBottomBarButtons:TRUE prevPage:TRUE nextPage:TRUE zoomIn:TRUE];
}
- (IBAction)signButtonAction:(id)sender {
[self enableTopBarButtons:false save:false confirm:true discard:true];
[self enableBottomBarButtons:false prevPage:false nextPage:false zoomIn:false];
[self.view makeToast:@"Puedes firmar ahora"];
[self.mobbSignView signDocument];
}
- (IBAction)saveButtonAction:(id)sender {
[self.eventsManager sendOnProcessEndEvent];
[self dismissViewControllerAnimated:YES completion:Nil];
}
- (IBAction)discardButtonAction:(id)sender {
[self.mobbSignView deleteSignature];
[self.view makeToast:@"Descartando firma..."];
[self enableTopBarButtons:true save:false confirm:false discard:false];
[self enableBottomBarButtons:true prevPage:true nextPage:true zoomIn:true];
}
- (IBAction)confirmButtonAction:(id)sender {
[self.mobbSignView stampDocument];
[self.view makeToast:@"Almacenando firma..."];
[self enableTopBarButtons:true save:true confirm:false discard:false];
[self enableBottomBarButtons:true prevPage:true nextPage:true zoomIn:true];
}
- (IBAction)zoomOutButtonAction:(id)sender {
[self.mobbSignView zoomOut];
}
- (IBAction)zoomInButtonAction:(id)sender {
[self.mobbSignView zoomIn];
}
- (IBAction)prevPageButtonAction:(id)sender {
[self.mobbSignView goToPreviousPage];
[self enableBottomBarButtons:true prevPage:true nextPage:true zoomIn:true];
}
- (IBAction)nextPageButtonAction:(id)sender {
[self.mobbSignView goToNextPage];
[self enableBottomBarButtons:true prevPage:true nextPage:true zoomIn:true];
}
- (void)enableTopBarButtons: (BOOL)sign save:(BOOL)save confirm:(BOOL)confirm discard:(BOOL)discard {
[self.signButton setHidden:!sign];
[self.saveButton setHidden:!save];
[self.confirmButton setHidden:!confirm];
[self.discardButton setHidden:!discard];
}
- (void)enableBottomBarButtons: (BOOL)zoomOut prevPage:(BOOL)prevPage nextPage:(BOOL)nextPage zoomIn:(BOOL)zoomIn {
[self.zoomOutButton setEnabled:zoomOut];
if (prevPage && [self.mobbSignView getCurrentPage] != 1) {
[self.prevPageButton setEnabled:true];
}else{
[self.prevPageButton setEnabled:false];
}
if ([self.mobbSignView getPageCount] == 0 || (nextPage && [self.mobbSignView getCurrentPage] != [self.mobbSignView getPageCount])){
[self.nextPageButton setEnabled:true];
}else{
[self.nextPageButton setEnabled:false];
}
[self.zoomInButton setEnabled:zoomIn];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
@end