读《Android电视机(机顶盒)初次开发的一些经验分享》后的笔记
原文: http://blog.csdn.net/tanghongchang123/article/details/52982818
一、基本命令:
1、adb connect [ip]
2、 adb disconnect [ip]
3、adb uninstall [package]
4、.adb shell input text ****:用来输入文字的,在调试程序的时候,很多情况下要键入文字,手机输入方便,电视上,用遥控器按键盘非常麻烦的,可以用这个命令。
二、 焦点控制
1、控制控件是否可获得焦点
android:focusable="true/false" 当这个属性置为true时,表示当前控件可以获得焦点,否则相反。也可以在程序中通过代码来设置:
v.setFocusable(true/false);
2、控制按遥控器上下左右时下一个获得焦点的控件
- android:nextFocusUp="@+id/..."
- android:nextFocusDown="@+id/..."
- android:nextFocusLeft="@+id/..."
- android:nextFocusRight="@+id/..."
- 以下是通过程序设置
- v.setNextFocusUp(id);
- v.setNextFocusDown(id);
- v.setNextFocusRight(id);
v.setNextFocusRight(id);
3、TV分辨率的适配问题
如果适配不对,容易出现OOM(out of memory)问题。按现有TV情况,一般建议设置
drawable-sw1080dp
drawable-sw720dp
相应地,提供对应分辨率下的尺寸:
values-sw1080dp
values-sw720dp
比如同样的都是1080P,有的是32寸,有的是42寸。尺寸小,dpi高,使得图片会被压缩。在values文件里,可以使用dp、PIX,默认dpi是160。也可以考虑values采用PX验证一下。
4、阴影、倒影的程序实现(完全可以由美工实现,这里代码只作参考)
倒影原理:基本上就是将原图倒置,画在画布上,然后加上一个半透明的蒙版。
阴影效果:网上有很多讲阴影实现的教程,而这里实现的是在一个圆角矩形的图片四周加上阴影效果。实现办法是在原图四边加上矩形的阴影,然后在四个圆角的地方画扇形阴影来实现。
- /**
- * @author: sunnybaby
- * @Title: createShadowBitmap
- * @Description: 生成带阴影图片
- * @param orignalBitmap:原图
- * @param shadowMargin:阴影边宽
- * @param iconCornerRadius:原图圆角半径
- * @return :生成的带阴影图片
- */
- public static Bitmap createShadowBitmap(Bitmap orignalBitmap,
- int shadowMargin, int iconCornerRadius) {
- int w = orignalBitmap.getWidth();
- int h = orignalBitmap.getHeight();
- Bitmap shadowBitmap = Bitmap.createBitmap(w + shadowMargin * 2, h
- + shadowMargin * 2, Config.ARGB_8888);
- int width = shadowBitmap.getWidth();
- int height = shadowBitmap.getHeight();
- Canvas canvas = new Canvas(shadowBitmap);
- canvas.drawBitmap(orignalBitmap, shadowMargin, shadowMargin, null);
- Paint paint = new Paint();
- paint.setXfermode(new PorterDuffXfermode(Mode.DST_OVER));
- int radius = shadowMargin + iconCornerRadius;
- // 四个边的阴影效果,采用线性阴影,宽度等于阴影边距+圆角半径
- LinearGradient leftGradient = new LinearGradient(radius, 0, 0, 0,
- 0x7F000000, 0x00000000, TileMode.CLAMP);
- LinearGradient rightGradient = new LinearGradient(width - radius, 0,
- width, 0, 0x7F000000, 0x00000000, TileMode.CLAMP);
- LinearGradient topGradient = new LinearGradient(0, radius, 0, 0,
- 0x7F000000, 0x00000000, TileMode.CLAMP);
- LinearGradient bottomGradient = new LinearGradient(0, height - radius,
- 0, height, 0x7F000000, 0x00000000, TileMode.CLAMP);
- paint.setShader(leftGradient);
- canvas.drawRect(0, radius, radius, height - radius, paint);
- paint.setShader(rightGradient);
- canvas.drawRect(width - radius, radius, width, height - radius, paint);
- paint.setShader(topGradient);
- canvas.drawRect(radius, 0, width - radius, radius, paint);
- paint.setShader(bottomGradient);
- canvas.drawRect(radius, height - radius, width - radius, height, paint);
- // 四个角的阴影效果,采用圆形阴影,半径等于阴影边距+圆角半径
- RadialGradient topLeftCornerGradient = new RadialGradient(radius,
- radius, radius, 0x7F000000, 0x00000000, TileMode.CLAMP);
- RadialGradient topRightCornerGradient = new RadialGradient(width
- - radius, radius, radius, 0x7F000000, 0x00000000,
- TileMode.CLAMP);
- RadialGradient bottomLeftCornerGradient = new RadialGradient(radius,
- height - radius, radius, 0x7F000000, 0x00000000, TileMode.CLAMP);
- RadialGradient bottomRightCornerGradient = new RadialGradient(width
- - radius, height - radius, radius, 0x7F000000, 0x00000000,
- TileMode.CLAMP);
- // 画四个角,就是画四个圆心角为90度的扇形,drawArc函数第一个参数为圆弧所在圆的的外接矩形,第二个参数为起始角度,第三个参数为扇形顺时针滑过的角度,第四个参数如果为true时,在绘制圆弧时将圆心包括在内(用来画扇形),第五个参数为画笔
- paint.setShader(topLeftCornerGradient);
- canvas.drawArc(new RectF(0, 0, radius * 2, radius * 2), 180, 90, true,
- paint);
- paint.setShader(topRightCornerGradient);
- canvas.drawArc(new RectF(width - radius * 2, 0, width, radius * 2),
- 270, 90, true, paint);
- paint.setShader(bottomLeftCornerGradient);
- canvas.drawArc(new RectF(0, height - radius * 2, radius * 2, height),
- 90, 90, true, paint);
- paint.setShader(bottomRightCornerGradient);
- canvas.drawArc(new RectF(width - radius * 2, height - radius * 2,
- width, height), 0, 90, true, paint);
- return shadowBitmap;
- }