?? container.java
字號:
package org.gggeye.easymf.ui;
import org.gggeye.easymf.log.Logger;
/**
* Web 視圖 1,包括頁面的渲染 2,頁面的控制邏輯
*
* @author wuhua
*
*/
public class Container {
Panel panel;
HtmlDocument htmlDocument;
final static byte VIEW_MOVE_UP = 1;
final static byte VIEW_MOVE_DOWN = 6;
final static byte VIEW_SCROLL_UP = 2;
final static byte VIEW_SCROLL_DOWN = 5;
final static byte VIEW_ENTER_CLICK = 8;
/**
* 事件監聽器
*/
EventListener eventListener;
Container(Panel _webBrowser) {
this.panel = _webBrowser;
}
protected void doPaintViews(Pen _point) {
doDrawDocument(_point, this.htmlDocument);
}
/**
* 繪制菜單
*
* @param player
*/
void doDrawMenu(Pen p) {
p.save();
p.setColor(0xCEF);
int y = Panel.height - Panel.labelHeight;
p.graphics.fillRect(0, y, Panel.width,
Panel.labelHeight);
y += (Panel.labelHeight - Panel.defaultFont.getHeight()) >> 1;
String title = "菜單";
// if(this.htmlDocument != null && htmlDocument.title == null){
// title = htmlDocument.title;
// }
p.setColor(0xFFFFFF);
p.graphics.drawString(Runtime.getRuntime().freeMemory() / 1024 + "",
50, y, 20);
if(this.panel.menu != null && this.panel.menu.menuItems.size() >1){
p.graphics.drawString(title, 0, y, 20);
}
p.reset();
}
/**
* doEnterClick
*/
private void doEnterClick(int _keyCode) {
View focus = htmlDocument.getFocusView();
if(focus == null)
return;
if(focus.eventListener == null)
focus.eventListener = this.eventListener;
//if(focus != null && eventListener != null){
//eventListener.htmlElementOnClick(focus);
//}else{
focus.doClick(_keyCode);
//}
}
/**
* 繪制標題
*
* @param player
*/
void doDrawTitle(Pen p) {
p.save();
p.setColor(0xCEF);
p.graphics.fillRect(0, 0, Panel.width,
Panel.labelHeight);
int y = (Panel.labelHeight - Panel.defaultFont.getHeight()) >> 1;
String title = "XWeb";
if (this.htmlDocument != null && htmlDocument.title != null) {
title = htmlDocument.title;
}
p.setColor(0xFFFFFF);
p.graphics.drawString(title, 0, y, 20);
p.reset();
}
/**
* doDrawDocument
*
* @param Pen
* Point
* @param doucment
* HtmlDocument
*/
private void doDrawDocument(Pen point, HtmlDocument document) {
if (htmlDocument == null) {
return;
}
try {
int defaultBackColor = 0xFFFFFF; // doucment.backColor;
fillBackground(point, defaultBackColor);
point.setColor(0x0);
// 繪制頁面的時候設置字體
point.setFont(Panel.defaultFont);
point.setStrokeStyle(0);
// int startId = document.tempStartHtmlElementId = dc[0];
// int endId = document.tempEndHtmlElementId = dc[1];
point.setOffset(0, document.position + Panel.labelHeight);
for (int i = 0; i < document.views.size(); i++) {
View he = (View) document.views
.elementAt(i);
// doDrawHtmlElement(Point, he);
he.doPaint(point, document);
// 為了加強性能,這里應該判斷下,當前元素是否在繪制屏幕以內,如果在的話,才需要繪制
}
} catch (Exception e) {
Logger.debug(e);
}
}
/**
* 移動頁面, 1,查找焦點 2,移動Y軸位置偏移量
*
* @param i
*/
private void scrollHtmlDocumentByHeight(int _height) {
// 文檔對象的屏幕在整個手機屏幕上的時候直接跳出
if (htmlDocument.height < Panel.viewHeight)
return;
htmlDocument.position += _height;
if (htmlDocument.position > 0) {
htmlDocument.position = 0;
// return;
}
if (Math.abs(htmlDocument.position) + Panel.viewHeight > htmlDocument.height) {
htmlDocument.position = -(htmlDocument.height - Panel.viewHeight);
}
// 下面是查找焦點_height < 0 表示像上查找
}
/**
* 查找焦點, 怎么樣查找焦點了。用什么算法了。這很頭疼啊 經過調試終于被我成功的解決了這個問題 主要是遞歸查找方式獲取焦點位置。
* 如果具有焦點,并且當前焦點在屏幕上則跳出循環
*
* @param _findType --
* -1 向上查找, 1向下查找
*/
private void findFocusHtmlElement(byte _findType) {
View htmlElement = this.htmlDocument
.nextFocusView(_findType);
// }
int elements = 0;
while (htmlElement != null) {
elements++;
if (htmlElement.inSreenContent(_findType, Math
.abs(htmlDocument.position), Math
.abs(htmlDocument.position)
+ Panel.viewHeight)) {
htmlDocument.focusIndex = htmlElement.index;
return;
}
htmlElement = this.htmlDocument.nextFocusView(_findType);
htmlDocument.focusIndex = htmlElement.index;
if (elements >= this.htmlDocument.size()) {
return;
}
}
}
final void doClick(int _keyCode){
switch(_keyCode){
case Container.VIEW_MOVE_UP: moveFocusElement(Container.VIEW_MOVE_UP);break;
case Container.VIEW_MOVE_DOWN: moveFocusElement(Container.VIEW_MOVE_DOWN);break;
case Container.VIEW_SCROLL_UP: moveFocusElement(Container.VIEW_SCROLL_UP);break;
case Container.VIEW_SCROLL_DOWN: moveFocusElement(Container.VIEW_SCROLL_DOWN); break;
//case Container.VIEW_ENTER_CLICK: doEnterClick(_keyCode);break;
default: break;
}
// View tView = this.htmlDocument.getFocusView();
// this.eventListener
this.doEnterClick(_keyCode);
}
/**
* 處理屏幕的滾動 1.焦點的滾動 2.滑動滾動
*
* @param hd
* HtmlDocument
* @param moveType
* byte 0 up, 1 down
*/
void moveFocusElement(byte moveType) {
switch (moveType) {
case VIEW_MOVE_UP:
moveDocumentUp();
break;
case VIEW_MOVE_DOWN:
moveDocumentDown();
break;
case VIEW_SCROLL_UP:
scrollHtmlDocumentByHeight(60);
findFocusHtmlElement(VIEW_MOVE_UP);
break;
case VIEW_SCROLL_DOWN:
scrollHtmlDocumentByHeight(-60);
findFocusHtmlElement(VIEW_MOVE_DOWN);
break;
}
}
private void moveDocumentDown() {
View he = this.htmlDocument.nextFocusView(VIEW_MOVE_DOWN);
if(he == null && this.htmlDocument.height - Math.abs(this.htmlDocument.position) > Panel.viewHeight){
this.scrollHtmlDocumentByHeight(-60);
return;
}
while (he != null) {
if ( !he.onSreenContent(VIEW_MOVE_DOWN, Math
.abs(htmlDocument.position ), Math
.abs(htmlDocument.position )
+ Panel.viewHeight)) {
this.scrollHtmlDocumentByHeight(-60);
return;
}
if (he.hasFocus) {
htmlDocument.focusIndex = he.index;
return;
}
}
}
private void moveDocumentUp() {
View he = this.htmlDocument.nextFocusView(VIEW_MOVE_UP);
if(he == null && this.htmlDocument.position < 0){
this.scrollHtmlDocumentByHeight(60);
return;
}
while (he != null) {
if ( !he.onSreenContent(VIEW_MOVE_UP,
Math.abs(htmlDocument.position
- Panel.labelHeight), Math
.abs(htmlDocument.position)
+ Panel.viewHeight)) {
this.scrollHtmlDocumentByHeight(60);
return;
}
if (he.hasFocus) {
htmlDocument.focusIndex = he.index;
return;
}
}
}
final void fillBackground(Pen point, int c) {
point.save();
point.setColor(c);
point.graphics.fillRect(0, 0, Panel.width,
Panel.height);
point.reset();
}
final void setEventListener(EventListener _eventListener){
this.eventListener = _eventListener;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -