Skip to content

Instantly share code, notes, and snippets.

@castorflex
Created September 5, 2013 13:39
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save castorflex/6450237 to your computer and use it in GitHub Desktop.
Save castorflex/6450237 to your computer and use it in GitHub Desktop.
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