-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
downgrade minSDK to 7 with UriCompact
- Loading branch information
Showing
5 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
activityrouter/src/main/java/com/github/mzule/activityrouter/router/UriCompact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.github.mzule.activityrouter.router; | ||
|
||
import android.net.Uri; | ||
|
||
import java.util.Collections; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Created by CaoDongping on 6/1/16. | ||
*/ | ||
public class UriCompact { | ||
|
||
/** | ||
* Uri#getQueryParameterNames() 不支持 11 以下版本,这个方法提供兼容. | ||
* | ||
* @param uri Uri | ||
* @return Set | ||
*/ | ||
public static Set<String> getQueryParameterNames(Uri uri) { | ||
String query = uri.getEncodedQuery(); | ||
if (query == null) { | ||
return Collections.emptySet(); | ||
} | ||
|
||
Set<String> names = new LinkedHashSet<String>(); | ||
int start = 0; | ||
do { | ||
int next = query.indexOf('&', start); | ||
int end = (next == -1) ? query.length() : next; | ||
|
||
int separator = query.indexOf('=', start); | ||
if (separator > end || separator == -1) { | ||
separator = end; | ||
} | ||
|
||
String name = query.substring(start, separator); | ||
names.add(Uri.decode(name)); | ||
// Move start to end of name. | ||
start = end + 1; | ||
} while (start < query.length()); | ||
|
||
return Collections.unmodifiableSet(names); | ||
} | ||
|
||
} |