如果无法当前按钮是一家专注于执行另一个按钮的功能 [英] Unable to perform another button's function if current button is focusing

查看:257
本文介绍了如果无法当前按钮是一家专注于执行另一个按钮的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这个code,

public class Custom_TopField extends Manager {
private Bitmap download = Config_GlobalFunction.Bitmap("btn_download.png");
private Bitmap downloadactive = Config_GlobalFunction
        .Bitmap("btn_download_active.png");
private Bitmap refresh = Config_GlobalFunction.Bitmap("icon_refresh.png");
private Bitmap refreshactive = Config_GlobalFunction
        .Bitmap("icon_refresh_active.png");
private Bitmap back = Config_GlobalFunction.Bitmap("btn_back.png");
private Bitmap backctive = Config_GlobalFunction
        .Bitmap("btn_back_active.png");
private Bitmap news = Config_GlobalFunction.Bitmap("icon_news.png");
private Bitmap newsactive = Config_GlobalFunction
        .Bitmap("icon_news_active.png");

private Custom_ButtonField downloadbtn, refreshbtn, backbtn, newsbtn;
private Custom_LabelField title;
private int left, right, fontsize;
private Database_Webservice webservice;

Custom_TopField(final MainScreen mainscreen, final int position,
        final int catsid, final String header, int left, int right) {
    super(Manager.USE_ALL_WIDTH | Manager.NO_VERTICAL_SCROLL
            | Manager.NO_HORIZONTAL_SCROLL);
    this.left = left;
    this.right = right;

    if (Display.getWidth() > 480)
        fontsize = 43;
    else if (Display.getWidth() < 481 && Display.getWidth() > 320)
        fontsize = 33;
    else
        fontsize = 23;

    webservice = new Database_Webservice();
    setBackground(Config_GlobalFunction.loadbackground(Display.getWidth()
            + "_" + "header_bar.png"));

    if (position != 0) {
        title = new Custom_LabelField(Config_GlobalFunction.maintitle,
                DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                        | DrawStyle.HCENTER | Field.FOCUSABLE, Color.WHITE) {
            protected boolean navigationClick(int status, int time) {
                Main.getUiApplication().pushScreen(
                        new Custom_LoadingScreen(1));
                Main.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        Main.getUiApplication().pushScreen(
                                new Main_AllLatestNews(false));
                    }
                }, 1 * 1000, false);
                return true;
            }

            protected boolean touchEvent(TouchEvent message) {
                int eventCode = message.getEvent();
                if (eventCode == TouchEvent.UNCLICK)
                    Main.getUiApplication().pushScreen(
                            new Menu_PopupMenu(position));

                return true;
            }
        };

    } else {
        title = new Custom_LabelField(Config_GlobalFunction.maintitle,
                DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                        | DrawStyle.HCENTER, Color.WHITE);
    }
    title.setFont(Font.getDefault().derive(Font.BOLD, fontsize));
    add(title);

    if (left == 1) {
        newsbtn = new Custom_ButtonField(news, newsactive, newsactive) {
            protected boolean navigationClick(int status, int time) {
                Main.getUiApplication().pushScreen(
                        new Menu_PopupMenu(position));
                return true;
            }

            protected boolean touchEvent(TouchEvent message) {
                int eventCode = message.getEvent();
                if (eventCode == TouchEvent.UP)
                    Main.getUiApplication().pushScreen(
                            new Menu_PopupMenu(position));

                return true;
            }
        };

        add(newsbtn);
    } else if (left == 2) {
        backbtn = new Custom_ButtonField(back, backctive, backctive) {
            protected boolean navigationClick(int status, int time) {
                Main.getUiApplication().popScreen(mainscreen);
                return true;
            }

            protected boolean touchEvent(TouchEvent message) {
                int eventCode = message.getEvent();
                if (eventCode == TouchEvent.UP)
                    Main.getUiApplication().popScreen(mainscreen);
                return true;
            }
        };
        add(backbtn);
    }

    if (right == 1) {
        downloadbtn = new Custom_ButtonField(download, downloadactive,
                downloadactive) {
            protected boolean navigationClick(int status, int time) {
                if (Config_GlobalFunction
                        .Dialog(Config_GlobalFunction.alertdownload)) {
                    if (Config_GlobalFunction.isConnected()) {
                        webservice.UpdateAllCatNews();
                    } else
                        Config_GlobalFunction.Message(
                                Config_GlobalFunction.nowifi, 1);
                } else
                    Config_GlobalFunction.CloseDialog();
                return true;
            }

            protected boolean touchEvent(TouchEvent message) {
                int eventCode = message.getEvent();
                if (eventCode == TouchEvent.UP) {
                    if (Config_GlobalFunction
                            .Dialog(Config_GlobalFunction.alertdownload)) {
                        if (Config_GlobalFunction.isConnected()) {
                            webservice.UpdateAllCatNews();
                        } else
                            Config_GlobalFunction.Message(
                                    Config_GlobalFunction.nowifi, 1);
                    } else
                        Config_GlobalFunction.CloseDialog();
                }
                return true;
            }
        };
        add(downloadbtn);
    } else if (right == 2) {
        refreshbtn = new Custom_ButtonField(refresh, refreshactive,
                refreshactive) {
            protected boolean navigationClick(int status, int time) {
                if (Config_GlobalFunction.isConnected()) {
                    webservice
                            .refreshCatNewsindex(catsid, position, header);
                } else
                    Config_GlobalFunction.Message(
                            Config_GlobalFunction.nowifi, 1);
                return true;
            }

            protected boolean touchEvent(TouchEvent message) {
                int eventCode = message.getEvent();
                if (eventCode == TouchEvent.UP) {
                    if (Config_GlobalFunction.isConnected())
                        webservice.refreshCatNewsindex(catsid, position,
                                header);
                    else
                        Config_GlobalFunction.Message(
                                Config_GlobalFunction.nowifi, 1);
                }
                return true;
            }
        };
        add(refreshbtn);
    }
}
}

