### Install vcpkg Source: https://github.com/houstudio/cdroid/blob/master/README.md Clone and bootstrap the vcpkg package manager. ```bash git clone https://www.github.com/microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ``` -------------------------------- ### Copy Header Files and Install Library Source: https://github.com/houstudio/cdroid/blob/master/src/3rdparty/pinyin/CMakeLists.txt This snippet handles copying header files from the 'include' directory to the build directory and installs the 'pinyin' library to the system's library path. ```cmake file(GLOB PINYININC ${PROJECT_SOURCE_DIR}/include/*.h) file(COPY ${PINYININC} DESTINATION ${CMAKE_BINARY_DIR}/include/pinyin PATTERN "*.h") install(TARGETS pinyin DESTINATION lib) ``` -------------------------------- ### Install CDroid Dependencies Source: https://github.com/houstudio/cdroid/blob/master/README.md Install the necessary build tools and libraries on an Ubuntu system. ```bash sudo apt install autoconf libtool build-essential aapt cmake gdb pkg-config zip gettext libx11-dev libxcursor-dev libxcb1-dev libxcb-image0-dev libxcb-cursor-dev bison python>=3.7 pip3-python python3-lxml meson ``` -------------------------------- ### Install Package Configuration File Source: https://github.com/houstudio/cdroid/blob/master/src/porting/r818/CMakeLists.txt Configures and installs a pkg-config file for the cdroidhal library. This allows other projects to easily find and link against this library. ```cmake set(PREFIX ${CMAKE_INSTALL_PREFIX}) configure_file(cdroidhal.pc.in cdroidhal.pc @ONLY) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/cdroidhal.pc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig) ``` -------------------------------- ### Dependency and Include Directory Setup Source: https://github.com/houstudio/cdroid/blob/master/apps/curldownload/CMakeLists.txt Finds necessary packages like CURL, OpenSSL, and MBEDTLS. It also sets up include directories for project headers and external libraries. ```cmake find_package(CURL) include_directories( ./ ${CDROID_INCLUDE_DIRS} ${CDROID_DEPINCLUDES} ${CMAKE_BINARY_DIR}/include ${CMAKE_BINARY_DIR}/include/gui ${CMAKE_BINARY_DIR}/include/porting ${CMAKE_BINARY_DIR}/include/cairo ${CMAKE_BINARY_DIR}/include/epg ${CMAKE_BINARY_DIR}/include/freetype2 ) ``` ```cmake find_package(OpenSSL) find_package(MBEDTLS) ``` -------------------------------- ### Install CDroid Dependencies via Script Source: https://github.com/houstudio/cdroid/blob/master/README.md Install required libraries using the provided installation script. ```bash ./cdroid_install_libs.sh --triplet=x64-linux-dynamic ``` -------------------------------- ### Install Test Executable Source: https://github.com/houstudio/cdroid/blob/master/tests/porting/CMakeLists.txt Installs the 'hal_tests' executable to the 'bin/tests' directory on the target system. This ensures the tests can be run after deployment. ```cmake install (TARGETS hal_tests DESTINATION bin/tests) ``` -------------------------------- ### Install mpp_ge Library Source: https://github.com/houstudio/cdroid/blob/master/src/porting/d211/ge/CMakeLists.txt Installs the mpp_ge shared library to the system's library directory if CMAKE_INSTALL_FULL_LIBDIR is defined. This ensures the library is available after installation. ```cmake if(DEFINED CMAKE_INSTALL_FULL_LIBDIR) install(TARGETS mpp_ge RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}") endif() # CMAKE_INSTALL_FULL_LIBDIR ``` -------------------------------- ### Create and Install Shared Library Source: https://github.com/houstudio/cdroid/blob/master/src/porting/r818/CMakeLists.txt Defines the tvhal shared library using the collected source files and links it with specified libraries. It then installs the library to the target destination. ```cmake add_library(tvhal SHARED ${R818_SRCS} ) target_link_libraries(tvhal ${R818_LIBS} dl) install (TARGETS tvhal DESTINATION lib) install (FILES ${MILIBS} DESTINATION lib) ``` -------------------------------- ### Define Project and Find Dependencies Source: https://github.com/houstudio/cdroid/blob/master/tests/porting/CMakeLists.txt Initializes the CMake project and finds the required Google Test framework. Ensure GTEST is installed and discoverable by CMake. ```cmake project(haltest C CXX) find_package(GTEST REQUIRED) ``` -------------------------------- ### Install CDroid Toolchain Patches Source: https://github.com/houstudio/cdroid/blob/master/README.md Apply the required patches to the vcpkg installation. ```bash cp cdroid/scripts/vcpkgpatch4cdroid.tar.gz vcpkg/ cd vcpkg tar -zxvf vcpkgpatch4cdroid.tar.gz ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/houstudio/cdroid/blob/master/apps/curldownload/CMakeLists.txt Configures the CMake project for C and C++ and sets the C++ standard to 11. This is the initial setup for the build system. ```cmake project(curldownload C CXX) set(CMAKE_CXX_STANDARD 11) ``` -------------------------------- ### Library Linking and Executable Build Source: https://github.com/houstudio/cdroid/blob/master/apps/curldownload/CMakeLists.txt Builds the 'curldownload' executable if all dependencies are found. It links against atomic, cdroid, MBEDTLS, OpenSSL, and CURL libraries. The executable is installed to the bin directory. ```cmake if(CURL_FOUND AND OPENSSL_FOUND AND MBEDTLS_FOUND) add_executable(curldownload ${CURLDLD_SRCS}) target_link_libraries(curldownload PRIVATE atomic cdroid -Wl,--start-group ${MBEDTLS_LIBRARIES} ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} -Wl,--end-group) install(TARGETS curldownload DESTINATION bin) endif() ``` -------------------------------- ### Implement Button Click and Long Click Handlers Source: https://context7.com/houstudio/cdroid/llms.txt Buttons and other clickable widgets can be configured with event listeners. This example demonstrates setting a click listener using a lambda function to log a message and the button's ID, and a long-click listener that returns a boolean indicating if the event was handled. ```cpp #include int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, 800, 600); // Create button with text, width, height Button* btn = new Button("Click Me!", 150, 50); btn->setId(100); btn->setTextSize(24); btn->setTextAlignment(View::TEXT_ALIGNMENT_CENTER); // Load background drawable from resources Drawable* d = app.getDrawable("cdroid:drawable/btn_default"); btn->setBackground(d); // Set click listener using lambda btn->setOnClickListener([](View& v) { LOGD("Button clicked! ID: %d", v.getId()); }); // Long click listener btn->setOnLongClickListener([](View& v) -> bool { LOGD("Button long-clicked!"); return true; // Return true if handled }); w->addView(btn); btn->layout(100, 100, 150, 50); return app.exec(); } ``` -------------------------------- ### Find and Include Libraries Source: https://github.com/houstudio/cdroid/blob/master/src/porting/r818/CMakeLists.txt Finds necessary libraries like SDL2 and DirectFB, and includes header files to check for system features such as poll.h and epoll.h. This setup is crucial for cross-platform compatibility and feature detection. ```cmake #find_package(DirectFB) find_package(SDL2) include(CheckIncludeFile) check_include_file(poll.h HAVE_POLL_H) check_include_file(sys/epoll.h HAVE_EPOLL_H) check_include_file(linux/input.h HAVE_INPUT_H) check_include_file(execinfo.h HAVE_EXECINFO_H) check_include_file(drm.h HAVE_DRM_H) find_package(drm) ``` -------------------------------- ### Animate View Properties Source: https://context7.com/houstudio/cdroid/llms.txt Apply fluent API animations to view properties like translation, rotation, and scale. Supports start delays and custom durations. ```cpp #include int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, 800, 600); TextView* tv = new TextView("Animate Me!", 160, 60); tv->setBackgroundColor(0xFF444444); w->addView(tv); tv->layout(50, 50, 160, 60); // Property animator with fluent API tv->animate() .setDuration(2000) .translationX(400) // Move 400px right .translationY(200) // Move 200px down .alpha(0.5f) // Fade to 50% .rotation(360) // Rotate 360 degrees .scaleX(1.5f) // Scale 1.5x horizontal .scaleY(1.5f) // Scale 1.5x vertical .start(); // Animation with delay Button* btn = new Button("Delayed", 150, 50); w->addView(btn); btn->layout(50, 150, 150, 50); btn->animate() .setStartDelay(1000) .setDuration(1500) .translationX(300) .start(); return app.exec(); } ``` -------------------------------- ### CDroid CMakeLists.txt Configuration Source: https://github.com/houstudio/cdroid/blob/master/apps/samples/CMakeLists.txt This CMake script sets up the build environment for CDroid projects. It finds required packages like PLPLOT, CDroid, and Freetype, configures include directories, and defines build rules for example applications. ```cmake cmake_minimum_required (VERSION 3.8) project(gui_test C CXX) set(CMAKE_CXX_STANDARD 14) find_package(PLPLOT) find_package(CDROID) find_package(Freetype) include_directories( ./ ${CDROID_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} ${FONTCONFIG_INCLUDE_DIRS} ${CMAKE_BINARY_DIR}/include ${CMAKE_BINARY_DIR}/include/gui ${CMAKE_BINARY_DIR}/include/porting ${PLPLOT_INCLUDE_DIR} ${CAIRO_INCLUDE_DIRS} ${FREETYPE_INCLUDE_DIRS} ) if(CMAKE_SYSTEM_NAME STREQUAL "Linux") #set(CMAKE_CXX_FLAGS "-Wl,--copy-dt-needed-entries") #prevent error adding symbols: DSO missing from command line endif() link_directories(${CMAKE_BINARY_DIR}/lib) file(GLOB ExamplesFileList RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") add_custom_target(build_app_examples COMMENT A target that requires all the examples.) if(NOT ENABLE_PLPLOT) list(REMOVE_ITEM ExamplesFileList plot.cc) endif() #add_definitions(--include cdtypes.h) #add_definitions(--include cdlog.h) #add_definitions(--include core/stdpatch.h) link_directories({CMAKE_BINARY_DIR}/src/gui/Debug) if(BUILD_EXAMPLES) foreach(Example ${ExamplesFileList}) message(STATUS "\tCreating build rule for ${Example}") get_filename_component(ExampleName ${Example} NAME_WE) # Define example executable add_executable(${ExampleName} ${Example}) # Link example against curlpp target_link_libraries(${ExampleName} cdroid) # make the meta target depend on this example. add_dependencies(build_app_examples ${ExampleName}) install(TARGETS ${ExampleName} DESTINATION bin/examples) endforeach(Example ${ExamplesFileList}) endif(BUILD_EXAMPLES) ``` -------------------------------- ### Conditional Source and Library Inclusion Source: https://github.com/houstudio/cdroid/blob/master/src/porting/r818/CMakeLists.txt Conditionally adds source files and libraries to the build based on feature flags or availability. This example shows how to include DRM, DirectFB, or SDL2 specific sources and libraries. ```cmake if(EXECINFO_LIBRARY) list(APPEND R818_LIBS ${EXECINFO_LIBRARY}) endif() if(FALSE) list(APPEND R818_SRCS gfxdrm.cc graph_drm.cc) list(APPEND R818_LIBS drm) elseif(FALSE) list(APPEND R818_SRCS ./graph_fb.c) elseif(FALSE) list(APPEND R818_SRCS ./graph_sdl.c) list(APPEND R818_INCLUDE_DIRS ${SDL2_INCLUDE_DIRS}) list(APPEND R818_LIBS ${SDL2_LIBRARIES}) elseif(DIRECTFB_FOUND OR TRUE) list(APPEND R818_SRCS ../common/graph_dfb.c) list(APPEND R818_INCLUDE_DIRS ./directfb/include)#${DIRECTFB_INCLUDE_DIRS}) list(APPEND R818_LIBS rt fusion direct directfb)#${DIRECTFB_LIBRARIES}) endif() ``` -------------------------------- ### Prepare System and App Resources Source: https://github.com/houstudio/cdroid/blob/master/README.md Copy the required .pak files to the working directory. ```bash cp src/gui/cdroid.pak ./ cp apps/appname/appname.pak ./ ``` -------------------------------- ### Run CDroid Samples Source: https://github.com/houstudio/cdroid/blob/master/README.md Execute sample applications from the build directory. ```bash apps/samples/helloworld apps/uidemo1/uidemo1 ``` -------------------------------- ### Create and Configure Compound Buttons in C++ Source: https://context7.com/houstudio/cdroid/llms.txt Demonstrates how to create and configure CheckBox, RadioButton, and ToggleButton widgets. Includes setting IDs, drawables, initial states, and event listeners for state changes. ```cpp #include int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, 800, 600); // CheckBox CheckBox* chk = new CheckBox("Enable Feature", 200, 60); chk->setId(1000); chk->setChecked(true); chk->setButtonDrawable(app.getDrawable("cdroid:drawable/btn_check.xml")); chk->setOnCheckedChangeListener([](CompoundButton& btn, bool checked) { LOGD("Checkbox %p checked: %d", &btn, checked); }); w->addView(chk); chk->layout(50, 50, 200, 60); // RadioButton RadioButton* radio = new RadioButton("Option A", 120, 60); radio->setId(1001); radio->setButtonDrawable(app.getDrawable("cdroid:drawable/btn_radio.xml")); radio->setChecked(true); w->addView(radio); radio->layout(50, 120, 120, 60); // ToggleButton ToggleButton* toggle = new ToggleButton(120, 40); toggle->setId(1002); toggle->setTextOn("ON"); toggle->setTextOff("OFF"); toggle->setBackgroundResource("cdroid:drawable/btn_toggle_bg.xml"); toggle->setOnCheckedChangeListener([](CompoundButton& btn, bool checked) { LOGD("Toggle state: %s", checked ? "ON" : "OFF"); }); w->addView(toggle); toggle->layout(50, 190, 120, 40); return app.exec(); } ``` -------------------------------- ### Configure Allwinner CMake Build Source: https://github.com/houstudio/cdroid/blob/master/src/porting/allwinner/CMakeLists.txt Defines source files, checks for system headers, manages library dependencies, and sets up the static library target. ```cmake project (allwinner C CXX) set(ALLWINNER_SRCS input_linux.cc graph_nx5fb.c ) include(CheckIncludeFile) check_include_file(poll.h HAVE_POLL_H) check_include_file(sys/epoll.h HAVE_EPOLL_H) check_include_file(linux/input.h HAVE_INPUT_H) check_include_file(execinfo.h HAVE_EXECINFO_H) if(HAVE_POLL_H) list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_POLL_H) endif() if(HAVE_EPOLL_H) list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_EPOLL_H) endif() if(HAVE_INPUT_H) list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_INPUT_H) endif() if(HAVE_EXECINFO_H) list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_EXECINFO_H) endif() set(NX5ROOT_DIR .) find_library(LIBVIDEODEC_PATH VideoDec ${NX5ROOT_DIR}/thirdparty/lib/codec) list(APPEND ALLWINNER_LIBS pthread) if(LIBVIDEODEC_PATH) add_definitions(-DHAVE_FY_TDE2=1) list(APPEND ALLWINNER_LIBS ${LIBVIDEODEC_PATH}) endif() #sudo apt install libx11-dev if( ENABLE_RFB ) add_definitions(-DENABLE_RFB=1) list(APPEND ALLWINNER_SRCS ../common/rfbcommon.cc) list(APPEND ALLWINNER_LIBS vncserver) endif() find_package(ZLIB) include_directories(./ ../include ${ZLIB_INCLUDE_DIR} ${NX5ROOT_DIR}/thirdparty/include ${CMAKE_SOURCE_DIR}/src/gui/ ${CMAKE_SOURCE_DIR}/src/gui/core ${CMAKE_BINARY_DIR}/include ${CMAKE_SOURCE_DIR}/deps/include ${CMAKE_SOURCE_DIR}/deps/include/gui #for eventcodes.h ) add_library(allwinner STATIC ${ALLWINNER_SRCS} ) target_link_libraries(allwinner ${ALLWINNER_LIBS}) ``` -------------------------------- ### Initialize CDroid Application and Access Arguments Source: https://context7.com/houstudio/cdroid/llms.txt The App class is the entry point for CDroid applications. It handles initialization and provides methods to access command-line arguments with default values and check for their existence. Use this to set up your application's core and retrieve initial configuration. ```cpp #include int main(int argc, const char* argv[]) { // Initialize the application App app(argc, argv); // Access command-line arguments std::string language = app.getArg("language", "eng"); // Get string argument with default int alpha = app.getArgAsInt("alpha", 255); // Get int argument with default float scale = app.getArgAsFloat("scale", 1.0f); // Get float argument with default // Check if argument exists if (app.hasArg("debug")) { // Enable debug mode } // Set window opacity (0-255) app.setOpacity(alpha); // Create your UI here... Window* w = new Window(0, 0, 800, 600); w->setBackgroundColor(0xFF112233); // Start the event loop (blocking call) return app.exec(); } ``` -------------------------------- ### Define Project and Source Files Source: https://github.com/houstudio/cdroid/blob/master/src/porting/r818/CMakeLists.txt Defines the project name and lists the source files for the build. This is a standard CMake command to initialize a build. ```cmake project (r818 C CXX) set(R818_SRCS ../common/cdlog.cc ../common/input_linux.cc mediaplayer.c) ``` -------------------------------- ### Create Executable and Link Libraries Source: https://github.com/houstudio/cdroid/blob/master/tests/porting/CMakeLists.txt Builds the 'hal_tests' executable using the defined source files and links it with necessary libraries like 'tvhal', 'pthread', and Google Test. ```cmake add_executable(hal_tests ${SRCS_HAL}) target_link_libraries(hal_tests tvhal ${PTHREAD_LIBRARIES} ${GTEST_LIBRARIES}) ``` -------------------------------- ### Build wpa_ctrl Library Source: https://github.com/houstudio/cdroid/blob/master/src/modules/wpa/CMakeLists.txt Creates a static library named 'wpa_ctrl' from specified C and C++ source files. It also includes utility files for OS-specific functions and buffer management. ```cmake add_library(wpa_ctrl wpa_ctrl.c utils/os_unix.c utils/wpabuf.c) ``` -------------------------------- ### CMake Project Configuration Source: https://github.com/houstudio/cdroid/blob/master/src/gui/widget/html/CMakeLists.txt Initializes the project, sets default build types, and locates necessary dependencies. ```cmake project(litebrowser CXX) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "No build type selected, default to Release") set(CMAKE_BUILD_TYPE "Release") endif() find_package(PkgConfig REQUIRED) find_package(litehtml CONFIG) find_package(CURL CONFIG) ``` -------------------------------- ### Target and Library Configuration Source: https://github.com/houstudio/cdroid/blob/master/src/gui/widget/html/CMakeLists.txt Configures include directories, link options, and target properties for the project. ```cmake if(litehtml_FOUND) add_library(${PROJECT_NAME} ${SOURCE} ${HEADERS}) include_directories( ./ src containers ${LITEHTML_INCLUDE_DIRS} ${LB_LIBS_INCLUDE_DIRS} ${CDROID_DEPINCLUDES} ${CMAKE_BINARY_DIR}/include ${CMAKE_BINARY_DIR}/include/gui ${CMAKE_BINARY_DIR}/include/porting ${CMAKE_BINARY_DIR}/include/cairo ${CMAKE_BINARY_DIR}/include/epg ${CMAKE_BINARY_DIR}/include/freetype2 ) target_link_options(${PROJECT_NAME} PRIVATE ${LB_LIBS_LDFLAGS}) target_link_libraries(${PROJECT_NAME} litehtml )#CURL::libcurl ${LB_LIBS_LIBRARIES}) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11 C_STANDARD 99) add_executable(htmltest main.cpp) target_link_libraries(htmltest litebrowser cdroid) endif() ``` -------------------------------- ### Implement RecyclerView with LayoutManager Source: https://context7.com/houstudio/cdroid/llms.txt Demonstrates creating a custom adapter and configuring a RecyclerView with either a linear or grid layout manager and item decorations. ```cpp #include #include #include #include #include class MyAdapter : public RecyclerView::Adapter { private: std::vector items; public: class ViewHolder : public RecyclerView::ViewHolder { public: TextView* textView; ViewHolder(View* itemView) : RecyclerView::ViewHolder(itemView) { textView = (TextView*)itemView; } }; ViewHolder* onCreateViewHolder(ViewGroup* parent, int viewType) override { TextView* view = new TextView("", 200, 64); view->setBackgroundColor(0xFF234567); view->setGravity(Gravity::CENTER); view->setLayoutParams(new LayoutParams(LayoutParams::MATCH_PARENT, 60)); return new ViewHolder(view); } void onBindViewHolder(RecyclerView::ViewHolder& holder, int position) override { TextView* tv = ((ViewHolder&)holder).textView; tv->setText(items.at(position)); tv->setId(position); tv->setOnClickListener([position](View& v) { LOGD("Clicked item %d", position); }); } int getItemCount() override { return items.size(); } void add(const std::string& str) { items.push_back(str); notifyItemInserted(items.size() - 1); } }; int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, -1, -1); // Create RecyclerView RecyclerView* rv = new RecyclerView(800, 480); // Set layout manager (Linear or Grid) rv->setLayoutManager(std::make_unique(&app)); // Or: rv->setLayoutManager(std::make_unique(&app, 3)); // Create and set adapter MyAdapter* adapter = new MyAdapter(); for (int i = 0; i < 100; i++) { adapter->add("Item " + std::to_string(i)); } rv->setAdapter(adapter); // Add item decoration (dividers) DividerItemDecoration* decoration = new DividerItemDecoration(&app, LinearLayout::VERTICAL); decoration->setDrawable(new ColorDrawable(0xFFFF0000)); rv->addItemDecoration(decoration); // Configure scrolling rv->setOverScrollMode(View::OVER_SCROLL_ALWAYS); w->addView(rv); return app.exec(); } ``` -------------------------------- ### Implement Text Input with EditText in C++ Source: https://context7.com/houstudio/cdroid/llms.txt Shows how to create an EditText widget for text input. Covers setting initial text, appearance, hint text, single-line mode, and adding a text change listener. ```cpp #include int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, 800, 600); // Create EditText with initial text EditText* edt = new EditText("Edit Me!", 250, 50); edt->setId(102); // Set appearance edt->setBackground(app.getDrawable("cdroid:drawable/edit_text.xml")); edt->setTextColor(app.getColorStateList("cdroid:color/textview.xml")); edt->setTextSize(20); edt->setHint("Enter text here..."); edt->setSingleLine(true); w->addView(edt); edt->layout(50, 50, 250, 50); // Add text change listener TextWatcher watcher; watcher.afterTextChanged = [](std::wstring& text) { LOGD("Text changed"); }; edt->addTextChangedListener(watcher); return app.exec(); } ``` -------------------------------- ### Implement GridView Layout Source: https://context7.com/houstudio/cdroid/llms.txt Shows how to display items in a scrollable grid using a custom ArrayAdapter and configuring grid properties like column count and spacing. ```cpp #include class GridAdapter : public ArrayAdapter { public: View* getView(int position, View* convertView, ViewGroup* parent) override { ImageView* iv = (ImageView*)convertView; if (convertView == nullptr) { iv = new ImageView(100, 100); iv->setScaleType(ScaleType::FIT_XY); } iv->setId(position); iv->setBackgroundColor(0xFF000000 | (position * 123456)); return iv; } }; int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, 1280, 720); GridAdapter* adapter = new GridAdapter(); for (int i = 0; i < 100; i++) adapter->add(""); GridView* gv = new GridView(800, 640); gv->setAdapter(adapter); gv->setNumColumns(4); gv->setColumnWidth(180); gv->setHorizontalSpacing(10); gv->setVerticalSpacing(10); gv->setVerticalScrollBarEnabled(true); gv->setOverScrollMode(View::OVER_SCROLL_ALWAYS); gv->setSelector(new ColorDrawable(0x8800FF00)); adapter->notifyDataSetChanged(); w->addView(gv); return app.exec(); } ``` -------------------------------- ### wpa_ctrl CMakeLists.txt Configuration Source: https://github.com/houstudio/cdroid/blob/master/src/modules/wpa/utils/CMakeLists.txt Defines the build settings for the wpa_ctrl library, including C/C++ standards, module paths, and preprocessor definitions. It also specifies the source files and include directories for the library, along with compiler flags. ```cmake cmake_minimum_required(VERSION 3.2.2) project(wpa_ctrl C CXX) set(EXECUTABLE_BUILD_TYPE Release) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") add_definitions( -DCONFIG_AP=y -DCONFIG_AUTOSCAN_EXPONENTIAL=y -DCONFIG_AUTOSCAN_PERIODIC=y -DCONFIG_BACKEND=file -DCONFIG_BGSCAN_SIMPLE=y -DCONFIG_CTRL_IFACE=y -DCONFIG_CTRL_IFACE_UNIX=y -DCONFIG_DEBUG_FILE=y -DCONFIG_DRIVER_NL80211=y -DCONFIG_DRIVER_WEXT=y -DCONFIG_DRIVER_WIRED=y -DCONFIG_EAP_FAST=y -DCONFIG_EAP_GTC=y -DCONFIG_EAP_LEAP=y -DCONFIG_EAP_MD5=y -DCONFIG_EAP_MSCHAPV2=y -DCONFIG_EAP_OTP=y -DCONFIG_EAP_PEAP=y -DCONFIG_EAP_PWD=y -DCONFIG_EAP_TLS=y -DCONFIG_EAP_TTLS=y -DCONFIG_HS20=y -DCONFIG_HT_OVERRIDES=y -DCONFIG_IBSS_RSN=y -DCONFIG_IEEE80211AC=y -DCONFIG_IEEE80211N=y -DCONFIG_IEEE80211R=y -DCONFIG_IEEE80211W=y -DCONFIG_IEEE8021X_EAPOL=y -DCONFIG_INTERWORKING=y -DCONFIG_IPV6=y -DCONFIG_LIBNL32=y -DCONFIG_NO_RANDOM_POOL=y -DCONFIG_P2P=y -DCONFIG_PEERKEY=y -DCONFIG_PKCS12=y -DCONFIG_READLINE=y -DCONFIG_SMARTCARD=y -DCONFIG_TDLS=y -DCONFIG_VHT_OVERRIDES=y -DCONFIG_WIFI_DISPLAY=y -DCONFIG_WPS=y -DCONFIG_WPS_NFC=y -DCONFIG_TLS_DEFAULT_CIPHERS="DEFAULT:!EXP:!LOW:3DES") add_library(wpa_ctrl wpa_ctrl.c utils/os_unix.c utils/wpabuf.c) target_include_directories(wpa_ctrl PUBLIC "utils") target_include_directories(wpa_ctrl PUBLIC "./") target_compile_options(wpa_ctrl PUBLIC -Wall -Wextra -Wno-variadic-macros) ``` -------------------------------- ### Configure Include and Link Directories Source: https://github.com/houstudio/cdroid/blob/master/tests/porting/CMakeLists.txt Sets the directories for header files and libraries. Ensure all necessary header files are in the specified include paths and libraries are in the link directories. ```cmake include_directories( ./ ${GTEST_INCLUDE_DIRS} ${CMAKE_BINARY_DIR}/include ${CMAKE_BINARY_DIR}/include/gui ${CMAKE_BINARY_DIR}/include/porting ${CMAKE_SOURCE_DIR}/src/porting/include ) link_directories(${CMAKE_BINARY_DIR}/lib) ``` -------------------------------- ### Build CDroid Source: https://github.com/houstudio/cdroid/blob/master/README.md Compile the CDroid engine from source. ```bash cd cdroid ./build.sh --build=debug cd outX64-Debug make -j ``` -------------------------------- ### CMake Build Configuration for w9 Source: https://github.com/houstudio/cdroid/blob/master/apps/w9/CMakeLists.txt Defines the project requirements, include directories, source files, and linking instructions for the w9 executable. ```cmake cmake_minimum_required (VERSION 3.8) project(w9 C CXX) set(CMAKE_CXX_STANDARD 11) include_directories( ./ ${CDROID_INCLUDE_DIRS} ${CDROID_DEPINCLUDES} ${CMAKE_BINARY_DIR}/include ${CMAKE_BINARY_DIR}/include/gui ${CMAKE_BINARY_DIR}/include/porting ) aux_source_directory(./ W9_SRCS) add_definitions(--include cdtypes.h) add_definitions(--include cdlog.h) link_directories(${CMAKE_BINARY_DIR}/lib) add_executable(w9 ${W9_SRCS}) CreatePAK(w9 ${PROJECT_SOURCE_DIR}/assets ${PROJECT_BINARY_DIR}/w9.pak ${PROJECT_SOURCE_DIR}/R.h) message("CDROID_LIBRARIES=${CDROID_LIBRARIES} CDROID_INCLUDE_DIRS=${CDROID_INCLUDE_DIRS}") target_link_libraries(w9 PRIVATE cdroid) install(TARGETS w9 DESTINATION bin) ``` -------------------------------- ### Source and Header Definitions Source: https://github.com/houstudio/cdroid/blob/master/src/gui/widget/html/CMakeLists.txt Defines the source and header files required for the build. ```cmake set(SOURCE src/htmlview.cc src/webhistory.cc containers/linux/container_linux.cpp ) set(HEADERS src/htmlview.h src/webhistory.h containers/linux/container_linux.h ) ``` -------------------------------- ### Define Project and Source Files Source: https://github.com/houstudio/cdroid/blob/master/src/porting/ali3528/CMakeLists.txt Defines the project name and lists the C/C++ source files for the ali3528 library. Conditional compilation is used to include DTV-specific sources if ENABLE_DTV is set. ```cmake project (ali3528 C CXX) set(ALI_SRCS ngl_os.c ngl_msgq.c ngl_timer.c ngl_nvm.c graph_ali.c ngl_tuner.c ngl_panel.c ngl_pvr.c ngl_ir.cc ngl_mediaplayer.c ) if (ENABLE_DTV) list(APPEND ALI_SRCS ngl_dsc.c ngl_smc.c ngl_tuner.c ngl_dmx.cc ngl_nvm.c ngl_pvr.c ngl_snd.c ngl_video.c alidisp.c ) endif() list(APPEND ALI_LIBS pthread direct directfb aui) link_directories( ${TOOLCHAIN_DIR}/target/mipsel-buildroot-linux-gnu/sysroot/usr/lib ${TOOLCHAIN_DIR}/target/mipsel-buildroot-linux-gnu/sysroot/lib ) include_directories(./ ../include ${CMAKE_SOURCE_DIR}/src/gui/core ${CMAKE_BINARY_DIR}/include ${CMAKE_SOURCE_DIR}/deps/include ${TOOLCHAIN_DIR}/target/mipsel-buildroot-linux-gnu/sysroot/usr/include/directfb ${TOOLCHAIN_DIR}/host/usr/mipsel-buildroot-linux-gnu/sysroot/usr/include/directfb ) add_library(ali3528 STATIC ${ALI_SRCS} ) target_link_libraries(ali3528 ${ALI_LIBS}) ``` -------------------------------- ### Display Images with ImageView in C++ Source: https://context7.com/houstudio/cdroid/llms.txt Illustrates how to use the ImageView widget to display images from resources or file paths. Includes setting image drawables, resource IDs, scaling types, and corner radii. ```cpp #include int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, 800, 600); // Create ImageView ImageView* img = new ImageView(200, 200); img->setId(100); // Load image from resource Drawable* dr = app.getDrawable("cdroid:mipmap/ic_launcher"); img->setImageDrawable(dr); // Or load from file path/URL img->setImageResource("/path/to/image.png"); // Configure scaling and appearance img->setScaleType(ScaleType::FIT_XY); // FIT_CENTER, CENTER_CROP, etc. img->setCornerRadii(20); // Rounded corners img->setBackgroundColor(0xFF112233); w->addView(img); img->layout(100, 100, 200, 200); return app.exec(); } ``` -------------------------------- ### Implement Progress Indicators with ProgressBar and SeekBar in C++ Source: https://context7.com/houstudio/cdroid/llms.txt Demonstrates the usage of ProgressBar for progress indication and SeekBar for user-adjustable sliders. Covers setting progress, max values, drawables, and indeterminate states. ```cpp #include int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, 800, 600); // Horizontal ProgressBar ProgressBar* pb = new ProgressBar(400, 30); pb->setProgressDrawable(app.getDrawable("cdroid:drawable/progress_horizontal.xml")); pb->setProgress(34); pb->setSecondaryProgress(50); pb->setMax(100); w->addView(pb); pb->layout(50, 50, 400, 30); // Indeterminate (spinning) ProgressBar ProgressBar* spinner = new ProgressBar(72, 72); spinner->setIndeterminateDrawable(app.getDrawable("cdroid:drawable/progress_large.xml")); spinner->setIndeterminate(true); w->addView(spinner); spinner->layout(50, 100, 72, 72); // SeekBar (draggable slider) SeekBar* sb = new SeekBar(400, 40); sb->setProgressDrawable(app.getDrawable("cdroid:drawable/progress_horizontal.xml")); sb->setThumb(app.getDrawable("cdroid:drawable/seek_thumb.xml")); sb->setMax(100); sb->setProgress(50); w->addView(sb); sb->layout(50, 200, 400, 40); return app.exec(); } ``` -------------------------------- ### Implement ViewPager for Swipeable Pages Source: https://context7.com/houstudio/cdroid/llms.txt Requires a custom PagerAdapter to manage view instantiation and destruction. Use setOffscreenPageLimit to control pre-loading behavior. ```cpp #include #include class MyPageAdapter : public PagerAdapter { public: int getCount() override { return 5; } bool isViewFromObject(View* view, void* object) override { return view == object; } void* instantiateItem(ViewGroup* container, int position) override { TextView* tv = new TextView("Page " + std::to_string(position), 100, 100); tv->setTextSize(40); tv->setGravity(Gravity::CENTER); tv->setBackgroundColor(0xFF000000 | (position * 0x303030)); container->addView(tv); tv->setId(position); return tv; } void destroyItem(ViewGroup* container, int position, void* object) override { container->removeView((View*)object); delete (View*)object; } }; int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, -1, -1); MyPageAdapter* adapter = new MyPageAdapter(); ViewPager* pager = new ViewPager(800, 400); pager->setOffscreenPageLimit(3); // Pre-load adjacent pages pager->setAdapter(adapter); pager->setOverScrollMode(View::OVER_SCROLL_ALWAYS); pager->setHorizontalFadingEdgeEnabled(true); pager->setFadingEdgeLength(100); adapter->notifyDataSetChanged(); pager->setCurrentItem(0); w->addView(pager); return app.exec(); } ``` -------------------------------- ### Download CDroid Source Code Source: https://github.com/houstudio/cdroid/blob/master/README.md Clone the CDroid repository from Gitee. ```bash cd ~ git clone http://www.gitee.com/houstudio/cdroid.git ``` -------------------------------- ### Create and Configure CDroid Windows Source: https://context7.com/houstudio/cdroid/llms.txt The Window class serves as the top-level container for UI elements. It allows for creation of windows with specific dimensions, fullscreen modes, and customization of properties like ID, background color, and transparency. Window positioning and stacking order can also be managed. ```cpp #include int main(int argc, const char* argv[]) { App app(argc, argv); // Create a window with position and size // Window(x, y, width, height, type) // Use -1 for width/height to fill screen Window* w = new Window(0, 0, 1280, 720); // Or create fullscreen window Window* fullscreen = new Window(0, 0, -1, -1); // Set window properties w->setId(1); w->setBackgroundColor(0xFF223344); // ARGB format w->setAlpha(0.9f); // Window transparency // Window positioning w->setPos(100, 100); w->bringToFront(); w->sendToBack(); // Close window when done // w->close(); return app.exec(); } ``` -------------------------------- ### Define pinyin Library and dictbuild Executable Source: https://github.com/houstudio/cdroid/blob/master/src/3rdparty/pinyin/CMakeLists.txt Configures the main 'pinyin' library and the 'dictbuild' executable. It finds the Pthread library and links it to both targets. The 'dictbuild' executable is also defined with a specific compile definition. ```cmake project(pinyin C CXX) aux_source_directory(share PINYIN_SRCS) find_package(Pthread) add_library(pinyin ${PINYIN_SRCS}) include_directories(include) target_link_libraries(pinyin ${PTHREAD_LIBRARIES}) add_executable(dictbuild ${PINYIN_SRCS} command/pinyinime_dictbuilder.cpp) target_link_libraries(dictbuild ${PTHREAD_LIBRARIES}) target_compile_definitions(dictbuild PRIVATE ___BUILD_MODEL___) ``` -------------------------------- ### Source Directory and Definitions Source: https://github.com/houstudio/cdroid/blob/master/apps/curldownload/CMakeLists.txt Collects source files from the current directory and adds preprocessor definitions for cdtypes.h and cdlog.h. This prepares the source files for compilation. ```cmake aux_source_directory(./ CURLDLD_SRCS) add_definitions(--include cdtypes.h) add_definitions(--include cdlog.h) ``` -------------------------------- ### Configure Include Directories for wpa_ctrl Source: https://github.com/houstudio/cdroid/blob/master/src/modules/wpa/CMakeLists.txt Specifies the include directories for the 'wpa_ctrl' library. This ensures that header files from various locations, including project-specific and generated directories, are accessible during compilation. ```cmake include_directories(wpa_ctrl PUBLIC "utils" "./" ${CDROID_INCLUDE_DIRS} ${CDROID_DEPINCLUDES} ${CMAKE_BINARY_DIR}/include ${CMAKE_BINARY_DIR}/include/gui ${CMAKE_BINARY_DIR}/include/porting) ``` -------------------------------- ### CMake Build Configuration for uidemo2 Source: https://github.com/houstudio/cdroid/blob/master/apps/uidemo2/CMakeLists.txt Defines project settings, include paths, source files, and resource packaging for the uidemo2 executable. ```cmake cmake_minimum_required (VERSION 3.8) project(uidemo2 C CXX) set(CMAKE_CXX_STANDARD 11) include_directories( ./ ${CDROID_INCLUDE_DIRS} ${CDROID_DEPINCLUDES} ${CMAKE_BINARY_DIR}/include ${CMAKE_BINARY_DIR}/include/gui ${CMAKE_BINARY_DIR}/include/porting ) aux_source_directory(./ DEMO_SRCS) link_directories(${CMAKE_BINARY_DIR}/lib) add_executable(uidemo2 ${DEMO_SRCS}) CreatePAK(uidemo2 ${PROJECT_SOURCE_DIR}/assets ${PROJECT_BINARY_DIR}/uidemo2.pak ${PROJECT_SOURCE_DIR}/R.h) set(RESOURCES_DIR "${PROJECT_SOURCE_DIR}/assets") file(GLOB ASSET_FILES "${RESOURCES_DIR}/*") source_group(TREE "${RESOURCES_DIR}" PREFIX "Resources" FILES ${ASSET_FILES}) set(ANDROID_RESOURCE_DIR "${RESOURCES_DIR}") #android_add_resource_dir("${ANDROID_RESOURCE_DIR}") set(CMAKE_ANDROID_ASSETS_DIRECTORIES ${ANDROID_RESOURCE_DIR}) target_link_libraries(uidemo2 cdroid) install(TARGETS uidemo2 DESTINATION bin) ``` -------------------------------- ### Implement Custom ArrayAdapter for ListView Source: https://context7.com/houstudio/cdroid/llms.txt Create a custom ArrayAdapter to manage data for a ListView. Implement getView to recycle and bind views, and set properties like padding, text, color, and size. ```cpp #include // Custom adapter for list items class MyAdapter : public ArrayAdapter { public: MyAdapter() : ArrayAdapter() {} View* getView(int position, View* convertView, ViewGroup* parent) override { TextView* tv = (TextView*)convertView; // Recycle views for performance if (convertView == nullptr) { tv = new TextView("", 600, 40); tv->setPadding(20, 0, 0, 0); } // Bind data to view tv->setId(position); tv->setText("Item " + std::to_string(position)); tv->setTextColor(0xFFFFFFFF); tv->setBackgroundColor(0x80002222); tv->setTextSize(24); return tv; } }; int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, 800, 600); // Create adapter and populate data MyAdapter* adapter = new MyAdapter(); for (int i = 0; i < 50; i++) { adapter->add(""); } // Create ListView ListView* lv = new ListView(400, 500); lv->setId(100); lv->setAdapter(adapter); lv->setVerticalScrollBarEnabled(true); lv->setOverScrollMode(View::OVER_SCROLL_ALWAYS); lv->setSelector(new ColorDrawable(0x8800FF00)); // Selection highlight lv->setDivider(new ColorDrawable(0x80224422)); lv->setDividerHeight(1); // Item click listener lv->setOnItemClickListener([](AdapterView& lv, View& v, int pos, long id) { LOGD("Clicked item %d", pos); }); // Selection listener ListView::OnItemSelectedListener listener = {nullptr, nullptr}; listener.onItemSelected = [](AdapterView& lv, View& v, int pos, long id) { LOGD("Selected item %d", pos); }; lv->setOnItemSelectedListener(listener); adapter->notifyDataSetChanged(); w->addView(lv); lv->layout(50, 50, 400, 500); return app.exec(); } ``` -------------------------------- ### Implement DrawerLayout for Navigation Source: https://context7.com/houstudio/cdroid/llms.txt Configures a sliding panel with specific gravity settings. Use DrawerListener to handle animation callbacks during slide events. ```cpp #include #include int main(int argc, const char* argv[]) { App app(argc, argv); Window* w = new Window(0, 0, -1, -1); DrawerLayout* drawer = new DrawerLayout(100, 100); // Main content area LinearLayout* content = new LinearLayout(100, 100); content->setOrientation(LinearLayout::VERTICAL); content->setBackgroundColor(0xFF333333); Button* openBtn = new Button("Open Drawer", 150, 50); openBtn->setOnClickListener([drawer](View&) { drawer->openDrawer(Gravity::START); }); content->addView(openBtn); DrawerLayout::LayoutParams* contentLp = new DrawerLayout::LayoutParams( LayoutParams::MATCH_PARENT, LayoutParams::MATCH_PARENT); contentLp->gravity = Gravity::NO_GRAVITY; drawer->addView(content, 0, contentLp); // Left drawer panel LinearLayout* leftPanel = new LinearLayout(0, 0); leftPanel->setOrientation(LinearLayout::VERTICAL); leftPanel->setBackgroundColor(0xFF00AA00); TextView* menuTitle = new TextView("Menu", 200, 50); menuTitle->setTextSize(24); leftPanel->addView(menuTitle); DrawerLayout::LayoutParams* leftLp = new DrawerLayout::LayoutParams( 240, LayoutParams::MATCH_PARENT); leftLp->gravity = Gravity::START; drawer->addView(leftPanel, 1, leftLp); // Drawer listener for animations DrawerLayout::DrawerListener listener; listener.onDrawerSlide = [](View& view, float offset) { view.setAlpha(offset); }; drawer->addDrawerListener(listener); w->addView(drawer); return app.exec(); } ```