id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
sequence | docstring
stringlengths 3
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
2,300 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/system.java | system.navigateToActivityByClassName | public static void navigateToActivityByClassName(Context context, String className) throws ClassNotFoundException {
Class<?> c = null;
if (className != null) {
try {
c = Class.forName(className);
} catch (ClassNotFoundException e) {
QuickUtils.log.d("ClassNotFound", e);
}
}
navigateToActivity(context, c);
} | java | public static void navigateToActivityByClassName(Context context, String className) throws ClassNotFoundException {
Class<?> c = null;
if (className != null) {
try {
c = Class.forName(className);
} catch (ClassNotFoundException e) {
QuickUtils.log.d("ClassNotFound", e);
}
}
navigateToActivity(context, c);
} | [
"public",
"static",
"void",
"navigateToActivityByClassName",
"(",
"Context",
"context",
",",
"String",
"className",
")",
"throws",
"ClassNotFoundException",
"{",
"Class",
"<",
"?",
">",
"c",
"=",
"null",
";",
"if",
"(",
"className",
"!=",
"null",
")",
"{",
"try",
"{",
"c",
"=",
"Class",
".",
"forName",
"(",
"className",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"d",
"(",
"\"ClassNotFound\"",
",",
"e",
")",
";",
"}",
"}",
"navigateToActivity",
"(",
"context",
",",
"c",
")",
";",
"}"
] | Navigate to an activity programmatically by providing the package +
activity name
@param context Context where I am coming from
@param className Full path to the desired Activity (e.g.
"com.sample.MainActivity") | [
"Navigate",
"to",
"an",
"activity",
"programmatically",
"by",
"providing",
"the",
"package",
"+",
"activity",
"name"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/system.java#L80-L91 |
2,301 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/system.java | system.getApplicationHashKey | public static String getApplicationHashKey(String packageName) {
String hash = "";
try {
PackageInfo info = QuickUtils.getContext().getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
hash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
}
} catch (NameNotFoundException e) {
QuickUtils.log.e("NameNotFoundException");
} catch (NoSuchAlgorithmException e) {
QuickUtils.log.e("NoSuchAlgorithmException");
}
return hash;
} | java | public static String getApplicationHashKey(String packageName) {
String hash = "";
try {
PackageInfo info = QuickUtils.getContext().getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
hash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
}
} catch (NameNotFoundException e) {
QuickUtils.log.e("NameNotFoundException");
} catch (NoSuchAlgorithmException e) {
QuickUtils.log.e("NoSuchAlgorithmException");
}
return hash;
} | [
"public",
"static",
"String",
"getApplicationHashKey",
"(",
"String",
"packageName",
")",
"{",
"String",
"hash",
"=",
"\"\"",
";",
"try",
"{",
"PackageInfo",
"info",
"=",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"getPackageManager",
"(",
")",
".",
"getPackageInfo",
"(",
"packageName",
",",
"PackageManager",
".",
"GET_SIGNATURES",
")",
";",
"for",
"(",
"Signature",
"signature",
":",
"info",
".",
"signatures",
")",
"{",
"MessageDigest",
"md",
"=",
"MessageDigest",
".",
"getInstance",
"(",
"\"SHA\"",
")",
";",
"md",
".",
"update",
"(",
"signature",
".",
"toByteArray",
"(",
")",
")",
";",
"hash",
"=",
"Base64",
".",
"encodeToString",
"(",
"md",
".",
"digest",
"(",
")",
",",
"Base64",
".",
"DEFAULT",
")",
";",
"}",
"}",
"catch",
"(",
"NameNotFoundException",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"NameNotFoundException\"",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"NoSuchAlgorithmException\"",
")",
";",
"}",
"return",
"hash",
";",
"}"
] | Your app key hash is required for example, for Facebook Login in order to
perform security check before authorizing your app.
@param packageName name of the package (e.g. "com.example.app")
@return the application hash key | [
"Your",
"app",
"key",
"hash",
"is",
"required",
"for",
"example",
"for",
"Facebook",
"Login",
"in",
"order",
"to",
"perform",
"security",
"check",
"before",
"authorizing",
"your",
"app",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/system.java#L180-L197 |
2,302 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/system.java | system.toast | public static void toast(String message) {
Toast toast = Toast.makeText(QuickUtils.getContext(), message, Toast.LENGTH_SHORT);
toast.show();
} | java | public static void toast(String message) {
Toast toast = Toast.makeText(QuickUtils.getContext(), message, Toast.LENGTH_SHORT);
toast.show();
} | [
"public",
"static",
"void",
"toast",
"(",
"String",
"message",
")",
"{",
"Toast",
"toast",
"=",
"Toast",
".",
"makeText",
"(",
"QuickUtils",
".",
"getContext",
"(",
")",
",",
"message",
",",
"Toast",
".",
"LENGTH_SHORT",
")",
";",
"toast",
".",
"show",
"(",
")",
";",
"}"
] | Quick toast method with short duration
@param message toast content | [
"Quick",
"toast",
"method",
"with",
"short",
"duration"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/system.java#L216-L220 |
2,303 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/system.java | system.getDeviceID | public static String getDeviceID() {
return Settings.Secure.getString(QuickUtils.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
} | java | public static String getDeviceID() {
return Settings.Secure.getString(QuickUtils.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
} | [
"public",
"static",
"String",
"getDeviceID",
"(",
")",
"{",
"return",
"Settings",
".",
"Secure",
".",
"getString",
"(",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"getContentResolver",
"(",
")",
",",
"Settings",
".",
"Secure",
".",
"ANDROID_ID",
")",
";",
"}"
] | Get device unique ID
@return | [
"Get",
"device",
"unique",
"ID"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/system.java#L255-L257 |
2,304 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/system.java | system.toggleKeyboard | public static void toggleKeyboard() {
InputMethodManager imm = ((InputMethodManager) QuickUtils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
imm.toggleSoftInput(0, 0);
} | java | public static void toggleKeyboard() {
InputMethodManager imm = ((InputMethodManager) QuickUtils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
imm.toggleSoftInput(0, 0);
} | [
"public",
"static",
"void",
"toggleKeyboard",
"(",
")",
"{",
"InputMethodManager",
"imm",
"=",
"(",
"(",
"InputMethodManager",
")",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"getSystemService",
"(",
"Context",
".",
"INPUT_METHOD_SERVICE",
")",
")",
";",
"imm",
".",
"toggleSoftInput",
"(",
"0",
",",
"0",
")",
";",
"}"
] | Toggles the SoftKeyboard Input be careful where you call this from as if you want to
hide the keyboard and its already hidden it will be shown | [
"Toggles",
"the",
"SoftKeyboard",
"Input",
"be",
"careful",
"where",
"you",
"call",
"this",
"from",
"as",
"if",
"you",
"want",
"to",
"hide",
"the",
"keyboard",
"and",
"its",
"already",
"hidden",
"it",
"will",
"be",
"shown"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/system.java#L264-L267 |
2,305 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/system.java | system.requestHideKeyboard | public static void requestHideKeyboard(View v) {
InputMethodManager imm = ((InputMethodManager) QuickUtils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
} | java | public static void requestHideKeyboard(View v) {
InputMethodManager imm = ((InputMethodManager) QuickUtils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
} | [
"public",
"static",
"void",
"requestHideKeyboard",
"(",
"View",
"v",
")",
"{",
"InputMethodManager",
"imm",
"=",
"(",
"(",
"InputMethodManager",
")",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"getSystemService",
"(",
"Context",
".",
"INPUT_METHOD_SERVICE",
")",
")",
";",
"imm",
".",
"hideSoftInputFromWindow",
"(",
"v",
".",
"getWindowToken",
"(",
")",
",",
"0",
")",
";",
"}"
] | Hides the SoftKeyboard input careful as if you pass a view that didn't open the
soft-keyboard it will ignore this call and not close
@param context the context / usually the activity that the view is being shown within
@param v the view that opened the soft-keyboard | [
"Hides",
"the",
"SoftKeyboard",
"input",
"careful",
"as",
"if",
"you",
"pass",
"a",
"view",
"that",
"didn",
"t",
"open",
"the",
"soft",
"-",
"keyboard",
"it",
"will",
"ignore",
"this",
"call",
"and",
"not",
"close"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/system.java#L276-L279 |
2,306 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/system.java | system.convertToDip | public static int convertToDip(DisplayMetrics displayMetrics, int sizeInPixels) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInPixels, displayMetrics);
} | java | public static int convertToDip(DisplayMetrics displayMetrics, int sizeInPixels) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInPixels, displayMetrics);
} | [
"public",
"static",
"int",
"convertToDip",
"(",
"DisplayMetrics",
"displayMetrics",
",",
"int",
"sizeInPixels",
")",
"{",
"return",
"(",
"int",
")",
"TypedValue",
".",
"applyDimension",
"(",
"TypedValue",
".",
"COMPLEX_UNIT_DIP",
",",
"sizeInPixels",
",",
"displayMetrics",
")",
";",
"}"
] | Converts the number in pixels to the number in dips | [
"Converts",
"the",
"number",
"in",
"pixels",
"to",
"the",
"number",
"in",
"dips"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/system.java#L284-L286 |
2,307 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/system.java | system.isServiceRunning | public static boolean isServiceRunning(Class<? extends Service> service) {
ActivityManager manager = (ActivityManager) QuickUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo runningServiceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
if (service.getName().equals(runningServiceInfo.service.getClassName())) {
return true;
}
}
return false;
} | java | public static boolean isServiceRunning(Class<? extends Service> service) {
ActivityManager manager = (ActivityManager) QuickUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo runningServiceInfo : manager.getRunningServices(Integer.MAX_VALUE)) {
if (service.getName().equals(runningServiceInfo.service.getClassName())) {
return true;
}
}
return false;
} | [
"public",
"static",
"boolean",
"isServiceRunning",
"(",
"Class",
"<",
"?",
"extends",
"Service",
">",
"service",
")",
"{",
"ActivityManager",
"manager",
"=",
"(",
"ActivityManager",
")",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"getSystemService",
"(",
"Context",
".",
"ACTIVITY_SERVICE",
")",
";",
"for",
"(",
"ActivityManager",
".",
"RunningServiceInfo",
"runningServiceInfo",
":",
"manager",
".",
"getRunningServices",
"(",
"Integer",
".",
"MAX_VALUE",
")",
")",
"{",
"if",
"(",
"service",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"runningServiceInfo",
".",
"service",
".",
"getClassName",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Is this service running?
@param service service to check
@return true if the service is running | [
"Is",
"this",
"service",
"running?"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/system.java#L303-L311 |
2,308 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/system.java | system.isDebuggable | public static boolean isDebuggable() {
boolean debuggable = false;
Context ctx = QuickUtils.getContext();
try {
PackageInfo pinfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
Signature signatures[] = pinfo.signatures;
CertificateFactory cf = CertificateFactory.getInstance("X.509");
for (int i = 0; i < signatures.length; i++) {
ByteArrayInputStream stream = new ByteArrayInputStream(signatures[i].toByteArray());
X509Certificate cert = (X509Certificate) cf.generateCertificate(stream);
debuggable = cert.getSubjectX500Principal().equals(DEBUG_DN);
if (debuggable)
break;
}
} catch (NameNotFoundException | CertificateException ignored) {
}
return debuggable;
} | java | public static boolean isDebuggable() {
boolean debuggable = false;
Context ctx = QuickUtils.getContext();
try {
PackageInfo pinfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
Signature signatures[] = pinfo.signatures;
CertificateFactory cf = CertificateFactory.getInstance("X.509");
for (int i = 0; i < signatures.length; i++) {
ByteArrayInputStream stream = new ByteArrayInputStream(signatures[i].toByteArray());
X509Certificate cert = (X509Certificate) cf.generateCertificate(stream);
debuggable = cert.getSubjectX500Principal().equals(DEBUG_DN);
if (debuggable)
break;
}
} catch (NameNotFoundException | CertificateException ignored) {
}
return debuggable;
} | [
"public",
"static",
"boolean",
"isDebuggable",
"(",
")",
"{",
"boolean",
"debuggable",
"=",
"false",
";",
"Context",
"ctx",
"=",
"QuickUtils",
".",
"getContext",
"(",
")",
";",
"try",
"{",
"PackageInfo",
"pinfo",
"=",
"ctx",
".",
"getPackageManager",
"(",
")",
".",
"getPackageInfo",
"(",
"ctx",
".",
"getPackageName",
"(",
")",
",",
"PackageManager",
".",
"GET_SIGNATURES",
")",
";",
"Signature",
"signatures",
"[",
"]",
"=",
"pinfo",
".",
"signatures",
";",
"CertificateFactory",
"cf",
"=",
"CertificateFactory",
".",
"getInstance",
"(",
"\"X.509\"",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"signatures",
".",
"length",
";",
"i",
"++",
")",
"{",
"ByteArrayInputStream",
"stream",
"=",
"new",
"ByteArrayInputStream",
"(",
"signatures",
"[",
"i",
"]",
".",
"toByteArray",
"(",
")",
")",
";",
"X509Certificate",
"cert",
"=",
"(",
"X509Certificate",
")",
"cf",
".",
"generateCertificate",
"(",
"stream",
")",
";",
"debuggable",
"=",
"cert",
".",
"getSubjectX500Principal",
"(",
")",
".",
"equals",
"(",
"DEBUG_DN",
")",
";",
"if",
"(",
"debuggable",
")",
"break",
";",
"}",
"}",
"catch",
"(",
"NameNotFoundException",
"|",
"CertificateException",
"ignored",
")",
"{",
"}",
"return",
"debuggable",
";",
"}"
] | Is this APK signed or is it a Debug build?
@return true if it is not signed | [
"Is",
"this",
"APK",
"signed",
"or",
"is",
"it",
"a",
"Debug",
"build?"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/system.java#L445-L465 |
2,309 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/cache/image/ImageLoaderHandler.java | ImageLoaderHandler.handleImageLoaded | protected boolean handleImageLoaded(Bitmap bitmap, Message msg) {
// If this handler is used for loading images in a ListAdapter,
// the thread will set the image only if it's the right position,
// otherwise it won't do anything.
String forUrl = (String) imageView.getTag();
if (imageUrl.equals(forUrl)) {
Bitmap image = bitmap != null || errorDrawable == null ? bitmap
: ((BitmapDrawable) errorDrawable).getBitmap();
if (image != null) {
imageView.setImageBitmap(image);
}
return true;
}
return false;
} | java | protected boolean handleImageLoaded(Bitmap bitmap, Message msg) {
// If this handler is used for loading images in a ListAdapter,
// the thread will set the image only if it's the right position,
// otherwise it won't do anything.
String forUrl = (String) imageView.getTag();
if (imageUrl.equals(forUrl)) {
Bitmap image = bitmap != null || errorDrawable == null ? bitmap
: ((BitmapDrawable) errorDrawable).getBitmap();
if (image != null) {
imageView.setImageBitmap(image);
}
return true;
}
return false;
} | [
"protected",
"boolean",
"handleImageLoaded",
"(",
"Bitmap",
"bitmap",
",",
"Message",
"msg",
")",
"{",
"// If this handler is used for loading images in a ListAdapter,",
"// the thread will set the image only if it's the right position,",
"// otherwise it won't do anything.",
"String",
"forUrl",
"=",
"(",
"String",
")",
"imageView",
".",
"getTag",
"(",
")",
";",
"if",
"(",
"imageUrl",
".",
"equals",
"(",
"forUrl",
")",
")",
"{",
"Bitmap",
"image",
"=",
"bitmap",
"!=",
"null",
"||",
"errorDrawable",
"==",
"null",
"?",
"bitmap",
":",
"(",
"(",
"BitmapDrawable",
")",
"errorDrawable",
")",
".",
"getBitmap",
"(",
")",
";",
"if",
"(",
"image",
"!=",
"null",
")",
"{",
"imageView",
".",
"setImageBitmap",
"(",
"image",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Override this method if you need custom handler logic. Note that this method can actually be
called directly for performance reasons, in which case the message will be null
@param bitmap the bitmap returned from the image loader
@param msg the handler message; can be null
@return true if the view was updated with the new image, false if it was discarded | [
"Override",
"this",
"method",
"if",
"you",
"need",
"custom",
"handler",
"logic",
".",
"Note",
"that",
"this",
"method",
"can",
"actually",
"be",
"called",
"directly",
"for",
"performance",
"reasons",
"in",
"which",
"case",
"the",
"message",
"will",
"be",
"null"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/cache/image/ImageLoaderHandler.java#L62-L78 |
2,310 | cesarferreira/AndroidQuickUtils | library/src/main/java/com/google/common/collect/MapMaker.java | MapMaker.expiration | public MapMaker expiration(long duration, TimeUnit unit) {
if (expirationNanos != 0) {
throw new IllegalStateException("expiration time of " + expirationNanos
+ " ns was already set");
}
if (duration <= 0) {
throw new IllegalArgumentException("invalid duration: " + duration);
}
this.expirationNanos = unit.toNanos(duration);
useCustomMap = true;
return this;
} | java | public MapMaker expiration(long duration, TimeUnit unit) {
if (expirationNanos != 0) {
throw new IllegalStateException("expiration time of " + expirationNanos
+ " ns was already set");
}
if (duration <= 0) {
throw new IllegalArgumentException("invalid duration: " + duration);
}
this.expirationNanos = unit.toNanos(duration);
useCustomMap = true;
return this;
} | [
"public",
"MapMaker",
"expiration",
"(",
"long",
"duration",
",",
"TimeUnit",
"unit",
")",
"{",
"if",
"(",
"expirationNanos",
"!=",
"0",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"expiration time of \"",
"+",
"expirationNanos",
"+",
"\" ns was already set\"",
")",
";",
"}",
"if",
"(",
"duration",
"<=",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"invalid duration: \"",
"+",
"duration",
")",
";",
"}",
"this",
".",
"expirationNanos",
"=",
"unit",
".",
"toNanos",
"(",
"duration",
")",
";",
"useCustomMap",
"=",
"true",
";",
"return",
"this",
";",
"}"
] | Specifies that each entry should be automatically removed from the map
once a fixed duration has passed since the entry's creation.
@param duration
the length of time after an entry is created that it should be
automatically removed
@param unit
the unit that {@code duration} is expressed in
@throws IllegalArgumentException
if {@code duration} is not positive
@throws IllegalStateException
if the expiration time was already set | [
"Specifies",
"that",
"each",
"entry",
"should",
"be",
"automatically",
"removed",
"from",
"the",
"map",
"once",
"a",
"fixed",
"duration",
"has",
"passed",
"since",
"the",
"entry",
"s",
"creation",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/com/google/common/collect/MapMaker.java#L255-L266 |
2,311 | cesarferreira/AndroidQuickUtils | library/src/main/java/com/google/common/collect/MapMaker.java | MapMaker.computing | @SuppressWarnings("unchecked")
// Safe because impl never uses a parameter or returns any non-null value
private static <K, V> ValueReference<K, V> computing() {
return (ValueReference<K, V>) COMPUTING;
} | java | @SuppressWarnings("unchecked")
// Safe because impl never uses a parameter or returns any non-null value
private static <K, V> ValueReference<K, V> computing() {
return (ValueReference<K, V>) COMPUTING;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"// Safe because impl never uses a parameter or returns any non-null value",
"private",
"static",
"<",
"K",
",",
"V",
">",
"ValueReference",
"<",
"K",
",",
"V",
">",
"computing",
"(",
")",
"{",
"return",
"(",
"ValueReference",
"<",
"K",
",",
"V",
">",
")",
"COMPUTING",
";",
"}"
] | Singleton placeholder that indicates a value is being computed. | [
"Singleton",
"placeholder",
"that",
"indicates",
"a",
"value",
"is",
"being",
"computed",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/com/google/common/collect/MapMaker.java#L768-L772 |
2,312 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/web.java | web.getJSONFromUrlViaPOST | public static JSONObject getJSONFromUrlViaPOST(String url, List<NameValuePair> params) {
InputStream is = null;
JSONObject jObj = null;
String json = "";
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
} | java | public static JSONObject getJSONFromUrlViaPOST(String url, List<NameValuePair> params) {
InputStream is = null;
JSONObject jObj = null;
String json = "";
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
} | [
"public",
"static",
"JSONObject",
"getJSONFromUrlViaPOST",
"(",
"String",
"url",
",",
"List",
"<",
"NameValuePair",
">",
"params",
")",
"{",
"InputStream",
"is",
"=",
"null",
";",
"JSONObject",
"jObj",
"=",
"null",
";",
"String",
"json",
"=",
"\"\"",
";",
"// Making HTTP request",
"try",
"{",
"// defaultHttpClient",
"DefaultHttpClient",
"httpClient",
"=",
"new",
"DefaultHttpClient",
"(",
")",
";",
"HttpPost",
"httpPost",
"=",
"new",
"HttpPost",
"(",
"url",
")",
";",
"httpPost",
".",
"setEntity",
"(",
"new",
"UrlEncodedFormEntity",
"(",
"params",
")",
")",
";",
"HttpResponse",
"httpResponse",
"=",
"httpClient",
".",
"execute",
"(",
"httpPost",
")",
";",
"HttpEntity",
"httpEntity",
"=",
"httpResponse",
".",
"getEntity",
"(",
")",
";",
"is",
"=",
"httpEntity",
".",
"getContent",
"(",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"catch",
"(",
"ClientProtocolException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"try",
"{",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"is",
",",
"\"iso-8859-1\"",
")",
",",
"8",
")",
";",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"String",
"line",
"=",
"null",
";",
"while",
"(",
"(",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
")",
"!=",
"null",
")",
"{",
"sb",
".",
"append",
"(",
"line",
"+",
"\"\\n\"",
")",
";",
"}",
"is",
".",
"close",
"(",
")",
";",
"json",
"=",
"sb",
".",
"toString",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"Log",
".",
"e",
"(",
"\"Buffer Error\"",
",",
"\"Error converting result \"",
"+",
"e",
".",
"toString",
"(",
")",
")",
";",
"}",
"// try parse the string to a JSON object",
"try",
"{",
"jObj",
"=",
"new",
"JSONObject",
"(",
"json",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e",
")",
"{",
"Log",
".",
"e",
"(",
"\"JSON Parser\"",
",",
"\"Error parsing data \"",
"+",
"e",
".",
"toString",
"(",
")",
")",
";",
"}",
"// return JSON String",
"return",
"jObj",
";",
"}"
] | Queries the given URL with a list of params via POST
@param url the url to query
@param params list of pair-values
@return the result JSON | [
"Queries",
"the",
"given",
"URL",
"with",
"a",
"list",
"of",
"params",
"via",
"POST"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/web.java#L104-L152 |
2,313 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/web.java | web.getJSONFromUrlViaGET | public static JSONObject getJSONFromUrlViaGET(String url) {
JSONObject jObj = null;
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
jObj = new JSONObject(builder.toString());
} else {
// Log.e(ParseJSON.class.toString(), "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return jObj;
} | java | public static JSONObject getJSONFromUrlViaGET(String url) {
JSONObject jObj = null;
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
jObj = new JSONObject(builder.toString());
} else {
// Log.e(ParseJSON.class.toString(), "Failed to download file");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return jObj;
} | [
"public",
"static",
"JSONObject",
"getJSONFromUrlViaGET",
"(",
"String",
"url",
")",
"{",
"JSONObject",
"jObj",
"=",
"null",
";",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"HttpClient",
"client",
"=",
"new",
"DefaultHttpClient",
"(",
")",
";",
"HttpGet",
"httpGet",
"=",
"new",
"HttpGet",
"(",
"url",
")",
";",
"try",
"{",
"HttpResponse",
"response",
"=",
"client",
".",
"execute",
"(",
"httpGet",
")",
";",
"StatusLine",
"statusLine",
"=",
"response",
".",
"getStatusLine",
"(",
")",
";",
"int",
"statusCode",
"=",
"statusLine",
".",
"getStatusCode",
"(",
")",
";",
"if",
"(",
"statusCode",
"==",
"200",
")",
"{",
"HttpEntity",
"entity",
"=",
"response",
".",
"getEntity",
"(",
")",
";",
"InputStream",
"content",
"=",
"entity",
".",
"getContent",
"(",
")",
";",
"BufferedReader",
"reader",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"content",
")",
")",
";",
"String",
"line",
";",
"while",
"(",
"(",
"line",
"=",
"reader",
".",
"readLine",
"(",
")",
")",
"!=",
"null",
")",
"{",
"builder",
".",
"append",
"(",
"line",
")",
";",
"}",
"jObj",
"=",
"new",
"JSONObject",
"(",
"builder",
".",
"toString",
"(",
")",
")",
";",
"}",
"else",
"{",
"// Log.e(ParseJSON.class.toString(), \"Failed to download file\");",
"}",
"}",
"catch",
"(",
"ClientProtocolException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"catch",
"(",
"JSONException",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"return",
"jObj",
";",
"}"
] | Queries the given URL with a GET request
@param url the url to query
@return the result JSON | [
"Queries",
"the",
"given",
"URL",
"with",
"a",
"GET",
"request"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/web.java#L160-L192 |
2,314 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/web.java | web.hasInternetConnection | public static boolean hasInternetConnection() {
ConnectivityManager connectivity = (ConnectivityManager) QuickUtils.getContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
} | java | public static boolean hasInternetConnection() {
ConnectivityManager connectivity = (ConnectivityManager) QuickUtils.getContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
} | [
"public",
"static",
"boolean",
"hasInternetConnection",
"(",
")",
"{",
"ConnectivityManager",
"connectivity",
"=",
"(",
"ConnectivityManager",
")",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"getSystemService",
"(",
"Context",
".",
"CONNECTIVITY_SERVICE",
")",
";",
"if",
"(",
"connectivity",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"NetworkInfo",
"[",
"]",
"info",
"=",
"connectivity",
".",
"getAllNetworkInfo",
"(",
")",
";",
"if",
"(",
"info",
"!=",
"null",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"info",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"info",
"[",
"i",
"]",
".",
"getState",
"(",
")",
"==",
"NetworkInfo",
".",
"State",
".",
"CONNECTED",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if the app has connectivity to the Internet
@return true if has connection to the Internet and false if it doesn't | [
"Checks",
"if",
"the",
"app",
"has",
"connectivity",
"to",
"the",
"Internet"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/web.java#L199-L215 |
2,315 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/web.java | web.changeWirelessState | public static boolean changeWirelessState(boolean state) {
try {
WifiManager wifi = (WifiManager) QuickUtils.getContext().getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(state);
return true;
} catch (Exception e) {
return false;
}
} | java | public static boolean changeWirelessState(boolean state) {
try {
WifiManager wifi = (WifiManager) QuickUtils.getContext().getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(state);
return true;
} catch (Exception e) {
return false;
}
} | [
"public",
"static",
"boolean",
"changeWirelessState",
"(",
"boolean",
"state",
")",
"{",
"try",
"{",
"WifiManager",
"wifi",
"=",
"(",
"WifiManager",
")",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"getSystemService",
"(",
"Context",
".",
"WIFI_SERVICE",
")",
";",
"wifi",
".",
"setWifiEnabled",
"(",
"state",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Set wireless connectivity On, also this method will need the permissions
"android.permission.CHANGE_WIFI_STATE" and
"android.permission.ACCESS_WIFI_STATE"
@param state - set enable or disable wireless connection
@return true if was set successfully and false if it wasn't | [
"Set",
"wireless",
"connectivity",
"On",
"also",
"this",
"method",
"will",
"need",
"the",
"permissions",
"android",
".",
"permission",
".",
"CHANGE_WIFI_STATE",
"and",
"android",
".",
"permission",
".",
"ACCESS_WIFI_STATE"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/web.java#L264-L272 |
2,316 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/string.java | string.join | public static String join(Collection<?> objectsToJoin, String separator) {
if ((objectsToJoin != null) && !objectsToJoin.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (Object object : objectsToJoin) {
builder.append(object);
builder.append(separator);
}
// Remove the last separator
return builder.substring(0, builder.length() - separator.length());
} else {
return EMPTY;
}
} | java | public static String join(Collection<?> objectsToJoin, String separator) {
if ((objectsToJoin != null) && !objectsToJoin.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (Object object : objectsToJoin) {
builder.append(object);
builder.append(separator);
}
// Remove the last separator
return builder.substring(0, builder.length() - separator.length());
} else {
return EMPTY;
}
} | [
"public",
"static",
"String",
"join",
"(",
"Collection",
"<",
"?",
">",
"objectsToJoin",
",",
"String",
"separator",
")",
"{",
"if",
"(",
"(",
"objectsToJoin",
"!=",
"null",
")",
"&&",
"!",
"objectsToJoin",
".",
"isEmpty",
"(",
")",
")",
"{",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"Object",
"object",
":",
"objectsToJoin",
")",
"{",
"builder",
".",
"append",
"(",
"object",
")",
";",
"builder",
".",
"append",
"(",
"separator",
")",
";",
"}",
"// Remove the last separator",
"return",
"builder",
".",
"substring",
"(",
"0",
",",
"builder",
".",
"length",
"(",
")",
"-",
"separator",
".",
"length",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"EMPTY",
";",
"}",
"}"
] | Joins all the strings in the list in a single one separated by the separator sequence.
@param objectsToJoin The objects to join.
@param separator The separator sequence.
@return The joined strings. | [
"Joins",
"all",
"the",
"strings",
"in",
"the",
"list",
"in",
"a",
"single",
"one",
"separated",
"by",
"the",
"separator",
"sequence",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/string.java#L236-L248 |
2,317 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/string.java | string.truncate | public static String truncate(String text, Integer maxCharacters, Boolean truncateWords) {
if (isNotBlank(text)) {
StringBuilder truncatedTextBuilder = new StringBuilder();
if (text.length() > maxCharacters) {
if (truncateWords) {
// The words are truncated and the ellipsis is added when is possible
if (maxCharacters <= ELLIPSIS.length()) {
truncatedTextBuilder.append(text.substring(0, maxCharacters));
} else {
truncatedTextBuilder.append(text.substring(0, maxCharacters - ELLIPSIS.length()));
truncatedTextBuilder.append(ELLIPSIS);
}
} else {
// The words are not truncated and the ellipsis is not added
List<String> words = Lists.newArrayList(text.split(SPACE));
Iterator<String> it = words.iterator();
int usedChars = 0;
Boolean exit = false;
while (it.hasNext() && !exit) {
String word = it.next();
int increment = usedChars == 0 ? word.length() : word.length() + 1;
if ((usedChars + increment) <= maxCharacters) {
truncatedTextBuilder.append(usedChars == 0 ? word : SPACE + word);
usedChars += increment;
} else {
exit = true;
}
}
}
} else {
truncatedTextBuilder.append(text);
}
return truncatedTextBuilder.toString();
}
return text;
} | java | public static String truncate(String text, Integer maxCharacters, Boolean truncateWords) {
if (isNotBlank(text)) {
StringBuilder truncatedTextBuilder = new StringBuilder();
if (text.length() > maxCharacters) {
if (truncateWords) {
// The words are truncated and the ellipsis is added when is possible
if (maxCharacters <= ELLIPSIS.length()) {
truncatedTextBuilder.append(text.substring(0, maxCharacters));
} else {
truncatedTextBuilder.append(text.substring(0, maxCharacters - ELLIPSIS.length()));
truncatedTextBuilder.append(ELLIPSIS);
}
} else {
// The words are not truncated and the ellipsis is not added
List<String> words = Lists.newArrayList(text.split(SPACE));
Iterator<String> it = words.iterator();
int usedChars = 0;
Boolean exit = false;
while (it.hasNext() && !exit) {
String word = it.next();
int increment = usedChars == 0 ? word.length() : word.length() + 1;
if ((usedChars + increment) <= maxCharacters) {
truncatedTextBuilder.append(usedChars == 0 ? word : SPACE + word);
usedChars += increment;
} else {
exit = true;
}
}
}
} else {
truncatedTextBuilder.append(text);
}
return truncatedTextBuilder.toString();
}
return text;
} | [
"public",
"static",
"String",
"truncate",
"(",
"String",
"text",
",",
"Integer",
"maxCharacters",
",",
"Boolean",
"truncateWords",
")",
"{",
"if",
"(",
"isNotBlank",
"(",
"text",
")",
")",
"{",
"StringBuilder",
"truncatedTextBuilder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"if",
"(",
"text",
".",
"length",
"(",
")",
">",
"maxCharacters",
")",
"{",
"if",
"(",
"truncateWords",
")",
"{",
"// The words are truncated and the ellipsis is added when is possible",
"if",
"(",
"maxCharacters",
"<=",
"ELLIPSIS",
".",
"length",
"(",
")",
")",
"{",
"truncatedTextBuilder",
".",
"append",
"(",
"text",
".",
"substring",
"(",
"0",
",",
"maxCharacters",
")",
")",
";",
"}",
"else",
"{",
"truncatedTextBuilder",
".",
"append",
"(",
"text",
".",
"substring",
"(",
"0",
",",
"maxCharacters",
"-",
"ELLIPSIS",
".",
"length",
"(",
")",
")",
")",
";",
"truncatedTextBuilder",
".",
"append",
"(",
"ELLIPSIS",
")",
";",
"}",
"}",
"else",
"{",
"// The words are not truncated and the ellipsis is not added",
"List",
"<",
"String",
">",
"words",
"=",
"Lists",
".",
"newArrayList",
"(",
"text",
".",
"split",
"(",
"SPACE",
")",
")",
";",
"Iterator",
"<",
"String",
">",
"it",
"=",
"words",
".",
"iterator",
"(",
")",
";",
"int",
"usedChars",
"=",
"0",
";",
"Boolean",
"exit",
"=",
"false",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
"&&",
"!",
"exit",
")",
"{",
"String",
"word",
"=",
"it",
".",
"next",
"(",
")",
";",
"int",
"increment",
"=",
"usedChars",
"==",
"0",
"?",
"word",
".",
"length",
"(",
")",
":",
"word",
".",
"length",
"(",
")",
"+",
"1",
";",
"if",
"(",
"(",
"usedChars",
"+",
"increment",
")",
"<=",
"maxCharacters",
")",
"{",
"truncatedTextBuilder",
".",
"append",
"(",
"usedChars",
"==",
"0",
"?",
"word",
":",
"SPACE",
"+",
"word",
")",
";",
"usedChars",
"+=",
"increment",
";",
"}",
"else",
"{",
"exit",
"=",
"true",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"truncatedTextBuilder",
".",
"append",
"(",
"text",
")",
";",
"}",
"return",
"truncatedTextBuilder",
".",
"toString",
"(",
")",
";",
"}",
"return",
"text",
";",
"}"
] | Truncate the text adding "..." if the truncateWords parameter is true. The ellipsis will be taken into account
when counting the amount of characters.
@param text The text to truncate
@param maxCharacters The maximum amount of characters allowed for the returned text
@param truncateWords True if the words should be truncated
@return The truncated text | [
"Truncate",
"the",
"text",
"adding",
"...",
"if",
"the",
"truncateWords",
"parameter",
"is",
"true",
".",
"The",
"ellipsis",
"will",
"be",
"taken",
"into",
"account",
"when",
"counting",
"the",
"amount",
"of",
"characters",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/string.java#L269-L307 |
2,318 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/string.java | string.truncate | public static String truncate(String text, Integer maxCharacters) {
return truncate(text, maxCharacters, true);
} | java | public static String truncate(String text, Integer maxCharacters) {
return truncate(text, maxCharacters, true);
} | [
"public",
"static",
"String",
"truncate",
"(",
"String",
"text",
",",
"Integer",
"maxCharacters",
")",
"{",
"return",
"truncate",
"(",
"text",
",",
"maxCharacters",
",",
"true",
")",
";",
"}"
] | Truncate the text adding "...". The ellipsis will be taken into account when counting the amount of characters.
@param text The text to truncate
@param maxCharacters The maximum amount of characters allowed for the returned text
@return The truncated text | [
"Truncate",
"the",
"text",
"adding",
"...",
".",
"The",
"ellipsis",
"will",
"be",
"taken",
"into",
"account",
"when",
"counting",
"the",
"amount",
"of",
"characters",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/string.java#L316-L318 |
2,319 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/string.java | string.extractPlaceHolders | public static Set<String> extractPlaceHolders(String string) {
Matcher matcher = Pattern.compile(PLACEHOLDER_PATTERN).matcher(string);
Set<String> placeHolders = Sets.newHashSet();
while (matcher.find()) {
placeHolders.add(matcher.group(1));
}
return placeHolders;
} | java | public static Set<String> extractPlaceHolders(String string) {
Matcher matcher = Pattern.compile(PLACEHOLDER_PATTERN).matcher(string);
Set<String> placeHolders = Sets.newHashSet();
while (matcher.find()) {
placeHolders.add(matcher.group(1));
}
return placeHolders;
} | [
"public",
"static",
"Set",
"<",
"String",
">",
"extractPlaceHolders",
"(",
"String",
"string",
")",
"{",
"Matcher",
"matcher",
"=",
"Pattern",
".",
"compile",
"(",
"PLACEHOLDER_PATTERN",
")",
".",
"matcher",
"(",
"string",
")",
";",
"Set",
"<",
"String",
">",
"placeHolders",
"=",
"Sets",
".",
"newHashSet",
"(",
")",
";",
"while",
"(",
"matcher",
".",
"find",
"(",
")",
")",
"{",
"placeHolders",
".",
"add",
"(",
"matcher",
".",
"group",
"(",
"1",
")",
")",
";",
"}",
"return",
"placeHolders",
";",
"}"
] | Extract all the placeholder's names of the string
@param string The whole string with placeholders
@return A set with all the placeholder's names | [
"Extract",
"all",
"the",
"placeholder",
"s",
"names",
"of",
"the",
"string"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/string.java#L326-L333 |
2,320 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/string.java | string.toAlphanumeric | public static String toAlphanumeric(String value) {
return Pattern.compile(ALPHANUMERIC_PATTERN).matcher(value).replaceAll("");
} | java | public static String toAlphanumeric(String value) {
return Pattern.compile(ALPHANUMERIC_PATTERN).matcher(value).replaceAll("");
} | [
"public",
"static",
"String",
"toAlphanumeric",
"(",
"String",
"value",
")",
"{",
"return",
"Pattern",
".",
"compile",
"(",
"ALPHANUMERIC_PATTERN",
")",
".",
"matcher",
"(",
"value",
")",
".",
"replaceAll",
"(",
"\"\"",
")",
";",
"}"
] | Transform the received value removing all the not alphanumeric or spaces characters
@param value The string to transform
@return The transformed string | [
"Transform",
"the",
"received",
"value",
"removing",
"all",
"the",
"not",
"alphanumeric",
"or",
"spaces",
"characters"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/string.java#L341-L343 |
2,321 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/string.java | string.getFirstToken | public static String getFirstToken(String string, String token) {
if ((string != null) && string.contains(token)) {
return string.split(token)[0];
}
return string;
} | java | public static String getFirstToken(String string, String token) {
if ((string != null) && string.contains(token)) {
return string.split(token)[0];
}
return string;
} | [
"public",
"static",
"String",
"getFirstToken",
"(",
"String",
"string",
",",
"String",
"token",
")",
"{",
"if",
"(",
"(",
"string",
"!=",
"null",
")",
"&&",
"string",
".",
"contains",
"(",
"token",
")",
")",
"{",
"return",
"string",
".",
"split",
"(",
"token",
")",
"[",
"0",
"]",
";",
"}",
"return",
"string",
";",
"}"
] | Returns the first token of the string if that string can be split by the token, else return the unmodified input
string
@param string The string to split
@param token The token to use as splitter
@return The resultant string | [
"Returns",
"the",
"first",
"token",
"of",
"the",
"string",
"if",
"that",
"string",
"can",
"be",
"split",
"by",
"the",
"token",
"else",
"return",
"the",
"unmodified",
"input",
"string"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/string.java#L365-L370 |
2,322 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/string.java | string.wordWrapToTwoLines | public static String wordWrapToTwoLines(String text, int minLength) {
String wordWrapText = text != null ? text.trim() : null;
if ((wordWrapText != null) && (wordWrapText.length() > minLength)) {
int middle = wordWrapText.length() / 2;
int leftSpaceIndex = wordWrapText.substring(0, middle).lastIndexOf(SPACE);
int rightSpaceIndex = wordWrapText.indexOf(SPACE, middle);
int wordWrapIndex = rightSpaceIndex;
if ((leftSpaceIndex >= 0)
&& ((rightSpaceIndex < 0) || ((middle - leftSpaceIndex) < (rightSpaceIndex - middle)))) {
wordWrapIndex = leftSpaceIndex;
}
if (wordWrapIndex >= 0) {
wordWrapText = wordWrapText.substring(0, wordWrapIndex) + "\n"
+ wordWrapText.substring(wordWrapIndex + 1);
}
}
return wordWrapText;
} | java | public static String wordWrapToTwoLines(String text, int minLength) {
String wordWrapText = text != null ? text.trim() : null;
if ((wordWrapText != null) && (wordWrapText.length() > minLength)) {
int middle = wordWrapText.length() / 2;
int leftSpaceIndex = wordWrapText.substring(0, middle).lastIndexOf(SPACE);
int rightSpaceIndex = wordWrapText.indexOf(SPACE, middle);
int wordWrapIndex = rightSpaceIndex;
if ((leftSpaceIndex >= 0)
&& ((rightSpaceIndex < 0) || ((middle - leftSpaceIndex) < (rightSpaceIndex - middle)))) {
wordWrapIndex = leftSpaceIndex;
}
if (wordWrapIndex >= 0) {
wordWrapText = wordWrapText.substring(0, wordWrapIndex) + "\n"
+ wordWrapText.substring(wordWrapIndex + 1);
}
}
return wordWrapText;
} | [
"public",
"static",
"String",
"wordWrapToTwoLines",
"(",
"String",
"text",
",",
"int",
"minLength",
")",
"{",
"String",
"wordWrapText",
"=",
"text",
"!=",
"null",
"?",
"text",
".",
"trim",
"(",
")",
":",
"null",
";",
"if",
"(",
"(",
"wordWrapText",
"!=",
"null",
")",
"&&",
"(",
"wordWrapText",
".",
"length",
"(",
")",
">",
"minLength",
")",
")",
"{",
"int",
"middle",
"=",
"wordWrapText",
".",
"length",
"(",
")",
"/",
"2",
";",
"int",
"leftSpaceIndex",
"=",
"wordWrapText",
".",
"substring",
"(",
"0",
",",
"middle",
")",
".",
"lastIndexOf",
"(",
"SPACE",
")",
";",
"int",
"rightSpaceIndex",
"=",
"wordWrapText",
".",
"indexOf",
"(",
"SPACE",
",",
"middle",
")",
";",
"int",
"wordWrapIndex",
"=",
"rightSpaceIndex",
";",
"if",
"(",
"(",
"leftSpaceIndex",
">=",
"0",
")",
"&&",
"(",
"(",
"rightSpaceIndex",
"<",
"0",
")",
"||",
"(",
"(",
"middle",
"-",
"leftSpaceIndex",
")",
"<",
"(",
"rightSpaceIndex",
"-",
"middle",
")",
")",
")",
")",
"{",
"wordWrapIndex",
"=",
"leftSpaceIndex",
";",
"}",
"if",
"(",
"wordWrapIndex",
">=",
"0",
")",
"{",
"wordWrapText",
"=",
"wordWrapText",
".",
"substring",
"(",
"0",
",",
"wordWrapIndex",
")",
"+",
"\"\\n\"",
"+",
"wordWrapText",
".",
"substring",
"(",
"wordWrapIndex",
"+",
"1",
")",
";",
"}",
"}",
"return",
"wordWrapText",
";",
"}"
] | This method word wrap a text to two lines if the text has multiple words and its length is greater than the
specified minLength. To do the word wrap, the white space closest to the middle of the string is replaced by a
"\n" character
@param text A Sting, the text to word wrap to two lines.
@param minLength The min text length to appy word wrap.
@return The input text word wrapped to two lines or the original text. | [
"This",
"method",
"word",
"wrap",
"a",
"text",
"to",
"two",
"lines",
"if",
"the",
"text",
"has",
"multiple",
"words",
"and",
"its",
"length",
"is",
"greater",
"than",
"the",
"specified",
"minLength",
".",
"To",
"do",
"the",
"word",
"wrap",
"the",
"white",
"space",
"closest",
"to",
"the",
"middle",
"of",
"the",
"string",
"is",
"replaced",
"by",
"a",
"\\",
"n",
"character"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/string.java#L392-L410 |
2,323 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/views/image/ScrollableImageView.java | ScrollableImageView.onDraw | @Override
protected void onDraw(Canvas canvas) {
if (adaptedImage != null)
canvas.drawBitmap(adaptedImage, 0, 0, paint);
} | java | @Override
protected void onDraw(Canvas canvas) {
if (adaptedImage != null)
canvas.drawBitmap(adaptedImage, 0, 0, paint);
} | [
"@",
"Override",
"protected",
"void",
"onDraw",
"(",
"Canvas",
"canvas",
")",
"{",
"if",
"(",
"adaptedImage",
"!=",
"null",
")",
"canvas",
".",
"drawBitmap",
"(",
"adaptedImage",
",",
"0",
",",
"0",
",",
"paint",
")",
";",
"}"
] | Draws the view if the adapted image is not null | [
"Draws",
"the",
"view",
"if",
"the",
"adapted",
"image",
"is",
"not",
"null"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/views/image/ScrollableImageView.java#L43-L49 |
2,324 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/views/image/ScrollableImageView.java | ScrollableImageView.handleScroll | public void handleScroll(float distY) {
if (getHeight() > 0 && originalImage != null) {
if (scrollY <= originalImage.getHeight() - getHeight()) {
adaptedImage = Bitmap.createBitmap(originalImage, 0, (int) -distY, screenWidth, getHeight());
invalidate();
}
}
} | java | public void handleScroll(float distY) {
if (getHeight() > 0 && originalImage != null) {
if (scrollY <= originalImage.getHeight() - getHeight()) {
adaptedImage = Bitmap.createBitmap(originalImage, 0, (int) -distY, screenWidth, getHeight());
invalidate();
}
}
} | [
"public",
"void",
"handleScroll",
"(",
"float",
"distY",
")",
"{",
"if",
"(",
"getHeight",
"(",
")",
">",
"0",
"&&",
"originalImage",
"!=",
"null",
")",
"{",
"if",
"(",
"scrollY",
"<=",
"originalImage",
".",
"getHeight",
"(",
")",
"-",
"getHeight",
"(",
")",
")",
"{",
"adaptedImage",
"=",
"Bitmap",
".",
"createBitmap",
"(",
"originalImage",
",",
"0",
",",
"(",
"int",
")",
"-",
"distY",
",",
"screenWidth",
",",
"getHeight",
"(",
")",
")",
";",
"invalidate",
"(",
")",
";",
"}",
"}",
"}"
] | Handle an external scroll and render the image by switching it by a
distance
@param distY
the distance from the top | [
"Handle",
"an",
"external",
"scroll",
"and",
"render",
"the",
"image",
"by",
"switching",
"it",
"by",
"a",
"distance"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/views/image/ScrollableImageView.java#L58-L69 |
2,325 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/cache/image/ImageLoader.java | ImageLoader.load | public static void load(String imageUrl, ImageView imageView) {
load(imageUrl, imageView, new ImageLoaderHandler(imageView, imageUrl), null, null);
} | java | public static void load(String imageUrl, ImageView imageView) {
load(imageUrl, imageView, new ImageLoaderHandler(imageView, imageUrl), null, null);
} | [
"public",
"static",
"void",
"load",
"(",
"String",
"imageUrl",
",",
"ImageView",
"imageView",
")",
"{",
"load",
"(",
"imageUrl",
",",
"imageView",
",",
"new",
"ImageLoaderHandler",
"(",
"imageView",
",",
"imageUrl",
")",
",",
"null",
",",
"null",
")",
";",
"}"
] | Triggers the image loader for the given image and view. The image loading will be performed
concurrently to the UI main thread, using a fixed size thread pool. The loaded image will be
posted back to the given ImageView upon completion.
@param imageUrl the URL of the image to download
@param imageView the ImageView which should be updated with the new image | [
"Triggers",
"the",
"image",
"loader",
"for",
"the",
"given",
"image",
"and",
"view",
".",
"The",
"image",
"loading",
"will",
"be",
"performed",
"concurrently",
"to",
"the",
"UI",
"main",
"thread",
"using",
"a",
"fixed",
"size",
"thread",
"pool",
".",
"The",
"loaded",
"image",
"will",
"be",
"posted",
"back",
"to",
"the",
"given",
"ImageView",
"upon",
"completion",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/cache/image/ImageLoader.java#L107-L109 |
2,326 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/cache/image/ImageLoader.java | ImageLoader.run | public void run() {
// TODO: if we had a way to check for in-memory hits, we could improve performance by
// fetching an image from the in-memory cache on the main thread
Bitmap bitmap = imageCache.getBitmap(imageUrl);
if (bitmap == null) {
bitmap = downloadImage();
}
// TODO: gracefully handle this case.
notifyImageLoaded(imageUrl, bitmap);
} | java | public void run() {
// TODO: if we had a way to check for in-memory hits, we could improve performance by
// fetching an image from the in-memory cache on the main thread
Bitmap bitmap = imageCache.getBitmap(imageUrl);
if (bitmap == null) {
bitmap = downloadImage();
}
// TODO: gracefully handle this case.
notifyImageLoaded(imageUrl, bitmap);
} | [
"public",
"void",
"run",
"(",
")",
"{",
"// TODO: if we had a way to check for in-memory hits, we could improve performance by",
"// fetching an image from the in-memory cache on the main thread",
"Bitmap",
"bitmap",
"=",
"imageCache",
".",
"getBitmap",
"(",
"imageUrl",
")",
";",
"if",
"(",
"bitmap",
"==",
"null",
")",
"{",
"bitmap",
"=",
"downloadImage",
"(",
")",
";",
"}",
"// TODO: gracefully handle this case.",
"notifyImageLoaded",
"(",
"imageUrl",
",",
"bitmap",
")",
";",
"}"
] | The job method run on a worker thread. It will first query the image cache, and on a miss,
download the image from the Web. | [
"The",
"job",
"method",
"run",
"on",
"a",
"worker",
"thread",
".",
"It",
"will",
"first",
"query",
"the",
"image",
"cache",
"and",
"on",
"a",
"miss",
"download",
"the",
"image",
"from",
"the",
"Web",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/cache/image/ImageLoader.java#L225-L237 |
2,327 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/cache/image/ImageLoader.java | ImageLoader.downloadImage | protected Bitmap downloadImage() {
int timesTried = 1;
while (timesTried <= numRetries) {
try {
byte[] imageData = retrieveImageData();
if (imageData != null) {
imageCache.put(imageUrl, imageData);
} else {
break;
}
return BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
} catch (Throwable e) {
QuickUtils.log.w("download for " + imageUrl + " failed (attempt " + timesTried + ")");
e.printStackTrace();
SystemClock.sleep(DEFAULT_RETRY_HANDLER_SLEEP_TIME);
timesTried++;
}
}
return null;
} | java | protected Bitmap downloadImage() {
int timesTried = 1;
while (timesTried <= numRetries) {
try {
byte[] imageData = retrieveImageData();
if (imageData != null) {
imageCache.put(imageUrl, imageData);
} else {
break;
}
return BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
} catch (Throwable e) {
QuickUtils.log.w("download for " + imageUrl + " failed (attempt " + timesTried + ")");
e.printStackTrace();
SystemClock.sleep(DEFAULT_RETRY_HANDLER_SLEEP_TIME);
timesTried++;
}
}
return null;
} | [
"protected",
"Bitmap",
"downloadImage",
"(",
")",
"{",
"int",
"timesTried",
"=",
"1",
";",
"while",
"(",
"timesTried",
"<=",
"numRetries",
")",
"{",
"try",
"{",
"byte",
"[",
"]",
"imageData",
"=",
"retrieveImageData",
"(",
")",
";",
"if",
"(",
"imageData",
"!=",
"null",
")",
"{",
"imageCache",
".",
"put",
"(",
"imageUrl",
",",
"imageData",
")",
";",
"}",
"else",
"{",
"break",
";",
"}",
"return",
"BitmapFactory",
".",
"decodeByteArray",
"(",
"imageData",
",",
"0",
",",
"imageData",
".",
"length",
")",
";",
"}",
"catch",
"(",
"Throwable",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"w",
"(",
"\"download for \"",
"+",
"imageUrl",
"+",
"\" failed (attempt \"",
"+",
"timesTried",
"+",
"\")\"",
")",
";",
"e",
".",
"printStackTrace",
"(",
")",
";",
"SystemClock",
".",
"sleep",
"(",
"DEFAULT_RETRY_HANDLER_SLEEP_TIME",
")",
";",
"timesTried",
"++",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | after each and every download | [
"after",
"each",
"and",
"every",
"download"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/cache/image/ImageLoader.java#L241-L265 |
2,328 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/screen.java | screen.deviceResolution | public static String deviceResolution() {
DisplayMetrics metrics = QuickUtils.getContext().getResources().getDisplayMetrics();
return String.valueOf(metrics.widthPixels) + "x" + metrics.heightPixels;
} | java | public static String deviceResolution() {
DisplayMetrics metrics = QuickUtils.getContext().getResources().getDisplayMetrics();
return String.valueOf(metrics.widthPixels) + "x" + metrics.heightPixels;
} | [
"public",
"static",
"String",
"deviceResolution",
"(",
")",
"{",
"DisplayMetrics",
"metrics",
"=",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"getResources",
"(",
")",
".",
"getDisplayMetrics",
"(",
")",
";",
"return",
"String",
".",
"valueOf",
"(",
"metrics",
".",
"widthPixels",
")",
"+",
"\"x\"",
"+",
"metrics",
".",
"heightPixels",
";",
"}"
] | Current device resolution
@return the resolution | [
"Current",
"device",
"resolution"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/screen.java#L216-L219 |
2,329 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/text.java | text.join | public static String join(Collection<?> collection, String delimiter) {
if (collection == null || collection.isEmpty()) {
return EMPTY_STRING;
} else if (delimiter == null) {
delimiter = EMPTY_STRING;
}
StringBuilder builder = new StringBuilder();
Iterator<?> it = collection.iterator();
while (it.hasNext()) {
builder.append(it.next()).append(delimiter);
}
int length = builder.length();
builder.delete(length - delimiter.length(), length);
return builder.toString();
} | java | public static String join(Collection<?> collection, String delimiter) {
if (collection == null || collection.isEmpty()) {
return EMPTY_STRING;
} else if (delimiter == null) {
delimiter = EMPTY_STRING;
}
StringBuilder builder = new StringBuilder();
Iterator<?> it = collection.iterator();
while (it.hasNext()) {
builder.append(it.next()).append(delimiter);
}
int length = builder.length();
builder.delete(length - delimiter.length(), length);
return builder.toString();
} | [
"public",
"static",
"String",
"join",
"(",
"Collection",
"<",
"?",
">",
"collection",
",",
"String",
"delimiter",
")",
"{",
"if",
"(",
"collection",
"==",
"null",
"||",
"collection",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"EMPTY_STRING",
";",
"}",
"else",
"if",
"(",
"delimiter",
"==",
"null",
")",
"{",
"delimiter",
"=",
"EMPTY_STRING",
";",
"}",
"StringBuilder",
"builder",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"Iterator",
"<",
"?",
">",
"it",
"=",
"collection",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"it",
".",
"hasNext",
"(",
")",
")",
"{",
"builder",
".",
"append",
"(",
"it",
".",
"next",
"(",
")",
")",
".",
"append",
"(",
"delimiter",
")",
";",
"}",
"int",
"length",
"=",
"builder",
".",
"length",
"(",
")",
";",
"builder",
".",
"delete",
"(",
"length",
"-",
"delimiter",
".",
"length",
"(",
")",
",",
"length",
")",
";",
"return",
"builder",
".",
"toString",
"(",
")",
";",
"}"
] | Joins a Collection of typed objects using their toString method, separated by delimiter
@param collection Collection of objects
@param delimiter (optional) String to separate the items of the collection in the joined string - <code>null</code> is interpreted as empty string
@return the joined string | [
"Joins",
"a",
"Collection",
"of",
"typed",
"objects",
"using",
"their",
"toString",
"method",
"separated",
"by",
"delimiter"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/text.java#L93-L111 |
2,330 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/text.java | text.getWords | public static List<String> getWords(int count, boolean startLorem) {
LinkedList<String> wordList = new LinkedList<String>();
if (startLorem) {
if (count > COMMON_WORDS.length) {
wordList.addAll(Arrays.asList(COMMON_WORDS));
} else {
// add first "count" words
for (int i = 0; i < count; i++) {
wordList.add(COMMON_WORDS[i]);
}
}
}
// add remaining words (random)
for (int i = wordList.size(); i < count; i++) {
wordList.add(QuickUtils.math.getRandomPosition(DICTIONARY));
}
return wordList;
} | java | public static List<String> getWords(int count, boolean startLorem) {
LinkedList<String> wordList = new LinkedList<String>();
if (startLorem) {
if (count > COMMON_WORDS.length) {
wordList.addAll(Arrays.asList(COMMON_WORDS));
} else {
// add first "count" words
for (int i = 0; i < count; i++) {
wordList.add(COMMON_WORDS[i]);
}
}
}
// add remaining words (random)
for (int i = wordList.size(); i < count; i++) {
wordList.add(QuickUtils.math.getRandomPosition(DICTIONARY));
}
return wordList;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"getWords",
"(",
"int",
"count",
",",
"boolean",
"startLorem",
")",
"{",
"LinkedList",
"<",
"String",
">",
"wordList",
"=",
"new",
"LinkedList",
"<",
"String",
">",
"(",
")",
";",
"if",
"(",
"startLorem",
")",
"{",
"if",
"(",
"count",
">",
"COMMON_WORDS",
".",
"length",
")",
"{",
"wordList",
".",
"addAll",
"(",
"Arrays",
".",
"asList",
"(",
"COMMON_WORDS",
")",
")",
";",
"}",
"else",
"{",
"// add first \"count\" words",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"wordList",
".",
"add",
"(",
"COMMON_WORDS",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"// add remaining words (random)",
"for",
"(",
"int",
"i",
"=",
"wordList",
".",
"size",
"(",
")",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"wordList",
".",
"add",
"(",
"QuickUtils",
".",
"math",
".",
"getRandomPosition",
"(",
"DICTIONARY",
")",
")",
";",
"}",
"return",
"wordList",
";",
"}"
] | Returns a list of words.
@param count the number of words to get
@param startLorem whether to start with standard Lorem Ipsum text
@return a list of lorem ipsum words | [
"Returns",
"a",
"list",
"of",
"words",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/text.java#L121-L142 |
2,331 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/text.java | text.implode | public static String implode(String[] inputArr, String delimiter) {
String implodedStr = "";
implodedStr += inputArr[0];
for (int i = 1; i < inputArr.length; i++) {
implodedStr += delimiter;
implodedStr += inputArr[i];
}
return implodedStr;
} | java | public static String implode(String[] inputArr, String delimiter) {
String implodedStr = "";
implodedStr += inputArr[0];
for (int i = 1; i < inputArr.length; i++) {
implodedStr += delimiter;
implodedStr += inputArr[i];
}
return implodedStr;
} | [
"public",
"static",
"String",
"implode",
"(",
"String",
"[",
"]",
"inputArr",
",",
"String",
"delimiter",
")",
"{",
"String",
"implodedStr",
"=",
"\"\"",
";",
"implodedStr",
"+=",
"inputArr",
"[",
"0",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"inputArr",
".",
"length",
";",
"i",
"++",
")",
"{",
"implodedStr",
"+=",
"delimiter",
";",
"implodedStr",
"+=",
"inputArr",
"[",
"i",
"]",
";",
"}",
"return",
"implodedStr",
";",
"}"
] | Implodes an array into a string Similar to PHP implode function
@param inputArr the array to implode
@param delimiter the delimiter that will be used to merge items in array
@return the imploded string | [
"Implodes",
"an",
"array",
"into",
"a",
"string",
"Similar",
"to",
"PHP",
"implode",
"function"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/text.java#L240-L249 |
2,332 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/text.java | text.capitalize | public static String capitalize(String input) {
char[] stringArray = input.toCharArray();
stringArray[0] = Character.toUpperCase(stringArray[0]);
return new String(stringArray);
} | java | public static String capitalize(String input) {
char[] stringArray = input.toCharArray();
stringArray[0] = Character.toUpperCase(stringArray[0]);
return new String(stringArray);
} | [
"public",
"static",
"String",
"capitalize",
"(",
"String",
"input",
")",
"{",
"char",
"[",
"]",
"stringArray",
"=",
"input",
".",
"toCharArray",
"(",
")",
";",
"stringArray",
"[",
"0",
"]",
"=",
"Character",
".",
"toUpperCase",
"(",
"stringArray",
"[",
"0",
"]",
")",
";",
"return",
"new",
"String",
"(",
"stringArray",
")",
";",
"}"
] | Capitalize first word in a string
@param input string to capitalize
@return capitalized string(first letter only) | [
"Capitalize",
"first",
"word",
"in",
"a",
"string"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/text.java#L257-L261 |
2,333 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/log.java | log.e | public static int e(String message, Throwable throwable) {
return logger(QuickUtils.ERROR, message, throwable);
} | java | public static int e(String message, Throwable throwable) {
return logger(QuickUtils.ERROR, message, throwable);
} | [
"public",
"static",
"int",
"e",
"(",
"String",
"message",
",",
"Throwable",
"throwable",
")",
"{",
"return",
"logger",
"(",
"QuickUtils",
".",
"ERROR",
",",
"message",
",",
"throwable",
")",
";",
"}"
] | Sends an ERROR log message
@param message The message you would like logged.
@param throwable An exception to log | [
"Sends",
"an",
"ERROR",
"log",
"message"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/log.java#L31-L33 |
2,334 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/log.java | log.i | public static int i(String message, Throwable throwable) {
return logger(QuickUtils.INFO, message, throwable);
} | java | public static int i(String message, Throwable throwable) {
return logger(QuickUtils.INFO, message, throwable);
} | [
"public",
"static",
"int",
"i",
"(",
"String",
"message",
",",
"Throwable",
"throwable",
")",
"{",
"return",
"logger",
"(",
"QuickUtils",
".",
"INFO",
",",
"message",
",",
"throwable",
")",
";",
"}"
] | Sends an INFO log message.
@param message The message you would like logged.
@param throwable An exception to log | [
"Sends",
"an",
"INFO",
"log",
"message",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/log.java#L50-L52 |
2,335 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/log.java | log.v | public static int v(String message, Throwable throwable) {
return logger(QuickUtils.VERBOSE, message, throwable);
} | java | public static int v(String message, Throwable throwable) {
return logger(QuickUtils.VERBOSE, message, throwable);
} | [
"public",
"static",
"int",
"v",
"(",
"String",
"message",
",",
"Throwable",
"throwable",
")",
"{",
"return",
"logger",
"(",
"QuickUtils",
".",
"VERBOSE",
",",
"message",
",",
"throwable",
")",
";",
"}"
] | Sends a VERBBOSE log message.
@param message The message you would like logged.
@param throwable An exception to log | [
"Sends",
"a",
"VERBBOSE",
"log",
"message",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/log.java#L69-L71 |
2,336 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/log.java | log.w | public static int w(String message, Throwable throwable) {
return logger(QuickUtils.WARN, message, throwable);
} | java | public static int w(String message, Throwable throwable) {
return logger(QuickUtils.WARN, message, throwable);
} | [
"public",
"static",
"int",
"w",
"(",
"String",
"message",
",",
"Throwable",
"throwable",
")",
"{",
"return",
"logger",
"(",
"QuickUtils",
".",
"WARN",
",",
"message",
",",
"throwable",
")",
";",
"}"
] | Sends a WARNING log message.
@param message The message you would like logged.
@param throwable An exception to log | [
"Sends",
"a",
"WARNING",
"log",
"message",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/log.java#L88-L90 |
2,337 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/log.java | log.d | public static int d(String message, Throwable throwable) {
return logger(QuickUtils.DEBUG, message, throwable);
} | java | public static int d(String message, Throwable throwable) {
return logger(QuickUtils.DEBUG, message, throwable);
} | [
"public",
"static",
"int",
"d",
"(",
"String",
"message",
",",
"Throwable",
"throwable",
")",
"{",
"return",
"logger",
"(",
"QuickUtils",
".",
"DEBUG",
",",
"message",
",",
"throwable",
")",
";",
"}"
] | Sends a DEBUG log message and log the exception.
@param message The message you would like logged.
@param throwable An exception to log | [
"Sends",
"a",
"DEBUG",
"log",
"message",
"and",
"log",
"the",
"exception",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/log.java#L107-L110 |
2,338 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/log.java | log.logger | private static int logger(int level, String message, Throwable throwable) {
if (QuickUtils.shouldShowLogs()) {
switch (level) {
case QuickUtils.DEBUG:
return android.util.Log.d(QuickUtils.TAG, message, throwable);
case QuickUtils.VERBOSE:
return android.util.Log.v(QuickUtils.TAG, message, throwable);
case QuickUtils.INFO:
return android.util.Log.i(QuickUtils.TAG, message, throwable);
case QuickUtils.WARN:
return android.util.Log.w(QuickUtils.TAG, message, throwable);
case QuickUtils.ERROR:
return android.util.Log.e(QuickUtils.TAG, message, throwable);
default:
break;
}
}
return -1;
} | java | private static int logger(int level, String message, Throwable throwable) {
if (QuickUtils.shouldShowLogs()) {
switch (level) {
case QuickUtils.DEBUG:
return android.util.Log.d(QuickUtils.TAG, message, throwable);
case QuickUtils.VERBOSE:
return android.util.Log.v(QuickUtils.TAG, message, throwable);
case QuickUtils.INFO:
return android.util.Log.i(QuickUtils.TAG, message, throwable);
case QuickUtils.WARN:
return android.util.Log.w(QuickUtils.TAG, message, throwable);
case QuickUtils.ERROR:
return android.util.Log.e(QuickUtils.TAG, message, throwable);
default:
break;
}
}
return -1;
} | [
"private",
"static",
"int",
"logger",
"(",
"int",
"level",
",",
"String",
"message",
",",
"Throwable",
"throwable",
")",
"{",
"if",
"(",
"QuickUtils",
".",
"shouldShowLogs",
"(",
")",
")",
"{",
"switch",
"(",
"level",
")",
"{",
"case",
"QuickUtils",
".",
"DEBUG",
":",
"return",
"android",
".",
"util",
".",
"Log",
".",
"d",
"(",
"QuickUtils",
".",
"TAG",
",",
"message",
",",
"throwable",
")",
";",
"case",
"QuickUtils",
".",
"VERBOSE",
":",
"return",
"android",
".",
"util",
".",
"Log",
".",
"v",
"(",
"QuickUtils",
".",
"TAG",
",",
"message",
",",
"throwable",
")",
";",
"case",
"QuickUtils",
".",
"INFO",
":",
"return",
"android",
".",
"util",
".",
"Log",
".",
"i",
"(",
"QuickUtils",
".",
"TAG",
",",
"message",
",",
"throwable",
")",
";",
"case",
"QuickUtils",
".",
"WARN",
":",
"return",
"android",
".",
"util",
".",
"Log",
".",
"w",
"(",
"QuickUtils",
".",
"TAG",
",",
"message",
",",
"throwable",
")",
";",
"case",
"QuickUtils",
".",
"ERROR",
":",
"return",
"android",
".",
"util",
".",
"Log",
".",
"e",
"(",
"QuickUtils",
".",
"TAG",
",",
"message",
",",
"throwable",
")",
";",
"default",
":",
"break",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | Private Logger function to handle Log calls
@param level level of the log message
@param message log output
@param throwable | [
"Private",
"Logger",
"function",
"to",
"handle",
"Log",
"calls"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/log.java#L119-L140 |
2,339 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/location.java | location.getLocationByCoordinates | public static LocationModel getLocationByCoordinates(Double latitude, Double longitude ){
try {
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(QuickUtils.getContext());
addresses = geocoder.getFromLocation(latitude, longitude, 1);
LocationModel locationModel = new LocationModel();
locationModel.latitude = latitude;
locationModel.longitude = longitude;
try{
locationModel.address = addresses.get(0).getAddressLine(0);
}catch(Exception ex){
QuickUtils.log.e("empty address");
}
try{
locationModel.city = addresses.get(0).getAddressLine(1);
}catch(Exception ex){
QuickUtils.log.e("empty city");
}
try{
locationModel.country = addresses.get(0).getAddressLine(2);
}catch(Exception ex){
QuickUtils.log.e("empty country");
}
return locationModel;
} catch (IOException e) {
QuickUtils.log.e("empty location");
return new LocationModel();
}
} | java | public static LocationModel getLocationByCoordinates(Double latitude, Double longitude ){
try {
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(QuickUtils.getContext());
addresses = geocoder.getFromLocation(latitude, longitude, 1);
LocationModel locationModel = new LocationModel();
locationModel.latitude = latitude;
locationModel.longitude = longitude;
try{
locationModel.address = addresses.get(0).getAddressLine(0);
}catch(Exception ex){
QuickUtils.log.e("empty address");
}
try{
locationModel.city = addresses.get(0).getAddressLine(1);
}catch(Exception ex){
QuickUtils.log.e("empty city");
}
try{
locationModel.country = addresses.get(0).getAddressLine(2);
}catch(Exception ex){
QuickUtils.log.e("empty country");
}
return locationModel;
} catch (IOException e) {
QuickUtils.log.e("empty location");
return new LocationModel();
}
} | [
"public",
"static",
"LocationModel",
"getLocationByCoordinates",
"(",
"Double",
"latitude",
",",
"Double",
"longitude",
")",
"{",
"try",
"{",
"Geocoder",
"geocoder",
";",
"List",
"<",
"Address",
">",
"addresses",
";",
"geocoder",
"=",
"new",
"Geocoder",
"(",
"QuickUtils",
".",
"getContext",
"(",
")",
")",
";",
"addresses",
"=",
"geocoder",
".",
"getFromLocation",
"(",
"latitude",
",",
"longitude",
",",
"1",
")",
";",
"LocationModel",
"locationModel",
"=",
"new",
"LocationModel",
"(",
")",
";",
"locationModel",
".",
"latitude",
"=",
"latitude",
";",
"locationModel",
".",
"longitude",
"=",
"longitude",
";",
"try",
"{",
"locationModel",
".",
"address",
"=",
"addresses",
".",
"get",
"(",
"0",
")",
".",
"getAddressLine",
"(",
"0",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"empty address\"",
")",
";",
"}",
"try",
"{",
"locationModel",
".",
"city",
"=",
"addresses",
".",
"get",
"(",
"0",
")",
".",
"getAddressLine",
"(",
"1",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"empty city\"",
")",
";",
"}",
"try",
"{",
"locationModel",
".",
"country",
"=",
"addresses",
".",
"get",
"(",
"0",
")",
".",
"getAddressLine",
"(",
"2",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"empty country\"",
")",
";",
"}",
"return",
"locationModel",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"empty location\"",
")",
";",
"return",
"new",
"LocationModel",
"(",
")",
";",
"}",
"}"
] | Gets the location by Coordinates
@param latitude
@param longitude
@return Location model | [
"Gets",
"the",
"location",
"by",
"Coordinates"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/location.java#L24-L55 |
2,340 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/views/image/AspectRatioImageView.java | AspectRatioImageView.setDominantMeasurement | public void setDominantMeasurement(int dominantMeasurement) {
if (dominantMeasurement != MEASUREMENT_HEIGHT && dominantMeasurement != MEASUREMENT_WIDTH) {
throw new IllegalArgumentException("Invalid measurement type.");
}
this.dominantMeasurement = dominantMeasurement;
requestLayout();
} | java | public void setDominantMeasurement(int dominantMeasurement) {
if (dominantMeasurement != MEASUREMENT_HEIGHT && dominantMeasurement != MEASUREMENT_WIDTH) {
throw new IllegalArgumentException("Invalid measurement type.");
}
this.dominantMeasurement = dominantMeasurement;
requestLayout();
} | [
"public",
"void",
"setDominantMeasurement",
"(",
"int",
"dominantMeasurement",
")",
"{",
"if",
"(",
"dominantMeasurement",
"!=",
"MEASUREMENT_HEIGHT",
"&&",
"dominantMeasurement",
"!=",
"MEASUREMENT_WIDTH",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid measurement type.\"",
")",
";",
"}",
"this",
".",
"dominantMeasurement",
"=",
"dominantMeasurement",
";",
"requestLayout",
"(",
")",
";",
"}"
] | Set the dominant measurement for the aspect ratio.
@see #MEASUREMENT_WIDTH
@see #MEASUREMENT_HEIGHT | [
"Set",
"the",
"dominant",
"measurement",
"for",
"the",
"aspect",
"ratio",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/views/image/AspectRatioImageView.java#L113-L119 |
2,341 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/date.java | date.getTimeSinceMidnight | public static long getTimeSinceMidnight() {
Calendar c = Calendar.getInstance();
long now = c.getTimeInMillis();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return now - c.getTimeInMillis();
} | java | public static long getTimeSinceMidnight() {
Calendar c = Calendar.getInstance();
long now = c.getTimeInMillis();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return now - c.getTimeInMillis();
} | [
"public",
"static",
"long",
"getTimeSinceMidnight",
"(",
")",
"{",
"Calendar",
"c",
"=",
"Calendar",
".",
"getInstance",
"(",
")",
";",
"long",
"now",
"=",
"c",
".",
"getTimeInMillis",
"(",
")",
";",
"c",
".",
"set",
"(",
"Calendar",
".",
"HOUR_OF_DAY",
",",
"0",
")",
";",
"c",
".",
"set",
"(",
"Calendar",
".",
"MINUTE",
",",
"0",
")",
";",
"c",
".",
"set",
"(",
"Calendar",
".",
"SECOND",
",",
"0",
")",
";",
"c",
".",
"set",
"(",
"Calendar",
".",
"MILLISECOND",
",",
"0",
")",
";",
"return",
"now",
"-",
"c",
".",
"getTimeInMillis",
"(",
")",
";",
"}"
] | Miliseconds since midnight
@return the number of miliseconds since midnight | [
"Miliseconds",
"since",
"midnight"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/date.java#L69-L77 |
2,342 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/date.java | date.getDayAsDate | public static java.util.Date getDayAsDate(int day) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, day);
return cal.getTime();
} | java | public static java.util.Date getDayAsDate(int day) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, day);
return cal.getTime();
} | [
"public",
"static",
"java",
".",
"util",
".",
"Date",
"getDayAsDate",
"(",
"int",
"day",
")",
"{",
"Calendar",
"cal",
"=",
"Calendar",
".",
"getInstance",
"(",
")",
";",
"cal",
".",
"add",
"(",
"Calendar",
".",
"DATE",
",",
"day",
")",
";",
"return",
"cal",
".",
"getTime",
"(",
")",
";",
"}"
] | Gets the desired day as a Date
@param day Can be: <li>QuickUtils.date.YESTERDAY</li><li>
QuickUtils.date.TODAY</li><li>QuickUtils.date.TOMORROW</li>
@return returns a Date for that day | [
"Gets",
"the",
"desired",
"day",
"as",
"a",
"Date"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/date.java#L134-L138 |
2,343 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/date.java | date.getNumberWithSuffix | public static String getNumberWithSuffix(int number) {
int j = number % 10;
if (j == 1 && number != 11) {
return number + "st";
}
if (j == 2 && number != 12) {
return number + "nd";
}
if (j == 3 && number != 13) {
return number + "rd";
}
return number + "th";
} | java | public static String getNumberWithSuffix(int number) {
int j = number % 10;
if (j == 1 && number != 11) {
return number + "st";
}
if (j == 2 && number != 12) {
return number + "nd";
}
if (j == 3 && number != 13) {
return number + "rd";
}
return number + "th";
} | [
"public",
"static",
"String",
"getNumberWithSuffix",
"(",
"int",
"number",
")",
"{",
"int",
"j",
"=",
"number",
"%",
"10",
";",
"if",
"(",
"j",
"==",
"1",
"&&",
"number",
"!=",
"11",
")",
"{",
"return",
"number",
"+",
"\"st\"",
";",
"}",
"if",
"(",
"j",
"==",
"2",
"&&",
"number",
"!=",
"12",
")",
"{",
"return",
"number",
"+",
"\"nd\"",
";",
"}",
"if",
"(",
"j",
"==",
"3",
"&&",
"number",
"!=",
"13",
")",
"{",
"return",
"number",
"+",
"\"rd\"",
";",
"}",
"return",
"number",
"+",
"\"th\"",
";",
"}"
] | Get number with a suffix
@param number number that will be converted
@return (e.g. "1" becomes "1st", "3" becomes "3rd", etc) | [
"Get",
"number",
"with",
"a",
"suffix"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/date.java#L189-L201 |
2,344 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/date.java | date.convertMonth | public static String convertMonth(int month, boolean useShort) {
String monthStr;
switch (month) {
default:
monthStr = "January";
break;
case Calendar.FEBRUARY:
monthStr = "February";
break;
case Calendar.MARCH:
monthStr = "March";
break;
case Calendar.APRIL:
monthStr = "April";
break;
case Calendar.MAY:
monthStr = "May";
break;
case Calendar.JUNE:
monthStr = "June";
break;
case Calendar.JULY:
monthStr = "July";
break;
case Calendar.AUGUST:
monthStr = "August";
break;
case Calendar.SEPTEMBER:
monthStr = "September";
break;
case Calendar.OCTOBER:
monthStr = "October";
break;
case Calendar.NOVEMBER:
monthStr = "November";
break;
case Calendar.DECEMBER:
monthStr = "December";
break;
}
if (useShort) monthStr = monthStr.substring(0, 3);
return monthStr;
} | java | public static String convertMonth(int month, boolean useShort) {
String monthStr;
switch (month) {
default:
monthStr = "January";
break;
case Calendar.FEBRUARY:
monthStr = "February";
break;
case Calendar.MARCH:
monthStr = "March";
break;
case Calendar.APRIL:
monthStr = "April";
break;
case Calendar.MAY:
monthStr = "May";
break;
case Calendar.JUNE:
monthStr = "June";
break;
case Calendar.JULY:
monthStr = "July";
break;
case Calendar.AUGUST:
monthStr = "August";
break;
case Calendar.SEPTEMBER:
monthStr = "September";
break;
case Calendar.OCTOBER:
monthStr = "October";
break;
case Calendar.NOVEMBER:
monthStr = "November";
break;
case Calendar.DECEMBER:
monthStr = "December";
break;
}
if (useShort) monthStr = monthStr.substring(0, 3);
return monthStr;
} | [
"public",
"static",
"String",
"convertMonth",
"(",
"int",
"month",
",",
"boolean",
"useShort",
")",
"{",
"String",
"monthStr",
";",
"switch",
"(",
"month",
")",
"{",
"default",
":",
"monthStr",
"=",
"\"January\"",
";",
"break",
";",
"case",
"Calendar",
".",
"FEBRUARY",
":",
"monthStr",
"=",
"\"February\"",
";",
"break",
";",
"case",
"Calendar",
".",
"MARCH",
":",
"monthStr",
"=",
"\"March\"",
";",
"break",
";",
"case",
"Calendar",
".",
"APRIL",
":",
"monthStr",
"=",
"\"April\"",
";",
"break",
";",
"case",
"Calendar",
".",
"MAY",
":",
"monthStr",
"=",
"\"May\"",
";",
"break",
";",
"case",
"Calendar",
".",
"JUNE",
":",
"monthStr",
"=",
"\"June\"",
";",
"break",
";",
"case",
"Calendar",
".",
"JULY",
":",
"monthStr",
"=",
"\"July\"",
";",
"break",
";",
"case",
"Calendar",
".",
"AUGUST",
":",
"monthStr",
"=",
"\"August\"",
";",
"break",
";",
"case",
"Calendar",
".",
"SEPTEMBER",
":",
"monthStr",
"=",
"\"September\"",
";",
"break",
";",
"case",
"Calendar",
".",
"OCTOBER",
":",
"monthStr",
"=",
"\"October\"",
";",
"break",
";",
"case",
"Calendar",
".",
"NOVEMBER",
":",
"monthStr",
"=",
"\"November\"",
";",
"break",
";",
"case",
"Calendar",
".",
"DECEMBER",
":",
"monthStr",
"=",
"\"December\"",
";",
"break",
";",
"}",
"if",
"(",
"useShort",
")",
"monthStr",
"=",
"monthStr",
".",
"substring",
"(",
"0",
",",
"3",
")",
";",
"return",
"monthStr",
";",
"}"
] | Converts a month by number to full text
@param month number of the month 1..12
@param useShort boolean that gives "Jun" instead of "June" if true
@return returns "January" if "1" is given | [
"Converts",
"a",
"month",
"by",
"number",
"to",
"full",
"text"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/date.java#L211-L253 |
2,345 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/image.java | image.getBitmapByImageURL | public static void getBitmapByImageURL(String imageURL, final OnEventListener callback) {
new DownloadImageTask<Bitmap>(imageURL, new OnEventListener<Bitmap>() {
@Override
public void onSuccess(Bitmap bitmap) {
callback.onSuccess(bitmap);
}
@Override
public void onFailure(Exception e) {
callback.onFailure(e);
}
}).execute();
} | java | public static void getBitmapByImageURL(String imageURL, final OnEventListener callback) {
new DownloadImageTask<Bitmap>(imageURL, new OnEventListener<Bitmap>() {
@Override
public void onSuccess(Bitmap bitmap) {
callback.onSuccess(bitmap);
}
@Override
public void onFailure(Exception e) {
callback.onFailure(e);
}
}).execute();
} | [
"public",
"static",
"void",
"getBitmapByImageURL",
"(",
"String",
"imageURL",
",",
"final",
"OnEventListener",
"callback",
")",
"{",
"new",
"DownloadImageTask",
"<",
"Bitmap",
">",
"(",
"imageURL",
",",
"new",
"OnEventListener",
"<",
"Bitmap",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"onSuccess",
"(",
"Bitmap",
"bitmap",
")",
"{",
"callback",
".",
"onSuccess",
"(",
"bitmap",
")",
";",
"}",
"@",
"Override",
"public",
"void",
"onFailure",
"(",
"Exception",
"e",
")",
"{",
"callback",
".",
"onFailure",
"(",
"e",
")",
";",
"}",
"}",
")",
".",
"execute",
"(",
")",
";",
"}"
] | Get a bitmap by a given URL
@param imageURL given URL
@param callback callback | [
"Get",
"a",
"bitmap",
"by",
"a",
"given",
"URL"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/image.java#L77-L92 |
2,346 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/image.java | image.storeImage | public static void storeImage(Bitmap image, File pictureFile) {
if (pictureFile == null) {
QuickUtils.log.d("Error creating media file, check storage permissions: ");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
image.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
} catch (FileNotFoundException e) {
QuickUtils.log.d("File not found: " + e.getMessage());
} catch (IOException e) {
QuickUtils.log.d("Error accessing file: " + e.getMessage());
}
} | java | public static void storeImage(Bitmap image, File pictureFile) {
if (pictureFile == null) {
QuickUtils.log.d("Error creating media file, check storage permissions: ");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
image.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
} catch (FileNotFoundException e) {
QuickUtils.log.d("File not found: " + e.getMessage());
} catch (IOException e) {
QuickUtils.log.d("Error accessing file: " + e.getMessage());
}
} | [
"public",
"static",
"void",
"storeImage",
"(",
"Bitmap",
"image",
",",
"File",
"pictureFile",
")",
"{",
"if",
"(",
"pictureFile",
"==",
"null",
")",
"{",
"QuickUtils",
".",
"log",
".",
"d",
"(",
"\"Error creating media file, check storage permissions: \"",
")",
";",
"return",
";",
"}",
"try",
"{",
"FileOutputStream",
"fos",
"=",
"new",
"FileOutputStream",
"(",
"pictureFile",
")",
";",
"image",
".",
"compress",
"(",
"Bitmap",
".",
"CompressFormat",
".",
"PNG",
",",
"90",
",",
"fos",
")",
";",
"fos",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"FileNotFoundException",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"d",
"(",
"\"File not found: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"d",
"(",
"\"Error accessing file: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Stores an image on the storage
@param image the image to store.
@param pictureFile the file in which it must be stored | [
"Stores",
"an",
"image",
"on",
"the",
"storage"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/image.java#L188-L202 |
2,347 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/image.java | image.getScreenHeight | @SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getScreenHeight(Activity context) {
Display display = context.getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
Point size = new Point();
display.getSize(size);
return size.y;
}
return display.getHeight();
} | java | @SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getScreenHeight(Activity context) {
Display display = context.getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
Point size = new Point();
display.getSize(size);
return size.y;
}
return display.getHeight();
} | [
"@",
"SuppressWarnings",
"(",
"\"deprecation\"",
")",
"@",
"SuppressLint",
"(",
"\"NewApi\"",
")",
"public",
"static",
"int",
"getScreenHeight",
"(",
"Activity",
"context",
")",
"{",
"Display",
"display",
"=",
"context",
".",
"getWindowManager",
"(",
")",
".",
"getDefaultDisplay",
"(",
")",
";",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"Build",
".",
"VERSION_CODES",
".",
"HONEYCOMB_MR2",
")",
"{",
"Point",
"size",
"=",
"new",
"Point",
"(",
")",
";",
"display",
".",
"getSize",
"(",
"size",
")",
";",
"return",
"size",
".",
"y",
";",
"}",
"return",
"display",
".",
"getHeight",
"(",
")",
";",
"}"
] | Get the screen height.
@param context
@return the screen height | [
"Get",
"the",
"screen",
"height",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/image.java#L210-L221 |
2,348 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/image.java | image.getScreenWidth | @SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getScreenWidth(Activity context) {
Display display = context.getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
Point size = new Point();
display.getSize(size);
return size.x;
}
return display.getWidth();
} | java | @SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getScreenWidth(Activity context) {
Display display = context.getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
Point size = new Point();
display.getSize(size);
return size.x;
}
return display.getWidth();
} | [
"@",
"SuppressWarnings",
"(",
"\"deprecation\"",
")",
"@",
"SuppressLint",
"(",
"\"NewApi\"",
")",
"public",
"static",
"int",
"getScreenWidth",
"(",
"Activity",
"context",
")",
"{",
"Display",
"display",
"=",
"context",
".",
"getWindowManager",
"(",
")",
".",
"getDefaultDisplay",
"(",
")",
";",
"if",
"(",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"Build",
".",
"VERSION_CODES",
".",
"HONEYCOMB_MR2",
")",
"{",
"Point",
"size",
"=",
"new",
"Point",
"(",
")",
";",
"display",
".",
"getSize",
"(",
"size",
")",
";",
"return",
"size",
".",
"x",
";",
"}",
"return",
"display",
".",
"getWidth",
"(",
")",
";",
"}"
] | Get the screen width.
@param context
@return the screen width | [
"Get",
"the",
"screen",
"width",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/image.java#L229-L240 |
2,349 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/cache/image/AbstractCache.java | AbstractCache.sanitizeDiskCache | private void sanitizeDiskCache() {
File[] cachedFiles = new File(diskCacheDirectory).listFiles();
if (cachedFiles == null) {
return;
}
for (File f : cachedFiles) {
// if file older than expirationInMinutes, remove it
long lastModified = f.lastModified();
Date now = new Date();
long ageInMinutes = ((now.getTime() - lastModified) / (1000*60));
if (ageInMinutes >= expirationInMinutes) {
Log.d(name, "DISK cache expiration for file " + f.toString());
f.delete();
}
}
} | java | private void sanitizeDiskCache() {
File[] cachedFiles = new File(diskCacheDirectory).listFiles();
if (cachedFiles == null) {
return;
}
for (File f : cachedFiles) {
// if file older than expirationInMinutes, remove it
long lastModified = f.lastModified();
Date now = new Date();
long ageInMinutes = ((now.getTime() - lastModified) / (1000*60));
if (ageInMinutes >= expirationInMinutes) {
Log.d(name, "DISK cache expiration for file " + f.toString());
f.delete();
}
}
} | [
"private",
"void",
"sanitizeDiskCache",
"(",
")",
"{",
"File",
"[",
"]",
"cachedFiles",
"=",
"new",
"File",
"(",
"diskCacheDirectory",
")",
".",
"listFiles",
"(",
")",
";",
"if",
"(",
"cachedFiles",
"==",
"null",
")",
"{",
"return",
";",
"}",
"for",
"(",
"File",
"f",
":",
"cachedFiles",
")",
"{",
"// if file older than expirationInMinutes, remove it",
"long",
"lastModified",
"=",
"f",
".",
"lastModified",
"(",
")",
";",
"Date",
"now",
"=",
"new",
"Date",
"(",
")",
";",
"long",
"ageInMinutes",
"=",
"(",
"(",
"now",
".",
"getTime",
"(",
")",
"-",
"lastModified",
")",
"/",
"(",
"1000",
"*",
"60",
")",
")",
";",
"if",
"(",
"ageInMinutes",
">=",
"expirationInMinutes",
")",
"{",
"Log",
".",
"d",
"(",
"name",
",",
"\"DISK cache expiration for file \"",
"+",
"f",
".",
"toString",
"(",
")",
")",
";",
"f",
".",
"delete",
"(",
")",
";",
"}",
"}",
"}"
] | Sanitize disk cache. Remove files which are older than expirationInMinutes. | [
"Sanitize",
"disk",
"cache",
".",
"Remove",
"files",
"which",
"are",
"older",
"than",
"expirationInMinutes",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/cache/image/AbstractCache.java#L106-L122 |
2,350 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/cache/image/AbstractCache.java | AbstractCache.enableDiskCache | public boolean enableDiskCache(Context context, int storageDevice) {
Context appContext = context.getApplicationContext();
String rootDir = null;
if (storageDevice == DISK_CACHE_SDCARD
&& Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
// SD-card available
rootDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/"
+ appContext.getPackageName() + "/cache";
} else {
File internalCacheDir = appContext.getCacheDir();
// apparently on some configurations this can come back as null
if (internalCacheDir == null) {
return (isDiskCacheEnabled = false);
}
rootDir = internalCacheDir.getAbsolutePath();
}
setRootDir(rootDir);
File outFile = new File(diskCacheDirectory);
if (outFile.mkdirs()) {
File nomedia = new File(diskCacheDirectory, ".nomedia");
try {
nomedia.createNewFile();
} catch (IOException e) {
Log.e(LOG_TAG, "Failed creating .nomedia file");
}
}
isDiskCacheEnabled = outFile.exists();
if (!isDiskCacheEnabled) {
Log.w(LOG_TAG, "Failed creating disk cache directory " + diskCacheDirectory);
} else {
//Log.d(name, "enabled write through to " + diskCacheDirectory);
// sanitize disk cache
//Log.d(name, "sanitize DISK cache");
sanitizeDiskCache();
}
return isDiskCacheEnabled;
} | java | public boolean enableDiskCache(Context context, int storageDevice) {
Context appContext = context.getApplicationContext();
String rootDir = null;
if (storageDevice == DISK_CACHE_SDCARD
&& Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
// SD-card available
rootDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/"
+ appContext.getPackageName() + "/cache";
} else {
File internalCacheDir = appContext.getCacheDir();
// apparently on some configurations this can come back as null
if (internalCacheDir == null) {
return (isDiskCacheEnabled = false);
}
rootDir = internalCacheDir.getAbsolutePath();
}
setRootDir(rootDir);
File outFile = new File(diskCacheDirectory);
if (outFile.mkdirs()) {
File nomedia = new File(diskCacheDirectory, ".nomedia");
try {
nomedia.createNewFile();
} catch (IOException e) {
Log.e(LOG_TAG, "Failed creating .nomedia file");
}
}
isDiskCacheEnabled = outFile.exists();
if (!isDiskCacheEnabled) {
Log.w(LOG_TAG, "Failed creating disk cache directory " + diskCacheDirectory);
} else {
//Log.d(name, "enabled write through to " + diskCacheDirectory);
// sanitize disk cache
//Log.d(name, "sanitize DISK cache");
sanitizeDiskCache();
}
return isDiskCacheEnabled;
} | [
"public",
"boolean",
"enableDiskCache",
"(",
"Context",
"context",
",",
"int",
"storageDevice",
")",
"{",
"Context",
"appContext",
"=",
"context",
".",
"getApplicationContext",
"(",
")",
";",
"String",
"rootDir",
"=",
"null",
";",
"if",
"(",
"storageDevice",
"==",
"DISK_CACHE_SDCARD",
"&&",
"Environment",
".",
"MEDIA_MOUNTED",
".",
"equals",
"(",
"Environment",
".",
"getExternalStorageState",
"(",
")",
")",
")",
"{",
"// SD-card available",
"rootDir",
"=",
"Environment",
".",
"getExternalStorageDirectory",
"(",
")",
".",
"getAbsolutePath",
"(",
")",
"+",
"\"/Android/data/\"",
"+",
"appContext",
".",
"getPackageName",
"(",
")",
"+",
"\"/cache\"",
";",
"}",
"else",
"{",
"File",
"internalCacheDir",
"=",
"appContext",
".",
"getCacheDir",
"(",
")",
";",
"// apparently on some configurations this can come back as null",
"if",
"(",
"internalCacheDir",
"==",
"null",
")",
"{",
"return",
"(",
"isDiskCacheEnabled",
"=",
"false",
")",
";",
"}",
"rootDir",
"=",
"internalCacheDir",
".",
"getAbsolutePath",
"(",
")",
";",
"}",
"setRootDir",
"(",
"rootDir",
")",
";",
"File",
"outFile",
"=",
"new",
"File",
"(",
"diskCacheDirectory",
")",
";",
"if",
"(",
"outFile",
".",
"mkdirs",
"(",
")",
")",
"{",
"File",
"nomedia",
"=",
"new",
"File",
"(",
"diskCacheDirectory",
",",
"\".nomedia\"",
")",
";",
"try",
"{",
"nomedia",
".",
"createNewFile",
"(",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"Log",
".",
"e",
"(",
"LOG_TAG",
",",
"\"Failed creating .nomedia file\"",
")",
";",
"}",
"}",
"isDiskCacheEnabled",
"=",
"outFile",
".",
"exists",
"(",
")",
";",
"if",
"(",
"!",
"isDiskCacheEnabled",
")",
"{",
"Log",
".",
"w",
"(",
"LOG_TAG",
",",
"\"Failed creating disk cache directory \"",
"+",
"diskCacheDirectory",
")",
";",
"}",
"else",
"{",
"//Log.d(name, \"enabled write through to \" + diskCacheDirectory);",
"// sanitize disk cache",
"//Log.d(name, \"sanitize DISK cache\");",
"sanitizeDiskCache",
"(",
")",
";",
"}",
"return",
"isDiskCacheEnabled",
";",
"}"
] | Enable caching to the phone's internal storage or SD card.
@param context
the current context
@param storageDevice
where to store the cached files, either {@link #DISK_CACHE_INTERNAL} or
{@link #DISK_CACHE_SDCARD})
@return | [
"Enable",
"caching",
"to",
"the",
"phone",
"s",
"internal",
"storage",
"or",
"SD",
"card",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/cache/image/AbstractCache.java#L134-L177 |
2,351 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/cache/image/AbstractCache.java | AbstractCache.get | @SuppressWarnings("unchecked")
public synchronized ValT get(Object elementKey) {
KeyT key = (KeyT) elementKey;
ValT value = cache.get(key);
if (value != null) {
// memory hit
Log.d(name, "MEM cache hit for " + key.toString());
return value;
}
// memory miss, try reading from disk
File file = getFileForKey(key);
if (file.exists()) {
// if file older than expirationInMinutes, remove it
long lastModified = file.lastModified();
Date now = new Date();
long ageInMinutes = ((now.getTime() - lastModified) / (1000*60));
if (ageInMinutes >= expirationInMinutes) {
Log.d(name, "DISK cache expiration for file " + file.toString());
file.delete();
return null;
}
// disk hit
Log.d(name, "DISK cache hit for " + key.toString());
try {
value = readValueFromDisk(file);
} catch (IOException e) {
// treat decoding errors as a cache miss
e.printStackTrace();
return null;
}
if (value == null) {
return null;
}
cache.put(key, value);
return value;
}
// cache miss
return null;
} | java | @SuppressWarnings("unchecked")
public synchronized ValT get(Object elementKey) {
KeyT key = (KeyT) elementKey;
ValT value = cache.get(key);
if (value != null) {
// memory hit
Log.d(name, "MEM cache hit for " + key.toString());
return value;
}
// memory miss, try reading from disk
File file = getFileForKey(key);
if (file.exists()) {
// if file older than expirationInMinutes, remove it
long lastModified = file.lastModified();
Date now = new Date();
long ageInMinutes = ((now.getTime() - lastModified) / (1000*60));
if (ageInMinutes >= expirationInMinutes) {
Log.d(name, "DISK cache expiration for file " + file.toString());
file.delete();
return null;
}
// disk hit
Log.d(name, "DISK cache hit for " + key.toString());
try {
value = readValueFromDisk(file);
} catch (IOException e) {
// treat decoding errors as a cache miss
e.printStackTrace();
return null;
}
if (value == null) {
return null;
}
cache.put(key, value);
return value;
}
// cache miss
return null;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"synchronized",
"ValT",
"get",
"(",
"Object",
"elementKey",
")",
"{",
"KeyT",
"key",
"=",
"(",
"KeyT",
")",
"elementKey",
";",
"ValT",
"value",
"=",
"cache",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"// memory hit",
"Log",
".",
"d",
"(",
"name",
",",
"\"MEM cache hit for \"",
"+",
"key",
".",
"toString",
"(",
")",
")",
";",
"return",
"value",
";",
"}",
"// memory miss, try reading from disk",
"File",
"file",
"=",
"getFileForKey",
"(",
"key",
")",
";",
"if",
"(",
"file",
".",
"exists",
"(",
")",
")",
"{",
"// if file older than expirationInMinutes, remove it",
"long",
"lastModified",
"=",
"file",
".",
"lastModified",
"(",
")",
";",
"Date",
"now",
"=",
"new",
"Date",
"(",
")",
";",
"long",
"ageInMinutes",
"=",
"(",
"(",
"now",
".",
"getTime",
"(",
")",
"-",
"lastModified",
")",
"/",
"(",
"1000",
"*",
"60",
")",
")",
";",
"if",
"(",
"ageInMinutes",
">=",
"expirationInMinutes",
")",
"{",
"Log",
".",
"d",
"(",
"name",
",",
"\"DISK cache expiration for file \"",
"+",
"file",
".",
"toString",
"(",
")",
")",
";",
"file",
".",
"delete",
"(",
")",
";",
"return",
"null",
";",
"}",
"// disk hit",
"Log",
".",
"d",
"(",
"name",
",",
"\"DISK cache hit for \"",
"+",
"key",
".",
"toString",
"(",
")",
")",
";",
"try",
"{",
"value",
"=",
"readValueFromDisk",
"(",
"file",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"// treat decoding errors as a cache miss",
"e",
".",
"printStackTrace",
"(",
")",
";",
"return",
"null",
";",
"}",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"cache",
".",
"put",
"(",
"key",
",",
"value",
")",
";",
"return",
"value",
";",
"}",
"// cache miss",
"return",
"null",
";",
"}"
] | Reads a value from the cache by probing the in-memory cache, and if enabled and the in-memory
probe was a miss, the disk cache.
@param elementKey
the cache key
@return the cached value, or null if element was not cached | [
"Reads",
"a",
"value",
"from",
"the",
"cache",
"by",
"probing",
"the",
"in",
"-",
"memory",
"cache",
"and",
"if",
"enabled",
"and",
"the",
"in",
"-",
"memory",
"probe",
"was",
"a",
"miss",
"the",
"disk",
"cache",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/cache/image/AbstractCache.java#L255-L297 |
2,352 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/cache/image/AbstractCache.java | AbstractCache.containsKey | @SuppressWarnings("unchecked")
public synchronized boolean containsKey(Object key) {
return cache.containsKey(key) || (isDiskCacheEnabled && getFileForKey((KeyT) key).exists());
} | java | @SuppressWarnings("unchecked")
public synchronized boolean containsKey(Object key) {
return cache.containsKey(key) || (isDiskCacheEnabled && getFileForKey((KeyT) key).exists());
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"synchronized",
"boolean",
"containsKey",
"(",
"Object",
"key",
")",
"{",
"return",
"cache",
".",
"containsKey",
"(",
"key",
")",
"||",
"(",
"isDiskCacheEnabled",
"&&",
"getFileForKey",
"(",
"(",
"KeyT",
")",
"key",
")",
".",
"exists",
"(",
")",
")",
";",
"}"
] | Checks if a value is present in the cache. If the disk cached is enabled, this will also
check whether the value has been persisted to disk.
@param key
the cache key
@return true if the value is cached in memory or on disk, false otherwise | [
"Checks",
"if",
"a",
"value",
"is",
"present",
"in",
"the",
"cache",
".",
"If",
"the",
"disk",
"cached",
"is",
"enabled",
"this",
"will",
"also",
"check",
"whether",
"the",
"value",
"has",
"been",
"persisted",
"to",
"disk",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/cache/image/AbstractCache.java#L323-L326 |
2,353 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/cache/GsonCache.java | GsonCache.read | public static <T> T read(String key, Class<T> classOfT) throws Exception {
String json = cache.getString(key).getString();
T value = new Gson().fromJson(json, classOfT);
if (value == null) {
throw new NullPointerException();
}
return value;
} | java | public static <T> T read(String key, Class<T> classOfT) throws Exception {
String json = cache.getString(key).getString();
T value = new Gson().fromJson(json, classOfT);
if (value == null) {
throw new NullPointerException();
}
return value;
} | [
"public",
"static",
"<",
"T",
">",
"T",
"read",
"(",
"String",
"key",
",",
"Class",
"<",
"T",
">",
"classOfT",
")",
"throws",
"Exception",
"{",
"String",
"json",
"=",
"cache",
".",
"getString",
"(",
"key",
")",
".",
"getString",
"(",
")",
";",
"T",
"value",
"=",
"new",
"Gson",
"(",
")",
".",
"fromJson",
"(",
"json",
",",
"classOfT",
")",
";",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
")",
";",
"}",
"return",
"value",
";",
"}"
] | Get an object from Reservoir with the given key. This a blocking IO operation.
@param key the key string.
@param classOfT the Class type of the expected return object.
@return the object of the given type if it exists. | [
"Get",
"an",
"object",
"from",
"Reservoir",
"with",
"the",
"given",
"key",
".",
"This",
"a",
"blocking",
"IO",
"operation",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/cache/GsonCache.java#L80-L88 |
2,354 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/animation.java | animation.blink | public static View blink(View view, int duration, int offset) {
android.view.animation.Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(duration);
anim.setStartOffset(offset);
anim.setRepeatMode(android.view.animation.Animation.REVERSE);
anim.setRepeatCount(android.view.animation.Animation.INFINITE);
view.startAnimation(anim);
return view;
} | java | public static View blink(View view, int duration, int offset) {
android.view.animation.Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(duration);
anim.setStartOffset(offset);
anim.setRepeatMode(android.view.animation.Animation.REVERSE);
anim.setRepeatCount(android.view.animation.Animation.INFINITE);
view.startAnimation(anim);
return view;
} | [
"public",
"static",
"View",
"blink",
"(",
"View",
"view",
",",
"int",
"duration",
",",
"int",
"offset",
")",
"{",
"android",
".",
"view",
".",
"animation",
".",
"Animation",
"anim",
"=",
"new",
"AlphaAnimation",
"(",
"0.0f",
",",
"1.0f",
")",
";",
"anim",
".",
"setDuration",
"(",
"duration",
")",
";",
"anim",
".",
"setStartOffset",
"(",
"offset",
")",
";",
"anim",
".",
"setRepeatMode",
"(",
"android",
".",
"view",
".",
"animation",
".",
"Animation",
".",
"REVERSE",
")",
";",
"anim",
".",
"setRepeatCount",
"(",
"android",
".",
"view",
".",
"animation",
".",
"Animation",
".",
"INFINITE",
")",
";",
"view",
".",
"startAnimation",
"(",
"anim",
")",
";",
"return",
"view",
";",
"}"
] | Make a View Blink for a desired duration
@param view view that will be animated
@param duration for how long in ms will it blink
@param offset start offset of the animation
@return returns the same view with animation properties | [
"Make",
"a",
"View",
"Blink",
"for",
"a",
"desired",
"duration"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/animation.java#L23-L33 |
2,355 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/views/image/CompassImageView.java | CompassImageView.onDraw | @Override
public void onDraw(Canvas canvas) {
if (animationOn) {
if (angleRecalculate(new Date().getTime())) {
this.setRotation(angle1);
}
} else {
this.setRotation(angle1);
}
super.onDraw(canvas);
if (animationOn) {
this.invalidate();
}
} | java | @Override
public void onDraw(Canvas canvas) {
if (animationOn) {
if (angleRecalculate(new Date().getTime())) {
this.setRotation(angle1);
}
} else {
this.setRotation(angle1);
}
super.onDraw(canvas);
if (animationOn) {
this.invalidate();
}
} | [
"@",
"Override",
"public",
"void",
"onDraw",
"(",
"Canvas",
"canvas",
")",
"{",
"if",
"(",
"animationOn",
")",
"{",
"if",
"(",
"angleRecalculate",
"(",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
")",
")",
"{",
"this",
".",
"setRotation",
"(",
"angle1",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"setRotation",
"(",
"angle1",
")",
";",
"}",
"super",
".",
"onDraw",
"(",
"canvas",
")",
";",
"if",
"(",
"animationOn",
")",
"{",
"this",
".",
"invalidate",
"(",
")",
";",
"}",
"}"
] | onDraw override.
If animation is "on", view is invalidated after each redraw,
to perform recalculation on every loop of UI redraw | [
"onDraw",
"override",
".",
"If",
"animation",
"is",
"on",
"view",
"is",
"invalidated",
"after",
"each",
"redraw",
"to",
"perform",
"recalculation",
"on",
"every",
"loop",
"of",
"UI",
"redraw"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/views/image/CompassImageView.java#L82-L95 |
2,356 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/views/image/CompassImageView.java | CompassImageView.setPhysical | public void setPhysical(float inertiaMoment, float alpha, float mB) {
this.inertiaMoment = inertiaMoment >= 0 ? inertiaMoment : this.INERTIA_MOMENT_DEFAULT;
this.alpha = alpha >= 0 ? alpha : ALPHA_DEFAULT;
this.mB = mB >= 0 ? mB : MB_DEFAULT;
} | java | public void setPhysical(float inertiaMoment, float alpha, float mB) {
this.inertiaMoment = inertiaMoment >= 0 ? inertiaMoment : this.INERTIA_MOMENT_DEFAULT;
this.alpha = alpha >= 0 ? alpha : ALPHA_DEFAULT;
this.mB = mB >= 0 ? mB : MB_DEFAULT;
} | [
"public",
"void",
"setPhysical",
"(",
"float",
"inertiaMoment",
",",
"float",
"alpha",
",",
"float",
"mB",
")",
"{",
"this",
".",
"inertiaMoment",
"=",
"inertiaMoment",
">=",
"0",
"?",
"inertiaMoment",
":",
"this",
".",
"INERTIA_MOMENT_DEFAULT",
";",
"this",
".",
"alpha",
"=",
"alpha",
">=",
"0",
"?",
"alpha",
":",
"ALPHA_DEFAULT",
";",
"this",
".",
"mB",
"=",
"mB",
">=",
"0",
"?",
"mB",
":",
"MB_DEFAULT",
";",
"}"
] | Use this to set physical properties.
Negative values will be replaced by default values
@param inertiaMoment Moment of inertia (default 0.1)
@param alpha Damping coefficient (default 10)
@param mB Magnetic field coefficient (default 1000) | [
"Use",
"this",
"to",
"set",
"physical",
"properties",
".",
"Negative",
"values",
"will",
"be",
"replaced",
"by",
"default",
"values"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/views/image/CompassImageView.java#L105-L109 |
2,357 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/views/image/CompassImageView.java | CompassImageView.rotationUpdate | public void rotationUpdate(final float angleNew, final boolean animate) {
if (animate) {
if (Math.abs(angle0 - angleNew) > ANGLE_DELTA_THRESHOLD) {
angle0 = angleNew;
this.invalidate();
}
animationOn = true;
} else {
angle1 = angleNew;
angle2 = angleNew;
angle0 = angleNew;
angleLastDrawn = angleNew;
this.invalidate();
animationOn = false;
}
} | java | public void rotationUpdate(final float angleNew, final boolean animate) {
if (animate) {
if (Math.abs(angle0 - angleNew) > ANGLE_DELTA_THRESHOLD) {
angle0 = angleNew;
this.invalidate();
}
animationOn = true;
} else {
angle1 = angleNew;
angle2 = angleNew;
angle0 = angleNew;
angleLastDrawn = angleNew;
this.invalidate();
animationOn = false;
}
} | [
"public",
"void",
"rotationUpdate",
"(",
"final",
"float",
"angleNew",
",",
"final",
"boolean",
"animate",
")",
"{",
"if",
"(",
"animate",
")",
"{",
"if",
"(",
"Math",
".",
"abs",
"(",
"angle0",
"-",
"angleNew",
")",
">",
"ANGLE_DELTA_THRESHOLD",
")",
"{",
"angle0",
"=",
"angleNew",
";",
"this",
".",
"invalidate",
"(",
")",
";",
"}",
"animationOn",
"=",
"true",
";",
"}",
"else",
"{",
"angle1",
"=",
"angleNew",
";",
"angle2",
"=",
"angleNew",
";",
"angle0",
"=",
"angleNew",
";",
"angleLastDrawn",
"=",
"angleNew",
";",
"this",
".",
"invalidate",
"(",
")",
";",
"animationOn",
"=",
"false",
";",
"}",
"}"
] | Use this to set new "magnetic field" angle at which image should rotate
@param angleNew new magnetic field angle, deg., relative to vertical axis.
@param animate true, if image shoud rotate using animation, false to set new rotation instantly | [
"Use",
"this",
"to",
"set",
"new",
"magnetic",
"field",
"angle",
"at",
"which",
"image",
"should",
"rotate"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/views/image/CompassImageView.java#L118-L133 |
2,358 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/views/image/CompassImageView.java | CompassImageView.angleRecalculate | protected boolean angleRecalculate(final long timeNew) {
// recalculate angle using simple numerical integration of motion equation
float deltaT1 = (timeNew - time1) / 1000f;
if (deltaT1 > TIME_DELTA_THRESHOLD) {
deltaT1 = TIME_DELTA_THRESHOLD;
time1 = timeNew + Math.round(TIME_DELTA_THRESHOLD * 1000);
}
float deltaT2 = (time1 - time2) / 1000f;
if (deltaT2 > TIME_DELTA_THRESHOLD) {
deltaT2 = TIME_DELTA_THRESHOLD;
}
// circular acceleration coefficient
float koefI = inertiaMoment / deltaT1 / deltaT2;
// circular velocity coefficient
float koefAlpha = alpha / deltaT1;
// angular momentum coefficient
float koefk = mB * (float) (Math.sin(Math.toRadians(angle0)) * Math.cos(Math.toRadians(angle1)) -
(Math.sin(Math.toRadians(angle1)) * Math.cos(Math.toRadians(angle0))));
float angleNew = (koefI * (angle1 * 2f - angle2) + koefAlpha * angle1 + koefk) / (koefI + koefAlpha);
// reassign previous iteration variables
angle2 = angle1;
angle1 = angleNew;
time2 = time1;
time1 = timeNew;
// if angles changed less then threshold, return false - no need to redraw the view
if (Math.abs(angleLastDrawn - angle1) < ANGLE_DELTA_THRESHOLD) {
return false;
} else {
angleLastDrawn = angle1;
return true;
}
} | java | protected boolean angleRecalculate(final long timeNew) {
// recalculate angle using simple numerical integration of motion equation
float deltaT1 = (timeNew - time1) / 1000f;
if (deltaT1 > TIME_DELTA_THRESHOLD) {
deltaT1 = TIME_DELTA_THRESHOLD;
time1 = timeNew + Math.round(TIME_DELTA_THRESHOLD * 1000);
}
float deltaT2 = (time1 - time2) / 1000f;
if (deltaT2 > TIME_DELTA_THRESHOLD) {
deltaT2 = TIME_DELTA_THRESHOLD;
}
// circular acceleration coefficient
float koefI = inertiaMoment / deltaT1 / deltaT2;
// circular velocity coefficient
float koefAlpha = alpha / deltaT1;
// angular momentum coefficient
float koefk = mB * (float) (Math.sin(Math.toRadians(angle0)) * Math.cos(Math.toRadians(angle1)) -
(Math.sin(Math.toRadians(angle1)) * Math.cos(Math.toRadians(angle0))));
float angleNew = (koefI * (angle1 * 2f - angle2) + koefAlpha * angle1 + koefk) / (koefI + koefAlpha);
// reassign previous iteration variables
angle2 = angle1;
angle1 = angleNew;
time2 = time1;
time1 = timeNew;
// if angles changed less then threshold, return false - no need to redraw the view
if (Math.abs(angleLastDrawn - angle1) < ANGLE_DELTA_THRESHOLD) {
return false;
} else {
angleLastDrawn = angle1;
return true;
}
} | [
"protected",
"boolean",
"angleRecalculate",
"(",
"final",
"long",
"timeNew",
")",
"{",
"// recalculate angle using simple numerical integration of motion equation",
"float",
"deltaT1",
"=",
"(",
"timeNew",
"-",
"time1",
")",
"/",
"1000f",
";",
"if",
"(",
"deltaT1",
">",
"TIME_DELTA_THRESHOLD",
")",
"{",
"deltaT1",
"=",
"TIME_DELTA_THRESHOLD",
";",
"time1",
"=",
"timeNew",
"+",
"Math",
".",
"round",
"(",
"TIME_DELTA_THRESHOLD",
"*",
"1000",
")",
";",
"}",
"float",
"deltaT2",
"=",
"(",
"time1",
"-",
"time2",
")",
"/",
"1000f",
";",
"if",
"(",
"deltaT2",
">",
"TIME_DELTA_THRESHOLD",
")",
"{",
"deltaT2",
"=",
"TIME_DELTA_THRESHOLD",
";",
"}",
"// circular acceleration coefficient",
"float",
"koefI",
"=",
"inertiaMoment",
"/",
"deltaT1",
"/",
"deltaT2",
";",
"// circular velocity coefficient",
"float",
"koefAlpha",
"=",
"alpha",
"/",
"deltaT1",
";",
"// angular momentum coefficient",
"float",
"koefk",
"=",
"mB",
"*",
"(",
"float",
")",
"(",
"Math",
".",
"sin",
"(",
"Math",
".",
"toRadians",
"(",
"angle0",
")",
")",
"*",
"Math",
".",
"cos",
"(",
"Math",
".",
"toRadians",
"(",
"angle1",
")",
")",
"-",
"(",
"Math",
".",
"sin",
"(",
"Math",
".",
"toRadians",
"(",
"angle1",
")",
")",
"*",
"Math",
".",
"cos",
"(",
"Math",
".",
"toRadians",
"(",
"angle0",
")",
")",
")",
")",
";",
"float",
"angleNew",
"=",
"(",
"koefI",
"*",
"(",
"angle1",
"*",
"2f",
"-",
"angle2",
")",
"+",
"koefAlpha",
"*",
"angle1",
"+",
"koefk",
")",
"/",
"(",
"koefI",
"+",
"koefAlpha",
")",
";",
"// reassign previous iteration variables",
"angle2",
"=",
"angle1",
";",
"angle1",
"=",
"angleNew",
";",
"time2",
"=",
"time1",
";",
"time1",
"=",
"timeNew",
";",
"// if angles changed less then threshold, return false - no need to redraw the view",
"if",
"(",
"Math",
".",
"abs",
"(",
"angleLastDrawn",
"-",
"angle1",
")",
"<",
"ANGLE_DELTA_THRESHOLD",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"angleLastDrawn",
"=",
"angle1",
";",
"return",
"true",
";",
"}",
"}"
] | Recalculate angles using equation of dipole circular motion
@param timeNew timestamp of method invoke
@return if there is a need to redraw rotation | [
"Recalculate",
"angles",
"using",
"equation",
"of",
"dipole",
"circular",
"motion"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/views/image/CompassImageView.java#L141-L179 |
2,359 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/share.java | share.sendEmail | public static void sendEmail(String email, String subject, String emailBody) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
QuickUtils.getContext().startActivity(emailIntent);
} catch (android.content.ActivityNotFoundException ex) {
QuickUtils.system.toast("There are no email clients installed.");
}
} | java | public static void sendEmail(String email, String subject, String emailBody) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
QuickUtils.getContext().startActivity(emailIntent);
} catch (android.content.ActivityNotFoundException ex) {
QuickUtils.system.toast("There are no email clients installed.");
}
} | [
"public",
"static",
"void",
"sendEmail",
"(",
"String",
"email",
",",
"String",
"subject",
",",
"String",
"emailBody",
")",
"{",
"Intent",
"emailIntent",
"=",
"new",
"Intent",
"(",
"Intent",
".",
"ACTION_SEND",
")",
";",
"emailIntent",
".",
"setType",
"(",
"\"message/rfc822\"",
")",
";",
"emailIntent",
".",
"putExtra",
"(",
"Intent",
".",
"EXTRA_EMAIL",
",",
"new",
"String",
"[",
"]",
"{",
"email",
"}",
")",
";",
"emailIntent",
".",
"putExtra",
"(",
"Intent",
".",
"EXTRA_SUBJECT",
",",
"subject",
")",
";",
"emailIntent",
".",
"putExtra",
"(",
"Intent",
".",
"EXTRA_TEXT",
",",
"emailBody",
")",
";",
"emailIntent",
".",
"setFlags",
"(",
"Intent",
".",
"FLAG_ACTIVITY_NEW_TASK",
")",
";",
"try",
"{",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"startActivity",
"(",
"emailIntent",
")",
";",
"}",
"catch",
"(",
"android",
".",
"content",
".",
"ActivityNotFoundException",
"ex",
")",
"{",
"QuickUtils",
".",
"system",
".",
"toast",
"(",
"\"There are no email clients installed.\"",
")",
";",
"}",
"}"
] | Share via Email
@param email destination email (e.g. [email protected])
@param subject email subject
@param emailBody email body | [
"Share",
"via",
"Email"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/share.java#L22-L36 |
2,360 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/share.java | share.shareMethod | private static void shareMethod(String message, String activityInfoName) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
PackageManager pm = QuickUtils.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains(activityInfoName)) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
QuickUtils.getContext().startActivity(shareIntent);
break;
}
}
} | java | private static void shareMethod(String message, String activityInfoName) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, message);
PackageManager pm = QuickUtils.getContext().getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
if ((app.activityInfo.name).contains(activityInfoName)) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
shareIntent.setComponent(name);
QuickUtils.getContext().startActivity(shareIntent);
break;
}
}
} | [
"private",
"static",
"void",
"shareMethod",
"(",
"String",
"message",
",",
"String",
"activityInfoName",
")",
"{",
"Intent",
"shareIntent",
"=",
"new",
"Intent",
"(",
"Intent",
".",
"ACTION_SEND",
")",
";",
"shareIntent",
".",
"setType",
"(",
"\"text/plain\"",
")",
";",
"shareIntent",
".",
"putExtra",
"(",
"Intent",
".",
"EXTRA_TEXT",
",",
"message",
")",
";",
"PackageManager",
"pm",
"=",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"getPackageManager",
"(",
")",
";",
"List",
"<",
"ResolveInfo",
">",
"activityList",
"=",
"pm",
".",
"queryIntentActivities",
"(",
"shareIntent",
",",
"0",
")",
";",
"for",
"(",
"final",
"ResolveInfo",
"app",
":",
"activityList",
")",
"{",
"if",
"(",
"(",
"app",
".",
"activityInfo",
".",
"name",
")",
".",
"contains",
"(",
"activityInfoName",
")",
")",
"{",
"final",
"ActivityInfo",
"activity",
"=",
"app",
".",
"activityInfo",
";",
"final",
"ComponentName",
"name",
"=",
"new",
"ComponentName",
"(",
"activity",
".",
"applicationInfo",
".",
"packageName",
",",
"activity",
".",
"name",
")",
";",
"shareIntent",
".",
"addCategory",
"(",
"Intent",
".",
"CATEGORY_LAUNCHER",
")",
";",
"shareIntent",
".",
"setFlags",
"(",
"Intent",
".",
"FLAG_ACTIVITY_NEW_TASK",
"|",
"Intent",
".",
"FLAG_ACTIVITY_RESET_TASK_IF_NEEDED",
")",
";",
"shareIntent",
".",
"setComponent",
"(",
"name",
")",
";",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"startActivity",
"(",
"shareIntent",
")",
";",
"break",
";",
"}",
"}",
"}"
] | Private method that handles facebook and twitter sharing
@param message Message to be delivered
@param activityInfoName | [
"Private",
"method",
"that",
"handles",
"facebook",
"and",
"twitter",
"sharing"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/share.java#L53-L70 |
2,361 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/share.java | share.genericSharing | public static void genericSharing(String subject, String message) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
QuickUtils.getContext().startActivity(intent);
} | java | public static void genericSharing(String subject, String message) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, message);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
QuickUtils.getContext().startActivity(intent);
} | [
"public",
"static",
"void",
"genericSharing",
"(",
"String",
"subject",
",",
"String",
"message",
")",
"{",
"Intent",
"intent",
"=",
"new",
"Intent",
"(",
"Intent",
".",
"ACTION_SEND",
")",
";",
"intent",
".",
"setType",
"(",
"\"text/plain\"",
")",
";",
"intent",
".",
"putExtra",
"(",
"Intent",
".",
"EXTRA_TEXT",
",",
"message",
")",
";",
"intent",
".",
"putExtra",
"(",
"Intent",
".",
"EXTRA_SUBJECT",
",",
"subject",
")",
";",
"intent",
".",
"setFlags",
"(",
"Intent",
".",
"FLAG_ACTIVITY_NEW_TASK",
")",
";",
"QuickUtils",
".",
"getContext",
"(",
")",
".",
"startActivity",
"(",
"intent",
")",
";",
"}"
] | Generic method for sharing that Deliver some data to someone else. Who
the data is being delivered to is not specified; it is up to the receiver
of this action to ask the user where the data should be sent.
@param subject The title, if applied
@param message Message to be delivered | [
"Generic",
"method",
"for",
"sharing",
"that",
"Deliver",
"some",
"data",
"to",
"someone",
"else",
".",
"Who",
"the",
"data",
"is",
"being",
"delivered",
"to",
"is",
"not",
"specified",
";",
"it",
"is",
"up",
"to",
"the",
"receiver",
"of",
"this",
"action",
"to",
"ask",
"the",
"user",
"where",
"the",
"data",
"should",
"be",
"sent",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/share.java#L80-L87 |
2,362 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/sdcard.java | sdcard.isSDCardAvailable | public static boolean isSDCardAvailable() {
boolean mExternalStorageAvailable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
} else {
// Something else is wrong. It may be one of many other states,
// but all we need
// to know is we can neither read nor write
mExternalStorageAvailable = false;
}
return mExternalStorageAvailable;
} | java | public static boolean isSDCardAvailable() {
boolean mExternalStorageAvailable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
} else {
// Something else is wrong. It may be one of many other states,
// but all we need
// to know is we can neither read nor write
mExternalStorageAvailable = false;
}
return mExternalStorageAvailable;
} | [
"public",
"static",
"boolean",
"isSDCardAvailable",
"(",
")",
"{",
"boolean",
"mExternalStorageAvailable",
"=",
"false",
";",
"String",
"state",
"=",
"Environment",
".",
"getExternalStorageState",
"(",
")",
";",
"if",
"(",
"Environment",
".",
"MEDIA_MOUNTED",
".",
"equals",
"(",
"state",
")",
")",
"{",
"// We can read and write the media\r",
"mExternalStorageAvailable",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"Environment",
".",
"MEDIA_MOUNTED_READ_ONLY",
".",
"equals",
"(",
"state",
")",
")",
"{",
"// We can only read the media\r",
"mExternalStorageAvailable",
"=",
"true",
";",
"}",
"else",
"{",
"// Something else is wrong. It may be one of many other states,\r",
"// but all we need\r",
"// to know is we can neither read nor write\r",
"mExternalStorageAvailable",
"=",
"false",
";",
"}",
"return",
"mExternalStorageAvailable",
";",
"}"
] | Check if the SD Card is Available
@return true if the sd card is available and false if it is not | [
"Check",
"if",
"the",
"SD",
"Card",
"is",
"Available"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/sdcard.java#L44-L65 |
2,363 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/sdcard.java | sdcard.isSDCardWritable | public static boolean isSDCardWritable() {
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageWriteable = false;
} else {
// Something else is wrong. It may be one of many other states,
// but all we need
// to know is we can neither read nor write
mExternalStorageWriteable = false;
}
return mExternalStorageWriteable;
} | java | public static boolean isSDCardWritable() {
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageWriteable = false;
} else {
// Something else is wrong. It may be one of many other states,
// but all we need
// to know is we can neither read nor write
mExternalStorageWriteable = false;
}
return mExternalStorageWriteable;
} | [
"public",
"static",
"boolean",
"isSDCardWritable",
"(",
")",
"{",
"boolean",
"mExternalStorageWriteable",
"=",
"false",
";",
"String",
"state",
"=",
"Environment",
".",
"getExternalStorageState",
"(",
")",
";",
"if",
"(",
"Environment",
".",
"MEDIA_MOUNTED",
".",
"equals",
"(",
"state",
")",
")",
"{",
"// We can read and write the media\r",
"mExternalStorageWriteable",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"Environment",
".",
"MEDIA_MOUNTED_READ_ONLY",
".",
"equals",
"(",
"state",
")",
")",
"{",
"// We can only read the media\r",
"mExternalStorageWriteable",
"=",
"false",
";",
"}",
"else",
"{",
"// Something else is wrong. It may be one of many other states,\r",
"// but all we need\r",
"// to know is we can neither read nor write\r",
"mExternalStorageWriteable",
"=",
"false",
";",
"}",
"return",
"mExternalStorageWriteable",
";",
"}"
] | Check if the SD Card is writable
@return true if the sd card is writable and false if it is not | [
"Check",
"if",
"the",
"SD",
"Card",
"is",
"writable"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/sdcard.java#L95-L117 |
2,364 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/sdcard.java | sdcard.checkIfFileExists | public static boolean checkIfFileExists(String filePath) {
File file = new File(filePath);// getSDCardPath(), filePath);
return (file.exists() ? true : false);
} | java | public static boolean checkIfFileExists(String filePath) {
File file = new File(filePath);// getSDCardPath(), filePath);
return (file.exists() ? true : false);
} | [
"public",
"static",
"boolean",
"checkIfFileExists",
"(",
"String",
"filePath",
")",
"{",
"File",
"file",
"=",
"new",
"File",
"(",
"filePath",
")",
";",
"// getSDCardPath(), filePath);\r",
"return",
"(",
"file",
".",
"exists",
"(",
")",
"?",
"true",
":",
"false",
")",
";",
"}"
] | Check if file exists on SDCard or not
@param filePath - its the path of the file after SDCardDirectory (no need for
getExternalStorageDirectory())
@return boolean - if file exist on SDCard or not | [
"Check",
"if",
"file",
"exists",
"on",
"SDCard",
"or",
"not"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/sdcard.java#L192-L195 |
2,365 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/sdcard.java | sdcard.createFolder | public static boolean createFolder(String path) {
File direct = new File(Environment.getExternalStorageDirectory() + "/" + path);
if (!direct.exists()) {
if (direct.mkdir()) {
return true;
}
}
return false;
} | java | public static boolean createFolder(String path) {
File direct = new File(Environment.getExternalStorageDirectory() + "/" + path);
if (!direct.exists()) {
if (direct.mkdir()) {
return true;
}
}
return false;
} | [
"public",
"static",
"boolean",
"createFolder",
"(",
"String",
"path",
")",
"{",
"File",
"direct",
"=",
"new",
"File",
"(",
"Environment",
".",
"getExternalStorageDirectory",
"(",
")",
"+",
"\"/\"",
"+",
"path",
")",
";",
"if",
"(",
"!",
"direct",
".",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"direct",
".",
"mkdir",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Create folder in the SDCard
@param path
@return | [
"Create",
"folder",
"in",
"the",
"SDCard"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/sdcard.java#L203-L213 |
2,366 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/sdcard.java | sdcard.writeToFile | private static void writeToFile(String text, String logFilePath, boolean isDetailed) {
if (isSDCardAvailable() && isSDCardWritable() && text != null) {
try {
File file = new File(logFilePath);
OutputStream os = new FileOutputStream(file, true);
if (isDetailed) {
os.write(("---" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS").format(Calendar.getInstance().getTime()) + "---\n").getBytes());
}
os.write((text + "\n").getBytes());
// os.write(("------\n").getBytes());
os.close();
} catch (Exception e) {
QuickUtils.log.e("Exception", e);
}
} else {
return;
}
} | java | private static void writeToFile(String text, String logFilePath, boolean isDetailed) {
if (isSDCardAvailable() && isSDCardWritable() && text != null) {
try {
File file = new File(logFilePath);
OutputStream os = new FileOutputStream(file, true);
if (isDetailed) {
os.write(("---" + new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS").format(Calendar.getInstance().getTime()) + "---\n").getBytes());
}
os.write((text + "\n").getBytes());
// os.write(("------\n").getBytes());
os.close();
} catch (Exception e) {
QuickUtils.log.e("Exception", e);
}
} else {
return;
}
} | [
"private",
"static",
"void",
"writeToFile",
"(",
"String",
"text",
",",
"String",
"logFilePath",
",",
"boolean",
"isDetailed",
")",
"{",
"if",
"(",
"isSDCardAvailable",
"(",
")",
"&&",
"isSDCardWritable",
"(",
")",
"&&",
"text",
"!=",
"null",
")",
"{",
"try",
"{",
"File",
"file",
"=",
"new",
"File",
"(",
"logFilePath",
")",
";",
"OutputStream",
"os",
"=",
"new",
"FileOutputStream",
"(",
"file",
",",
"true",
")",
";",
"if",
"(",
"isDetailed",
")",
"{",
"os",
".",
"write",
"(",
"(",
"\"---\"",
"+",
"new",
"SimpleDateFormat",
"(",
"\"yyyy/MM/dd HH:mm:ss.SSS\"",
")",
".",
"format",
"(",
"Calendar",
".",
"getInstance",
"(",
")",
".",
"getTime",
"(",
")",
")",
"+",
"\"---\\n\"",
")",
".",
"getBytes",
"(",
")",
")",
";",
"}",
"os",
".",
"write",
"(",
"(",
"text",
"+",
"\"\\n\"",
")",
".",
"getBytes",
"(",
")",
")",
";",
"// os.write((\"------\\n\").getBytes());\r",
"os",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"QuickUtils",
".",
"log",
".",
"e",
"(",
"\"Exception\"",
",",
"e",
")",
";",
"}",
"}",
"else",
"{",
"return",
";",
"}",
"}"
] | private write to file method
@param text text to append
@param logFilePath path to the file
@param isDetailed if it should show the timestamp or not | [
"private",
"write",
"to",
"file",
"method"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/sdcard.java#L243-L261 |
2,367 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/categories/sdcard.java | sdcard.readAsBytes | public static byte[] readAsBytes(InputStream inputStream) throws IOException {
int cnt = 0;
byte[] buffer = new byte[BUFFER_SIZE];
InputStream is = new BufferedInputStream(inputStream);
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
cnt = is.read(buffer);
while (cnt != -1) {
outputStream.write(buffer, 0, cnt);
cnt = is.read(buffer);
}
return outputStream.toByteArray();
} finally {
safeClose(is);
}
} | java | public static byte[] readAsBytes(InputStream inputStream) throws IOException {
int cnt = 0;
byte[] buffer = new byte[BUFFER_SIZE];
InputStream is = new BufferedInputStream(inputStream);
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
cnt = is.read(buffer);
while (cnt != -1) {
outputStream.write(buffer, 0, cnt);
cnt = is.read(buffer);
}
return outputStream.toByteArray();
} finally {
safeClose(is);
}
} | [
"public",
"static",
"byte",
"[",
"]",
"readAsBytes",
"(",
"InputStream",
"inputStream",
")",
"throws",
"IOException",
"{",
"int",
"cnt",
"=",
"0",
";",
"byte",
"[",
"]",
"buffer",
"=",
"new",
"byte",
"[",
"BUFFER_SIZE",
"]",
";",
"InputStream",
"is",
"=",
"new",
"BufferedInputStream",
"(",
"inputStream",
")",
";",
"try",
"{",
"ByteArrayOutputStream",
"outputStream",
"=",
"new",
"ByteArrayOutputStream",
"(",
")",
";",
"cnt",
"=",
"is",
".",
"read",
"(",
"buffer",
")",
";",
"while",
"(",
"cnt",
"!=",
"-",
"1",
")",
"{",
"outputStream",
".",
"write",
"(",
"buffer",
",",
"0",
",",
"cnt",
")",
";",
"cnt",
"=",
"is",
".",
"read",
"(",
"buffer",
")",
";",
"}",
"return",
"outputStream",
".",
"toByteArray",
"(",
")",
";",
"}",
"finally",
"{",
"safeClose",
"(",
"is",
")",
";",
"}",
"}"
] | Reads the inputStream and returns a byte array with all the information
@param inputStream The inputStream to be read
@return A byte array with all the inputStream's information
@throws IOException The exception thrown when an error reading the inputStream happens | [
"Reads",
"the",
"inputStream",
"and",
"returns",
"a",
"byte",
"array",
"with",
"all",
"the",
"information"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/categories/sdcard.java#L354-L369 |
2,368 | cesarferreira/AndroidQuickUtils | library/src/main/java/com/google/common/base/internal/Finalizer.java | Finalizer.run | @SuppressWarnings("InfiniteLoopStatement")
@Override
public void run() {
try {
while (true) {
try {
cleanUp(queue.remove());
} catch (InterruptedException e) { /* ignore */ }
}
} catch (ShutDown shutDown) { /* ignore */ }
} | java | @SuppressWarnings("InfiniteLoopStatement")
@Override
public void run() {
try {
while (true) {
try {
cleanUp(queue.remove());
} catch (InterruptedException e) { /* ignore */ }
}
} catch (ShutDown shutDown) { /* ignore */ }
} | [
"@",
"SuppressWarnings",
"(",
"\"InfiniteLoopStatement\"",
")",
"@",
"Override",
"public",
"void",
"run",
"(",
")",
"{",
"try",
"{",
"while",
"(",
"true",
")",
"{",
"try",
"{",
"cleanUp",
"(",
"queue",
".",
"remove",
"(",
")",
")",
";",
"}",
"catch",
"(",
"InterruptedException",
"e",
")",
"{",
"/* ignore */",
"}",
"}",
"}",
"catch",
"(",
"ShutDown",
"shutDown",
")",
"{",
"/* ignore */",
"}",
"}"
] | Loops continuously, pulling references off the queue and cleaning them up. | [
"Loops",
"continuously",
"pulling",
"references",
"off",
"the",
"queue",
"and",
"cleaning",
"them",
"up",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/com/google/common/base/internal/Finalizer.java#L121-L131 |
2,369 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/views/image/TopCenterImageView.java | TopCenterImageView.setFrame | @Override
protected boolean setFrame(int l, int t, int r, int b) {
if (getDrawable() == null) {
return super.setFrame(l, t, r, b);
}
Matrix matrix = getImageMatrix();
float scaleFactor = getWidth() / (float) getDrawable().getIntrinsicWidth();
matrix.setScale(scaleFactor, scaleFactor, 0, 0);
setImageMatrix(matrix);
return super.setFrame(l, t, r, b);
} | java | @Override
protected boolean setFrame(int l, int t, int r, int b) {
if (getDrawable() == null) {
return super.setFrame(l, t, r, b);
}
Matrix matrix = getImageMatrix();
float scaleFactor = getWidth() / (float) getDrawable().getIntrinsicWidth();
matrix.setScale(scaleFactor, scaleFactor, 0, 0);
setImageMatrix(matrix);
return super.setFrame(l, t, r, b);
} | [
"@",
"Override",
"protected",
"boolean",
"setFrame",
"(",
"int",
"l",
",",
"int",
"t",
",",
"int",
"r",
",",
"int",
"b",
")",
"{",
"if",
"(",
"getDrawable",
"(",
")",
"==",
"null",
")",
"{",
"return",
"super",
".",
"setFrame",
"(",
"l",
",",
"t",
",",
"r",
",",
"b",
")",
";",
"}",
"Matrix",
"matrix",
"=",
"getImageMatrix",
"(",
")",
";",
"float",
"scaleFactor",
"=",
"getWidth",
"(",
")",
"/",
"(",
"float",
")",
"getDrawable",
"(",
")",
".",
"getIntrinsicWidth",
"(",
")",
";",
"matrix",
".",
"setScale",
"(",
"scaleFactor",
",",
"scaleFactor",
",",
"0",
",",
"0",
")",
";",
"setImageMatrix",
"(",
"matrix",
")",
";",
"return",
"super",
".",
"setFrame",
"(",
"l",
",",
"t",
",",
"r",
",",
"b",
")",
";",
"}"
] | Top crop scale type | [
"Top",
"crop",
"scale",
"type"
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/views/image/TopCenterImageView.java#L34-L44 |
2,370 | cesarferreira/AndroidQuickUtils | library/src/main/java/quickutils/core/adapters/BindableAdapter.java | BindableAdapter.newDropDownView | public View newDropDownView(LayoutInflater inflater, int position, ViewGroup container) {
return newView(inflater, position, container);
} | java | public View newDropDownView(LayoutInflater inflater, int position, ViewGroup container) {
return newView(inflater, position, container);
} | [
"public",
"View",
"newDropDownView",
"(",
"LayoutInflater",
"inflater",
",",
"int",
"position",
",",
"ViewGroup",
"container",
")",
"{",
"return",
"newView",
"(",
"inflater",
",",
"position",
",",
"container",
")",
";",
"}"
] | Create a new instance of a drop-down view for the specified position. | [
"Create",
"a",
"new",
"instance",
"of",
"a",
"drop",
"-",
"down",
"view",
"for",
"the",
"specified",
"position",
"."
] | 73a91daedbb9f7be7986ea786fbc441c9e5a881c | https://github.com/cesarferreira/AndroidQuickUtils/blob/73a91daedbb9f7be7986ea786fbc441c9e5a881c/library/src/main/java/quickutils/core/adapters/BindableAdapter.java#L59-L61 |
2,371 | mguymon/model-citizen | core/src/main/java/com/tobedevoured/modelcitizen/policy/SkipReferenceFieldPolicy.java | SkipReferenceFieldPolicy.process | public Map<ModelField,Set<Command>> process(ModelFactory modelFactory, Erector erector, Object model) throws PolicyException {
Map<ModelField,Set<Command>> modelFieldCommands = new HashMap<ModelField,Set<Command>>();
for ( ModelField modelField : erector.getModelFields() ) {
logger.debug( " {} {}", getTarget(), modelField);
if ( modelField.getName().equals( field ) ) {
Set<Command> commands = modelFieldCommands.get( modelField );
if ( commands == null ) {
commands = new HashSet<Command>();
}
commands.add( Command.SKIP_REFERENCE_INJECTION );
modelFieldCommands.put( modelField, commands );
}
}
return modelFieldCommands;
} | java | public Map<ModelField,Set<Command>> process(ModelFactory modelFactory, Erector erector, Object model) throws PolicyException {
Map<ModelField,Set<Command>> modelFieldCommands = new HashMap<ModelField,Set<Command>>();
for ( ModelField modelField : erector.getModelFields() ) {
logger.debug( " {} {}", getTarget(), modelField);
if ( modelField.getName().equals( field ) ) {
Set<Command> commands = modelFieldCommands.get( modelField );
if ( commands == null ) {
commands = new HashSet<Command>();
}
commands.add( Command.SKIP_REFERENCE_INJECTION );
modelFieldCommands.put( modelField, commands );
}
}
return modelFieldCommands;
} | [
"public",
"Map",
"<",
"ModelField",
",",
"Set",
"<",
"Command",
">",
">",
"process",
"(",
"ModelFactory",
"modelFactory",
",",
"Erector",
"erector",
",",
"Object",
"model",
")",
"throws",
"PolicyException",
"{",
"Map",
"<",
"ModelField",
",",
"Set",
"<",
"Command",
">",
">",
"modelFieldCommands",
"=",
"new",
"HashMap",
"<",
"ModelField",
",",
"Set",
"<",
"Command",
">",
">",
"(",
")",
";",
"for",
"(",
"ModelField",
"modelField",
":",
"erector",
".",
"getModelFields",
"(",
")",
")",
"{",
"logger",
".",
"debug",
"(",
"\" {} {}\"",
",",
"getTarget",
"(",
")",
",",
"modelField",
")",
";",
"if",
"(",
"modelField",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"field",
")",
")",
"{",
"Set",
"<",
"Command",
">",
"commands",
"=",
"modelFieldCommands",
".",
"get",
"(",
"modelField",
")",
";",
"if",
"(",
"commands",
"==",
"null",
")",
"{",
"commands",
"=",
"new",
"HashSet",
"<",
"Command",
">",
"(",
")",
";",
"}",
"commands",
".",
"add",
"(",
"Command",
".",
"SKIP_REFERENCE_INJECTION",
")",
";",
"modelFieldCommands",
".",
"put",
"(",
"modelField",
",",
"commands",
")",
";",
"}",
"}",
"return",
"modelFieldCommands",
";",
"}"
] | Prevents Model from being set by the Reference Model | [
"Prevents",
"Model",
"from",
"being",
"set",
"by",
"the",
"Reference",
"Model"
] | 9078ab4121897a21e598dd4f0efa6996b46e4dea | https://github.com/mguymon/model-citizen/blob/9078ab4121897a21e598dd4f0efa6996b46e4dea/core/src/main/java/com/tobedevoured/modelcitizen/policy/SkipReferenceFieldPolicy.java#L65-L85 |
2,372 | mguymon/model-citizen | spring/src/main/java/com/tobedevoured/modelcitizen/spring/ModelFactoryBean.java | ModelFactoryBean.createNewInstance | @Override
protected Object createNewInstance(Erector erector) throws BlueprintTemplateException {
SpringBlueprint springBlueprint = erector.getBlueprint().getClass().getAnnotation(SpringBlueprint.class);
if ( springBlueprint != null && springBlueprint.bean() ) {
Class beanClass = springBlueprint.beanClass();
if ( beanClass.equals( NotSet.class) ) {
beanClass = erector.getTarget();
}
try {
if ( StringUtils.isNotBlank( springBlueprint.beanName() ) ) {
logger.debug( "Retrieving model from Spring [{},{}]", springBlueprint.beanName(), beanClass );
return applicationContext.getBean( springBlueprint.beanName(), beanClass );
} else {
logger.debug( "Retrieving model from Spring [{}]", beanClass );
return applicationContext.getBean( beanClass );
}
} catch( NoSuchBeanDefinitionException e ) {
// Model not directly registered with Spring, autowire it manually.
Object instance = super.createNewInstance(erector);
beanFactory.autowireBean( instance );
return instance;
}
} else {
return super.createNewInstance(erector);
}
} | java | @Override
protected Object createNewInstance(Erector erector) throws BlueprintTemplateException {
SpringBlueprint springBlueprint = erector.getBlueprint().getClass().getAnnotation(SpringBlueprint.class);
if ( springBlueprint != null && springBlueprint.bean() ) {
Class beanClass = springBlueprint.beanClass();
if ( beanClass.equals( NotSet.class) ) {
beanClass = erector.getTarget();
}
try {
if ( StringUtils.isNotBlank( springBlueprint.beanName() ) ) {
logger.debug( "Retrieving model from Spring [{},{}]", springBlueprint.beanName(), beanClass );
return applicationContext.getBean( springBlueprint.beanName(), beanClass );
} else {
logger.debug( "Retrieving model from Spring [{}]", beanClass );
return applicationContext.getBean( beanClass );
}
} catch( NoSuchBeanDefinitionException e ) {
// Model not directly registered with Spring, autowire it manually.
Object instance = super.createNewInstance(erector);
beanFactory.autowireBean( instance );
return instance;
}
} else {
return super.createNewInstance(erector);
}
} | [
"@",
"Override",
"protected",
"Object",
"createNewInstance",
"(",
"Erector",
"erector",
")",
"throws",
"BlueprintTemplateException",
"{",
"SpringBlueprint",
"springBlueprint",
"=",
"erector",
".",
"getBlueprint",
"(",
")",
".",
"getClass",
"(",
")",
".",
"getAnnotation",
"(",
"SpringBlueprint",
".",
"class",
")",
";",
"if",
"(",
"springBlueprint",
"!=",
"null",
"&&",
"springBlueprint",
".",
"bean",
"(",
")",
")",
"{",
"Class",
"beanClass",
"=",
"springBlueprint",
".",
"beanClass",
"(",
")",
";",
"if",
"(",
"beanClass",
".",
"equals",
"(",
"NotSet",
".",
"class",
")",
")",
"{",
"beanClass",
"=",
"erector",
".",
"getTarget",
"(",
")",
";",
"}",
"try",
"{",
"if",
"(",
"StringUtils",
".",
"isNotBlank",
"(",
"springBlueprint",
".",
"beanName",
"(",
")",
")",
")",
"{",
"logger",
".",
"debug",
"(",
"\"Retrieving model from Spring [{},{}]\"",
",",
"springBlueprint",
".",
"beanName",
"(",
")",
",",
"beanClass",
")",
";",
"return",
"applicationContext",
".",
"getBean",
"(",
"springBlueprint",
".",
"beanName",
"(",
")",
",",
"beanClass",
")",
";",
"}",
"else",
"{",
"logger",
".",
"debug",
"(",
"\"Retrieving model from Spring [{}]\"",
",",
"beanClass",
")",
";",
"return",
"applicationContext",
".",
"getBean",
"(",
"beanClass",
")",
";",
"}",
"}",
"catch",
"(",
"NoSuchBeanDefinitionException",
"e",
")",
"{",
"// Model not directly registered with Spring, autowire it manually.",
"Object",
"instance",
"=",
"super",
".",
"createNewInstance",
"(",
"erector",
")",
";",
"beanFactory",
".",
"autowireBean",
"(",
"instance",
")",
";",
"return",
"instance",
";",
"}",
"}",
"else",
"{",
"return",
"super",
".",
"createNewInstance",
"(",
"erector",
")",
";",
"}",
"}"
] | Create new instance of model before blueprint values are set. Autowire them from Spring Context if they have the
SpringBlueprint annotation
@param erector Erector
@return Object
@throws BlueprintTemplateException failed to apply blueprint | [
"Create",
"new",
"instance",
"of",
"model",
"before",
"blueprint",
"values",
"are",
"set",
".",
"Autowire",
"them",
"from",
"Spring",
"Context",
"if",
"they",
"have",
"the",
"SpringBlueprint",
"annotation"
] | 9078ab4121897a21e598dd4f0efa6996b46e4dea | https://github.com/mguymon/model-citizen/blob/9078ab4121897a21e598dd4f0efa6996b46e4dea/spring/src/main/java/com/tobedevoured/modelcitizen/spring/ModelFactoryBean.java#L62-L90 |
2,373 | mguymon/model-citizen | spring/src/main/java/com/tobedevoured/modelcitizen/spring/ModelFactoryBean.java | ModelFactoryBean.registerBlueprint | @Override
public void registerBlueprint(Object blueprint) throws RegisterBlueprintException {
SpringBlueprint springBlueprint = blueprint.getClass().getAnnotation(SpringBlueprint.class);
if ( springBlueprint != null && springBlueprint.autowire() ) {
logger.debug( "Autowiring blueprint {}", blueprint );
beanFactory.autowireBean( blueprint );
}
super.registerBlueprint(blueprint);
} | java | @Override
public void registerBlueprint(Object blueprint) throws RegisterBlueprintException {
SpringBlueprint springBlueprint = blueprint.getClass().getAnnotation(SpringBlueprint.class);
if ( springBlueprint != null && springBlueprint.autowire() ) {
logger.debug( "Autowiring blueprint {}", blueprint );
beanFactory.autowireBean( blueprint );
}
super.registerBlueprint(blueprint);
} | [
"@",
"Override",
"public",
"void",
"registerBlueprint",
"(",
"Object",
"blueprint",
")",
"throws",
"RegisterBlueprintException",
"{",
"SpringBlueprint",
"springBlueprint",
"=",
"blueprint",
".",
"getClass",
"(",
")",
".",
"getAnnotation",
"(",
"SpringBlueprint",
".",
"class",
")",
";",
"if",
"(",
"springBlueprint",
"!=",
"null",
"&&",
"springBlueprint",
".",
"autowire",
"(",
")",
")",
"{",
"logger",
".",
"debug",
"(",
"\"Autowiring blueprint {}\"",
",",
"blueprint",
")",
";",
"beanFactory",
".",
"autowireBean",
"(",
"blueprint",
")",
";",
"}",
"super",
".",
"registerBlueprint",
"(",
"blueprint",
")",
";",
"}"
] | Register Blueprints, autowire them from Spring Context if they have the SpringBlueprint annotation
@param blueprint Blueprint
@throws RegisterBlueprintException failed to register blueprint | [
"Register",
"Blueprints",
"autowire",
"them",
"from",
"Spring",
"Context",
"if",
"they",
"have",
"the",
"SpringBlueprint",
"annotation"
] | 9078ab4121897a21e598dd4f0efa6996b46e4dea | https://github.com/mguymon/model-citizen/blob/9078ab4121897a21e598dd4f0efa6996b46e4dea/spring/src/main/java/com/tobedevoured/modelcitizen/spring/ModelFactoryBean.java#L98-L106 |
2,374 | mguymon/model-citizen | core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java | ModelFactory.addPolicy | public void addPolicy(Policy policy) throws PolicyException {
// Add BlueprintPolicy
if (policy instanceof BlueprintPolicy) {
if (erectors.get(policy.getTarget()) == null) {
throw new PolicyException("Blueprint does not exist for BlueprintPolicy target: " + policy.getTarget());
}
List<BlueprintPolicy> policies = blueprintPolicies.get(policy.getTarget());
if (policies == null) {
policies = new ArrayList<BlueprintPolicy>();
}
policies.add((BlueprintPolicy) policy);
logger.info("Setting BlueprintPolicy {} for {}", policy, policy.getTarget());
blueprintPolicies.put(policy.getTarget(), policies);
// Add FieldPolicy
} else if (policy instanceof FieldPolicy) {
// XXX: force FieldPolicy's to be mapped to a blueprint? Limits their scope, but enables validation
if (erectors.get(policy.getTarget()) == null) {
throw new PolicyException("Blueprint does not exist for FieldPolicy target: " + policy.getTarget());
}
List<FieldPolicy> policies = fieldPolicies.get(policy.getTarget());
if (policies == null) {
policies = new ArrayList<FieldPolicy>();
}
policies.add((FieldPolicy) policy);
logger.info("Setting FieldPolicy {} for {}", policy, policy.getTarget());
fieldPolicies.put(policy.getTarget(), policies);
}
} | java | public void addPolicy(Policy policy) throws PolicyException {
// Add BlueprintPolicy
if (policy instanceof BlueprintPolicy) {
if (erectors.get(policy.getTarget()) == null) {
throw new PolicyException("Blueprint does not exist for BlueprintPolicy target: " + policy.getTarget());
}
List<BlueprintPolicy> policies = blueprintPolicies.get(policy.getTarget());
if (policies == null) {
policies = new ArrayList<BlueprintPolicy>();
}
policies.add((BlueprintPolicy) policy);
logger.info("Setting BlueprintPolicy {} for {}", policy, policy.getTarget());
blueprintPolicies.put(policy.getTarget(), policies);
// Add FieldPolicy
} else if (policy instanceof FieldPolicy) {
// XXX: force FieldPolicy's to be mapped to a blueprint? Limits their scope, but enables validation
if (erectors.get(policy.getTarget()) == null) {
throw new PolicyException("Blueprint does not exist for FieldPolicy target: " + policy.getTarget());
}
List<FieldPolicy> policies = fieldPolicies.get(policy.getTarget());
if (policies == null) {
policies = new ArrayList<FieldPolicy>();
}
policies.add((FieldPolicy) policy);
logger.info("Setting FieldPolicy {} for {}", policy, policy.getTarget());
fieldPolicies.put(policy.getTarget(), policies);
}
} | [
"public",
"void",
"addPolicy",
"(",
"Policy",
"policy",
")",
"throws",
"PolicyException",
"{",
"// Add BlueprintPolicy",
"if",
"(",
"policy",
"instanceof",
"BlueprintPolicy",
")",
"{",
"if",
"(",
"erectors",
".",
"get",
"(",
"policy",
".",
"getTarget",
"(",
")",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"PolicyException",
"(",
"\"Blueprint does not exist for BlueprintPolicy target: \"",
"+",
"policy",
".",
"getTarget",
"(",
")",
")",
";",
"}",
"List",
"<",
"BlueprintPolicy",
">",
"policies",
"=",
"blueprintPolicies",
".",
"get",
"(",
"policy",
".",
"getTarget",
"(",
")",
")",
";",
"if",
"(",
"policies",
"==",
"null",
")",
"{",
"policies",
"=",
"new",
"ArrayList",
"<",
"BlueprintPolicy",
">",
"(",
")",
";",
"}",
"policies",
".",
"add",
"(",
"(",
"BlueprintPolicy",
")",
"policy",
")",
";",
"logger",
".",
"info",
"(",
"\"Setting BlueprintPolicy {} for {}\"",
",",
"policy",
",",
"policy",
".",
"getTarget",
"(",
")",
")",
";",
"blueprintPolicies",
".",
"put",
"(",
"policy",
".",
"getTarget",
"(",
")",
",",
"policies",
")",
";",
"// Add FieldPolicy",
"}",
"else",
"if",
"(",
"policy",
"instanceof",
"FieldPolicy",
")",
"{",
"// XXX: force FieldPolicy's to be mapped to a blueprint? Limits their scope, but enables validation",
"if",
"(",
"erectors",
".",
"get",
"(",
"policy",
".",
"getTarget",
"(",
")",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"PolicyException",
"(",
"\"Blueprint does not exist for FieldPolicy target: \"",
"+",
"policy",
".",
"getTarget",
"(",
")",
")",
";",
"}",
"List",
"<",
"FieldPolicy",
">",
"policies",
"=",
"fieldPolicies",
".",
"get",
"(",
"policy",
".",
"getTarget",
"(",
")",
")",
";",
"if",
"(",
"policies",
"==",
"null",
")",
"{",
"policies",
"=",
"new",
"ArrayList",
"<",
"FieldPolicy",
">",
"(",
")",
";",
"}",
"policies",
".",
"add",
"(",
"(",
"FieldPolicy",
")",
"policy",
")",
";",
"logger",
".",
"info",
"(",
"\"Setting FieldPolicy {} for {}\"",
",",
"policy",
",",
"policy",
".",
"getTarget",
"(",
")",
")",
";",
"fieldPolicies",
".",
"put",
"(",
"policy",
".",
"getTarget",
"(",
")",
",",
"policies",
")",
";",
"}",
"}"
] | Add Policy to ModelFactory
@param policy FieldPolicy or BlueprintPolicy
@throws PolicyException failed to apply policy | [
"Add",
"Policy",
"to",
"ModelFactory"
] | 9078ab4121897a21e598dd4f0efa6996b46e4dea | https://github.com/mguymon/model-citizen/blob/9078ab4121897a21e598dd4f0efa6996b46e4dea/core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java#L83-L121 |
2,375 | mguymon/model-citizen | core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java | ModelFactory.setRegisterBlueprintsByPackage | public void setRegisterBlueprintsByPackage(String _package) throws RegisterBlueprintException {
Set<Class<?>> annotated = null;
try {
annotated = new ClassesInPackageScanner().findAnnotatedClasses(_package, Blueprint.class);
} catch (IOException e) {
throw new RegisterBlueprintException(e);
}
logger.info("Scanned {} and found {}", _package, annotated);
this.setRegisterBlueprints(annotated);
} | java | public void setRegisterBlueprintsByPackage(String _package) throws RegisterBlueprintException {
Set<Class<?>> annotated = null;
try {
annotated = new ClassesInPackageScanner().findAnnotatedClasses(_package, Blueprint.class);
} catch (IOException e) {
throw new RegisterBlueprintException(e);
}
logger.info("Scanned {} and found {}", _package, annotated);
this.setRegisterBlueprints(annotated);
} | [
"public",
"void",
"setRegisterBlueprintsByPackage",
"(",
"String",
"_package",
")",
"throws",
"RegisterBlueprintException",
"{",
"Set",
"<",
"Class",
"<",
"?",
">",
">",
"annotated",
"=",
"null",
";",
"try",
"{",
"annotated",
"=",
"new",
"ClassesInPackageScanner",
"(",
")",
".",
"findAnnotatedClasses",
"(",
"_package",
",",
"Blueprint",
".",
"class",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"RegisterBlueprintException",
"(",
"e",
")",
";",
"}",
"logger",
".",
"info",
"(",
"\"Scanned {} and found {}\"",
",",
"_package",
",",
"annotated",
")",
";",
"this",
".",
"setRegisterBlueprints",
"(",
"annotated",
")",
";",
"}"
] | Register all Blueprint in package.
@param _package String package to scan
@throws RegisterBlueprintException failed to register blueprint | [
"Register",
"all",
"Blueprint",
"in",
"package",
"."
] | 9078ab4121897a21e598dd4f0efa6996b46e4dea | https://github.com/mguymon/model-citizen/blob/9078ab4121897a21e598dd4f0efa6996b46e4dea/core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java#L129-L141 |
2,376 | mguymon/model-citizen | core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java | ModelFactory.setRegisterBlueprints | public void setRegisterBlueprints(Collection blueprints) throws RegisterBlueprintException {
for (Object blueprint : blueprints) {
if (blueprint instanceof Class) {
registerBlueprint((Class) blueprint);
} else if (blueprint instanceof String) {
registerBlueprint((String) blueprint);
} else if (blueprint instanceof String) {
registerBlueprint(blueprint);
} else {
throw new RegisterBlueprintException("Only supports List comprised of Class<Blueprint>, Blueprint, or String className");
}
}
} | java | public void setRegisterBlueprints(Collection blueprints) throws RegisterBlueprintException {
for (Object blueprint : blueprints) {
if (blueprint instanceof Class) {
registerBlueprint((Class) blueprint);
} else if (blueprint instanceof String) {
registerBlueprint((String) blueprint);
} else if (blueprint instanceof String) {
registerBlueprint(blueprint);
} else {
throw new RegisterBlueprintException("Only supports List comprised of Class<Blueprint>, Blueprint, or String className");
}
}
} | [
"public",
"void",
"setRegisterBlueprints",
"(",
"Collection",
"blueprints",
")",
"throws",
"RegisterBlueprintException",
"{",
"for",
"(",
"Object",
"blueprint",
":",
"blueprints",
")",
"{",
"if",
"(",
"blueprint",
"instanceof",
"Class",
")",
"{",
"registerBlueprint",
"(",
"(",
"Class",
")",
"blueprint",
")",
";",
"}",
"else",
"if",
"(",
"blueprint",
"instanceof",
"String",
")",
"{",
"registerBlueprint",
"(",
"(",
"String",
")",
"blueprint",
")",
";",
"}",
"else",
"if",
"(",
"blueprint",
"instanceof",
"String",
")",
"{",
"registerBlueprint",
"(",
"blueprint",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RegisterBlueprintException",
"(",
"\"Only supports List comprised of Class<Blueprint>, Blueprint, or String className\"",
")",
";",
"}",
"}",
"}"
] | Register a List of Blueprint, Class, or String
class names of Blueprint
@param blueprints List
@throws RegisterBlueprintException failed to register blueprint | [
"Register",
"a",
"List",
"of",
"Blueprint",
"Class",
"or",
"String",
"class",
"names",
"of",
"Blueprint"
] | 9078ab4121897a21e598dd4f0efa6996b46e4dea | https://github.com/mguymon/model-citizen/blob/9078ab4121897a21e598dd4f0efa6996b46e4dea/core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java#L150-L162 |
2,377 | mguymon/model-citizen | core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java | ModelFactory.registerBlueprint | public void registerBlueprint(String className) throws RegisterBlueprintException {
try {
registerBlueprint(Class.forName(className));
} catch (ClassNotFoundException e) {
throw new RegisterBlueprintException(e);
}
} | java | public void registerBlueprint(String className) throws RegisterBlueprintException {
try {
registerBlueprint(Class.forName(className));
} catch (ClassNotFoundException e) {
throw new RegisterBlueprintException(e);
}
} | [
"public",
"void",
"registerBlueprint",
"(",
"String",
"className",
")",
"throws",
"RegisterBlueprintException",
"{",
"try",
"{",
"registerBlueprint",
"(",
"Class",
".",
"forName",
"(",
"className",
")",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"e",
")",
"{",
"throw",
"new",
"RegisterBlueprintException",
"(",
"e",
")",
";",
"}",
"}"
] | Register a Blueprint from a String Class name
@param className String | [
"Register",
"a",
"Blueprint",
"from",
"a",
"String",
"Class",
"name"
] | 9078ab4121897a21e598dd4f0efa6996b46e4dea | https://github.com/mguymon/model-citizen/blob/9078ab4121897a21e598dd4f0efa6996b46e4dea/core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java#L169-L175 |
2,378 | mguymon/model-citizen | core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java | ModelFactory.registerBlueprint | public void registerBlueprint(Class clazz) throws RegisterBlueprintException {
Object blueprint = null;
try {
blueprint = clazz.newInstance();
} catch (InstantiationException e) {
throw new RegisterBlueprintException(e);
} catch (IllegalAccessException e) {
throw new RegisterBlueprintException(e);
}
registerBlueprint(blueprint);
} | java | public void registerBlueprint(Class clazz) throws RegisterBlueprintException {
Object blueprint = null;
try {
blueprint = clazz.newInstance();
} catch (InstantiationException e) {
throw new RegisterBlueprintException(e);
} catch (IllegalAccessException e) {
throw new RegisterBlueprintException(e);
}
registerBlueprint(blueprint);
} | [
"public",
"void",
"registerBlueprint",
"(",
"Class",
"clazz",
")",
"throws",
"RegisterBlueprintException",
"{",
"Object",
"blueprint",
"=",
"null",
";",
"try",
"{",
"blueprint",
"=",
"clazz",
".",
"newInstance",
"(",
")",
";",
"}",
"catch",
"(",
"InstantiationException",
"e",
")",
"{",
"throw",
"new",
"RegisterBlueprintException",
"(",
"e",
")",
";",
"}",
"catch",
"(",
"IllegalAccessException",
"e",
")",
"{",
"throw",
"new",
"RegisterBlueprintException",
"(",
"e",
")",
";",
"}",
"registerBlueprint",
"(",
"blueprint",
")",
";",
"}"
] | Register a Blueprint from Class
@param clazz Blueprint class
@throws RegisterBlueprintException failed to register blueprint | [
"Register",
"a",
"Blueprint",
"from",
"Class"
] | 9078ab4121897a21e598dd4f0efa6996b46e4dea | https://github.com/mguymon/model-citizen/blob/9078ab4121897a21e598dd4f0efa6996b46e4dea/core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java#L183-L195 |
2,379 | mguymon/model-citizen | core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java | ModelFactory.createModel | @SuppressWarnings({"rawtypes", "unchecked"})
public <T> T createModel(T referenceModel, boolean withPolicies) throws CreateModelException {
Erector erector = erectors.get(referenceModel.getClass());
if (erector == null) {
throw new CreateModelException("Unregistered class: " + referenceModel.getClass());
}
return createModel(erector, referenceModel, withPolicies);
} | java | @SuppressWarnings({"rawtypes", "unchecked"})
public <T> T createModel(T referenceModel, boolean withPolicies) throws CreateModelException {
Erector erector = erectors.get(referenceModel.getClass());
if (erector == null) {
throw new CreateModelException("Unregistered class: " + referenceModel.getClass());
}
return createModel(erector, referenceModel, withPolicies);
} | [
"@",
"SuppressWarnings",
"(",
"{",
"\"rawtypes\"",
",",
"\"unchecked\"",
"}",
")",
"public",
"<",
"T",
">",
"T",
"createModel",
"(",
"T",
"referenceModel",
",",
"boolean",
"withPolicies",
")",
"throws",
"CreateModelException",
"{",
"Erector",
"erector",
"=",
"erectors",
".",
"get",
"(",
"referenceModel",
".",
"getClass",
"(",
")",
")",
";",
"if",
"(",
"erector",
"==",
"null",
")",
"{",
"throw",
"new",
"CreateModelException",
"(",
"\"Unregistered class: \"",
"+",
"referenceModel",
".",
"getClass",
"(",
")",
")",
";",
"}",
"return",
"createModel",
"(",
"erector",
",",
"referenceModel",
",",
"withPolicies",
")",
";",
"}"
] | Create a Model for a registered Blueprint. Values set in the
model will not be overridden by defaults in the Blueprint.
@param <T> model Class
@param referenceModel Object
@param withPolicies boolean if Policies should be applied to the create
@return Model
@throws CreateModelException model failed to create | [
"Create",
"a",
"Model",
"for",
"a",
"registered",
"Blueprint",
".",
"Values",
"set",
"in",
"the",
"model",
"will",
"not",
"be",
"overridden",
"by",
"defaults",
"in",
"the",
"Blueprint",
"."
] | 9078ab4121897a21e598dd4f0efa6996b46e4dea | https://github.com/mguymon/model-citizen/blob/9078ab4121897a21e598dd4f0efa6996b46e4dea/core/src/main/java/com/tobedevoured/modelcitizen/ModelFactory.java#L497-L506 |
2,380 | aaronhe42/ThreeTen-Backport-Gson-Adapter | src/main/java/org/aaronhe/threetengson/ThreeTenGsonAdapter.java | ThreeTenGsonAdapter.registerAll | public static GsonBuilder registerAll(GsonBuilder gsonBuilder) {
registerInstant(gsonBuilder);
registerLocalDate(gsonBuilder);
registerLocalDateTime(gsonBuilder);
registerLocalTime(gsonBuilder);
registerLocalDate(gsonBuilder);
registerOffsetDateTime(gsonBuilder);
registerOffsetTime(gsonBuilder);
registerZonedDateTime(gsonBuilder);
return gsonBuilder;
} | java | public static GsonBuilder registerAll(GsonBuilder gsonBuilder) {
registerInstant(gsonBuilder);
registerLocalDate(gsonBuilder);
registerLocalDateTime(gsonBuilder);
registerLocalTime(gsonBuilder);
registerLocalDate(gsonBuilder);
registerOffsetDateTime(gsonBuilder);
registerOffsetTime(gsonBuilder);
registerZonedDateTime(gsonBuilder);
return gsonBuilder;
} | [
"public",
"static",
"GsonBuilder",
"registerAll",
"(",
"GsonBuilder",
"gsonBuilder",
")",
"{",
"registerInstant",
"(",
"gsonBuilder",
")",
";",
"registerLocalDate",
"(",
"gsonBuilder",
")",
";",
"registerLocalDateTime",
"(",
"gsonBuilder",
")",
";",
"registerLocalTime",
"(",
"gsonBuilder",
")",
";",
"registerLocalDate",
"(",
"gsonBuilder",
")",
";",
"registerOffsetDateTime",
"(",
"gsonBuilder",
")",
";",
"registerOffsetTime",
"(",
"gsonBuilder",
")",
";",
"registerZonedDateTime",
"(",
"gsonBuilder",
")",
";",
"return",
"gsonBuilder",
";",
"}"
] | A convenient method to register all supported ThreeTen BP types.
@param gsonBuilder a GsonBuilder to be registered.
@return a GsonBuilder knows how to de/serialize all supported ThreeTen BP types. | [
"A",
"convenient",
"method",
"to",
"register",
"all",
"supported",
"ThreeTen",
"BP",
"types",
"."
] | 15f9567fb037ceef8244f0f4f18ab04a1391d020 | https://github.com/aaronhe42/ThreeTen-Backport-Gson-Adapter/blob/15f9567fb037ceef8244f0f4f18ab04a1391d020/src/main/java/org/aaronhe/threetengson/ThreeTenGsonAdapter.java#L58-L69 |
2,381 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/RemoterProcessor.java | RemoterProcessor.getSupportedAnnotations | private Set<Class<? extends Annotation>> getSupportedAnnotations() {
Set<Class<? extends Annotation>> annotations = new LinkedHashSet<>();
annotations.add(Remoter.class);
return annotations;
} | java | private Set<Class<? extends Annotation>> getSupportedAnnotations() {
Set<Class<? extends Annotation>> annotations = new LinkedHashSet<>();
annotations.add(Remoter.class);
return annotations;
} | [
"private",
"Set",
"<",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
">",
"getSupportedAnnotations",
"(",
")",
"{",
"Set",
"<",
"Class",
"<",
"?",
"extends",
"Annotation",
">",
">",
"annotations",
"=",
"new",
"LinkedHashSet",
"<>",
"(",
")",
";",
"annotations",
".",
"add",
"(",
"Remoter",
".",
"class",
")",
";",
"return",
"annotations",
";",
"}"
] | Only one annotation is supported at class level - @{@link Remoter} | [
"Only",
"one",
"annotation",
"is",
"supported",
"at",
"class",
"level",
"-"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/RemoterProcessor.java#L62-L66 |
2,382 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/BindingManager.java | BindingManager.generateProxy | public void generateProxy(Element element) {
try {
getClassBuilder(element)
.buildProxyClass()
.build()
.writeTo(filer);
} catch (Exception ex) {
messager.printMessage(Diagnostic.Kind.WARNING, "Error while generating Proxy " + ex.getMessage());
}
} | java | public void generateProxy(Element element) {
try {
getClassBuilder(element)
.buildProxyClass()
.build()
.writeTo(filer);
} catch (Exception ex) {
messager.printMessage(Diagnostic.Kind.WARNING, "Error while generating Proxy " + ex.getMessage());
}
} | [
"public",
"void",
"generateProxy",
"(",
"Element",
"element",
")",
"{",
"try",
"{",
"getClassBuilder",
"(",
"element",
")",
".",
"buildProxyClass",
"(",
")",
".",
"build",
"(",
")",
".",
"writeTo",
"(",
"filer",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"messager",
".",
"printMessage",
"(",
"Diagnostic",
".",
"Kind",
".",
"WARNING",
",",
"\"Error while generating Proxy \"",
"+",
"ex",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Generates the Proxy for the given @{@link Remoter} interface element | [
"Generates",
"the",
"Proxy",
"for",
"the",
"given"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/BindingManager.java#L66-L75 |
2,383 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/BindingManager.java | BindingManager.generateStub | public void generateStub(Element element) {
try {
getClassBuilder(element)
.buildStubClass()
.build()
.writeTo(filer);
} catch (Exception ex) {
messager.printMessage(Diagnostic.Kind.WARNING, "Error while generating Stub " + ex.getMessage());
}
} | java | public void generateStub(Element element) {
try {
getClassBuilder(element)
.buildStubClass()
.build()
.writeTo(filer);
} catch (Exception ex) {
messager.printMessage(Diagnostic.Kind.WARNING, "Error while generating Stub " + ex.getMessage());
}
} | [
"public",
"void",
"generateStub",
"(",
"Element",
"element",
")",
"{",
"try",
"{",
"getClassBuilder",
"(",
"element",
")",
".",
"buildStubClass",
"(",
")",
".",
"build",
"(",
")",
".",
"writeTo",
"(",
"filer",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"messager",
".",
"printMessage",
"(",
"Diagnostic",
".",
"Kind",
".",
"WARNING",
",",
"\"Error while generating Stub \"",
"+",
"ex",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Generates the Stub for the given @{@link Remoter} interface element | [
"Generates",
"the",
"Stub",
"for",
"the",
"given"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/BindingManager.java#L80-L89 |
2,384 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/BindingManager.java | BindingManager.getGenericType | public TypeElement getGenericType(TypeMirror typeMirror) {
return typeMirror.accept(new SimpleTypeVisitor6<TypeElement, Void>() {
@Override
public TypeElement visitDeclared(DeclaredType declaredType, Void v) {
TypeElement genericTypeElement = null;
TypeElement typeElement = (TypeElement) declaredType.asElement();
if (parcelClass != null && typeUtils.isAssignable(typeElement.asType(), listTypeMirror)) {
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (!typeArguments.isEmpty()) {
for (TypeMirror genericType : typeArguments) {
if (genericType instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) genericType;
TypeMirror extendsType = wildcardType.getExtendsBound();
if (extendsType != null) {
typeElement = elementUtils.getTypeElement(extendsType.toString());
if (typeElement.getAnnotation(parcelClass) != null) {
genericTypeElement = typeElement;
break;
}
}
} else {
typeElement = elementUtils.getTypeElement(genericType.toString());
if (typeElement.getAnnotation(parcelClass) != null) {
genericTypeElement = typeElement;
break;
}
}
}
}
}
return genericTypeElement;
}
}, null);
} | java | public TypeElement getGenericType(TypeMirror typeMirror) {
return typeMirror.accept(new SimpleTypeVisitor6<TypeElement, Void>() {
@Override
public TypeElement visitDeclared(DeclaredType declaredType, Void v) {
TypeElement genericTypeElement = null;
TypeElement typeElement = (TypeElement) declaredType.asElement();
if (parcelClass != null && typeUtils.isAssignable(typeElement.asType(), listTypeMirror)) {
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (!typeArguments.isEmpty()) {
for (TypeMirror genericType : typeArguments) {
if (genericType instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) genericType;
TypeMirror extendsType = wildcardType.getExtendsBound();
if (extendsType != null) {
typeElement = elementUtils.getTypeElement(extendsType.toString());
if (typeElement.getAnnotation(parcelClass) != null) {
genericTypeElement = typeElement;
break;
}
}
} else {
typeElement = elementUtils.getTypeElement(genericType.toString());
if (typeElement.getAnnotation(parcelClass) != null) {
genericTypeElement = typeElement;
break;
}
}
}
}
}
return genericTypeElement;
}
}, null);
} | [
"public",
"TypeElement",
"getGenericType",
"(",
"TypeMirror",
"typeMirror",
")",
"{",
"return",
"typeMirror",
".",
"accept",
"(",
"new",
"SimpleTypeVisitor6",
"<",
"TypeElement",
",",
"Void",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"TypeElement",
"visitDeclared",
"(",
"DeclaredType",
"declaredType",
",",
"Void",
"v",
")",
"{",
"TypeElement",
"genericTypeElement",
"=",
"null",
";",
"TypeElement",
"typeElement",
"=",
"(",
"TypeElement",
")",
"declaredType",
".",
"asElement",
"(",
")",
";",
"if",
"(",
"parcelClass",
"!=",
"null",
"&&",
"typeUtils",
".",
"isAssignable",
"(",
"typeElement",
".",
"asType",
"(",
")",
",",
"listTypeMirror",
")",
")",
"{",
"List",
"<",
"?",
"extends",
"TypeMirror",
">",
"typeArguments",
"=",
"declaredType",
".",
"getTypeArguments",
"(",
")",
";",
"if",
"(",
"!",
"typeArguments",
".",
"isEmpty",
"(",
")",
")",
"{",
"for",
"(",
"TypeMirror",
"genericType",
":",
"typeArguments",
")",
"{",
"if",
"(",
"genericType",
"instanceof",
"WildcardType",
")",
"{",
"WildcardType",
"wildcardType",
"=",
"(",
"WildcardType",
")",
"genericType",
";",
"TypeMirror",
"extendsType",
"=",
"wildcardType",
".",
"getExtendsBound",
"(",
")",
";",
"if",
"(",
"extendsType",
"!=",
"null",
")",
"{",
"typeElement",
"=",
"elementUtils",
".",
"getTypeElement",
"(",
"extendsType",
".",
"toString",
"(",
")",
")",
";",
"if",
"(",
"typeElement",
".",
"getAnnotation",
"(",
"parcelClass",
")",
"!=",
"null",
")",
"{",
"genericTypeElement",
"=",
"typeElement",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"typeElement",
"=",
"elementUtils",
".",
"getTypeElement",
"(",
"genericType",
".",
"toString",
"(",
")",
")",
";",
"if",
"(",
"typeElement",
".",
"getAnnotation",
"(",
"parcelClass",
")",
"!=",
"null",
")",
"{",
"genericTypeElement",
"=",
"typeElement",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"genericTypeElement",
";",
"}",
"}",
",",
"null",
")",
";",
"}"
] | Return the generic type if any | [
"Return",
"the",
"generic",
"type",
"if",
"any"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/BindingManager.java#L217-L251 |
2,385 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/ParamBuilder.java | ParamBuilder.writeParamsToStub | public void writeParamsToStub(VariableElement param, ParamType paramType, String paramName, MethodSpec.Builder methodBuilder) {
methodBuilder.addStatement("$T " + paramName, param.asType());
} | java | public void writeParamsToStub(VariableElement param, ParamType paramType, String paramName, MethodSpec.Builder methodBuilder) {
methodBuilder.addStatement("$T " + paramName, param.asType());
} | [
"public",
"void",
"writeParamsToStub",
"(",
"VariableElement",
"param",
",",
"ParamType",
"paramType",
",",
"String",
"paramName",
",",
"MethodSpec",
".",
"Builder",
"methodBuilder",
")",
"{",
"methodBuilder",
".",
"addStatement",
"(",
"\"$T \"",
"+",
"paramName",
",",
"param",
".",
"asType",
"(",
")",
")",
";",
"}"
] | Called to generate code to write params for stub | [
"Called",
"to",
"generate",
"code",
"to",
"write",
"params",
"for",
"stub"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/ParamBuilder.java#L41-L43 |
2,386 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/ParamBuilder.java | ParamBuilder.writeOutParamsToStub | public void writeOutParamsToStub(VariableElement param, ParamType paramType, String paramName, MethodSpec.Builder methodBuilder) {
if (paramType != ParamType.IN) {
methodBuilder.addStatement("int " + paramName + "_length = data.readInt()");
methodBuilder.beginControlFlow("if (" + paramName + "_length < 0 )");
methodBuilder.addStatement(paramName + " = null");
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement(paramName + " = new " + (((ArrayType) param.asType()).getComponentType().toString())
+ "[" + paramName + "_length]");
methodBuilder.endControlFlow();
}
} | java | public void writeOutParamsToStub(VariableElement param, ParamType paramType, String paramName, MethodSpec.Builder methodBuilder) {
if (paramType != ParamType.IN) {
methodBuilder.addStatement("int " + paramName + "_length = data.readInt()");
methodBuilder.beginControlFlow("if (" + paramName + "_length < 0 )");
methodBuilder.addStatement(paramName + " = null");
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement(paramName + " = new " + (((ArrayType) param.asType()).getComponentType().toString())
+ "[" + paramName + "_length]");
methodBuilder.endControlFlow();
}
} | [
"public",
"void",
"writeOutParamsToStub",
"(",
"VariableElement",
"param",
",",
"ParamType",
"paramType",
",",
"String",
"paramName",
",",
"MethodSpec",
".",
"Builder",
"methodBuilder",
")",
"{",
"if",
"(",
"paramType",
"!=",
"ParamType",
".",
"IN",
")",
"{",
"methodBuilder",
".",
"addStatement",
"(",
"\"int \"",
"+",
"paramName",
"+",
"\"_length = data.readInt()\"",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"if (\"",
"+",
"paramName",
"+",
"\"_length < 0 )\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"paramName",
"+",
"\" = null\"",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"else\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"paramName",
"+",
"\" = new \"",
"+",
"(",
"(",
"(",
"ArrayType",
")",
"param",
".",
"asType",
"(",
")",
")",
".",
"getComponentType",
"(",
")",
".",
"toString",
"(",
")",
")",
"+",
"\"[\"",
"+",
"paramName",
"+",
"\"_length]\"",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"}",
"}"
] | Called to generate code to write @{@link remoter.annotations.ParamOut} params for stub | [
"Called",
"to",
"generate",
"code",
"to",
"write"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/ParamBuilder.java#L48-L59 |
2,387 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/ParamBuilder.java | ParamBuilder.writeArrayOutParamsToProxy | protected void writeArrayOutParamsToProxy(VariableElement param, MethodSpec.Builder methodBuilder) {
methodBuilder.beginControlFlow("if (" + param.getSimpleName() + " == null)");
methodBuilder.addStatement("data.writeInt(-1)");
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement("data.writeInt(" + param.getSimpleName() + ".length)");
methodBuilder.endControlFlow();
} | java | protected void writeArrayOutParamsToProxy(VariableElement param, MethodSpec.Builder methodBuilder) {
methodBuilder.beginControlFlow("if (" + param.getSimpleName() + " == null)");
methodBuilder.addStatement("data.writeInt(-1)");
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement("data.writeInt(" + param.getSimpleName() + ".length)");
methodBuilder.endControlFlow();
} | [
"protected",
"void",
"writeArrayOutParamsToProxy",
"(",
"VariableElement",
"param",
",",
"MethodSpec",
".",
"Builder",
"methodBuilder",
")",
"{",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"if (\"",
"+",
"param",
".",
"getSimpleName",
"(",
")",
"+",
"\" == null)\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"data.writeInt(-1)\"",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"else\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"data.writeInt(\"",
"+",
"param",
".",
"getSimpleName",
"(",
")",
"+",
"\".length)\"",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"}"
] | Called to generate code that writes the out params for array type | [
"Called",
"to",
"generate",
"code",
"that",
"writes",
"the",
"out",
"params",
"for",
"array",
"type"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/ParamBuilder.java#L76-L83 |
2,388 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java | MethodBuilder.addStubMethods | public void addStubMethods(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("onTransact")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.returns(boolean.class)
.addException(ClassName.get("android.os", "RemoteException"))
.addParameter(int.class, "code")
.addParameter(ClassName.get("android.os", "Parcel"), "data")
.addParameter(ClassName.get("android.os", "Parcel"), "reply")
.addParameter(int.class, "flags");
methodBuilder.beginControlFlow("try");
methodBuilder.beginControlFlow("switch (code)");
methodBuilder.beginControlFlow("case INTERFACE_TRANSACTION:");
methodBuilder.addStatement("reply.writeString(DESCRIPTOR)");
methodBuilder.addStatement("return true");
methodBuilder.endControlFlow();
processRemoterElements(classBuilder, new ElementVisitor() {
@Override
public void visitElement(TypeSpec.Builder classBuilder, Element member, int methodIndex, MethodSpec.Builder methodBuilder) {
addStubMethods(classBuilder, member, methodIndex, methodBuilder);
}
}, methodBuilder);
methodBuilder.beginControlFlow("case TRANSACTION__getStubID:");
methodBuilder.addStatement("data.enforceInterface(DESCRIPTOR)");
methodBuilder.addStatement("reply.writeNoException()");
methodBuilder.addStatement("reply.writeInt(serviceImpl.hashCode())");
methodBuilder.addStatement("return true");
methodBuilder.endControlFlow();
//end switch
methodBuilder.endControlFlow();
//end of try
methodBuilder.endControlFlow();
//catch rethrow
methodBuilder.beginControlFlow("catch ($T re)", Throwable.class);
methodBuilder.beginControlFlow("if ((flags & FLAG_ONEWAY) == 0)");
methodBuilder.addStatement("reply.setDataPosition(0)");
methodBuilder.addStatement("reply.writeInt(REMOTER_EXCEPTION_CODE)");
methodBuilder.addStatement("reply.writeString(re.getMessage())");
methodBuilder.addStatement("reply.writeSerializable(re)");
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement("$T.w(serviceImpl.getClass().getName(), \"Binder call failed.\", re)", ClassName.get("android.util", "Log"));
methodBuilder.endControlFlow();
methodBuilder.addStatement("return true");
methodBuilder.endControlFlow();
methodBuilder.addStatement("return super.onTransact(code, data, reply, flags)");
classBuilder.addMethod(methodBuilder.build());
addCommonExtras(classBuilder);
addStubExtras(classBuilder);
} | java | public void addStubMethods(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("onTransact")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.returns(boolean.class)
.addException(ClassName.get("android.os", "RemoteException"))
.addParameter(int.class, "code")
.addParameter(ClassName.get("android.os", "Parcel"), "data")
.addParameter(ClassName.get("android.os", "Parcel"), "reply")
.addParameter(int.class, "flags");
methodBuilder.beginControlFlow("try");
methodBuilder.beginControlFlow("switch (code)");
methodBuilder.beginControlFlow("case INTERFACE_TRANSACTION:");
methodBuilder.addStatement("reply.writeString(DESCRIPTOR)");
methodBuilder.addStatement("return true");
methodBuilder.endControlFlow();
processRemoterElements(classBuilder, new ElementVisitor() {
@Override
public void visitElement(TypeSpec.Builder classBuilder, Element member, int methodIndex, MethodSpec.Builder methodBuilder) {
addStubMethods(classBuilder, member, methodIndex, methodBuilder);
}
}, methodBuilder);
methodBuilder.beginControlFlow("case TRANSACTION__getStubID:");
methodBuilder.addStatement("data.enforceInterface(DESCRIPTOR)");
methodBuilder.addStatement("reply.writeNoException()");
methodBuilder.addStatement("reply.writeInt(serviceImpl.hashCode())");
methodBuilder.addStatement("return true");
methodBuilder.endControlFlow();
//end switch
methodBuilder.endControlFlow();
//end of try
methodBuilder.endControlFlow();
//catch rethrow
methodBuilder.beginControlFlow("catch ($T re)", Throwable.class);
methodBuilder.beginControlFlow("if ((flags & FLAG_ONEWAY) == 0)");
methodBuilder.addStatement("reply.setDataPosition(0)");
methodBuilder.addStatement("reply.writeInt(REMOTER_EXCEPTION_CODE)");
methodBuilder.addStatement("reply.writeString(re.getMessage())");
methodBuilder.addStatement("reply.writeSerializable(re)");
methodBuilder.endControlFlow();
methodBuilder.beginControlFlow("else");
methodBuilder.addStatement("$T.w(serviceImpl.getClass().getName(), \"Binder call failed.\", re)", ClassName.get("android.util", "Log"));
methodBuilder.endControlFlow();
methodBuilder.addStatement("return true");
methodBuilder.endControlFlow();
methodBuilder.addStatement("return super.onTransact(code, data, reply, flags)");
classBuilder.addMethod(methodBuilder.build());
addCommonExtras(classBuilder);
addStubExtras(classBuilder);
} | [
"public",
"void",
"addStubMethods",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
")",
"{",
"MethodSpec",
".",
"Builder",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"onTransact\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PUBLIC",
")",
".",
"addAnnotation",
"(",
"Override",
".",
"class",
")",
".",
"returns",
"(",
"boolean",
".",
"class",
")",
".",
"addException",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"RemoteException\"",
")",
")",
".",
"addParameter",
"(",
"int",
".",
"class",
",",
"\"code\"",
")",
".",
"addParameter",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"Parcel\"",
")",
",",
"\"data\"",
")",
".",
"addParameter",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"Parcel\"",
")",
",",
"\"reply\"",
")",
".",
"addParameter",
"(",
"int",
".",
"class",
",",
"\"flags\"",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"try\"",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"switch (code)\"",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"case INTERFACE_TRANSACTION:\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"reply.writeString(DESCRIPTOR)\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"return true\"",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"processRemoterElements",
"(",
"classBuilder",
",",
"new",
"ElementVisitor",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"visitElement",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
",",
"Element",
"member",
",",
"int",
"methodIndex",
",",
"MethodSpec",
".",
"Builder",
"methodBuilder",
")",
"{",
"addStubMethods",
"(",
"classBuilder",
",",
"member",
",",
"methodIndex",
",",
"methodBuilder",
")",
";",
"}",
"}",
",",
"methodBuilder",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"case TRANSACTION__getStubID:\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"data.enforceInterface(DESCRIPTOR)\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"reply.writeNoException()\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"reply.writeInt(serviceImpl.hashCode())\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"return true\"",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"//end switch\r",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"//end of try\r",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"//catch rethrow\r",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"catch ($T re)\"",
",",
"Throwable",
".",
"class",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"if ((flags & FLAG_ONEWAY) == 0)\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"reply.setDataPosition(0)\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"reply.writeInt(REMOTER_EXCEPTION_CODE)\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"reply.writeString(re.getMessage())\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"reply.writeSerializable(re)\"",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"else\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"$T.w(serviceImpl.getClass().getName(), \\\"Binder call failed.\\\", re)\"",
",",
"ClassName",
".",
"get",
"(",
"\"android.util\"",
",",
"\"Log\"",
")",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"return true\"",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"return super.onTransact(code, data, reply, flags)\"",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"addCommonExtras",
"(",
"classBuilder",
")",
";",
"addStubExtras",
"(",
"classBuilder",
")",
";",
"}"
] | Build the stub methods | [
"Build",
"the",
"stub",
"methods"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java#L196-L255 |
2,389 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java | MethodBuilder.addProxyExtras | private void addProxyExtras(TypeSpec.Builder classBuilder) {
addRemoterProxyMethods(classBuilder);
addProxyDeathMethod(classBuilder, "linkToDeath", "Register a {@link android.os.IBinder.DeathRecipient} to know of binder connection lose\n");
addProxyDeathMethod(classBuilder, "unlinkToDeath", "UnRegisters a {@link android.os.IBinder.DeathRecipient}\n");
addProxyRemoteAlive(classBuilder);
addProxyCheckException(classBuilder);
addGetId(classBuilder);
addHashCode(classBuilder);
addEquals(classBuilder);
addProxyDestroyMethods(classBuilder);
} | java | private void addProxyExtras(TypeSpec.Builder classBuilder) {
addRemoterProxyMethods(classBuilder);
addProxyDeathMethod(classBuilder, "linkToDeath", "Register a {@link android.os.IBinder.DeathRecipient} to know of binder connection lose\n");
addProxyDeathMethod(classBuilder, "unlinkToDeath", "UnRegisters a {@link android.os.IBinder.DeathRecipient}\n");
addProxyRemoteAlive(classBuilder);
addProxyCheckException(classBuilder);
addGetId(classBuilder);
addHashCode(classBuilder);
addEquals(classBuilder);
addProxyDestroyMethods(classBuilder);
} | [
"private",
"void",
"addProxyExtras",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
")",
"{",
"addRemoterProxyMethods",
"(",
"classBuilder",
")",
";",
"addProxyDeathMethod",
"(",
"classBuilder",
",",
"\"linkToDeath\"",
",",
"\"Register a {@link android.os.IBinder.DeathRecipient} to know of binder connection lose\\n\"",
")",
";",
"addProxyDeathMethod",
"(",
"classBuilder",
",",
"\"unlinkToDeath\"",
",",
"\"UnRegisters a {@link android.os.IBinder.DeathRecipient}\\n\"",
")",
";",
"addProxyRemoteAlive",
"(",
"classBuilder",
")",
";",
"addProxyCheckException",
"(",
"classBuilder",
")",
";",
"addGetId",
"(",
"classBuilder",
")",
";",
"addHashCode",
"(",
"classBuilder",
")",
";",
"addEquals",
"(",
"classBuilder",
")",
";",
"addProxyDestroyMethods",
"(",
"classBuilder",
")",
";",
"}"
] | Add other extra methods | [
"Add",
"other",
"extra",
"methods"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java#L438-L448 |
2,390 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java | MethodBuilder.addProxyDestroyMethods | private void addProxyDestroyMethods(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("destroyStub")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.addParameter(Object.class, "object")
.returns(TypeName.VOID)
.beginControlFlow("if(object != null)")
.beginControlFlow("synchronized (stubMap)")
.addStatement("IBinder binder = stubMap.get(object)")
.beginControlFlow("if (binder != null)")
.addStatement("(($T)binder).destroyStub()", RemoterStub.class)
.addStatement("stubMap.remove(object)")
.endControlFlow()
.endControlFlow()
.endControlFlow();
classBuilder.addMethod(methodBuilder.build());
methodBuilder = MethodSpec.methodBuilder("__checkProxy")
.addModifiers(Modifier.PRIVATE)
.returns(TypeName.VOID)
.addStatement("if(mRemote == null) throw new RuntimeException(\"Trying to use a destroyed Proxy\")");
classBuilder.addMethod(methodBuilder.build());
methodBuilder = MethodSpec.methodBuilder("destroyProxy")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.returns(TypeName.VOID)
.addStatement("this.mRemote = null")
.addStatement("unRegisterProxyListener(null)")
.beginControlFlow("synchronized (stubMap)")
.beginControlFlow("for(IBinder binder:stubMap.values())")
.addStatement("((RemoterStub)binder).destroyStub()")
.endControlFlow()
.addStatement("stubMap.clear()")
.endControlFlow();
classBuilder.addMethod(methodBuilder.build());
} | java | private void addProxyDestroyMethods(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("destroyStub")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.addParameter(Object.class, "object")
.returns(TypeName.VOID)
.beginControlFlow("if(object != null)")
.beginControlFlow("synchronized (stubMap)")
.addStatement("IBinder binder = stubMap.get(object)")
.beginControlFlow("if (binder != null)")
.addStatement("(($T)binder).destroyStub()", RemoterStub.class)
.addStatement("stubMap.remove(object)")
.endControlFlow()
.endControlFlow()
.endControlFlow();
classBuilder.addMethod(methodBuilder.build());
methodBuilder = MethodSpec.methodBuilder("__checkProxy")
.addModifiers(Modifier.PRIVATE)
.returns(TypeName.VOID)
.addStatement("if(mRemote == null) throw new RuntimeException(\"Trying to use a destroyed Proxy\")");
classBuilder.addMethod(methodBuilder.build());
methodBuilder = MethodSpec.methodBuilder("destroyProxy")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.returns(TypeName.VOID)
.addStatement("this.mRemote = null")
.addStatement("unRegisterProxyListener(null)")
.beginControlFlow("synchronized (stubMap)")
.beginControlFlow("for(IBinder binder:stubMap.values())")
.addStatement("((RemoterStub)binder).destroyStub()")
.endControlFlow()
.addStatement("stubMap.clear()")
.endControlFlow();
classBuilder.addMethod(methodBuilder.build());
} | [
"private",
"void",
"addProxyDestroyMethods",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
")",
"{",
"MethodSpec",
".",
"Builder",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"destroyStub\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PUBLIC",
")",
".",
"addAnnotation",
"(",
"Override",
".",
"class",
")",
".",
"addParameter",
"(",
"Object",
".",
"class",
",",
"\"object\"",
")",
".",
"returns",
"(",
"TypeName",
".",
"VOID",
")",
".",
"beginControlFlow",
"(",
"\"if(object != null)\"",
")",
".",
"beginControlFlow",
"(",
"\"synchronized (stubMap)\"",
")",
".",
"addStatement",
"(",
"\"IBinder binder = stubMap.get(object)\"",
")",
".",
"beginControlFlow",
"(",
"\"if (binder != null)\"",
")",
".",
"addStatement",
"(",
"\"(($T)binder).destroyStub()\"",
",",
"RemoterStub",
".",
"class",
")",
".",
"addStatement",
"(",
"\"stubMap.remove(object)\"",
")",
".",
"endControlFlow",
"(",
")",
".",
"endControlFlow",
"(",
")",
".",
"endControlFlow",
"(",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"__checkProxy\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PRIVATE",
")",
".",
"returns",
"(",
"TypeName",
".",
"VOID",
")",
".",
"addStatement",
"(",
"\"if(mRemote == null) throw new RuntimeException(\\\"Trying to use a destroyed Proxy\\\")\"",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"destroyProxy\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PUBLIC",
")",
".",
"addAnnotation",
"(",
"Override",
".",
"class",
")",
".",
"returns",
"(",
"TypeName",
".",
"VOID",
")",
".",
"addStatement",
"(",
"\"this.mRemote = null\"",
")",
".",
"addStatement",
"(",
"\"unRegisterProxyListener(null)\"",
")",
".",
"beginControlFlow",
"(",
"\"synchronized (stubMap)\"",
")",
".",
"beginControlFlow",
"(",
"\"for(IBinder binder:stubMap.values())\"",
")",
".",
"addStatement",
"(",
"\"((RemoterStub)binder).destroyStub()\"",
")",
".",
"endControlFlow",
"(",
")",
".",
"addStatement",
"(",
"\"stubMap.clear()\"",
")",
".",
"endControlFlow",
"(",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"}"
] | Add proxy method for destroystub | [
"Add",
"proxy",
"method",
"for",
"destroystub"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java#L454-L495 |
2,391 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java | MethodBuilder.addProxyDeathMethod | private void addProxyDeathMethod(TypeSpec.Builder classBuilder, String deathMethod, String doc) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(deathMethod)
.addModifiers(Modifier.PUBLIC)
.returns(TypeName.VOID)
.addParameter(ClassName.get("android.os", "IBinder.DeathRecipient"), "deathRecipient")
.beginControlFlow("try")
.addStatement("mRemote." + deathMethod + "(deathRecipient, 0)")
.endControlFlow()
.beginControlFlow("catch ($T ignored)", Exception.class)
.endControlFlow()
.addJavadoc(doc);
classBuilder.addMethod(methodBuilder.build());
} | java | private void addProxyDeathMethod(TypeSpec.Builder classBuilder, String deathMethod, String doc) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(deathMethod)
.addModifiers(Modifier.PUBLIC)
.returns(TypeName.VOID)
.addParameter(ClassName.get("android.os", "IBinder.DeathRecipient"), "deathRecipient")
.beginControlFlow("try")
.addStatement("mRemote." + deathMethod + "(deathRecipient, 0)")
.endControlFlow()
.beginControlFlow("catch ($T ignored)", Exception.class)
.endControlFlow()
.addJavadoc(doc);
classBuilder.addMethod(methodBuilder.build());
} | [
"private",
"void",
"addProxyDeathMethod",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
",",
"String",
"deathMethod",
",",
"String",
"doc",
")",
"{",
"MethodSpec",
".",
"Builder",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"deathMethod",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PUBLIC",
")",
".",
"returns",
"(",
"TypeName",
".",
"VOID",
")",
".",
"addParameter",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"IBinder.DeathRecipient\"",
")",
",",
"\"deathRecipient\"",
")",
".",
"beginControlFlow",
"(",
"\"try\"",
")",
".",
"addStatement",
"(",
"\"mRemote.\"",
"+",
"deathMethod",
"+",
"\"(deathRecipient, 0)\"",
")",
".",
"endControlFlow",
"(",
")",
".",
"beginControlFlow",
"(",
"\"catch ($T ignored)\"",
",",
"Exception",
".",
"class",
")",
".",
"endControlFlow",
"(",
")",
".",
"addJavadoc",
"(",
"doc",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"}"
] | Add proxy method that exposes the linkToDeath | [
"Add",
"proxy",
"method",
"that",
"exposes",
"the",
"linkToDeath"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java#L528-L540 |
2,392 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java | MethodBuilder.addProxyRemoteAlive | private void addProxyRemoteAlive(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("isRemoteAlive")
.addModifiers(Modifier.PUBLIC)
.returns(boolean.class)
.addStatement("boolean alive = false")
.beginControlFlow("try")
.addStatement("alive = mRemote.isBinderAlive()")
.endControlFlow()
.beginControlFlow("catch ($T ignored)", Exception.class)
.endControlFlow()
.addStatement("return alive")
.addJavadoc("Checks whether the remote process is alive\n");
classBuilder.addMethod(methodBuilder.build());
} | java | private void addProxyRemoteAlive(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("isRemoteAlive")
.addModifiers(Modifier.PUBLIC)
.returns(boolean.class)
.addStatement("boolean alive = false")
.beginControlFlow("try")
.addStatement("alive = mRemote.isBinderAlive()")
.endControlFlow()
.beginControlFlow("catch ($T ignored)", Exception.class)
.endControlFlow()
.addStatement("return alive")
.addJavadoc("Checks whether the remote process is alive\n");
classBuilder.addMethod(methodBuilder.build());
} | [
"private",
"void",
"addProxyRemoteAlive",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
")",
"{",
"MethodSpec",
".",
"Builder",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"isRemoteAlive\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PUBLIC",
")",
".",
"returns",
"(",
"boolean",
".",
"class",
")",
".",
"addStatement",
"(",
"\"boolean alive = false\"",
")",
".",
"beginControlFlow",
"(",
"\"try\"",
")",
".",
"addStatement",
"(",
"\"alive = mRemote.isBinderAlive()\"",
")",
".",
"endControlFlow",
"(",
")",
".",
"beginControlFlow",
"(",
"\"catch ($T ignored)\"",
",",
"Exception",
".",
"class",
")",
".",
"endControlFlow",
"(",
")",
".",
"addStatement",
"(",
"\"return alive\"",
")",
".",
"addJavadoc",
"(",
"\"Checks whether the remote process is alive\\n\"",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"}"
] | Add proxy method that exposes whether remote is alive | [
"Add",
"proxy",
"method",
"that",
"exposes",
"whether",
"remote",
"is",
"alive"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java#L545-L558 |
2,393 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java | MethodBuilder.addProxyCheckException | private void addProxyCheckException(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("checkException")
.addModifiers(Modifier.PRIVATE)
.returns(Throwable.class)
.addParameter(ClassName.get("android.os", "Parcel"), "reply")
.addStatement("int code = reply.readInt()")
.addStatement("Throwable exception = null")
.beginControlFlow("if (code != 0)")
.addStatement("String msg = reply.readString()")
.beginControlFlow("if (code == REMOTER_EXCEPTION_CODE)")
.addStatement("exception = (Throwable) reply.readSerializable()")
.endControlFlow()
.beginControlFlow("else")
.addStatement("exception = new RuntimeException(msg)")
.endControlFlow()
.endControlFlow()
.addStatement("return exception");
classBuilder.addMethod(methodBuilder.build());
} | java | private void addProxyCheckException(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("checkException")
.addModifiers(Modifier.PRIVATE)
.returns(Throwable.class)
.addParameter(ClassName.get("android.os", "Parcel"), "reply")
.addStatement("int code = reply.readInt()")
.addStatement("Throwable exception = null")
.beginControlFlow("if (code != 0)")
.addStatement("String msg = reply.readString()")
.beginControlFlow("if (code == REMOTER_EXCEPTION_CODE)")
.addStatement("exception = (Throwable) reply.readSerializable()")
.endControlFlow()
.beginControlFlow("else")
.addStatement("exception = new RuntimeException(msg)")
.endControlFlow()
.endControlFlow()
.addStatement("return exception");
classBuilder.addMethod(methodBuilder.build());
} | [
"private",
"void",
"addProxyCheckException",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
")",
"{",
"MethodSpec",
".",
"Builder",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"checkException\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PRIVATE",
")",
".",
"returns",
"(",
"Throwable",
".",
"class",
")",
".",
"addParameter",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"Parcel\"",
")",
",",
"\"reply\"",
")",
".",
"addStatement",
"(",
"\"int code = reply.readInt()\"",
")",
".",
"addStatement",
"(",
"\"Throwable exception = null\"",
")",
".",
"beginControlFlow",
"(",
"\"if (code != 0)\"",
")",
".",
"addStatement",
"(",
"\"String msg = reply.readString()\"",
")",
".",
"beginControlFlow",
"(",
"\"if (code == REMOTER_EXCEPTION_CODE)\"",
")",
".",
"addStatement",
"(",
"\"exception = (Throwable) reply.readSerializable()\"",
")",
".",
"endControlFlow",
"(",
")",
".",
"beginControlFlow",
"(",
"\"else\"",
")",
".",
"addStatement",
"(",
"\"exception = new RuntimeException(msg)\"",
")",
".",
"endControlFlow",
"(",
")",
".",
"endControlFlow",
"(",
")",
".",
"addStatement",
"(",
"\"return exception\"",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"}"
] | Add proxy method to check for exception | [
"Add",
"proxy",
"method",
"to",
"check",
"for",
"exception"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java#L563-L581 |
2,394 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java | MethodBuilder.addHashCode | private void addHashCode(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("hashCode")
.addModifiers(Modifier.PUBLIC)
.returns(int.class)
.addAnnotation(Override.class)
.addStatement("return _binderID");
classBuilder.addMethod(methodBuilder.build());
} | java | private void addHashCode(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("hashCode")
.addModifiers(Modifier.PUBLIC)
.returns(int.class)
.addAnnotation(Override.class)
.addStatement("return _binderID");
classBuilder.addMethod(methodBuilder.build());
} | [
"private",
"void",
"addHashCode",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
")",
"{",
"MethodSpec",
".",
"Builder",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"hashCode\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PUBLIC",
")",
".",
"returns",
"(",
"int",
".",
"class",
")",
".",
"addAnnotation",
"(",
"Override",
".",
"class",
")",
".",
"addStatement",
"(",
"\"return _binderID\"",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"}"
] | Add proxy method to set hashcode to uniqueu id of binder | [
"Add",
"proxy",
"method",
"to",
"set",
"hashcode",
"to",
"uniqueu",
"id",
"of",
"binder"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java#L587-L594 |
2,395 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java | MethodBuilder.addEquals | private void addEquals(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("equals")
.addModifiers(Modifier.PUBLIC)
.addParameter(ClassName.get(Object.class), "obj")
.returns(boolean.class)
.addAnnotation(Override.class)
.addStatement("return (obj instanceof " + getRemoterInterfaceClassName() + ClassBuilder.PROXY_SUFFIX + ") && obj.hashCode() == hashCode()");
classBuilder.addMethod(methodBuilder.build());
} | java | private void addEquals(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("equals")
.addModifiers(Modifier.PUBLIC)
.addParameter(ClassName.get(Object.class), "obj")
.returns(boolean.class)
.addAnnotation(Override.class)
.addStatement("return (obj instanceof " + getRemoterInterfaceClassName() + ClassBuilder.PROXY_SUFFIX + ") && obj.hashCode() == hashCode()");
classBuilder.addMethod(methodBuilder.build());
} | [
"private",
"void",
"addEquals",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
")",
"{",
"MethodSpec",
".",
"Builder",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"equals\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PUBLIC",
")",
".",
"addParameter",
"(",
"ClassName",
".",
"get",
"(",
"Object",
".",
"class",
")",
",",
"\"obj\"",
")",
".",
"returns",
"(",
"boolean",
".",
"class",
")",
".",
"addAnnotation",
"(",
"Override",
".",
"class",
")",
".",
"addStatement",
"(",
"\"return (obj instanceof \"",
"+",
"getRemoterInterfaceClassName",
"(",
")",
"+",
"ClassBuilder",
".",
"PROXY_SUFFIX",
"+",
"\") && obj.hashCode() == hashCode()\"",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"}"
] | Add proxy method for equals | [
"Add",
"proxy",
"method",
"for",
"equals"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java#L599-L607 |
2,396 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java | MethodBuilder.addGetId | private void addGetId(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("__getStubID")
.addModifiers(Modifier.PRIVATE)
.returns(int.class)
.addStatement("android.os.Parcel data = android.os.Parcel.obtain()")
.addStatement("android.os.Parcel reply = android.os.Parcel.obtain()")
.addStatement("int result");
methodBuilder.beginControlFlow("try");
//write the descriptor
methodBuilder.addStatement("data.writeInterfaceToken(DESCRIPTOR)");
methodBuilder.addStatement("mRemote.transact(TRANSACTION__getStubID, data, reply, 0)");
//read exception if any
methodBuilder.addStatement("Throwable exception = checkException(reply)");
methodBuilder.beginControlFlow("if(exception != null)");
methodBuilder.addStatement("throw ($T)exception", RuntimeException.class);
methodBuilder.endControlFlow();
methodBuilder.addStatement("result = reply.readInt()");
//end of try
methodBuilder.endControlFlow();
//catch rethrow
methodBuilder.beginControlFlow("catch ($T re)", ClassName.get("android.os", "RemoteException"));
methodBuilder.addStatement("throw new $T(re)", RuntimeException.class);
methodBuilder.endControlFlow();
//finally block
methodBuilder.beginControlFlow("finally");
methodBuilder.addStatement("reply.recycle()");
methodBuilder.addStatement("data.recycle()");
methodBuilder.endControlFlow();
methodBuilder.addStatement("return result");
classBuilder.addMethod(methodBuilder.build());
} | java | private void addGetId(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("__getStubID")
.addModifiers(Modifier.PRIVATE)
.returns(int.class)
.addStatement("android.os.Parcel data = android.os.Parcel.obtain()")
.addStatement("android.os.Parcel reply = android.os.Parcel.obtain()")
.addStatement("int result");
methodBuilder.beginControlFlow("try");
//write the descriptor
methodBuilder.addStatement("data.writeInterfaceToken(DESCRIPTOR)");
methodBuilder.addStatement("mRemote.transact(TRANSACTION__getStubID, data, reply, 0)");
//read exception if any
methodBuilder.addStatement("Throwable exception = checkException(reply)");
methodBuilder.beginControlFlow("if(exception != null)");
methodBuilder.addStatement("throw ($T)exception", RuntimeException.class);
methodBuilder.endControlFlow();
methodBuilder.addStatement("result = reply.readInt()");
//end of try
methodBuilder.endControlFlow();
//catch rethrow
methodBuilder.beginControlFlow("catch ($T re)", ClassName.get("android.os", "RemoteException"));
methodBuilder.addStatement("throw new $T(re)", RuntimeException.class);
methodBuilder.endControlFlow();
//finally block
methodBuilder.beginControlFlow("finally");
methodBuilder.addStatement("reply.recycle()");
methodBuilder.addStatement("data.recycle()");
methodBuilder.endControlFlow();
methodBuilder.addStatement("return result");
classBuilder.addMethod(methodBuilder.build());
} | [
"private",
"void",
"addGetId",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
")",
"{",
"MethodSpec",
".",
"Builder",
"methodBuilder",
"=",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"__getStubID\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PRIVATE",
")",
".",
"returns",
"(",
"int",
".",
"class",
")",
".",
"addStatement",
"(",
"\"android.os.Parcel data = android.os.Parcel.obtain()\"",
")",
".",
"addStatement",
"(",
"\"android.os.Parcel reply = android.os.Parcel.obtain()\"",
")",
".",
"addStatement",
"(",
"\"int result\"",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"try\"",
")",
";",
"//write the descriptor\r",
"methodBuilder",
".",
"addStatement",
"(",
"\"data.writeInterfaceToken(DESCRIPTOR)\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"mRemote.transact(TRANSACTION__getStubID, data, reply, 0)\"",
")",
";",
"//read exception if any\r",
"methodBuilder",
".",
"addStatement",
"(",
"\"Throwable exception = checkException(reply)\"",
")",
";",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"if(exception != null)\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"throw ($T)exception\"",
",",
"RuntimeException",
".",
"class",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"result = reply.readInt()\"",
")",
";",
"//end of try\r",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"//catch rethrow\r",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"catch ($T re)\"",
",",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"RemoteException\"",
")",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"throw new $T(re)\"",
",",
"RuntimeException",
".",
"class",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"//finally block\r",
"methodBuilder",
".",
"beginControlFlow",
"(",
"\"finally\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"reply.recycle()\"",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"data.recycle()\"",
")",
";",
"methodBuilder",
".",
"endControlFlow",
"(",
")",
";",
"methodBuilder",
".",
"addStatement",
"(",
"\"return result\"",
")",
";",
"classBuilder",
".",
"addMethod",
"(",
"methodBuilder",
".",
"build",
"(",
")",
")",
";",
"}"
] | Add proxy method to get unique id | [
"Add",
"proxy",
"method",
"to",
"get",
"unique",
"id"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/MethodBuilder.java#L613-L654 |
2,397 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/ClassBuilder.java | ClassBuilder.getBinderWrapper | private TypeSpec getBinderWrapper() {
TypeSpec.Builder staticBinderWrapperClassBuilder = TypeSpec
.classBuilder("BinderWrapper")
.addModifiers(Modifier.PRIVATE)
.addModifiers(Modifier.STATIC)
.addField(ClassName.get("android.os", "IBinder"), "binder", Modifier.PRIVATE)
.addMethod(MethodSpec.constructorBuilder()
.addParameter(ClassName.get("android.os", "IBinder"), "binder")
.addStatement("this.binder = binder")
.build())
.addMethod(MethodSpec.methodBuilder("asBinder")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.returns(ClassName.get("android.os", "IBinder"))
.addStatement("return binder")
.build())
.addSuperinterface(ClassName.get("android.os", "IInterface"));
return staticBinderWrapperClassBuilder.build();
} | java | private TypeSpec getBinderWrapper() {
TypeSpec.Builder staticBinderWrapperClassBuilder = TypeSpec
.classBuilder("BinderWrapper")
.addModifiers(Modifier.PRIVATE)
.addModifiers(Modifier.STATIC)
.addField(ClassName.get("android.os", "IBinder"), "binder", Modifier.PRIVATE)
.addMethod(MethodSpec.constructorBuilder()
.addParameter(ClassName.get("android.os", "IBinder"), "binder")
.addStatement("this.binder = binder")
.build())
.addMethod(MethodSpec.methodBuilder("asBinder")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.returns(ClassName.get("android.os", "IBinder"))
.addStatement("return binder")
.build())
.addSuperinterface(ClassName.get("android.os", "IInterface"));
return staticBinderWrapperClassBuilder.build();
} | [
"private",
"TypeSpec",
"getBinderWrapper",
"(",
")",
"{",
"TypeSpec",
".",
"Builder",
"staticBinderWrapperClassBuilder",
"=",
"TypeSpec",
".",
"classBuilder",
"(",
"\"BinderWrapper\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PRIVATE",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"STATIC",
")",
".",
"addField",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"IBinder\"",
")",
",",
"\"binder\"",
",",
"Modifier",
".",
"PRIVATE",
")",
".",
"addMethod",
"(",
"MethodSpec",
".",
"constructorBuilder",
"(",
")",
".",
"addParameter",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"IBinder\"",
")",
",",
"\"binder\"",
")",
".",
"addStatement",
"(",
"\"this.binder = binder\"",
")",
".",
"build",
"(",
")",
")",
".",
"addMethod",
"(",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"asBinder\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PUBLIC",
")",
".",
"addAnnotation",
"(",
"Override",
".",
"class",
")",
".",
"returns",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"IBinder\"",
")",
")",
".",
"addStatement",
"(",
"\"return binder\"",
")",
".",
"build",
"(",
")",
")",
".",
"addSuperinterface",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"IInterface\"",
")",
")",
";",
"return",
"staticBinderWrapperClassBuilder",
".",
"build",
"(",
")",
";",
"}"
] | Add the static inner Binder wrapper | [
"Add",
"the",
"static",
"inner",
"Binder",
"wrapper"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/ClassBuilder.java#L114-L133 |
2,398 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/ClassBuilder.java | ClassBuilder.getDeathRecipientWrapper | private TypeSpec getDeathRecipientWrapper() {
TypeSpec.Builder staticBinderWrapperClassBuilder = TypeSpec
.classBuilder("DeathRecipient")
.addModifiers(Modifier.PRIVATE)
.addModifiers(Modifier.STATIC)
.addField(RemoterProxyListener.class, "proxyListener", Modifier.PRIVATE)
.addMethod(MethodSpec.constructorBuilder()
.addParameter(RemoterProxyListener.class, "proxyListener")
.addStatement("this.proxyListener = proxyListener")
.build())
.addMethod(MethodSpec.methodBuilder("binderDied")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.beginControlFlow("if (proxyListener != null)")
.addStatement("proxyListener.onProxyDead()")
.endControlFlow()
.build())
.addSuperinterface(ClassName.get("android.os", "IBinder.DeathRecipient"));
return staticBinderWrapperClassBuilder.build();
} | java | private TypeSpec getDeathRecipientWrapper() {
TypeSpec.Builder staticBinderWrapperClassBuilder = TypeSpec
.classBuilder("DeathRecipient")
.addModifiers(Modifier.PRIVATE)
.addModifiers(Modifier.STATIC)
.addField(RemoterProxyListener.class, "proxyListener", Modifier.PRIVATE)
.addMethod(MethodSpec.constructorBuilder()
.addParameter(RemoterProxyListener.class, "proxyListener")
.addStatement("this.proxyListener = proxyListener")
.build())
.addMethod(MethodSpec.methodBuilder("binderDied")
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class)
.beginControlFlow("if (proxyListener != null)")
.addStatement("proxyListener.onProxyDead()")
.endControlFlow()
.build())
.addSuperinterface(ClassName.get("android.os", "IBinder.DeathRecipient"));
return staticBinderWrapperClassBuilder.build();
} | [
"private",
"TypeSpec",
"getDeathRecipientWrapper",
"(",
")",
"{",
"TypeSpec",
".",
"Builder",
"staticBinderWrapperClassBuilder",
"=",
"TypeSpec",
".",
"classBuilder",
"(",
"\"DeathRecipient\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PRIVATE",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"STATIC",
")",
".",
"addField",
"(",
"RemoterProxyListener",
".",
"class",
",",
"\"proxyListener\"",
",",
"Modifier",
".",
"PRIVATE",
")",
".",
"addMethod",
"(",
"MethodSpec",
".",
"constructorBuilder",
"(",
")",
".",
"addParameter",
"(",
"RemoterProxyListener",
".",
"class",
",",
"\"proxyListener\"",
")",
".",
"addStatement",
"(",
"\"this.proxyListener = proxyListener\"",
")",
".",
"build",
"(",
")",
")",
".",
"addMethod",
"(",
"MethodSpec",
".",
"methodBuilder",
"(",
"\"binderDied\"",
")",
".",
"addModifiers",
"(",
"Modifier",
".",
"PUBLIC",
")",
".",
"addAnnotation",
"(",
"Override",
".",
"class",
")",
".",
"beginControlFlow",
"(",
"\"if (proxyListener != null)\"",
")",
".",
"addStatement",
"(",
"\"proxyListener.onProxyDead()\"",
")",
".",
"endControlFlow",
"(",
")",
".",
"build",
"(",
")",
")",
".",
"addSuperinterface",
"(",
"ClassName",
".",
"get",
"(",
"\"android.os\"",
",",
"\"IBinder.DeathRecipient\"",
")",
")",
";",
"return",
"staticBinderWrapperClassBuilder",
".",
"build",
"(",
")",
";",
"}"
] | Add the static inner DeathRecipient wrapper | [
"Add",
"the",
"static",
"inner",
"DeathRecipient",
"wrapper"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/ClassBuilder.java#L138-L158 |
2,399 | josesamuel/remoter | remoter/src/main/java/remoter/compiler/builder/RemoteBuilder.java | RemoteBuilder.processRemoterElements | protected void processRemoterElements(TypeSpec.Builder classBuilder, ElementVisitor elementVisitor, MethodSpec.Builder methodBuilder) {
processRemoterElements(classBuilder, getRemoterInterfaceElement(), 0, elementVisitor, methodBuilder);
} | java | protected void processRemoterElements(TypeSpec.Builder classBuilder, ElementVisitor elementVisitor, MethodSpec.Builder methodBuilder) {
processRemoterElements(classBuilder, getRemoterInterfaceElement(), 0, elementVisitor, methodBuilder);
} | [
"protected",
"void",
"processRemoterElements",
"(",
"TypeSpec",
".",
"Builder",
"classBuilder",
",",
"ElementVisitor",
"elementVisitor",
",",
"MethodSpec",
".",
"Builder",
"methodBuilder",
")",
"{",
"processRemoterElements",
"(",
"classBuilder",
",",
"getRemoterInterfaceElement",
"(",
")",
",",
"0",
",",
"elementVisitor",
",",
"methodBuilder",
")",
";",
"}"
] | Finds that elements that needs to be processed | [
"Finds",
"that",
"elements",
"that",
"needs",
"to",
"be",
"processed"
] | 007401868c319740d40134ebc07c3406988f9a86 | https://github.com/josesamuel/remoter/blob/007401868c319740d40134ebc07c3406988f9a86/remoter/src/main/java/remoter/compiler/builder/RemoteBuilder.java#L101-L103 |
Subsets and Splits