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 / 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 / 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 / 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();
@Ray33
Ray33 / IsDeviceLowEnd.java
Last active November 15, 2017 14:01
Check if device is low end.Low end= Low Memory || Bad Network
private boolean getIsLowDevice(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
double availableMegs = (double)mi.availMem / 1048576d;
String networkType = getNetworkClass(context);
return "2G".equalsIgnoreCase(networkType) && availableMegs > 400;
}
@Ray33
Ray33 / NewsArticlesAdapter.java
Created December 6, 2017 14:12
Call visibility URL on bind
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int i) {
NewsArticle newsArticle = newsArticles.get(i);
final String articleVisibleUrl = newsArticle.visibleUrl;
if (!TextUtils.isEmpty(articleVisibleUrl) && newsArticle.isPromoted) {
Volley.newRequestQueue(context).add(new StringRequest(articleVisibleUrl, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
// Do nothing
@Ray33
Ray33 / visibility.js
Last active January 24, 2018 07:10
Visibility call via HTML
//initialize variables
var visible_urls = new Map();
var fired_urls = [];
//When news item is created, add it's id and the it's visibilityUrl to map
visible_urls.set(news_item.id, news_item.visibleUrl);
//call the url in background
function open_visible_url(url) {
if (url){