Skip to content

Commit dde8df7

Browse files
authored
Merge pull request flutter#10 from flutter/master
update master
2 parents 485a419 + 6b97d7d commit dde8df7

File tree

110 files changed

+1055
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1055
-150
lines changed

packages/connectivity/CHANGELOG.md

Lines changed: 4 additions & 0 deletions

packages/connectivity/example/README.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/connectivity/lib/connectivity.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:meta/meta.dart';
1515
/// None: Device not connected to any network
1616
enum ConnectivityResult { wifi, mobile, none }
1717

18+
/// Discover network connectivity configurations: Distinguish between WI-FI and cellular, check WI-FI status and more.
1819
class Connectivity {
1920
/// Constructs a singleton instance of [Connectivity].
2021
///
@@ -35,11 +36,13 @@ class Connectivity {
3536

3637
Stream<ConnectivityResult> _onConnectivityChanged;
3738

39+
/// Exposed for testing purposes and should not be used by users of the plugin.
3840
@visibleForTesting
3941
static const MethodChannel methodChannel = MethodChannel(
4042
'plugins.flutter.io/connectivity',
4143
);
4244

45+
/// Exposed for testing purposes and should not be used by users of the plugin.
4346
@visibleForTesting
4447
static const EventChannel eventChannel = EventChannel(
4548
'plugins.flutter.io/connectivity_status',

packages/connectivity/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for discovering the state of the network (WiFi &
33
mobile/cellular) connectivity on Android and iOS.
44
author: Flutter Team <[email protected]>
55
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity
6-
version: 0.4.5+3
6+
version: 0.4.5+4
77

88
flutter:
99
plugin:

packages/google_sign_in/CHANGELOG.md renamed to packages/google_sign_in/google_sign_in/CHANGELOG.md

Lines changed: 8 additions & 0 deletions

packages/google_sign_in/README.md renamed to packages/google_sign_in/google_sign_in/README.md

Lines changed: 2 additions & 2 deletions
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2019 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// A regular expression that matches against the "size directive" path
6+
/// segment of Google profile image URLs.
7+
///
8+
/// The format is is "`/sNN-c/`", where `NN` is the max width/height of the
9+
/// image, and "`c`" indicates we want the image cropped.
10+
final RegExp sizeDirective = RegExp(r'^s[0-9]{1,5}(-c)?$');
11+
12+
/// Adds [size] (and crop) directive to [photoUrl].
13+
///
14+
/// There are two formats for photoUrls coming from the Sign In backend.
15+
///
16+
/// The two formats can be told apart by the number of path segments in the
17+
/// URL (path segments: parts of the URL separated by slashes "/"):
18+
///
19+
/// * If the URL has 2 or less path segments, it is a *new* style URL.
20+
/// * If the URL has more than 2 path segments, it is an old style URL.
21+
///
22+
/// Old style URLs encode the image transformation directives as the last
23+
/// path segment. Look at the [sizeDirective] Regular Expression for more
24+
/// information about these URLs.
25+
///
26+
/// New style URLs carry the same directives at the end of the URL,
27+
/// after an = sign, like: "`=s120-c-fSoften=1,50,0`".
28+
///
29+
/// Directives may contain the "=" sign (`fSoften=1,50,0`), but it seems the
30+
/// base URL of the images don't. "Everything after the first = sign" is a
31+
/// good heuristic to split new style URLs.
32+
///
33+
/// Each directive is separated from others by dashes. Directives are the same
34+
/// as described in the [sizeDirective] RegExp.
35+
///
36+
/// Modified image URLs are recomposed by performing the parsing steps in reverse.
37+
String addSizeDirectiveToUrl(String photoUrl, double size) {
38+
final Uri profileUri = Uri.parse(photoUrl);
39+
final List<String> pathSegments = List<String>.from(profileUri.pathSegments);
40+
if (pathSegments.length <= 2) {
41+
final String imagePath = pathSegments.last;
42+
// Does this have any existing transformation directives?
43+
final int directiveSeparator = imagePath.indexOf('=');
44+
if (directiveSeparator >= 0) {
45+
// Split the baseUrl from the sizing directive by the first "="
46+
final String baseUrl = imagePath.substring(0, directiveSeparator);
47+
final String directive = imagePath.substring(directiveSeparator + 1);
48+
// Split the directive by "-"
49+
final Set<String> directives = Set<String>.from(directive.split('-'))
50+
// Remove the size directive, if present, and any empty values
51+
..removeWhere((String s) => s.isEmpty || sizeDirective.hasMatch(s))
52+
// Add the size and crop directives
53+
..addAll(<String>['c', 's${size.round()}']);
54+
// Recompose the URL by performing the reverse of the parsing
55+
pathSegments.last = '$baseUrl=${directives.join("-")}';
56+
} else {
57+
pathSegments.last = '${pathSegments.last}=c-s${size.round()}';
58+
}
59+
} else {
60+
// Old style URLs
61+
pathSegments
62+
..removeWhere(sizeDirective.hasMatch)
63+
..insert(pathSegments.length - 1, 's${size.round()}-c');
64+
}
65+
return Uri(
66+
scheme: profileUri.scheme,
67+
host: profileUri.host,
68+
pathSegments: pathSegments,
69+
).toString();
70+
}

packages/google_sign_in/lib/widgets.dart renamed to packages/google_sign_in/google_sign_in/lib/widgets.dart

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
88
import 'package:flutter/material.dart';
99

1010
import 'src/common.dart';
11+
import 'src/fife.dart' as fife;
1112

1213
/// Builds a CircleAvatar profile image of the appropriate resolution
1314
class GoogleUserCircleAvatar extends StatelessWidget {
@@ -33,7 +34,7 @@ class GoogleUserCircleAvatar extends StatelessWidget {
3334
///
3435
/// The format is is "`/sNN-c/`", where `NN` is the max width/height of the
3536
/// image, and "`c`" indicates we want the image cropped.
36-
static final RegExp sizeDirective = RegExp(r'^s[0-9]{1,5}(-c)?$');
37+
static final RegExp sizeDirective = fife.sizeDirective;
3738

3839
/// The Google user's identity; guaranteed to be non-null.
3940
final GoogleIdentity identity;
@@ -67,8 +68,7 @@ class GoogleUserCircleAvatar extends StatelessWidget {
6768
);
6869
}
6970

70-
/// Adds sizing information to [photoUrl], inserted as the last path segment
71-
/// before the image filename. The format is described in [sizeDirective].
71+
/// Adds correct sizing information to [photoUrl].
7272
///
7373
/// Falls back to the default profile photo if [photoUrl] is [null].
7474
static String _sizedProfileImageUrl(String photoUrl, double size) {
@@ -77,17 +77,7 @@ class GoogleUserCircleAvatar extends StatelessWidget {
7777
// the default profile photo as a last resort.
7878
return 'https://lh3.googleusercontent.com/a/default-user=s${size.round()}-c';
7979
}
80-
final Uri profileUri = Uri.parse(photoUrl);
81-
final List<String> pathSegments =
82-
List<String>.from(profileUri.pathSegments);
83-
pathSegments
84-
..removeWhere(sizeDirective.hasMatch)
85-
..insert(pathSegments.length - 1, 's${size.round()}-c');
86-
return Uri(
87-
scheme: profileUri.scheme,
88-
host: profileUri.host,
89-
pathSegments: pathSegments,
90-
).toString();
80+
return fife.addSizeDirectiveToUrl(photoUrl, size);
9181
}
9282

9383
Widget _buildClippedImage(BuildContext context, BoxConstraints constraints) {

packages/google_sign_in/pubspec.yaml renamed to packages/google_sign_in/google_sign_in/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: google_sign_in
22
description: Flutter plugin for Google Sign-In, a secure authentication system
33
for signing in with a Google account on Android and iOS.
44
author: Flutter Team <[email protected]>
5-
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in
6-
version: 4.0.11
5+
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
6+
version: 4.0.13
77

88
flutter:
99
plugin:
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2019 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:google_sign_in/src/fife.dart';
7+
8+
void main() {
9+
group('addSizeDirectiveToUrl', () {
10+
const double size = 20;
11+
12+
group('Old style URLs', () {
13+
const String base =
14+
'https://lh3.googleusercontent.com/-ukEAtRyRhw8/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3rfhID9XACtdb9q_xK43VSXQvBV11Q.CMID';
15+
const String expected = '$base/s20-c/photo.jpg';
16+
17+
test('with directives, sets size', () {
18+
final String url = '$base/s64-c/photo.jpg';
19+
expect(addSizeDirectiveToUrl(url, size), expected);
20+
});
21+
22+
test('no directives, sets size and crop', () {
23+
final String url = '$base/photo.jpg';
24+
expect(addSizeDirectiveToUrl(url, size), expected);
25+
});
26+
27+
test('no crop, sets size and crop', () {
28+
final String url = '$base/s64/photo.jpg';
29+
expect(addSizeDirectiveToUrl(url, size), expected);
30+
});
31+
});
32+
33+
group('New style URLs', () {
34+
const String base =
35+
'https://lh3.googleusercontent.com/a-/AAuE7mC0Lh4F4uDtEaY7hpe-GIsbDpqfMZ3_2UhBQ8Qk';
36+
const String expected = '$base=c-s20';
37+
38+
test('with directives, sets size', () {
39+
final String url = '$base=s120-c';
40+
expect(addSizeDirectiveToUrl(url, size), expected);
41+
});
42+
43+
test('no directives, sets size and crop', () {
44+
final String url = base;
45+
expect(addSizeDirectiveToUrl(url, size), expected);
46+
});
47+
48+
test('no directives, but with an equals sign, sets size and crop', () {
49+
final String url = '$base=';
50+
expect(addSizeDirectiveToUrl(url, size), expected);
51+
});
52+
53+
test('no crop, adds crop', () {
54+
final String url = '$base=s120';
55+
expect(addSizeDirectiveToUrl(url, size), expected);
56+
});
57+
58+
test('many directives, sets size and crop, preserves other directives',
59+
() {
60+
final String url = '$base=s120-c-fSoften=1,50,0';
61+
final String expected = '$base=c-fSoften=1,50,0-s20';
62+
expect(addSizeDirectiveToUrl(url, size), expected);
63+
});
64+
});
65+
});
66+
}
Lines changed: 3 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 26 additions & 0 deletions

0 commit comments

Comments
 (0)