[apps] Alpha Lock icon

Change-Id: Ie5a2f4e6b3fae2e14808430e2207306cae2bd7c2
This commit is contained in:
Émilie Feral
2017-04-26 17:26:34 +02:00
parent dd958dcbd8
commit 4f5b35a4b3
10 changed files with 174 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ include apps/statistics/Makefile
#include apps/picview/Makefile
app_objs += $(addprefix apps/,\
alpha_lock_view.o\
apps_container.o\
apps_window.o\
battery_timer.o\
@@ -22,6 +23,7 @@ app_objs += $(addprefix apps/,\
global_preferences.o\
i18n.o\
led_timer.o\
lock_view.o\
main.o\
math_toolbox.o\
node.o\

65
apps/alpha_lock_view.cpp Normal file
View File

@@ -0,0 +1,65 @@
#include "alpha_lock_view.h"
AlphaLockView::AlphaLockView() :
View(),
m_alphaView(KDText::FontSize::Small, I18n::Message::Default, 1.0f, 0.5f, KDColorWhite, Palette::YellowDark),
m_status(Status::Default)
{
}
void AlphaLockView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), Palette::YellowDark);
}
bool AlphaLockView::setStatus(Status status) {
if (status != m_status) {
m_status = status;
if (m_status == Status::Alpha || m_status == Status::AlphaLock) {
m_alphaView.setMessage(I18n::Message::Alpha);
} else if (m_status == Status::CapitalAlpha || m_status == Status::CapitalAlphaLock) {
m_alphaView.setMessage(I18n::Message::CapitalAlpha);
} else {
m_alphaView.setMessage(I18n::Message::Default);
}
markRectAsDirty(bounds());
return true;
}
return false;
}
KDSize AlphaLockView::minimalSizeForOptimalDisplay() const {
KDSize alphaSize = KDText::stringSize(I18n::translate(I18n::Message::Alpha));
KDSize lockSize = m_lockView.minimalSizeForOptimalDisplay();
KDCoordinate height = lockSize.height() > alphaSize.height() ? lockSize.height() : alphaSize.height();
return KDSize(alphaSize.width() + lockSize.width() + k_lockRightMargin, height);
}
int AlphaLockView::numberOfSubviews() const {
switch (m_status) {
case Status::Alpha:
return 1;
case Status::AlphaLock:
return 2;
case Status::CapitalAlpha:
return 1;
case Status::CapitalAlphaLock:
return 2;
default:
return 0;
}
}
View * AlphaLockView::subviewAtIndex(int index) {
if (index == 0) {
return &m_alphaView;
}
return &m_lockView;
}
void AlphaLockView::layoutSubviews() {
KDSize alphaSize = KDText::stringSize(I18n::translate(I18n::Message::Alpha), KDText::FontSize::Small);
m_alphaView.setFrame(KDRect(bounds().width() - alphaSize.width(), (bounds().height()- alphaSize.height())/2, alphaSize));
KDSize lockSize = m_lockView.minimalSizeForOptimalDisplay();
m_lockView.setFrame(KDRect(bounds().width() - alphaSize.width() - lockSize.width() - k_lockRightMargin, (bounds().height()- lockSize.height())/2, lockSize));
}

31
apps/alpha_lock_view.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef APPS_ALPHA_LOCK_VIEW_H
#define APPS_ALPHA_LOCK_VIEW_H
#include <escher.h>
#include "lock_view.h"
#include "i18n.h"
class AlphaLockView : public View {
public:
enum class Status {
Default,
Alpha,
AlphaLock,
CapitalAlpha,
CapitalAlphaLock
};
AlphaLockView();
void drawRect(KDContext * ctx, KDRect rect) const override;
bool setStatus(Status status);
KDSize minimalSizeForOptimalDisplay() const override;
private:
constexpr static KDCoordinate k_lockRightMargin = 5;
int numberOfSubviews() const override;
void layoutSubviews() override;
View * subviewAtIndex(int index) override;
LockView m_lockView;
MessageTextView m_alphaView;
Status m_status;
};
#endif

View File

@@ -92,6 +92,9 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
m_backlightDimmingTimer.reset();
m_suspendTimer.reset();
Ion::Backlight::setBrightness(Ion::Backlight::MaxBrightness);
bool alphaLockWantsRedraw = m_window.updateAlphaLock();
// Home and Power buttons are not sent to apps. We handle them straight away.
if (event == Ion::Events::Home && activeApp() != &m_hardwareTestApp) {
switchTo(appAtIndex(0));
@@ -106,6 +109,10 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
switchTo(appAtIndex(0));
return true;
}
if (!didProcessEvent && alphaLockWantsRedraw) {
window()->redraw();
return true;
}
return didProcessEvent;
}

View File

