Refactor ClipboardManager wrapper

There are a lot of alternative method signatures, so restructure to
avoid an additional level of indentation for each one.
pr4822
Romain Vimont 2 months ago
parent 7011dd1ef0
commit d1a0f9b054

@ -38,38 +38,47 @@ public final class ClipboardManager {
if (getPrimaryClipMethod == null) { if (getPrimaryClipMethod == null) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class); getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class);
} else { return getPrimaryClipMethod;
try { }
getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, int.class); try {
getMethodVersion = 0; getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, int.class);
} catch (NoSuchMethodException e1) { getMethodVersion = 0;
try { return getPrimaryClipMethod;
getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, String.class, int.class); } catch (NoSuchMethodException e) {
getMethodVersion = 1; // fall through
} catch (NoSuchMethodException e2) { }
try { try {
getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, String.class, int.class, int.class); getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, String.class, int.class);
getMethodVersion = 2; getMethodVersion = 1;
} catch (NoSuchMethodException e3) { return getPrimaryClipMethod;
try { } catch (NoSuchMethodException e) {
getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, int.class, String.class); // fall through
getMethodVersion = 3; }
} catch (NoSuchMethodException e4) { try {
try { getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, String.class, int.class, int.class);
getPrimaryClipMethod = manager.getClass() getMethodVersion = 2;
.getMethod("getPrimaryClip", String.class, String.class, int.class, int.class, boolean.class); return getPrimaryClipMethod;
getMethodVersion = 4; } catch (NoSuchMethodException e) {
} catch (NoSuchMethodException e5) { // fall through
getPrimaryClipMethod = manager.getClass() }
.getMethod("getPrimaryClip", String.class, String.class, String.class, String.class, int.class, int.class, try {
boolean.class); getPrimaryClipMethod = manager.getClass().getMethod("getPrimaryClip", String.class, int.class, String.class);
getMethodVersion = 5; getMethodVersion = 3;
} return getPrimaryClipMethod;
} } catch (NoSuchMethodException e) {
} // fall through
}
}
} }
try {
getPrimaryClipMethod = manager.getClass()
.getMethod("getPrimaryClip", String.class, String.class, int.class, int.class, boolean.class);
getMethodVersion = 4;
return getPrimaryClipMethod;
} catch (NoSuchMethodException e) {
// fall through
}
getPrimaryClipMethod = manager.getClass()
.getMethod("getPrimaryClip", String.class, String.class, String.class, String.class, int.class, int.class, boolean.class);
getMethodVersion = 5;
} }
return getPrimaryClipMethod; return getPrimaryClipMethod;
} }
@ -78,27 +87,33 @@ public final class ClipboardManager {
if (setPrimaryClipMethod == null) { if (setPrimaryClipMethod == null) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
setPrimaryClipMethod = manager.getClass().getMethod("setPrimaryClip", ClipData.class, String.class); setPrimaryClipMethod = manager.getClass().getMethod("setPrimaryClip", ClipData.class, String.class);
} else { return setPrimaryClipMethod;
try { }
setPrimaryClipMethod = manager.getClass().getMethod("setPrimaryClip", ClipData.class, String.class, int.class); try {
setMethodVersion = 0; setPrimaryClipMethod = manager.getClass().getMethod("setPrimaryClip", ClipData.class, String.class, int.class);
} catch (NoSuchMethodException e1) { setMethodVersion = 0;
try { return setPrimaryClipMethod;
setPrimaryClipMethod = manager.getClass().getMethod("setPrimaryClip", ClipData.class, String.class, String.class, int.class); } catch (NoSuchMethodException e) {
setMethodVersion = 1; // fall through
} catch (NoSuchMethodException e2) { }
try { try {
setPrimaryClipMethod = manager.getClass() setPrimaryClipMethod = manager.getClass().getMethod("setPrimaryClip", ClipData.class, String.class, String.class, int.class);
.getMethod("setPrimaryClip", ClipData.class, String.class, String.class, int.class, int.class); setMethodVersion = 1;
setMethodVersion = 2; return setPrimaryClipMethod;
} catch (NoSuchMethodException e3) { } catch (NoSuchMethodException e) {
setPrimaryClipMethod = manager.getClass() // fall through
.getMethod("setPrimaryClip", ClipData.class, String.class, String.class, int.class, int.class, boolean.class); }
setMethodVersion = 3; try {
} setPrimaryClipMethod = manager.getClass()
} .getMethod("setPrimaryClip", ClipData.class, String.class, String.class, int.class, int.class);
} setMethodVersion = 2;
return setPrimaryClipMethod;
} catch (NoSuchMethodException e) {
// fall though
} }
setPrimaryClipMethod = manager.getClass()
.getMethod("setPrimaryClip", ClipData.class, String.class, String.class, int.class, int.class, boolean.class);
setMethodVersion = 3;
} }
return setPrimaryClipMethod; return setPrimaryClipMethod;
} }

Loading…
Cancel
Save