[apps] Add a battery icon for "is plugged and charged"

Change-Id: I874da0d15d57706338d6638dad911fdac9cc4397
This commit is contained in:
Émilie Feral
2017-05-04 16:56:12 +02:00
parent 9a52cf4f01
commit 3112ec07fc
7 changed files with 44 additions and 3 deletions

View File

@@ -176,7 +176,7 @@ void AppsContainer::switchTo(App * app) {
}
void AppsContainer::updateBatteryState() {
if (m_window.updateBatteryLevel() || m_window.updateIsChargingState()) {
if (m_window.updateBatteryLevel() || m_window.updateIsChargingState() || m_window.updatePluggedState()) {
m_window.redraw();
}
}

View File

@@ -22,6 +22,10 @@ bool AppsWindow::updateIsChargingState() {
return m_titleBarView.setIsCharging(Ion::Battery::isCharging());
}
bool AppsWindow::updatePluggedState() {
return m_titleBarView.setIsPlugged(Ion::USB::isPlugged());
}
void AppsWindow::refreshPreferences() {
m_titleBarView.refreshPreferences();
}

View File

@@ -10,6 +10,7 @@ public:
void setTitle(I18n::Message title);
bool updateBatteryLevel();
bool updateIsChargingState();
bool updatePluggedState();
void refreshPreferences();
bool updateAlphaLock();
void hideTitleBarView(bool hide);

View File

@@ -11,10 +11,22 @@ const uint8_t flashMask[BatteryView::k_flashHeight][BatteryView::k_flashWidth] =
{0xFF, 0x00, 0x00, 0xDB},
};
const uint8_t tickMask[BatteryView::k_tickHeight][BatteryView::k_tickWidth] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDB, 0x00, 0x24},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x6D, 0x00, 0xDB},
{0x6D, 0x00, 0xB7, 0xFF, 0xB7, 0x00, 0x24, 0xFF},
{0xDB, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0xFF},
{0xFF, 0xB7, 0x00, 0x24, 0x00, 0xB7, 0xFF, 0xFF},
{0xFF, 0xFF, 0x24, 0x00, 0x24, 0xFF, 0xFF, 0xFF},
};
BatteryView::BatteryView() :
View(),
m_chargeState(Ion::Battery::Charge::SOMEWHERE_INBETWEEN),
m_isCharging(false)
m_isCharging(false),
m_isPlugged(false)
{
}
@@ -36,7 +48,17 @@ bool BatteryView::setIsCharging(bool isCharging) {
return false;
}
bool BatteryView::setIsPlugged(bool isPlugged) {
if (m_isPlugged != isPlugged) {
m_isPlugged = isPlugged;
markRectAsDirty(bounds());
return true;
}
return false;
}
KDColor s_flashWorkingBuffer[BatteryView::k_flashHeight*BatteryView::k_flashWidth];
KDColor s_tickWorkingBuffer[BatteryView::k_tickHeight*BatteryView::k_tickWidth];
void BatteryView::drawRect(KDContext * ctx, KDRect rect) const {
/* We draw from left to right. The middle part representing the battery
@@ -47,6 +69,11 @@ void BatteryView::drawRect(KDContext * ctx, KDRect rect) const {
KDRect frame((k_batteryWidth-k_flashWidth)/2, 0, k_flashWidth, k_flashHeight);
ctx->blendRectWithMask(frame, KDColorWhite, (const uint8_t *)flashMask, s_flashWorkingBuffer);
}
if (!m_isCharging && m_isPlugged && m_chargeState == Ion::Battery::Charge::FULL) {
ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, k_batteryWidth-3*k_elementWidth-2*k_separatorThickness, k_batteryHeight), KDColorWhite);
KDRect frame((k_batteryWidth-k_tickWidth)/2, (k_batteryHeight-k_tickHeight)/2, k_tickWidth, k_tickHeight);
ctx->blendRectWithMask(frame, Palette::YellowDark, (const uint8_t *)tickMask, s_tickWorkingBuffer);
}
if (!m_isCharging && m_chargeState == Ion::Battery::Charge::LOW) {
ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, 2*k_elementWidth, k_batteryHeight), Palette::LowBattery);
ctx->fillRect(KDRect(3*k_elementWidth+k_separatorThickness, 0, k_batteryWidth-5*k_elementWidth-2*k_separatorThickness, k_batteryHeight), Palette::YellowLight);
@@ -55,7 +82,7 @@ void BatteryView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, (k_batteryWidth-3*k_elementWidth-2*k_separatorThickness)/2, k_batteryHeight), KDColorWhite);
ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness+(k_batteryWidth-3*k_elementWidth-2*k_separatorThickness)/2, 0, (k_batteryWidth-3*k_elementWidth-2*k_separatorThickness)/2, k_batteryHeight), Palette::YellowLight);
}
if (!m_isCharging && m_chargeState == Ion::Battery::Charge::FULL) {
if (!m_isCharging && !m_isPlugged && m_chargeState == Ion::Battery::Charge::FULL) {
ctx->fillRect(KDRect(k_elementWidth+k_separatorThickness, 0, k_batteryWidth-3*k_elementWidth-2*k_separatorThickness, k_batteryHeight), KDColorWhite);
}
ctx->fillRect(KDRect(k_batteryWidth-2*k_elementWidth, 0, k_elementWidth, k_batteryHeight), KDColorWhite);

View File

@@ -8,10 +8,13 @@ public:
BatteryView();
bool setChargeState(Ion::Battery::Charge chargeState);
bool setIsCharging(bool isCharging);
bool setIsPlugged(bool isPlugged);
void drawRect(KDContext * ctx, KDRect rect) const override;
KDSize minimalSizeForOptimalDisplay() const override;
constexpr static int k_flashHeight = 8;
constexpr static int k_flashWidth = 4;
constexpr static int k_tickHeight = 6;
constexpr static int k_tickWidth = 8;
private:
constexpr static KDCoordinate k_batteryHeight = 8;
constexpr static KDCoordinate k_batteryWidth = 15;
@@ -20,6 +23,7 @@ private:
constexpr static KDCoordinate k_separatorThickness = 1;
Ion::Battery::Charge m_chargeState;
bool m_isCharging;
bool m_isPlugged;
};
#endif

View File

@@ -34,6 +34,10 @@ bool TitleBarView::setIsCharging(bool isCharging) {
return m_batteryView.setIsCharging(isCharging);
}
bool TitleBarView::setIsPlugged(bool isPlugged) {
return m_batteryView.setIsPlugged(isPlugged);
}
bool TitleBarView::setAlphaLockStatus(AlphaLockView::Status status) {
return m_alphaLockView.setStatus(status);
}

View File

@@ -13,6 +13,7 @@ public:
void setTitle(I18n::Message title);
bool setChargeState(Ion::Battery::Charge chargeState);
bool setIsCharging(bool isCharging);
bool setIsPlugged(bool isPlugged);
bool setAlphaLockStatus(AlphaLockView::Status status);
void refreshPreferences();
private: