#include "calculator/include/CalculatorPresenter.h"
#include "calculator/include/CalculatorModel.h"
#include "wearable_log.h"
+#include <math.h>
namespace OHOS {
delete image1_;
image1_=nullptr;
}
+ if(hint)
+ {
+ delete hint;
+ hint=nullptr;
+ }
if(group)
{
delete group;
group =nullptr;
}
+
+ if(call_roll_timer)
+ {
+ osTimerStop(call_roll_timer);
+ osTimerDelete(call_roll_timer);
+ call_roll_timer = NULL;
+
+ }
+}
+static int8_t roll_falg=0;//0.1s一次变换
+
+ static void label_Timer_CallBack(int data)
+{
+ roll_falg--;
+ if(roll_falg<=0)
+ {
+ if(CalculatorView::GetInstance())
+ CalculatorView::GetInstance()->show_hint_label(false);
+
+ if(g_pMainView->call_roll_timer)
+ {
+ osTimerStop(g_pMainView->call_roll_timer);
+ osTimerDelete(g_pMainView->call_roll_timer);
+ g_pMainView->call_roll_timer = NULL;
+ }
+ }
}
CalculatorView *CalculatorView::GetInstance()
return g_pMainView;
}
+
+void CalculatorView::show_hint_label(bool data)
+{
+ hint->SetVisible(data);
+ RootView::GetInstance()->Invalidate();
+}
+
+void CalculatorView::start_call_roll_timer()
+ {
+ uint32_t tick;
+ osStatus_t retTimer;
+ if(call_roll_timer)
+ {
+ roll_falg=10;
+ }
+ else
+ {
+ roll_falg=10;
+
+ call_roll_timer = osTimerNew((osTimerFunc_t)label_Timer_CallBack, osTimerPeriodic, NULL, NULL);
+ tick =100;// osMs2Tick(1000);
+ retTimer = osTimerStart(call_roll_timer, tick);
+ if (retTimer != osOK && call_roll_timer != NULL) {
+ osTimerDelete(call_roll_timer);
+ call_roll_timer = NULL;
+ return ;
+ }
+ }
+ }
+
+
void CalculatorView::number_text_updata_buf(const char *buf)
{
- char new_buf[16]={0};
+ char new_buf[64]={0};
const char*text_buf=NULL;
if(number_falg==1)
text_buf=number->GetText();
else
text_buf="";
- sprintf_s(new_buf,16,"%s%s",text_buf,buf);
+ if(strlen(text_buf)>20)
+ {
+ //超出长度限制
+ start_call_roll_timer();
+ show_hint_label(true);
+ return;
+ }
+ sprintf_s(new_buf,64,"%s%s",text_buf,buf);
number->SetText(new_buf);
number_falg=1;
RootView::GetInstance()->Invalidate();
void CalculatorView::symbol_text_updata_buf(const char *buf)
{
- char new_buf[16]={0};
+ char new_buf[64]={0};
const char*text_buf=number->GetText();
if(number_falg==0)
{
RootView::GetInstance()->Invalidate();
return;
}
- float number_float=strtof(text_buf,NULL);
+ double number_float=strtod(text_buf,NULL);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%lf %s",number_float,text_buf);
CalculatorModel::GetInstance()->number_push_stack(number_float);
}
- sprintf_s(new_buf,16,"%s",buf);
+ sprintf_s(new_buf,64,"%s",buf);
number->SetText(new_buf);
RootView::GetInstance()->Invalidate();
char new_buf[16]={0};
const char*text_buf=number->GetText();
- float number_float=strtof(text_buf,NULL);
+ double number_float=strtod(text_buf,NULL);
if(buf[0]=='C')
{
CalculatorModel::GetInstance()->clean_stack();
}
else if (buf[0]=='%')
{
- number_float=0.01*number_float;
- sprintf_s(new_buf,16,"%.02f",number_float);
+ number_float=0.01*number_float;
+
+ double number_float_=number_float;
+ int decimal_places = 0;
+ double frac;
+
+ while (modf(number_float_ * pow(10, decimal_places), &frac) != 0.0f)
+ {
+ decimal_places++;
+ }
+
+ printf("该浮点数的小数部分有 %d %lf 位。\n", decimal_places,number_float);
+ switch (decimal_places)
+ {
+ case 0:
+ sprintf_s(new_buf,64,"%.00lf",number_float);
+ break;
+ case 1:
+ sprintf_s(new_buf,64,"%.01lf",number_float);
+ break;
+ case 2:
+ sprintf_s(new_buf,64,"%.02lf",number_float);
+ break;
+ case 3:
+ sprintf_s(new_buf,64,"%.03lf",number_float);
+ break;
+ case 4:
+ sprintf_s(new_buf,64,"%.04lf",number_float);
+ break;
+ case 6:
+ sprintf_s(new_buf,64,"%.06lf",number_float);
+ break;
+ case 7:
+ sprintf_s(new_buf,64,"%.07lf",number_float);
+ break;
+ case 8:
+ sprintf_s(new_buf,64,"%.08lf",number_float);
+ break;
+ default:
+ sprintf_s(new_buf,64,"%.09lf",number_float);
+ break;
+ }
number->SetText(new_buf);
RootView::GetInstance()->Invalidate();
}
else if (buf[0]=='D')
{
number_float=0;
- sprintf_s(new_buf,16,"%.02f",number_float);
+ sprintf_s(new_buf,16,"%.00lf",number_float);
number->SetText(new_buf);
number_falg=2;
RootView::GetInstance()->Invalidate();
void CalculatorView::symbol_text_updata_calculate_buf(const char *buf)
{
- char new_buf[32]={0};
+ char new_buf[64]={0};
const char*text_buf=number->GetText();
- float number_float=strtof(text_buf,NULL);
+
+ double number_float=strtod(text_buf,NULL);
+
CalculatorModel::GetInstance()->number_push_stack(number_float);
number_float =CalculatorModel::GetInstance()->calculate_stack();
+ double number_float_=number_float;
+ int decimal_places = 0;
+ double frac;
+
+ while (modf(number_float_ * pow(10, decimal_places), &frac) != 0.0f)
+ {
+ decimal_places++;
+ }
+
+ printf("该浮点数的小数部分有 %d %lf 位。\n", decimal_places,number_float);
+ switch (decimal_places)
+ {
+ case 0:
+ sprintf_s(new_buf,64,"%.00lf",number_float);
+ break;
+ case 1:
+ sprintf_s(new_buf,64,"%.01lf",number_float);
+ break;
+ case 2:
+ sprintf_s(new_buf,64,"%.02lf",number_float);
+ break;
+ case 3:
+ sprintf_s(new_buf,64,"%.03lf",number_float);
+ break;
+ case 4:
+ sprintf_s(new_buf,64,"%.04lf",number_float);
+ break;
+ case 6:
+ sprintf_s(new_buf,64,"%.06lf",number_float);
+ break;
+ case 7:
+ sprintf_s(new_buf,64,"%.07lf",number_float);
+ break;
+ case 8:
+ sprintf_s(new_buf,64,"%.08lf",number_float);
+ break;
+ default:
+ sprintf_s(new_buf,64,"%.09lf",number_float);
+ break;
+ }
+
// CalculatorModel::GetInstance()->number_push_stack(number_float);
number_falg=2;
- sprintf_s(new_buf,32,"%.02f",number_float);
+
number->SetText(new_buf);
RootView::GetInstance()->Invalidate();
Button[showdial_i]->SetViewId(dial_id_str[showdial_i]);// Set style
Button[showdial_i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+ Button[showdial_i]->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED);
if(j>2)
{
Button[showdial_i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFFF8A36);
+ Button[showdial_i]->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xFFFF8A36, UIButton::PRESSED);
if(i==0)
{
Button[showdial_i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFAAAAAA);
+ Button[showdial_i]->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xFFAAAAAA, UIButton::PRESSED);
}
}
Button[showdial_i]->SetText(dial_id_str[showdial_i]);
Button[showdial_i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40);
- Button[showdial_i]->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+
group->Add(Button[showdial_i]);
Button[showdial_i]->SetVisible(true);
// Set additional property
number->SetText("");
- number->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ number->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER);
number->SetRollSpeed(0);
number->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 50);
image1_ = new UIImageView();
}
image1_->SetPosition(378, 85); // widget's left position and top position
- image1_->Resize(100, 100); // widget's width and height
+ image1_->Resize(60, 60); // widget's width and height
image1_->SetViewId("D");// Set style
+ image1_->SetAutoEnable(false);
+ image1_->SetResizeMode(UIImageView::CENTER);
char* DimagesPath = "/user/res/Vector.bin";
group->Add(image1_);
image1_->SetVisible(true);
+
+
+ if (hint == nullptr) {
+ hint = new UILabelExt();
+ }
+ hint->SetPosition(109, 169); // widget's left position and top position
+ hint->Resize(247, 60); // widget's width and height
+ hint->SetViewId("label2");// Set style
+ hint->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+ hint->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ hint->SetStyle(STYLE_BORDER_RADIUS, 25);
+ hint->SetStyle(STYLE_PADDING_BOTTOM, 8);
+ hint->SetStyle(STYLE_TEXT_FONT, 30);
+ hint->SetStyle(STYLE_LINE_HEIGHT, 20);
+
+ // Set additional property
+ hint->SetText("超过数字长度范围");
+ hint->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
+ hint->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ hint->SetRollSpeed(0);
+ hint->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ group->Add(hint);
+ hint->SetVisible(false);
+
+
return true;
}