Created
September 5, 2013 13:39
-
-
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.
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
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