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

📄 healthmenstural.c

📁 mtk工具箱,计算器的详细设计,可以由此入手了解mtk的
💻 C
📖 第 1 页 / 共 5 页
字号:
        (U8*) get_string(STR_SCR_HEALTH_MENSIS_CAPTION),
        GetRootTitleIcon(EXTRA_HEALTH_MENU),
        STR_GLOBAL_OK,
        0,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        IMG_SCR_HEALTH_MENSIS,
        guiBuffer);

    SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
    SetLeftSoftkeyFunction(MensPreEntryInput, KEY_EVENT_UP);
#else /* __MMI_MAINLCD_240X320__ */ 
    MensPreEntryInput();
#endif /* __MMI_MAINLCD_240X320__ */ 
}

#define MENS_INPUT_SCREEN


/*****************************************************************************
 * FUNCTION
 *  MensFillInlineStruct
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void MensFillInlineStruct(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    SetInlineItemActivation(&wgui_inline_items[MENS_INLINE_DATE_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemCaption(&wgui_inline_items[MENS_INLINE_DATE_CAP], (U8*) GetString(STR_LAST_DATE));

    SetInlineItemActivation(&wgui_inline_items[MEMS_INLINE_DATE], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemDate(
        &wgui_inline_items[MEMS_INLINE_DATE],
        (U8*) g_mens_cntx->DayBuf,
        (U8*) g_mens_cntx->MonBuf,
        (U8*) g_mens_cntx->YearBuf,
        ClndrDateEditorCallBack);
    RightJustifyInlineItem(&wgui_inline_items[MEMS_INLINE_DATE]);
    EnableInlineItemBoundary(&wgui_inline_items[MEMS_INLINE_DATE]);
    set_inline_date_boundary(2030, 1970, 12, 1);

    SetInlineItemActivation(&wgui_inline_items[MEMS_INLINE_PERIOD_CAP], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemCaption(&wgui_inline_items[MEMS_INLINE_PERIOD_CAP], (U8*) GetString(STR_AVERAGE_DAYS_HEALTH_MENSIS));

    SetInlineItemActivation(&wgui_inline_items[MEMS_INLINE_PERIOD], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemTextEdit(&wgui_inline_items[MEMS_INLINE_PERIOD], (U8*) g_mens_cntx->PeriodBuf, 3, INPUT_TYPE_NUMERIC);

    RightJustifyInlineItem(&wgui_inline_items[MEMS_INLINE_PERIOD]);
    EnableInlineItemBoundary(&wgui_inline_items[MEMS_INLINE_PERIOD]);

    SetInlineItemActivation(&wgui_inline_items[MEMS_INLINE_NUM_DAYS], INLINE_ITEM_ACTIVATE_WITHOUT_KEY_EVENT, 0);
    SetInlineItemCaption(&wgui_inline_items[MEMS_INLINE_NUM_DAYS], (U8*) GetString(STR_DATE_FORMAT_HEALTH_MENSIS));

}


/*****************************************************************************
 * FUNCTION
 *  MensPreEntryInput
 * DESCRIPTION
 *  Initialize variables for input screen and then go to input screen.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void MensPreEntryInput(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MYTIME currTime;
    S8 tmpMon[MENS_MON_LEN];
    S8 tmpDay[MENS_MON_LEN];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mens_cntx == NULL)
    {
        g_mens_cntx = OslMalloc(sizeof(mens_context_struct));
    }

    memset(g_mens_cntx, 0, sizeof(mens_context_struct));

    GetDateTime(&currTime);

    gui_itoa((S32) currTime.nYear, (U16*) g_mens_cntx->YearBuf, 10);

    sprintf(tmpMon, "%02d", currTime.nMonth);
    AnsiiToUnicodeString(g_mens_cntx->MonBuf, tmpMon);

    sprintf(tmpDay, "%02d", currTime.nDay);
    AnsiiToUnicodeString(g_mens_cntx->DayBuf, tmpDay);

    EntryMensInput();
}


/*****************************************************************************
 * FUNCTION
 *  EntryMensInput
 * DESCRIPTION
 *  Display screen to input
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void EntryMensInput(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *guiBuffer;  /* Buffer holding history data */

    U8 *inputBuffer;
    U16 inputBufferSize;    /* added for inline edit history */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    EntryNewScreen(SCR_ID_MENS_INPUT, ExitMensInput, NULL, NULL);
    SetDelScrnIDCallbackHandler(SCR_ID_MENS_INPUT, (HistoryDelCBPtr) MensDelScrCB);

    InitializeCategory57Screen();

    MensFillInlineStruct();
    RegisterHighlightHandler(HighlightMensInputItem);

    guiBuffer = GetCurrGuiBuffer(SCR_ID_MENS_INPUT);

    inputBuffer = GetCurrNInputBuffer(SCR_ID_MENS_INPUT, &inputBufferSize);

    if (inputBuffer != NULL)    /* added for inline edit history */
    {
        SetCategory57Data(wgui_inline_items, MEMS_INLINE_TOTAL, inputBuffer);   /* sets the data */
    }

    DisableCategory57ScreenDone();

#ifndef __MMI_MAINLCD_240X320__
    ShowCategory57Screen(
        STR_HEALTH_MENSIS_DATE_CAPTION,
        GetRootTitleIcon(EXTRA_HEALTH_MENU),
        STR_GLOBAL_OK,
        IMG_GLOBAL_OK,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        MEMS_INLINE_TOTAL,
        NULL,
        wgui_inline_items,
        1,
        guiBuffer);
