Skip to content

Instantly share code, notes, and snippets.

@Ray33
Ray33 / ImageResolutionChange.java
Created December 13, 2015 13:37
Sample code to change image resolution in url
protected String replaceImageResolution(String images) {
int sqIndex = images.indexOf("sq");
String f;
if (sqIndex != -1){
String prefix = images.substring(0,sqIndex + 3);
String suffix = images.substring(sqIndex + 3);
char c;
int startTrim = 0;
for(int i=0; i< suffix.length();i++){
c = suffix.charAt(i);
@Ray33
Ray33 / OpenChromeWithLink.java
Created April 7, 2016 05:15
Open chrome app with a given link, if user doesn't have chrome, will open with other browser app
{
"IAB1": "Arts & Entertainment",
"IAB1-1": "Books & Literature",
"IAB1-2": "Celebrity Fan/Gossip",
"IAB1-3": "Fine Art",
"IAB1-4": "Humor",
"IAB1-5": "Movies",
"IAB1-6": "Music",
"IAB1-7": "Television",
"IAB2": "Automotive",
@Ray33
Ray33 / WebViewLoading.java
Created November 18, 2016 07:42
Some webview settings to load web pages
private void initWebView() {
mWebView.setWebViewClient(new WebViewClientImpl());
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.loadUrl(mUrl);
}
@Ray33
Ray33 / IABCategory.java
Last active June 19, 2017 13:28
Supported IAB Categories The category Id is the enum name, without the IAB, e.g: for IAB25_2, the id would be 25_2
IAB25("Non-Standard Content",CategoryTier.T1),
IAB25_3("Pornography", CategoryTier.T2),
IAB25_2("Extreme Graphic and Explicit Violence",CategoryTier.T2),
IAB25_1("Unmoderated UGC",CategoryTier.T2),
IAB25_7("Incentivized",CategoryTier.T2),
IAB25_6("Under Construction",CategoryTier.T2),
IAB25_5("Hate Content",CategoryTier.T2),
IAB25_4("Profane Content",CategoryTier.T2),
IAB13("Personal Finance",CategoryTier.T1),
IAB13_9("Options",CategoryTier.T2),
@Ray33
Ray33 / GetBrowser.java
Created February 26, 2017 13:01
Get browser package
public static String getBrowserPackage(Intent intent, Context context){
PackageManager pm = context.getPackageManager();
List<ResolveInfo> appsList = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
String tmpPkg = "", pkg="";
for (ResolveInfo app : appsList){
tmpPkg = app.activityInfo.packageName.toLowerCase();
if ("com.android.chrome".equals(tmpPkg)){
return tmpPkg;
}
if (tmpPkg.contains("browse") || tmpPkg.contains("chrome") || tmpPkg.contains("com.UCMobile.intl") || tmpPkg.contains("org.mozilla.firefox") || tmpPkg.contains("com.opera.mini.native")){
@Ray33
Ray33 / Animation.java
Created April 10, 2017 09:13
open and close animation
private void animateClosing() {
AnimatorSet animator = new AnimatorSet();
ObjectAnimator translation = ObjectAnimator.ofFloat(mSideTabs, "translationX", 0, sideTabsWidth);
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(mSideTabs, "alpha", 1f, 0f);
animator.playTogether(translation, fadeOut);
animator.setDuration(300);
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
isAnimated = true;
@Ray33
Ray33 / UserCountryUtil.java
Created May 17, 2017 12:13
Get user country by network
/**
* Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
* @param context Context reference to get the TelephonyManager instance from
* @return country code or null
*/
public String getUserCountry(Context context) {
try {
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String simCountry = tm.getSimCountryIso();
if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
@Ray33
Ray33 / YourApplicationClass.java
Last active March 8, 2019 03:20
An Asynchronous method to get user google advertising id.
//callback for user id:
//Either takes the user's advertiserId or creates a unique ID, if
AsyncTask<Void, Void, String> task = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
try {
AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(YourApplicationClass.this);
if (!adInfo.isLimitAdTrackingEnabled()) {//if user hasn't opt-out
return adInfo.getId();
}else{
@Ray33
Ray33 / VideoAdsHelper.java
Last active November 14, 2017 15:42
Assemble requred parameters for video
public static String getVideoUrl(View view, String clickUrl) {
int height = 300, width = 600;
String appName ="";
String gpUrl="";
try {
appName = URLEncoder.encode(view.getContext().getString(R.string.app_name), "UTF-8");
gpUrl = URLEncoder.encode( "http://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();