前言
金三银四之际被离职,入职了一家TV开发的公司。入职一月,简单总结下TV开发需要注意的一些东西。
知识点
适配
试用了一下sw 即最小宽度适配(推荐此适配方法)
1280*720 对应的分辨率 mdpi
具体这方面分析的文章有很多 也很全面,不多哔哔。
常用adb
adb connect ip:port
adb shell am start packet/packet.Main
adb root (获取root权限)
adb install
adb uninstall
adb shell (进linux)
布局及处理
先上几个图片
模板有好几套,由于后台直接返的是html里的table表格 所以要用jsoup自己去转换,因为portal模板是后台动态创建的,一开始想自定义GridLayout来实现 后来发现挑起来问题挺多,加上工期紧张,暂定写死5套模板,根据td数量决定用哪套模板。
在手机端中,主要靠点击事件,大部分情况不用主观通知用户焦点所在位置,tv端则不是,主要靠焦点高亮来通知。主要有以下几种方式:
- drawable目录下创建 selector :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@mipmap/bill_focus"></item>
<item android:drawable="@mipmap/bill"></item>
</selector>
- View设置onFoucsChangeListener,然后根据状态更改背景:
private View.OnFocusChangeListener titlefocusChangeListener = new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
int id = v.getId();
for (int i = 0 ;i < ll_title.getChildCount();i++){
if(id == ll_title.getChildAt(i).getId()){
Button btn = (Button) ll_title.getChildAt(i);
if(hasFocus){
resetTitleColor();
setTab(i);
btn.setTextSize(AppConfig.HOME_TITLE_SIZE_CHECKED);
btn.setTextColor(Color.WHITE);
}else {
btn.setTextSize(AppConfig.HOME_TILE_SIZE_NORMAL);
if(i == select_index)
btn.setTextColor(getResources().getColor(R.color.title_blue));
else
btn.setTextColor(getResources().getColor(R.color.title_grey));
}
break;
}
}
}
};
接下来就是焦点的处理,同阶级布局可直接在代码中写死:
<View
android:layout_width="30dp"
android:layout_height="30dp"
android:focusable="true"
android:nextFocusDown="@null"
android:nextFocusLeft="@null"
android:nextFocusRight="@null"
android:nextFocusUp="@null" />
其余的需要自己判断 (Android系统的处理方式是就近原则,获取所有view的位置然后算距离方向最近的view)比如在我的项目中 如果移动到了最右边,再按右键则应跳转至下一个页面。或者顶部再按上应title获取焦点,再上菜单获取焦点。
具体的处理方式可以参考以下代码:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
LogService.e(TAG,"Action:" +event.getKeyCode());
if(frags[select_index] == null){
return super.dispatchKeyEvent(event);
}
if(event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN) {
if (MainUtils.getFocusToolBarIndex(toolViews) != -1) {//顶部焦点 直接
ll_title.getChildAt(select_index).requestFocus();
return true;
}
if (MainUtils.isFocusinTitle(ll_title)) {// 焦点在标题
frags[select_index].childViewrequestFocus(0);
return true;
}
}
if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP) {
if (MainUtils.getFocusToolBarIndex(toolViews) != -1) {//顶部焦点 直接
return true;
}
if (MainUtils.isFocusinTitle(ll_title)) {// 焦点在标题
btn_search.requestFocus();
return true;
}
if (frags[select_index].isOnTopSide()) {
ll_title.getChildAt(select_index).requestFocus();
return true;
}
}
if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT) {
if (btn_search.isFocused()) {
ll_title.getChildAt(select_index).requestFocus();
return true;
}
if (frags[select_index].isOnLeftSide() && select_index != 0) {
setTab(select_index - 1);
frags[select_index].childViewrequestFocus(1);
resetTitleColor();
((Button)ll_title.getChildAt(select_index)).setTextColor(getResources().getColor(R.color.title_blue));
return true;
}
}
if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {
if (ll_title.getChildAt(ll_title.getChildCount() - 1).isFocused()) {
btn_search.requestFocus();
return true;
}
if (frags[select_index].isOnRightSide() && select_index != ll_title.getChildCount() - 1) {
setTab(select_index + 1);
frags[select_index].childViewrequestFocus(0);
resetTitleColor();
((Button)ll_title.getChildAt(select_index)).setTextColor(getResources().getColor(R.color.title_blue));
return true;
}
}
}
return super.dispatchKeyEvent(event);
}
自己屡一下逻辑即可。
提供一些常用的KeyCode:
public static final int KEYCODE_DPAD_UP = 19;
/** Key code constant: Directional Pad Down key.
* May also be synthesized from trackball motions. */
public static final int KEYCODE_DPAD_DOWN = 20;
/** Key code constant: Directional Pad Left key.
* May also be synthesized from trackball motions. */
public static final int KEYCODE_DPAD_LEFT = 21;
/** Key code constant: Directional Pad Right key.
* May also be synthesized from trackball motions. */
public static final int KEYCODE_DPAD_RIGHT = 22;
/** Key code constant: Directional Pad Center key.
* May also be synthesized from trackball motions. */
public static final int KEYCODE_DPAD_CENTER = 23;
/** Key code constant: Home key.
* This key is handled by the framework and is never delivered to applications. */
public static final int KEYCODE_HOME = 3;
/** Key code constant: Back key. */
public static final int KEYCODE_BACK = 4;
/** Key code constant: A Button key.
* On a game controller, the A button should be either the button labeled A
* or the first button on the bottom row of controller buttons. */
public static final int KEYCODE_BUTTON_A = 96;
/** Key code constant: B Button key.
* On a game controller, the B button should be either the button labeled B
* or the second button on the bottom row of controller buttons. */
public static final int KEYCODE_BUTTON_B = 97;
/** Key code constant: C Button key.
* On a game controller, the C button should be either the button labeled C
* or the third button on the bottom row of controller buttons. */
public static final int KEYCODE_BUTTON_C = 98;
/** Key code constant: X Button key.
* On a game controller, the X button should be either the button labeled X
* or the first button on the upper row of controller buttons. */
public static final int KEYCODE_BUTTON_X = 99;
/** Key code constant: Y Button key.
* On a game controller, the Y button should be either the button labeled Y
* or the second button on the upper row of controller buttons. */
public static final int KEYCODE_BUTTON_Y = 100;
大部分手柄厂家在GamePad模式下适配A对应确定键 B对应back键
判断触发案件的设备方法:
if(event.getSource() == InputDevice.SOURCE_GAMEPAD){//手柄模式,其他自己看源码
}
待研发
- 动态布局(暂时想法是GridLayout 有想法可以提出 一起讨论)
- 焦点动画(偏向于用位移动画去做)
- 支付模块抽离
- ending