#else /* __MMI_MAINLCD_240X320__ */ 
    ShowCategory357Screen(
        STR_HEALTH_MENSIS_DATE_CAPTION,
        GetRootTitleIcon(EXTRA_HEALTH_MENU),
        STR_GLOBAL_OK,
        IMG_GLOBAL_OK,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        IMG_SCR_HEALTH_MENSIS,
        MEMS_INLINE_TOTAL,
        NULL,
        wgui_inline_items,
        1,
        guiBuffer);
#endif /* __MMI_MAINLCD_240X320__ */ 

    SetKeyHandler(MensDisplayResult, KEY_LSK, KEY_EVENT_UP);

    SetCategory57RightSoftkeyFunctions(MensDisplayResult, GoBackHistory);
}


/*****************************************************************************
 * FUNCTION
 *  ExitMensInput
 * DESCRIPTION
 *  Exit function of input screen.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void ExitMensInput(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    history Scr;
    U16 inputBufferSize;    /* added for inline edit history */

    S16 nHistory = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    Scr.scrnID = SCR_ID_MENS_INPUT;
    if (g_mens_cntx)
    {
        CloseCategory57Screen();
    }
    Scr.entryFuncPtr = EntryMensInput;
    UCS2Strcpy((S8*) Scr.inputBuffer, (S8*) & nHistory);
    GetCategoryHistory(Scr.guiBuffer);
    GetCategory57Data((U8*) Scr.inputBuffer);           /* added for inline edit history */
    inputBufferSize = (U16) GetCategory57DataSize();    /* added for inline edit history */
    AddNHistory(Scr, inputBufferSize);                  /* added for inline edit history */

}


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

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    ChangeLeftSoftkey(STR_GLOBAL_OK, IMG_GLOBAL_OK);
    SetCategory57LeftSoftkeyFunction(MensDisplayResult);
}

#define MENS_RESULT_SCREEN


/*****************************************************************************
 * FUNCTION
 *  MensDisplayResult
 * DESCRIPTION
 *  Display corresponding screen according to computation result.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void MensDisplayResult(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S8 error;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    CloseCategory57Screen();
    error = MensValidateInput();

    switch (error)
    {
        case MENS_ERR_DATE:
            DisplayPopup(
                (U8*) GetString(STR_HEALTH_WRONG_DATE_MSG),
                IMG_GLOBAL_WARNING,
                0,
                UI_POPUP_NOTIFYDURATION_TIME,
                (U8) WARNING_TONE);
            break;
        case MENS_ERR_PERIOD:
            DisplayPopup(
                (U8*) GetString(STR_INVALID_AVERAGE_DAY_MESSAGE),
                IMG_GLOBAL_WARNING,
                0,
                UI_POPUP_NOTIFYDURATION_TIME,
                (U8) WARNING_TONE);
            break;
        default:    /* correct */
            MensPreEntryResult();
            break;
    }
}


/*****************************************************************************
 * FUNCTION
 *  MensValidateInput
 * DESCRIPTION
 *  Validate the correctness of user input.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
U8 MensValidateInput(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S8 tmpMon[MENS_MON_LEN];
    S8 tmpDay[MENS_DAY_LEN];
    S8 tmpYear[MENS_YEAR_LEN];
    S8 AvgDays[MENS_PERIOD_LEN];
    MYTIME currTime, incTime, finalTime;
    U8 tmpPeriod;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* validate period */
    UnicodeToAnsii(AvgDays, g_mens_cntx->PeriodBuf);
    g_mens_cntx->AvgPeriod = tmpPeriod = (U8) atoi(AvgDays);
    if (tmpPeriod < MENS_MIN_PERIOD || tmpPeriod > MENS_MAX_PERIOD)
    {
        return MENS_ERR_PERIOD;
    }

    /* validate day */
    UnicodeToAnsii(tmpDay, g_mens_cntx->DayBuf);
    UnicodeToAnsii(tmpMon, g_mens_cntx->MonBuf);
    UnicodeToAnsii(tmpYear, g_mens_cntx->YearBuf);

    memset(&g_mens_cntx->InputDate, 0, sizeof(MYTIME));
    g_mens_cntx->InputDate.nDay = atoi(tmpDay);
    g_mens_cntx->InputDate.nMonth = atoi(tmpMon);
    g_mens_cntx->InputDate.nYear = atoi(tmpYear);

    /* daty out of boundary */
    g_mens_cntx->DayOfMon = LastDayOfMonth(g_mens_cntx->InputDate.nMonth, g_mens_cntx->InputDate.nYear);
    if (g_mens_cntx->InputDate.nDay > g_mens_cntx->DayOfMon)
    {
        return MENS_ERR_DATE;
    }

    /* date too large */
    GetDateTime(&currTime);
    if (CompareTime(currTime, g_mens_cntx->InputDate, NULL) == TIME_LESS)
    {
        return MENS_ERR_DATE;
    }

    /* date too small */
    memset(&incTime, 0, sizeof(MYTIME));
    incTime.nMonth = MENS_NUM_PREV_MON;
    DecrementTime(currTime, incTime, &finalTime);
    if (CompareTime(g_mens_cntx->InputDate, finalTime, NULL) == TIME_LESS)
    {
        return MENS_ERR_DATE;
    }

    return MENS_ERR_NONE;
}


/*****************************************************************************
 * FUNCTION
 *  ExitMensResult
 * DESCRIPTION
 *  Exit function of calendar screen.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void ExitMensResult(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_mens_cntx != NULL && g_mens_cntx->IsAddToHistory)
    {
        history Scr;    /* Variable to hold the history data */
        S16 nHistory = 0;

        Scr.scrnID = SCR_ID_MENS_RESULT;

⌨️ 快捷键说明

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