Read android config values [skip ci]

This commit is contained in:
saschawillems 2017-03-25 11:15:30 +01:00
parent 219da74df4
commit 9edc993bf9
4 changed files with 18 additions and 9 deletions

View file

@ -122,16 +122,15 @@ public:
#if defined(__ANDROID__) #if defined(__ANDROID__)
// Scale text on Android devices with high DPI // Scale text on Android devices with high DPI
int32_t screenDensity = vks::android::getScreenDensity(); if (vks::android::screenDensity >= ACONFIGURATION_DENSITY_XXHIGH) {
if (screenDensity >= ACONFIGURATION_DENSITY_XXHIGH) {
LOGD("XXHIGH"); LOGD("XXHIGH");
scale = 2.0f; scale = 2.0f;
} }
else if (screenDensity >= ACONFIGURATION_DENSITY_XHIGH) { else if (vks::android::screenDensity >= ACONFIGURATION_DENSITY_XHIGH) {
LOGD("XHIGH"); LOGD("XHIGH");
scale = 1.5f; scale = 1.5f;
} }
else if (screenDensity >= ACONFIGURATION_DENSITY_HIGH) { else if (vks::android::screenDensity >= ACONFIGURATION_DENSITY_HIGH) {
LOGD("HIGH"); LOGD("HIGH");
scale = 1.25f; scale = 1.25f;
}; };

View file

@ -119,6 +119,8 @@ PFN_vkCmdCopyQueryPoolResults vkCmdCopyQueryPoolResults;
PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR; PFN_vkCreateAndroidSurfaceKHR vkCreateAndroidSurfaceKHR;
PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR; PFN_vkDestroySurfaceKHR vkDestroySurfaceKHR;
int32_t vks::android::screenDensity;
void *libVulkan; void *libVulkan;
namespace vks namespace vks
@ -282,13 +284,13 @@ namespace vks
dlclose(libVulkan); dlclose(libVulkan);
} }
int32_t getScreenDensity() void getDeviceConfig()
{ {
// Screen density
AConfiguration* config = AConfiguration_new(); AConfiguration* config = AConfiguration_new();
AConfiguration_fromAssetManager(config, androidApp->activity->assetManager); AConfiguration_fromAssetManager(config, androidApp->activity->assetManager);
int32_t density = AConfiguration_getDensity(config); vks::android::screenDensity = AConfiguration_getDensity(config);
AConfiguration_delete(config); AConfiguration_delete(config);
return density;
} }
} }
} }

View file

@ -156,11 +156,17 @@ namespace vks
{ {
namespace android namespace android
{ {
/* @brief Touch control thresholds from Android NDK samples */
const int32_t DOUBLE_TAP_TIMEOUT = 300 * 1000000;
const int32_t DOUBLE_TAP_SLOP = 100;
/** @brief Density of the device screen (in DPI) */
extern int32_t screenDensity;
bool loadVulkanLibrary(); bool loadVulkanLibrary();
void loadVulkanFunctions(VkInstance instance); void loadVulkanFunctions(VkInstance instance);
void freeVulkanLibrary(); void freeVulkanLibrary();
/** @brief Returns the density of the device screen (in DPI) */ void getDeviceConfig();
int32_t getScreenDensity();
} }
} }

View file

@ -204,6 +204,7 @@ public:
} touchPos; } touchPos;
bool touchDown = false; bool touchDown = false;
double touchTimer = 0.0; double touchTimer = 0.0;
int64_t lastTapTime = 0;
/** @brief Product model and manufacturer of the Android device (via android.Product*) */ /** @brief Product model and manufacturer of the Android device (via android.Product*) */
std::string androidProduct; std::string androidProduct;
#elif defined(VK_USE_PLATFORM_WAYLAND_KHR) #elif defined(VK_USE_PLATFORM_WAYLAND_KHR)
@ -423,6 +424,7 @@ void android_main(android_app* state) \
state->onAppCmd = VulkanExample::handleAppCommand; \ state->onAppCmd = VulkanExample::handleAppCommand; \
state->onInputEvent = VulkanExample::handleAppInput; \ state->onInputEvent = VulkanExample::handleAppInput; \
androidApp = state; \ androidApp = state; \
vks::android::getDeviceConfig(); \
vulkanExample->renderLoop(); \ vulkanExample->renderLoop(); \
delete(vulkanExample); \ delete(vulkanExample); \
} }