有一个按钮 newsbtn 左侧和 downloadbtn 右。当 newsbtn 的重点是,我点击 downloadbtn ,也不会提示对话框却会 pushscreen 。通过正确的,如果我点击 downloadbtn ,它会提示对话框而不是 pushscreen

There is a button newsbtn at left and downloadbtn at right. When the newsbtn is focusing, I click on downloadbtn, it will not prompt Dialog but it will pushscreen. By right, if I click on downloadbtn, it will prompt Dialog instead of pushscreen.

在这两个按钮是无焦点的,我点击按钮,按钮的重点是演的预期。

When both button is unfocus, I click on the button, the button is focusing and performed expected.

我试着集中默认按钮是 ButtonField字段,然后我点击另一个领域,它正确地执行。

I tried on focusing default button which is ButtonField, then I click another field, it perform correctly.

我觉得是 custom_buttonfield 类的问题。

下面是我的 Custom_FieldButton

public class Custom_ButtonField extends ButtonField {
Bitmap mNormal;
Bitmap mFocused;
Bitmap mActive;

int mWidth;
int mHeight;

private int color = -1;
String text;

public Custom_ButtonField(Bitmap normal, Bitmap focused, Bitmap active) {
    super(CONSUME_CLICK | Field.FOCUSABLE | Field.FIELD_HCENTER
            | Field.FIELD_VCENTER);
    mNormal = normal;
    mFocused = focused;
    mActive = active;
    mWidth = mNormal.getWidth();
    mHeight = mNormal.getHeight();
    setMargin(0, 0, 0, 0);
    setPadding(0, 0, 0, 0);
    setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE,
            BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
}

public Custom_ButtonField(String text, Bitmap normal, Bitmap focused,
        Bitmap active, int color) {
    super(CONSUME_CLICK | Field.FOCUSABLE | Field.FIELD_HCENTER
            | Field.FIELD_VCENTER);
    this.color = color;
    mNormal = normal;
    mFocused = focused;
    mActive = active;
    mWidth = mNormal.getWidth();
    mHeight = mNormal.getHeight();
    setMargin(0, 0, 0, 0);
    setPadding(0, 0, 0, 0);
    setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE,
            BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    this.text = text;
}

public Custom_ButtonField(String text, Bitmap normal, Bitmap focused,
        Bitmap active, int color, long style) {
    super(style);
    this.color = color;
    mNormal = normal;
    mFocused = focused;
    mActive = active;
    mWidth = mNormal.getWidth();
    mHeight = mNormal.getHeight();
    setMargin(0, 0, 0, 0);
    setPadding(0, 0, 0, 0);
    setBorder(BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE,
            BorderFactory.createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    this.text = text;
}

public void setText(String text) {
    this.text = text;
    invalidate();
}

public String getText() {
    return text;
}

public void setColor(int color) {
    this.color = color;
}

protected void onFocus(int direction) {
    super.onFocus(direction);
    color = 0x540604;
    this.invalidate();
}

protected void onUnfocus() {
    super.onUnfocus();
    color = Color.WHITE;
    this.invalidate();
}

protected void paint(Graphics graphics) {
    int fontcontent;
    if (Display.getWidth() > 480)
        fontcontent = 28;
    else if (Display.getWidth() < 481 && Display.getWidth() > 320)
        fontcontent = 23;
    else
        fontcontent = 18;

    Bitmap bitmap = null;
    switch (getVisualState()) {
    case VISUAL_STATE_NORMAL:
        bitmap = mNormal;
        break;
    case VISUAL_STATE_FOCUS:
        bitmap = mFocused;
        break;
    case VISUAL_STATE_ACTIVE:
        bitmap = mActive;
        break;
    default:
        bitmap = mNormal;
    }
    setBackground(BackgroundFactory.createBitmapBackground(bitmap));
    graphics.setFont(Font.getDefault().derive(Font.PLAIN, fontcontent));
    graphics.setColor(color);
    graphics.drawText(text, (mNormal.getWidth() - Font.getDefault()
            .getAdvance(text)) / 2, ((mNormal.getHeight() - Font
            .getDefault().getHeight()) / 2) + 10, DrawStyle.HCENTER
            | DrawStyle.VCENTER);
}

public int getPreferredWidth() {
    return mWidth;
}

public int getPreferredHeight() {
    return mHeight;
}

protected void layout(int width, int height) {
    setExtent(mWidth, mHeight);
}
}

谁能帮我编辑类,以便该按钮的*的焦点状态会不会影响功能?的*

Who can help me to edit the class so that the button's *focus state will not affect the function?*

推荐答案

使用 setFieldChangeListener 将所有动作做的。

