Android native dpi (#2173)

* fix compiling error

* android get dpi in C++
This commit is contained in:
minggo
2020-02-24 16:09:13 +08:00
committed by GitHub
parent 20edb6a63e
commit bd68b01b4d
4 changed files with 8 additions and 22 deletions
@@ -489,7 +489,8 @@ void CanvasRenderingContext2D::set_font(const std::string& font)
// if regex rule that does not conform to the rules,such as Chinese,it defaults to sans-serif
std::match_results<std::string::const_iterator> fontResults;
std::regex fontRe("([\\w\\s-]+|\"[\\w\\s-]+\"$)");
if(std::regex_match(results[4].str(), fontResults, fontRe))
std::string tmp(results[4].str());
if(std::regex_match(tmp, fontResults, fontRe))
{
fontName = results[4].str();
}
@@ -148,7 +148,11 @@ int Device::getDPI()
static int dpi = -1;
if (dpi == -1)
{
dpi = JniHelper::callStaticIntMethod(JCLS_HELPER, "getDPI");
AConfiguration* config = AConfiguration_new();
AConfiguration_fromAssetManager(config, JniHelper::getAndroidApp()->activity->assetManager);
int32_t density = AConfiguration_getDensity(config);
AConfiguration_delete(config);
dpi = density * 160;
}
return dpi;
}
@@ -389,25 +389,6 @@ public class Cocos2dxHelper {
android.os.Process.killProcess(android.os.Process.myPid());
}
public static int getDPI()
{
if (sActivity != null)
{
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = sActivity.getWindowManager();
if (wm != null)
{
Display d = wm.getDefaultDisplay();
if (d != null)
{
d.getMetrics(metrics);
return (int)(metrics.density*160.0f);
}
}
}
return -1;
}
public static byte[] conversionEncoding(byte[] text, String fromCharset,String newCharset)
{
try {
@@ -3,7 +3,7 @@ APP_STL := c++_static
# Uncomment this line to compile to armeabi-v7a, your application will run faster but support less devices
APP_ABI := armeabi-v7a
APP_CPPFLAGS := -frtti -std=c++11 -fsigned-char
APP_CPPFLAGS := -frtti -std=c++14 -fsigned-char
APP_LDFLAGS := -latomic
# To solve windows commands char length too long