Skip to content

Instantly share code, notes, and snippets.

@andreban
andreban / web.xml
Created December 12, 2013 18:48
Enabling trim white spaces on web.xml!
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
@andreban
andreban / gist:2f249ff1f9b45f2c5300
Created November 5, 2014 15:11
Creating a CORS Request that Works on IE 8 and IE 9
function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr){
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined"){
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
Intent actionIntent = new Intent(
this.getApplicationContext(), ShareBroadcastReceiver.class)
PendingIntent menuItemPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, actionIntent, 0);
String menuItemTitle = getString(R.string.menu_item_title);
intentBuilder.addMenuItem(menuItemTitle, menuItemPendingIntent);
public class CopyLinkBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Uri uri = intent.getData();
if (uri != null) {
ClipboardManager clipboardManager =
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newUri(null, uri.toString(), uri);
clipboardManager.setPrimaryClip(clipData);
}
//Append the parameter that identifies it is coming from the app
//to the URI. The name of the parameter and it's value is specific to
//the Analytics platform and how the developer wants to identify the app.
String url = "http;//www.google.com";
Uri uri = Uri.parse(url);
uri.buildUpon().appendQueryParameter("utm_source", "myApp");
Intent intent = new Intent(Intent.ACTION_SEND, uri);
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setCloseButtonIcon(BitmapFactory.decodeResource(
getResources(), R.drawable.ic_arrow_back));
CustomTabActivityHelper.openCustomTab(
this, intentBuilder.build(), Uri.parse(url), new WebviewFallback());
@andreban
andreban / gist:b809ba40454091845dd5
Last active June 14, 2017 07:48
Handling Clicks on android:linkify with Custom Tabs
/** CustomClickURLSpan **/
package com.example.android.customtabsadvanced;
import android.text.style.URLSpan;
import android.view.View;
public class CustomClickURLSpan extends URLSpan {
private OnClickListener mOnClickListener;
public CustomClickURLSpan(String url) {
public static Set<String> getNativeAppPackage(Context context, Uri uri) {
PackageManager pm = context.getPackageManager();
//Get all Apps that resolve a generic url
Intent browserActivityIntent
= new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
Set<String> genericResolvedList
= extractPackagenames(pm.queryIntentActivities(browserActivityIntent, 0));
//Get all apps that resolve the specific Url
@andreban
andreban / InternalLinks.java
Last active January 27, 2016 10:27
Handling Links on a WebView with Custom Tabs
@andreban
andreban / amp-carousel-captions.html
Created February 4, 2016 17:12
Adding a caption to amp-carousel