@@ -25,6 +25,22 @@ void AppsWindow::refreshPreferences() {
m_titleBarView.refreshPreferences();
}
bool AppsWindow::updateAlphaLock() {
AlphaLockView::Status alphaLockStatus = AlphaLockView::Status::Default;
if (Ion::Events::isAlphaLocked()) {
alphaLockStatus = AlphaLockView::Status::AlphaLock;
} else if (Ion::Events::isShiftAlphaLocked()) {
alphaLockStatus = AlphaLockView::Status::CapitalAlphaLock;
} else if (Ion::Events::isAlphaActive()) {
if (Ion::Events::isShiftActive()) {
alphaLockStatus = AlphaLockView::Status::CapitalAlpha;
} else {
alphaLockStatus = AlphaLockView::Status::Alpha;
}
}
return m_titleBarView.setAlphaLockStatus(alphaLockStatus);
}
int AppsWindow::numberOfSubviews() const {
return (m_contentView == nullptr ? 1 : 2);
}

View File

@@ -11,6 +11,7 @@ public:
bool updateBatteryLevel();
bool updateIsChargingState();
void refreshPreferences();
bool updateAlphaLock();
private:
constexpr static KDCoordinate k_titleBarHeight = 18;
int numberOfSubviews() const override;

24
apps/lock_view.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include "lock_view.h"
const uint8_t lockMask[LockView::k_lockHeight][LockView::k_lockWidth] = {
{0xFF, 0xE1, 0x0C, 0x00, 0x0C, 0xE1, 0xFF},
{0xFF, 0x0C, 0xE1, 0xFF, 0xE1, 0x0C, 0xFF},
{0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
};
KDColor s_lockWorkingBuffer[LockView::k_lockHeight*LockView::k_lockWidth];
void LockView::drawRect(KDContext * ctx, KDRect rect) const {
KDRect frame((bounds().width() - k_lockWidth)/2, (bounds().height()-k_lockHeight)/2, k_lockWidth, k_lockHeight);
ctx->blendRectWithMask(frame, KDColorWhite, (const uint8_t *)lockMask, s_lockWorkingBuffer);
}
KDSize LockView::minimalSizeForOptimalDisplay() const {
return KDSize(k_lockWidth, k_lockHeight);
}

14
apps/lock_view.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef APPS_LOCK_VIEW_H
#define APPS_LOCK_VIEW_H
#include <escher.h>
class LockView : public View {
public:
void drawRect(KDContext * ctx, KDRect rect) const override;
KDSize minimalSizeForOptimalDisplay() const override;
constexpr static int k_lockHeight = 9;
constexpr static int k_lockWidth = 7;
};
#endif

View File

@@ -34,8 +34,12 @@ bool TitleBarView::setIsCharging(bool isCharging) {
return m_batteryView.setIsCharging(isCharging);
}
bool TitleBarView::setAlphaLockStatus(AlphaLockView::Status status) {
return m_alphaLockView.setStatus(status);
}
int TitleBarView::numberOfSubviews() const {
return 4;
return 5;
}
View * TitleBarView::subviewAtIndex(int index) {
@@ -48,6 +52,9 @@ View * TitleBarView::subviewAtIndex(int index) {
if (index == 2) {
return &m_examModeIconView;
}
if (index == 3) {
return &m_alphaLockView;
}
return &m_batteryView;
}
@@ -66,6 +73,8 @@ void TitleBarView::layoutSubviews() {
} else {
m_examModeIconView.setFrame(KDRectZero);
}
KDSize alphaLockSize = m_alphaLockView.minimalSizeForOptimalDisplay();
m_alphaLockView.setFrame(KDRect(bounds().width()-batterySize.width()-k_batteryRightMargin-k_alphaRightMargin-alphaLockSize.width(), (bounds().height()- alphaLockSize.height())/2, alphaLockSize));
}
void TitleBarView::refreshPreferences() {

View File

@@ -3,6 +3,7 @@
#include <escher.h>
#include "battery_view.h"
#include "alpha_lock_view.h"
#include "i18n.h"
class TitleBarView : public View {
@@ -12,9 +13,11 @@ public:
void setTitle(I18n::Message title);
bool setChargeState(Ion::Battery::Charge chargeState);
bool setIsCharging(bool isCharging);
bool setAlphaLockStatus(AlphaLockView::Status status);
void refreshPreferences();
private:
constexpr static KDCoordinate k_batteryRightMargin = 5;
constexpr static KDCoordinate k_alphaRightMargin = 5;
constexpr static KDCoordinate k_preferenceMargin = 3;
constexpr static KDCoordinate k_examIconWidth = 18;
constexpr static KDCoordinate k_examIconHeight = 9;
@@ -24,6 +27,7 @@ private:
View * subviewAtIndex(int index) override;
MessageTextView m_titleView;
BatteryView m_batteryView;
AlphaLockView m_alphaLockView;
BufferTextView m_preferenceView;
ImageView m_examModeIconView;
};