⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmi.c

📁 mtk工具箱,计算器的详细设计,可以由此入手了解mtk的
💻 C
📖 第 1 页 / 共 2 页
字号:
    {
        SetCategory57Data(wgui_inline_items, ENUM_INLINE_TOTAL, inputBuffer);   /* sets the data */
    }

    DisableCategory57ScreenDone();

#ifdef __MMI_SLIM_LISTMENU_NUMBER__
    wgui_override_list_menu_slim_style(WGUI_LIST_MENU_SLIM_STYLE_DRAW_ICON);
#endif 

    /* 041205 Calvin added : Add an image on top of category57 */
    /* Category57AppendTopImage(IMG_BMI_WELCOME_SCREEN, TRUE); */
    /* Calvin end */
#ifndef __MMI_MAINLCD_240X320__
    ShowCategory57Screen(
        STR_BMI_INPUT_CAPTION,
        GetRootTitleIcon(EXTRA_HEALTH_MENU),
        STR_GLOBAL_OK,
        IMG_GLOBAL_OK,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        ENUM_INLINE_TOTAL,
        BMIImageList,
        wgui_inline_items,
        g_bmi_cntx->CurrHilite,
        guiBuffer);
#else /* __MMI_MAINLCD_240X320__ */ 
    ShowCategory357Screen(
        STR_BMI_INPUT_CAPTION,
        GetRootTitleIcon(EXTRA_HEALTH_MENU),
        STR_GLOBAL_OK,
        IMG_GLOBAL_OK,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        IMG_BMI_WELCOME_SCREEN,
        ENUM_INLINE_TOTAL,
        BMIImageList,
        wgui_inline_items,
        g_bmi_cntx->CurrHilite,
        guiBuffer);
#endif /* __MMI_MAINLCD_240X320__ */ 

    SetCategory57RightSoftkeyFunctions(BmiComputeResult, GoBackHistory);

}


/*****************************************************************************
 * FUNCTION
 *  ExitBMIInputScreen
 * DESCRIPTION
 *  Exit handler of EntryBMIInputScreen
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void ExitBMIInputScreen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    history h;
    U16 inputBufferSize;    /* added for inline edit history */
    U16 nHistory = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    set_leading_zero(TRUE);
    if (g_bmi_cntx)
    {
        CloseCategory57Screen();
    }
    h.scrnID = SCR_BMI_INPUT;
    h.entryFuncPtr = EntryBMIInputScreen;
    UCS2Strcpy((S8*) h.inputBuffer, (S8*) & nHistory);
    GetCategoryHistory(h.guiBuffer);

    inputBufferSize = (U16) GetCategory57DataSize();    /* added for inline edit history */
    GetCategory57Data((U8*) h.inputBuffer);             /* added for inline edit history */
    AddNHistory(h, inputBufferSize);                    /* added for inline edit history */

#ifdef __MMI_SLIM_LISTMENU_NUMBER__
    wgui_restore_list_menu_slim_style();
#endif 
}


/*****************************************************************************
 * FUNCTION
 *  BMIFillInlineStruct
 * DESCRIPTION
 *  Initialize inline structure of input screen.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void BMIFillInlineStruct(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    set_leading_zero(FALSE);

    g_bmi_cntx->GenderList[0] = (U8*) GetString(STR_BMI_MALE_TEXT);
    g_bmi_cntx->GenderList[1] = (U8*) GetString(STR_BMI_FEMALE_TEXT);

    /* gender */
    SetInlineItemActivation(&wgui_inline_items[ENUM_GENDER], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemSelect(&wgui_inline_items[ENUM_GENDER], 2, (U8 **) g_bmi_cntx->GenderList, &g_bmi_cntx->Gender);
    RegisterInlineSelectHighlightHandler(&wgui_inline_items[ENUM_GENDER], HighlightBMIGender);

    /* height caption */
    SetInlineItemActivation(&wgui_inline_items[ENUM_HEIGHT_CAPTION], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemCaption(&wgui_inline_items[ENUM_HEIGHT_CAPTION], (U8*) GetString(STR_BMI_HEIGHT_TEXT));
    SetInlineItemFullWidth(&wgui_inline_items[ENUM_HEIGHT_CAPTION]);

    /* height */
    SetInlineItemActivation(&wgui_inline_items[ENUM_HEIGHT], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemTextEdit(
        &wgui_inline_items[ENUM_HEIGHT],
        (U8*) g_bmi_cntx->HeightBuf,
        (BMI_MAX_INPUT + 1),
        INPUT_TYPE_DECIMAL_NUMERIC);
    RightJustifyInlineItem(&wgui_inline_items[ENUM_HEIGHT]);
    SetInlineItemFullWidth(&wgui_inline_items[ENUM_HEIGHT]);
    EnableInlineItemBoundary(&wgui_inline_items[ENUM_HEIGHT]);

    /* weight caption */
    SetInlineItemActivation(&wgui_inline_items[ENUM_WEIGHT_CAPTION], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemCaption(&wgui_inline_items[ENUM_WEIGHT_CAPTION], (U8*) GetString(STR_BMI_WEIGHT_TEXT));
    SetInlineItemFullWidth(&wgui_inline_items[ENUM_WEIGHT_CAPTION]);

    /* weight */
    SetInlineItemActivation(&wgui_inline_items[ENUM_WEIGHT], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemTextEdit(
        &wgui_inline_items[ENUM_WEIGHT],
        (U8*) g_bmi_cntx->WeightBuf,
        (BMI_MAX_INPUT + 1),
        INPUT_TYPE_DECIMAL_NUMERIC);
    RightJustifyInlineItem(&wgui_inline_items[ENUM_WEIGHT]);
    SetInlineItemFullWidth(&wgui_inline_items[ENUM_WEIGHT]);
    EnableInlineItemBoundary(&wgui_inline_items[ENUM_WEIGHT]);
}


/*****************************************************************************
 * FUNCTION
 *  EntryBMIResultScreen
 * DESCRIPTION
 *  Display result screen of calculation
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void EntryBMIResultScreen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *guiBuffer;
    DOUBLE bmiValue;
    U8 *bmiBuf;
    U8 percentageValue;
    U16 FolwerIndex;
    U8 LB, UB, prec;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(g_bmi_cntx->ResultBuf, 0, sizeof(g_bmi_cntx->ResultBuf));

    guiBuffer = GetCurrGuiBuffer(SCR_BMI_RESULT);

    EntryNewScreen(SCR_BMI_RESULT, NULL, EntryBMIResultScreen, NULL);

    bmiValue = g_bmi_cntx->Weight / (g_bmi_cntx->Height * g_bmi_cntx->Height) * 10000;

    prec = CalcComputePrecision(bmiValue, BMI_MAX_DIGITS);
    gui_float_string(bmiValue, prec, g_bmi_cntx->ResultBuf);

    if (g_bmi_cntx->Gender == 0)
    {
        LB = BMI_MALE_LB;
        UB = BMI_MALE_UB;
        FolwerIndex = IMG_BMI_BLUE_FLOWER;
    }
    else
    {
        LB = BMI_FEMALE_LB;
        UB = BMI_FEMALE_UB;
        FolwerIndex = IMG_BMI_RED_FLOWER;
    }

    gui_itoa(LB, (U16*) g_bmi_cntx->LBBuf, 10);
    gui_itoa(UB, (U16*) g_bmi_cntx->UBBuf, 10);

    if (bmiValue > UB)
    {
        bmiBuf = (U8*) GetString(STR_BMI_FAT);
        percentageValue = 2;
    }
    else if (bmiValue < LB)
    {
        bmiBuf = (U8*) GetString(STR_BMI_THIN);
        percentageValue = 0;
    }
    else
    {
        bmiBuf = (U8*) GetString(STR_BMI_NORMAL);
        percentageValue = 1;
    }

    ShowCategory122Screen(
        STR_BMI_RESULT_CAPTION,
        GetRootTitleIcon(EXTRA_HEALTH_MENU),
        0,
        0,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        STR_BMI_BMI_TEXT,
        percentageValue,
        guiBuffer,
        g_bmi_cntx->ResultBuf,
        bmiBuf,
        FolwerIndex,
        (U8*) g_bmi_cntx->LBBuf,
        (U8*) g_bmi_cntx->UBBuf);

    SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
}


/*****************************************************************************
 * FUNCTION
 *  HighlightBMIInlineEditor
 * DESCRIPTION
 *  Highlight handler of inline editor in input screen.
 * PARAMETERS
 *  index       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void HighlightBMIInlineEditor(S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_bmi_cntx->CurrHilite = (U8) index;
    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    SetLeftSoftkeyFunction(BmiComputeResult, KEY_EVENT_UP);
    return;
}


/*****************************************************************************
 * FUNCTION
 *  HighlightBMIGender
 * DESCRIPTION
 *  Highlight handler of Gender item in input screen.
 *  Change display folwer when gender changed.
 * PARAMETERS
 *  index       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void HighlightBMIGender(S32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_bmi_cntx->Gender == 0)
    {
        Category57ChangeItemIcon(0, IMG_BMI_BLUE_FLOWER);
    }
    else
    {
        Category57ChangeItemIcon(0, IMG_BMI_RED_FLOWER);
    }

    RedrawCategory57Screen();
}


/*****************************************************************************
 * FUNCTION
 *  BmiComputeResult
 * DESCRIPTION
 *  Validate correctness of input data and calcalute result.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void BmiComputeResult(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S8 temp_buf[100];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    CloseCategory57Screen();

    UnicodeToAnsii(temp_buf, (S8*) g_bmi_cntx->HeightBuf);
    g_bmi_cntx->Height = atof(temp_buf);

    UnicodeToAnsii(temp_buf, (S8*) g_bmi_cntx->WeightBuf);
    g_bmi_cntx->Weight = atof(temp_buf);

    if (((g_bmi_cntx->Height < BMI_MIN_HEIGHT) || (g_bmi_cntx->Height > BMI_MAX_HEIGHT)) &&
        ((g_bmi_cntx->Weight < BMI_MIN_WEIGHT) || (g_bmi_cntx->Weight > BMI_MAX_WEIGHT)))
    {
        DisplayPopup(
            (U8*) GetString(STR_BMI_HEIGHT_WEIGHT_ERROR),
            IMG_GLOBAL_WARNING,
            0,
            UI_POPUP_NOTIFYDURATION_TIME,
            WARNING_TONE);
        g_bmi_cntx->CurrHilite = 2;
        return;
    }
    else if ((g_bmi_cntx->Height < BMI_MIN_HEIGHT) || (g_bmi_cntx->Height > BMI_MAX_HEIGHT))
    {
        DisplayPopup(
            (U8*) GetString(STR_BMI_HEIGHT_ERROR_TEXT),
            IMG_GLOBAL_WARNING,
            0,
            UI_POPUP_NOTIFYDURATION_TIME,
            WARNING_TONE);
        g_bmi_cntx->CurrHilite = 2;
        return;
    }
    else if ((g_bmi_cntx->Weight < BMI_MIN_WEIGHT) || (g_bmi_cntx->Weight > BMI_MAX_WEIGHT))
    {
        DisplayPopup(
            (U8*) GetString(STR_BMI_WEIGHT_ERROR_TEXT),
            IMG_GLOBAL_WARNING,
            0,
            UI_POPUP_NOTIFYDURATION_TIME,
            WARNING_TONE);
        g_bmi_cntx->CurrHilite = 4;
        return;
    }

    g_bmi_cntx->CurrHilite = 0;
    EntryBMIResultScreen();
}

#endif /* __MMI_BMI__ */ // #ifdef __MMI_BMI__
#endif /* _MMI_BMI_C */ // #ifndef _MMI_BMI_C

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -