You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello again and welcome to the third post in the Android Development Tidbits series. We’re glad so many of you have found the series interesting so far, and thank you for expressing your support through comments and emails to us! For anyone that’s here for the first time, we (the Android team) have been sharing tidbits we learn throughout the week with each other internally for quite some time. Recently, we began sharing our tidbits with the rest of the development community on the blog. You can find our two earlier posts in the series here and here. Perhaps one of these weeks we’ll share some of our earliest tidbits for a few laughs! Anywho, without further ado, here are this week’s tidbits.
If you’re using QRCodeWriter by ZXing to generate qr codes, it’s rather slow to generate large image sizes. Instead, you can pass a size of 0x0 and it will then return a BitMatrix of the minimum possible size (each block is 1 pixel). Then you can write that matrix into a BitmapDrawable and set it as the background on some view. Make sure you call setFilterBitmap(false) on the drawable first, though, so it doesn’t blur when scaling.
I used Bitmap.Config.ARGB_4444 because I needed the background of the QR code to be transparent. If you just want black and white, you could use Bitmap.Config.RGB_565. And if you want to be safe, you can change the creation of the QR code to BitMatrix matrix = new QRCodeWriter().encode("content here", BarcodeFormat.QR_CODE, 10, 10); just in case the lib stops accepting oxo in the future, as I don’t believe a QR code will ever be smaller than 10×10.
41
-
42
36
由于我需要二维码的背景是透明的,所以我使用了 Bitmap.Config.ARGB_4444。如果你想让二维码只有黑白两种颜色,可以用 Bitmap.Config.RGB_565。如果你怕乱改会有什么麻烦,你可以把二维码的创建方法改为:BitMatrix matrix = new QRCodeWriter().encode("content here", BarcodeFormat.QR_CODE, 10, 10)。但有一点一定要注意,库可能在未来被更新为不接受 0 x 0 参数,毕竟二维码最小也不可能比 10 x 10 还小吧。
43
37
44
38
– Tidbit contributor, James Sun
45
39
46
40
##Tidbit Two
47
41
48
-
Next time you go to use “adb shell” type “adb hell” instead. Trust me.
49
42
50
43
键入 adb hell 和 adb shell 的结果是一样的
51
44
52
45
– Tidbit contributor, Tyler Romeo
53
46
54
47
##Tidbit Three
55
48
56
-
TextUtils.concat() will give you a CharSequence concatenating the input CharSequences, retaining their spans.
“Leaf” views get first dibs on touch events, but “root” views get first dibs on intercept touch events, so if you need to use a touch event that a child view is using, use the intercept event. And if that child view is calling setRequestDisallowInterceptTouchEvent and you don’t want it to do that, just override it and don’t do anything.
When doing bulk operations you can use SqliteDatabase beginTransaction() and endTransaction() methods, but make sure to call setTransactionSuccessful() or else the changes will be rolled back on endTransaction().
If you’re doing tests, you should probably be wary of using static methods! Why? Well among other reasons, methods provided by the Android framework won’t work in tests, and since they’re static methods you can’t mock them out.
0 commit comments