diff options
Diffstat (limited to 'include/utils')
-rw-r--r-- | include/utils/ResourceTypes.h | 87 | ||||
-rw-r--r-- | include/utils/String8.h | 116 |
2 files changed, 170 insertions, 33 deletions
diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h index 93bca4a..edd0cae 100644 --- a/include/utils/ResourceTypes.h +++ b/include/utils/ResourceTypes.h @@ -825,7 +825,11 @@ struct ResTable_config }; enum { - DENSITY_ANY = 0 + DENSITY_DEFAULT = 0, + DENSITY_LOW = 120, + DENSITY_MEDIUM = 160, + DENSITY_HIGH = 240, + DENSITY_NONE = 0xffff }; union { @@ -854,7 +858,6 @@ struct ResTable_config enum { MASK_KEYSHIDDEN = 0x0003, - SHIFT_KEYSHIDDEN = 0, KEYSHIDDEN_ANY = 0x0000, KEYSHIDDEN_NO = 0x0001, KEYSHIDDEN_YES = 0x0002, @@ -906,10 +909,18 @@ struct ResTable_config }; enum { - SCREENLAYOUT_ANY = 0x0000, - SCREENLAYOUT_SMALL = 0x0001, - SCREENLAYOUT_NORMAL = 0x0002, - SCREENLAYOUT_LARGE = 0x0003, + // screenLayout bits for screen size class. + MASK_SCREENSIZE = 0x0f, + SCREENSIZE_ANY = 0x00, + SCREENSIZE_SMALL = 0x01, + SCREENSIZE_NORMAL = 0x02, + SCREENSIZE_LARGE = 0x03, + + // screenLayout bits for wide/long screen variation. + MASK_SCREENLONG = 0x30, + SCREENLONG_ANY = 0x00, + SCREENLONG_NO = 0x10, + SCREENLONG_YES = 0x20, }; union { @@ -1039,6 +1050,17 @@ struct ResTable_config } } + if (screenConfig || o.screenConfig) { + if (((screenLayout^o.screenLayout) & MASK_SCREENSIZE) != 0) { + if (!(screenLayout & MASK_SCREENSIZE)) return false; + if (!(o.screenLayout & MASK_SCREENSIZE)) return true; + } + if (((screenLayout^o.screenLayout) & MASK_SCREENLONG) != 0) { + if (!(screenLayout & MASK_SCREENLONG)) return false; + if (!(o.screenLayout & MASK_SCREENLONG)) return true; + } + } + if (screenType || o.screenType) { if (orientation != o.orientation) { if (!orientation) return false; @@ -1055,7 +1077,7 @@ struct ResTable_config } if (input || o.input) { - if (inputFlags != o.inputFlags) { + if (((inputFlags^o.inputFlags) & MASK_KEYSHIDDEN) != 0) { if (!(inputFlags & MASK_KEYSHIDDEN)) return false; if (!(o.inputFlags & MASK_KEYSHIDDEN)) return true; } @@ -1083,13 +1105,6 @@ struct ResTable_config } } - if (screenConfig || o.screenConfig) { - if (screenLayout != o.screenLayout) { - if (!screenLayout) return false; - if (!o.screenLayout) return true; - } - } - if (version || o.version) { if (sdkVersion != o.sdkVersion) { if (!sdkVersion) return false; @@ -1138,6 +1153,17 @@ struct ResTable_config } } + if (screenConfig || o.screenConfig) { + if (((screenLayout^o.screenLayout) & MASK_SCREENSIZE) != 0 + && (requested->screenLayout & MASK_SCREENSIZE)) { + return (screenLayout & MASK_SCREENSIZE); + } + if (((screenLayout^o.screenLayout) & MASK_SCREENLONG) != 0 + && (requested->screenLayout & MASK_SCREENLONG)) { + return (screenLayout & MASK_SCREENLONG); + } + } + if (screenType || o.screenType) { if ((orientation != o.orientation) && requested->orientation) { return (orientation); @@ -1219,12 +1245,6 @@ struct ResTable_config } } - if (screenConfig || o.screenConfig) { - if ((screenLayout != o.screenLayout) && requested->screenLayout) { - return (screenLayout); - } - } - if (version || o.version) { if ((sdkVersion != o.sdkVersion) && requested->sdkVersion) { return (sdkVersion); @@ -1272,6 +1292,21 @@ struct ResTable_config return false; } } + if (screenConfig != 0) { + const int screenSize = screenLayout&MASK_SCREENSIZE; + const int setScreenSize = settings.screenLayout&MASK_SCREENSIZE; + if (setScreenSize != 0 && screenSize != 0 + && screenSize != setScreenSize) { + return false; + } + + const int screenLong = screenLayout&MASK_SCREENLONG; + const int setScreenLong = settings.screenLayout&MASK_SCREENLONG; + if (setScreenLong != 0 && screenLong != 0 + && screenLong != setScreenLong) { + return false; + } + } if (screenType != 0) { if (settings.orientation != 0 && orientation != 0 && orientation != settings.orientation) { @@ -1316,12 +1351,6 @@ struct ResTable_config return false; } } - if (screenConfig != 0) { - if (settings.screenLayout != 0 && screenLayout != 0 - && screenLayout != settings.screenLayout) { - return false; - } - } if (version != 0) { if (settings.sdkVersion != 0 && sdkVersion != 0 && sdkVersion != settings.sdkVersion) { @@ -1351,12 +1380,14 @@ struct ResTable_config String8 toString() const { char buf[200]; sprintf(buf, "imsi=%d/%d lang=%c%c reg=%c%c orient=%d touch=%d dens=%d " - "kbd=%d nav=%d input=%d scrnW=%d scrnH=%d layout=%d vers=%d.%d", + "kbd=%d nav=%d input=%d scrnW=%d scrnH=%d sz=%d long=%d vers=%d.%d", mcc, mnc, language[0] ? language[0] : '-', language[1] ? language[1] : '-', country[0] ? country[0] : '-', country[1] ? country[1] : '-', orientation, touchscreen, density, keyboard, navigation, inputFlags, - screenWidth, screenHeight, screenLayout, sdkVersion, minorVersion); + screenWidth, screenHeight, + screenLayout&MASK_SCREENSIZE, screenLayout&MASK_SCREENLONG, + sdkVersion, minorVersion); return String8(buf); } }; diff --git a/include/utils/String8.h b/include/utils/String8.h index c49faf6..ecc5774 100644 --- a/include/utils/String8.h +++ b/include/utils/String8.h @@ -29,11 +29,107 @@ // --------------------------------------------------------------------------- +extern "C" { + +typedef uint32_t char32_t; + +size_t strlen32(const char32_t *); +size_t strnlen32(const char32_t *, size_t); + +/* + * Returns the length of "src" when "src" is valid UTF-8 string. + * Returns 0 if src is NULL, 0-length string or non UTF-8 string. + * This function should be used to determine whether "src" is valid UTF-8 + * characters with valid unicode codepoints. "src" must be null-terminated. + * + * If you are going to use other GetUtf... functions defined in this header + * with string which may not be valid UTF-8 with valid codepoint (form 0 to + * 0x10FFFF), you should use this function before calling others, since the + * other functions do not check whether the string is valid UTF-8 or not. + * + * If you do not care whether "src" is valid UTF-8 or not, you should use + * strlen() as usual, which should be much faster. + */ +size_t utf8_length(const char *src); + +/* + * Returns the UTF-32 length of "src". + */ +size_t utf32_length(const char *src, size_t src_len); + +/* + * Returns the UTF-8 length of "src". + */ +size_t utf8_length_from_utf32(const char32_t *src, size_t src_len); + +/* + * Returns the unicode value at "index". + * Returns -1 when the index is invalid (equals to or more than "src_len"). + * If returned value is positive, it is able to be converted to char32_t, which + * is unsigned. Then, if "next_index" is not NULL, the next index to be used is + * stored in "next_index". "next_index" can be NULL. + */ +int32_t utf32_at(const char *src, size_t src_len, + size_t index, size_t *next_index); + +/* + * Stores a UTF-32 string converted from "src" in "dst", if "dst_length" is not + * large enough to store the string, the part of the "src" string is stored + * into "dst". + * Returns the size actually used for storing the string. + * "dst" is not null-terminated when dst_len is fully used (like strncpy). + */ +size_t utf8_to_utf32(const char* src, size_t src_len, + char32_t* dst, size_t dst_len); + +/* + * Stores a UTF-8 string converted from "src" in "dst", if "dst_length" is not + * large enough to store the string, the part of the "src" string is stored + * into "dst" as much as possible. See the examples for more detail. + * Returns the size actually used for storing the string. + * dst" is not null-terminated when dst_len is fully used (like strncpy). + * + * Example 1 + * "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84) + * "src_len" == 2 + * "dst_len" >= 7 + * -> + * Returned value == 6 + * "dst" becomes \xE3\x81\x82\xE3\x81\x84\0 + * (note that "dst" is null-terminated) + * + * Example 2 + * "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84) + * "src_len" == 2 + * "dst_len" == 5 + * -> + * Returned value == 3 + * "dst" becomes \xE3\x81\x82\0 + * (note that "dst" is null-terminated, but \u3044 is not stored in "dst" + * since "dst" does not have enough size to store the character) + * + * Example 3 + * "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84) + * "src_len" == 2 + * "dst_len" == 6 + * -> + * Returned value == 6 + * "dst" becomes \xE3\x81\x82\xE3\x81\x84 + * (note that "dst" is NOT null-terminated, like strncpy) + */ +size_t utf32_to_utf8(const char32_t* src, size_t src_len, + char* dst, size_t dst_len); + +} + +// --------------------------------------------------------------------------- + namespace android { class TextOutput; -//! This is a string holding UTF-8 characters. +//! This is a string holding UTF-8 characters. Does not allow the value more +// than 0x10FFFF, which is not valid unicode codepoint. class String8 { public: @@ -45,7 +141,8 @@ public: explicit String8(const String16& o); explicit String8(const char16_t* o); explicit String8(const char16_t* o, size_t numChars); - + explicit String8(const char32_t* o); + explicit String8(const char32_t* o, size_t numChars); ~String8(); inline const char* string() const; @@ -59,11 +156,20 @@ public: status_t setTo(const char* other); status_t setTo(const char* other, size_t numChars); status_t setTo(const char16_t* other, size_t numChars); - + status_t setTo(const char32_t* other, + size_t length); + status_t append(const String8& other); status_t append(const char* other); status_t append(const char* other, size_t numChars); + // Note that this function takes O(N) time to calculate the value. + // No cache value is stored. + size_t getUtf32Length() const; + int32_t getUtf32At(size_t index, + size_t *next_index) const; + size_t getUtf32(char32_t* dst, size_t dst_len) const; + inline String8& operator=(const String8& other); inline String8& operator=(const char* other); @@ -103,7 +209,7 @@ public: void toLower(size_t start, size_t numChars); void toUpper(); void toUpper(size_t start, size_t numChars); - + /* * These methods operate on the string as if it were a path name. */ @@ -346,7 +452,7 @@ inline String8::operator const char*() const return mString; } -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- |