Skip to content

Instantly share code, notes, and snippets.

View XinyueZ's full-sized avatar
🙊
Make sense, don't touch

ChrisDEV XinyueZ

🙊
Make sense, don't touch
View GitHub Profile
@XinyueZ
XinyueZ / uninstallapp.rb
Last active September 12, 2017 15:28
Uninstall app from multi-devices
DEBUG = false
def puts(s)
print("@Tool@: ")
super
end
def help
@XinyueZ
XinyueZ / .gitignore
Last active July 14, 2016 11:36
.gitnore for Android Studio projects works for me perfect
#For this file, you might execute following codes after update your ignore file.
#git rm -r --cached .
#git add .
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
@XinyueZ
XinyueZ / bars.java
Last active September 14, 2016 11:31
Operation on Android "bar"s.
public static int getActionBarHeight(Context cxt) {
int[] abSzAttr;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
abSzAttr = new int[] { android.R.attr.actionBarSize };
} else {
abSzAttr = new int[] { R.attr.actionBarSize };
}
TypedArray a = cxt.obtainStyledAttributes(abSzAttr);
return a.getDimensionPixelSize(0, -1);
}
@XinyueZ
XinyueZ / imageview.kt
Created September 25, 2017 15:11
A binding-adapter for imageview which can load remote uri.
@BindingAdapter(value = *arrayOf("imageUris", "errorDrawableRes"), requireAll = false)
@JvmStatic
fun setImage(view: ImageView, imageUris: Array<Uri>?, @DrawableRes errorDrawableRes: Int) {
when (imageUris == null || imageUris.isEmpty()) {
true -> {
when (errorDrawableRes > 0) {
true -> view.setImageResource(errorDrawableRes)
false -> view.setImageBitmap(null)
}
return
@XinyueZ
XinyueZ / reflact_to_get_members.kt
Created December 6, 2017 13:00
For test, use this method to get member of object
inline fun <reified T : Any, reified E : Any> E.getValueOf(propertyName: String): T? =
E::class.memberProperties
.find { it.name == propertyName }
.apply {
when {
this == null -> throw IllegalArgumentException("Property <$propertyName> not found for class <${T::class}>!")
else -> isAccessible = true
}
}
?.invoke(this) as T?
@XinyueZ
XinyueZ / compare_drawable_bitmap.kt
Last active March 19, 2025 11:06
Compare drawable or bitmap content
// Usage:
// drawable1.bytesEqualTo(drawable2)
// drawable1.pixelsEqualTo(drawable2)
// bitmap1.bytesEqualTo(bitmap1)
// bitmap1.pixelsEqualTo(bitmap2)
fun <T : Drawable> T.bytesEqualTo(t: T?) = toBitmap().bytesEqualTo(t?.toBitmap(), true)
fun <T : Drawable> T.pixelsEqualTo(t: T?) = toBitmap().pixelsEqualTo(t?.toBitmap(), true)
@XinyueZ
XinyueZ / navi_view_find_menu_item.kt
Created January 11, 2018 15:01
Find menu-item's view with menu-item-id
fun NavigationView.getMenuItemView(@IdRes id: Int): NavigationMenuItemView? {
for (i in 0 until childCount) {
with(getChildAt(i)) {
if (this is NavigationMenuView) {
return (0 until childCount)
.map { getChildAt(it) }
.filter { it is NavigationMenuItemView }
.map { it as NavigationMenuItemView }
.firstOrNull { it.itemData.itemId == id }
}
@XinyueZ
XinyueZ / network_wifi_on_off.java
Last active January 24, 2018 20:46
Simulate network connection with robolectric
private boolean sendRequest() throws Exception
{
URL url = new URL("http://example.com");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection( );
int statusCode = urlConnection.getResponseCode( );
return statusCode == 200;
}
public static void setConnectivity( boolean enabled) throws Exception
{
@XinyueZ
XinyueZ / cell_strength_level.kt
Last active January 24, 2018 21:09
Get device strength-level(Cell network), support on >= M and pro M (level 0 -> 3)
// For WIFI: Easy
(context.getSystemService(WIFI_SERVICE) as WifiManager).run {
calculateSignalLevel(
connectionInfo.rssi,
netStatusView.strengthLevelCount
)
}
// Define listener
private val phoneStateEvents by lazy { LISTEN_SERVICE_STATE or LISTEN_SIGNAL_STRENGTHS or LISTEN_DATA_CONNECTION_STATE or LISTEN_DATA_ACTIVITY }
@XinyueZ
XinyueZ / activity_fragment_ext.kt
Last active February 22, 2018 20:10
Extension for create, new fragments or activities.
fun <E : Activity, T : KClass<out E>> T.showSingleTopActivity(
context: E?,
args: Bundle? = null
) =
context?.run {
with(Intent(this, [email protected])) {
if (args != null)
putExtras(args)
flags = FLAG_ACTIVITY_SINGLE_TOP or FLAG_ACTIVITY_CLEAR_TOP
ActivityCompat.startActivity(this@run, this, EMPTY)