AutoPtr<IRect> CRect::UnflattenFromString( /* [in] */ const String& str) { AutoPtr<IMatcher> matcher = UnflattenHelper::GetMatcher(str); Boolean matched = FALSE; if (matcher->Matches(&matched), !matched) { return NULL; } IMatchResult* matchResult = IMatchResult::Probe(matcher); String g1, g2, g3, g4; matchResult->Group(1, &g1); matchResult->Group(2, &g2); matchResult->Group(3, &g3); matchResult->Group(4, &g4); AutoPtr<IRect> rect; CRect::New(StringUtils::ParseInt32(g1), StringUtils::ParseInt32(g2), StringUtils::ParseInt32(g3), StringUtils::ParseInt32(g4), (IRect**)&rect); return rect; }
String Patterns::ConcatGroups( /* [in] */ IMatcher* matcher) { if (matcher == NULL) { return String(NULL); } IMatchResult* mr = IMatchResult::Probe(matcher); StringBuilder b; Int32 numGroups; mr->GroupCount(&numGroups); String s; for (Int32 i = 1; i <= numGroups; i++) { mr->Group(i, &s); if (s != NULL) { b += s; } } return b.ToString(); }
String Patterns::DigitsAndPlusOnly( /* [in] */ IMatcher* matcher) { if (matcher == NULL) { return String(NULL); } IMatchResult* mr = IMatchResult::Probe(matcher); StringBuilder buffer; String matchingRegion; mr->Group(&matchingRegion); AutoPtr<ArrayOf<Char32> > charArray = matchingRegion.GetChars(); Char32 character; for (UInt32 i = 0, size = charArray->GetLength(); i < size; i++) { character = (*charArray)[i]; if (character == '+' || Character::IsDigit(character)) { buffer += character; } } return buffer.ToString(); }
void OverlayDisplayAdapter::UpdateOverlayDisplayDevicesLocked() { AutoPtr<IContext> context = GetContext(); AutoPtr<IContentResolver> cr; context->GetContentResolver((IContentResolver**)&cr); String value; Settings::Global::GetString(cr, ISettingsGlobal::OVERLAY_DISPLAY_DEVICES, &value); if (value.IsNull()) { value = String(""); } if (value.Equals(mCurrentOverlaySetting)) { return; } mCurrentOverlaySetting = value; if (!mOverlays.IsEmpty()) { Slogger::I(TAG, "Dismissing all overlay display devices."); List<AutoPtr<OverlayDisplayHandle> >::Iterator iter = mOverlays.Begin(); for (; iter != mOverlays.End(); ++iter) { (*iter)->DismissLocked(); } mOverlays.Clear(); } AutoPtr<ArrayOf<String> > parts; StringUtils::Split(value, String(";"), (ArrayOf<String> **)&parts); if (parts != NULL) { AutoPtr<IResources> resources; context->GetResources((IResources**)&resources); assert(resources != NULL); String part; Int32 count = 0, width, height, densityDpi; Boolean matched; ECode ec = NOERROR; for (Int32 i = 0; i < parts->GetLength(); ++i) { part = (*parts)[i]; AutoPtr<IMatcher> matcher; SETTING_PATTERN->Matcher(part, (IMatcher**)&matcher); matcher->Matches(&matched); if (matched) { if (count >= 4) { Slogger::W(TAG, "Too many overlay display devices specified: %s", value.string()); break; } IMatchResult* mr = IMatchResult::Probe(matcher); String strGroup; mr->Group(1, &strGroup); ec = StringUtils::Parse(strGroup, 10, &width); if (ec == (ECode)E_NUMBER_FORMAT_EXCEPTION) continue; mr->Group(2, &strGroup); ec = StringUtils::Parse(strGroup, 10, &height); if (ec == (ECode)E_NUMBER_FORMAT_EXCEPTION) continue; mr->Group(3, &strGroup); ec = StringUtils::Parse(strGroup, 10, &densityDpi); if (ec == (ECode)E_NUMBER_FORMAT_EXCEPTION) continue; String flagString; mr->Group(4, &flagString); if (width >= MIN_WIDTH && width <= MAX_WIDTH && height >= MIN_HEIGHT && height <= MAX_HEIGHT && densityDpi >= IDisplayMetrics::DENSITY_LOW && densityDpi <= IDisplayMetrics::DENSITY_XXHIGH) { Int32 number = ++count; String name; resources->GetString(R::string::display_manager_overlay_display_name, &name); Int32 gravity = ChooseOverlayGravity(number); Boolean secure = !flagString.IsNull() && flagString.Contains(",secure"); Slogger::I(TAG, "Showing overlay display device #%d: name=%s, width=%d, height=%d, densityDpi=%d, secure=%d", number, name.string(), width, height, densityDpi, secure); AutoPtr<OverlayDisplayHandle> handle = new OverlayDisplayHandle(this, name, width, height, densityDpi, gravity, secure); mOverlays.PushBack(handle); continue; } } else if (part.IsEmpty()) { continue; } Slogger::W(TAG, "Malformed overlay display devices setting: %s", value.string()); } } }