    if (position != 0) {
        title = new Custom_LabelField(Config_GlobalFunction.maintitle,
                DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                        | DrawStyle.HCENTER | Field.FOCUSABLE
                        | ButtonField.CONSUME_CLICK, Color.WHITE) {
            protected boolean navigationClick(int status, int time) {
                Main.getUiApplication().pushScreen(
                        new Custom_LoadingScreen(1));
                Main.getUiApplication().invokeLater(new Runnable() {
                    public void run() {
                        Main.getUiApplication().pushScreen(
                                new Main_AllLatestNews());
                    }
                }, 1 * 1000, false);
                return true;
            }
        };
    } else {
        title = new Custom_LabelField(Config_GlobalFunction.maintitle,
                DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                        | DrawStyle.HCENTER, Color.WHITE);
    }
    title.setFont(Font.getDefault().derive(Font.BOLD, fontsize));
    add(title);

    if (left == 1) {
        newsbtn = new Custom_ButtonField(news, newsactive, newsactive);
        newsbtn.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                Main.getUiApplication().pushScreen(
                        new Menu_PopupMenu(position));
            }
        });
        add(newsbtn);
    } else if (left == 2) {
        backbtn = new Custom_ButtonField(back, backctive, backctive);
        backbtn.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                Main.getUiApplication().popScreen(mainscreen);
            }
        });
        add(backbtn);
    }

    if (right == 1) {
        downloadbtn = new Custom_ButtonField(download, downloadactive,
                downloadactive);
        downloadbtn.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                if (Config_GlobalFunction
                        .Dialog(Config_GlobalFunction.alertdownload)) {
                    if (Config_GlobalFunction.isConnected()) {
                        webservice.UpdateAllCatNews();
                    } else
                        Config_GlobalFunction.Message(
                                Config_GlobalFunction.nowifi, 1);
                } else
                    Config_GlobalFunction.CloseDialog();
            }
        });
        add(downloadbtn);
    } else if (right == 2) {
        refreshbtn = new Custom_ButtonField(refresh, refreshactive,
                refreshactive);
        refreshbtn.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field field, int context) {
                if (Config_GlobalFunction.isConnected()) {
                    Config_GlobalFunction.Message(
                            Config_GlobalFunction.refreshing, 1);
                    webservice.UpdateMoreCatNews(catsid, position, header);
                } else
                    Config_GlobalFunction.Message(
                            Config_GlobalFunction.nowifi, 1);
            }
        });
        add(refreshbtn);
    }
}

不过,有一件坏事,当你点击或使用拨轮来按一下按钮,它会出现蓝色是。

However, there is a bad thing which is when you click or use trackwheel to click the button, it will appear blue color.

这篇关于如果无法当前按钮是一家专注于执行另一个按钮的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