@@ -252,7 +252,7 @@ public class PApplet extends Object implements PConstants {
252
252
/**
253
253
* Callback methods to handle permission requests
254
254
*/
255
- protected HashMap <String , Method > permissionMethods = new HashMap <String , Method >();
255
+ protected HashMap <String , String > permissionMethods = new HashMap <String , String >();
256
256
257
257
258
258
/**
@@ -599,32 +599,21 @@ public void requestPermission(String permission) {
599
599
600
600
601
601
public void requestPermission (String permission , String callback ) {
602
- Method handleMethod = null ;
603
- try {
604
- Class <?> callbackClass = this .getClass ();
605
- handleMethod = callbackClass .getMethod (callback , new Class [] { boolean .class });
606
- } catch (NoSuchMethodException nsme ) {
607
- System .err .println (callback + "() could not be found" );
608
- }
609
- if (handleMethod != null ) {
610
- if (hasPermission (permission )) {
611
- // If the app already has permission, still call the handle method as it
612
- // may be doing some initialization
613
- try {
614
- handleMethod .invoke (this , new Object [] { true });
615
- } catch (IllegalAccessException e ) {
616
- e .printStackTrace ();
617
- } catch (IllegalArgumentException e ) {
618
- e .printStackTrace ();
619
- } catch (InvocationTargetException e ) {
620
- e .printStackTrace ();
621
- }
622
- } else {
623
- permissionMethods .put (permission , handleMethod );
624
- // Accumulating permissions so they requested all at once at the end
625
- // of draw.
626
- reqPermissions .add (permission );
627
- }
602
+ requestPermission (permission , callback , this );
603
+ }
604
+
605
+
606
+ public void requestPermission (String permission , String callback , Object target ) {
607
+ registerWithArgs (callback , target , new Class [] { boolean .class });
608
+ if (hasPermission (permission )) {
609
+ // If the app already has permission, still call the handle method as it
610
+ // may be doing some initialization
611
+ handleMethods (callback , new Object [] { true });
612
+ } else {
613
+ permissionMethods .put (permission , callback );
614
+ // Accumulating permissions so they requested all at once at the end
615
+ // of draw.
616
+ reqPermissions .add (permission );
628
617
}
629
618
}
630
619
@@ -642,17 +631,10 @@ public void onRequestPermissionsResult(int requestCode,
642
631
643
632
644
633
private void handlePermissionsResult (String permission , boolean granted ) {
645
- Method handleMethod = permissionMethods .get (permission );
646
- if (handleMethod != null ) {
647
- try {
648
- handleMethod .invoke (this , new Object [] { granted });
649
- } catch (IllegalAccessException e ) {
650
- e .printStackTrace ();
651
- } catch (IllegalArgumentException e ) {
652
- e .printStackTrace ();
653
- } catch (InvocationTargetException e ) {
654
- e .printStackTrace ();
655
- }
634
+ String methodName = permissionMethods .get (permission );
635
+ RegisteredMethods meth = registerMap .get (methodName );
636
+ if (meth != null ) {
637
+ meth .handle (new Object [] { granted });
656
638
}
657
639
}
658
640
0 commit comments