Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple snippet building a docs.google URL if you have a webview with a pdf, doc, etc URL.
public class URLUtils {
private static final String fGOOGLE_DOC_URL = "http://docs.google.com/gview?embedded=true&url=%s";
private enum GoogleDocType{
PDF(".pdf"), DOC(".doc"), XLS(".xls"), DOCX(".docx"), XLSX(".xlsx");
private String mSuffix;
GoogleDocType(String suffix){
mSuffix = suffix;
}
private boolean isTypeOf(String url){
return url.endsWith(mSuffix);
}
}
public static String buildGoogleDocURL(String url){
if(TextUtils.isEmpty(url)) return null;
for(GoogleDocType type : GoogleDocType.values())
if(type.isTypeOf(url))
return String.format(fGOOGLE_DOC_URL, url);
return url;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment