Files
android_vendor_pawlet/recovery_ui/gui/checkbox.cpp
T
oxmc f6176009b1 Add recovery_ui and recovery_toolkit scaffolding (first draft, not build-tested)
Stages TWRP's GUI engine and standalone tooling as PawletOS-owned modules
instead of a bootable/recovery fork, per the plugin-architecture finding in
NOTES-ota-recovery-ab.md: stock recovery_main.cpp already dlopen()s
librecovery_ui_ext.so and dlsym()s make_device() from it at runtime, so the
UI layer doesn't require touching stock bootable/recovery at all. Confirmed
via source grep that recovery.cpp/install.cpp have zero references into the
partition manager/backup engine/GUI code and vice versa.

recovery_ui/: TWRP's gui/, minuitwrp/, libpixelflinger/ (copied verbatim,
GPL-3.0), plus a new device/ providing PawletTwrpUI (a ScreenRecoveryUI
subclass) and make_device() — written from scratch against stock's
RecoveryUI/ScreenRecoveryUI virtual-method contract, since TWRP's own fork
never ships a make_device() (every real TWRP device provides its own, and
no reference device tree was available to copy from). Top-level Android.bp
defines librecovery_ui_pawlet_twrp, the module TARGET_RECOVERY_UI_LIB should
point at. gui/Android.bp and minuitwrp/Android.bp had their include_dirs
rewritten for the new paths.

recovery_toolkit/: partition manager, backup engine (tar/digest/adbbu/apex),
filesystem/format support (exfat/dosfstools/gpt/fuse/mtp/crypto), scripting
(openrecoveryscript/orscmd/twrpinstall), shared helpers. Source only, no
Android.bp yet for any of it.

Known gap blocking recovery_ui from actually linking: gui/'s libguitwrp
depends on libaosprecovery, built from recovery_toolkit/helpers/twrp.cpp via
a Go Soong plugin (libaosprecovery_defaults.go) not yet ported. Neither repo
has been build-tested — no local AOSP build environment available in this
workspace. See each directory's README.md for a precise done/not-done
breakdown.
2026-07-11 16:34:35 -07:00

195 lines
4.1 KiB
C++

/*
Copyright 2017 TeamWin
This file is part of TWRP/TeamWin Recovery Project.
TWRP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
TWRP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with TWRP. If not, see <http://www.gnu.org/licenses/>.
*/
// checkbox.cpp - GUICheckbox object
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/reboot.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <string>
extern "C" {
#include "../twcommon.h"
}
#include "minuitwrp/minui.h"
#include "rapidxml.hpp"
#include "objects.hpp"
GUICheckbox::GUICheckbox(xml_node<>* node)
: GUIObject(node)
{
xml_attribute<>* attr;
xml_node<>* child;
mChecked = NULL;
mUnchecked = NULL;
mLabel = NULL;
mRendered = false;
mLastState = 0;
if (!node)
return;
// The label can be loaded directly
mLabel = new GUIText(node);
// Read the check states
child = FindNode(node, "image");
if (child)
{
mChecked = LoadAttrImage(child, "checked");
mUnchecked = LoadAttrImage(child, "unchecked");
}
// Get the variable data
child = FindNode(node, "data");
if (child)
{
attr = child->first_attribute("variable");
if (attr)
mVarName = attr->value();
attr = child->first_attribute("default");
if (attr) {
DataManager::SetValue(mVarName, attr->value());
} else {
int val;
if (DataManager::GetValue(mVarName, val) != 0)
DataManager::SetValue(mVarName, 0); // Prevents check boxes from having to be tapped twice the first time
}
}
mCheckW = mCheckH = 0;
if (mChecked && mChecked->GetResource()) {
mCheckW = mChecked->GetWidth();
mCheckH = mChecked->GetHeight();
} else if (mUnchecked && mUnchecked->GetResource()) {
mCheckW = mUnchecked->GetWidth();
mCheckH = mUnchecked->GetHeight();
}
int x, y, w, h;
mLabel->GetRenderPos(x, y, w, h);
SetRenderPos(x, y, 0, 0);
}
GUICheckbox::~GUICheckbox()
{
}
int GUICheckbox::Render(void)
{
if (!isConditionTrue())
{
mRendered = false;
return 0;
}
int ret = 0;
int lastState = 0;
DataManager::GetValue(mVarName, lastState);
if (lastState)
{
if (mChecked && mChecked->GetResource())
gr_blit(mChecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
}
else
{
if (mUnchecked && mUnchecked->GetResource())
gr_blit(mUnchecked->GetResource(), 0, 0, mCheckW, mCheckH, mRenderX, mRenderY);
}
if (mLabel)
ret = mLabel->Render();
mLastState = lastState;
mRendered = true;
return ret;
}
int GUICheckbox::Update(void)
{
if (!isConditionTrue()) return (mRendered ? 2 : 0);
if (!mRendered) return 2;
int lastState = 0;
DataManager::GetValue(mVarName, lastState);
if (lastState != mLastState)
return 2;
return 0;
}
int GUICheckbox::SetRenderPos(int x, int y, int w, int h)
{
mRenderX = x;
mRenderY = y;
if (w || h)
return -1;
int textW, textH;
mLabel->GetCurrentBounds(textW, textH);
w = textW + mCheckW + 5;
mRenderW = w;
mRenderH = mCheckH;
mTextX = mRenderX + mCheckW + 5;
mTextY = mRenderY + (mCheckH / 2);
mLabel->SetRenderPos(mTextX, mTextY, 0, 0);
mLabel->SetPlacement(TEXT_ONLY_RIGHT);
mLabel->SetMaxWidth(gr_fb_width() - mTextX);
SetActionPos(mRenderX, mRenderY, mRenderW, mRenderH);
return 0;
}
int GUICheckbox::NotifyTouch(TOUCH_STATE state, int x __unused, int y __unused)
{
if (!isConditionTrue())
return -1;
if (state == TOUCH_RELEASE)
{
int lastState;
DataManager::GetValue(mVarName, lastState);
lastState = (lastState == 0) ? 1 : 0;
DataManager::SetValue(mVarName, lastState);
#ifndef TW_NO_HAPTICS
DataManager::Vibrate("tw_button_vibrate");
#endif
}
return 0;
}