Android Open Source - octodroid Link From Project Back to project page octodroid .
License The source code is released under:
MIT License
If you think the Android project octodroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.rejasupotaro.octodroid.http;
/ / w w w . j a v a 2 s . c o m
import android.net.Uri;
import android.text.TextUtils;
public class Link {
public static enum Rel {
FIRST,
PREV,
NEXT,
LAST
}
private int page;
private int perPage;
private Rel rel;
public int getPage() {
return page;
}
public int getPerPage() {
return perPage;
}
public Rel getRel() {
return rel;
}
public Link(int page, int perPage, Rel rel) {
this.page = page;
this.perPage = perPage;
this.rel = rel;
}
public static Link fromSource(String source) {
if (TextUtils.isEmpty(source)) return null;
Uri resourceUri = getResourceUri(source);
int page = getPage(resourceUri);
int perPage = getPerPage(resourceUri);
Rel rel = getRel(source);
return new Link(page, perPage, rel);
}
private static Uri getResourceUri(String source) {
int startIndex = source.indexOf("<" );
int endIndex = source.indexOf(">" );
if (startIndex < 0 || endIndex < 0) {
return null;
} else {
String resourceString = source.substring(startIndex, endIndex + 1);
return Uri.parse(resourceString.substring(1, resourceString.length() - 1));
}
}
private static int getPage(Uri resourceUri) {
return getQueryParameter(resourceUri, "page" );
}
private static int getPerPage(Uri resourceUri) {
return getQueryParameter(resourceUri, "per_page" );
}
private static int getQueryParameter(Uri resourceUri, String key) {
if (resourceUri == null) return -1;
String param = resourceUri.getQueryParameter(key);
if (TextUtils.isEmpty(param)) {
return -1;
} else {
return Integer.valueOf(param);
}
}
private static Rel getRel(String source) {
if (source != null) {
for (Rel rel : Rel.values()) {
String pattern = "rel=\"" + rel.name().toLowerCase() + "\"" ;
if (source.indexOf(pattern) != -1) {
return rel;
}
}
}
return null;
}
}
Java Source Code List com.example.octodroid.ApplicationTest.java com.example.octodroid.MyApplication.java com.example.octodroid.SessionPrefsSchema.java com.example.octodroid.activities.LoginActivity.java com.example.octodroid.activities.MainActivity.java com.example.octodroid.activities.SearchResultActivity.java com.example.octodroid.adapters.HottestRepositoryAdapter.java com.example.octodroid.adapters.SearchResultAdapter.java com.example.octodroid.views.DividerItemDecoration.java com.example.octodroid.views.MoreLoadScrollListener.java com.example.octodroid.views.ProfileView.java com.example.octodroid.views.helpers.ProgressDialogHelper.java com.example.octodroid.views.helpers.ToastHelper.java com.example.octodroid.views.holders.ProgressViewHolder.java com.example.octodroid.views.holders.RepositoryItemViewHolder.java com.rejasupotaro.octodroid.ApplicationTest.java com.rejasupotaro.octodroid.AuthenticationRequired.java com.rejasupotaro.octodroid.ConnectivityObserver.java com.rejasupotaro.octodroid.GitHubClient.java com.rejasupotaro.octodroid.GitHub.java com.rejasupotaro.octodroid.GsonProvider.java com.rejasupotaro.octodroid.http.AbstractClient.java com.rejasupotaro.octodroid.http.ApiClient.java com.rejasupotaro.octodroid.http.CacheControl.java com.rejasupotaro.octodroid.http.Header.java com.rejasupotaro.octodroid.http.Link.java com.rejasupotaro.octodroid.http.Method.java com.rejasupotaro.octodroid.http.PaginationHeaderParserTest.java com.rejasupotaro.octodroid.http.PaginationHeaderParser.java com.rejasupotaro.octodroid.http.Pagination.java com.rejasupotaro.octodroid.http.RequestCreator.java com.rejasupotaro.octodroid.http.Response.java com.rejasupotaro.octodroid.http.params.All.java com.rejasupotaro.octodroid.http.params.Order.java com.rejasupotaro.octodroid.http.params.Participating.java com.rejasupotaro.octodroid.http.params.Sort.java com.rejasupotaro.octodroid.http.params.Type.java com.rejasupotaro.octodroid.models.Notification.java com.rejasupotaro.octodroid.models.Plan.java com.rejasupotaro.octodroid.models.Repository.java com.rejasupotaro.octodroid.models.Resource.java com.rejasupotaro.octodroid.models.SearchResult.java com.rejasupotaro.octodroid.models.Subject.java com.rejasupotaro.octodroid.models.User.java