Skip to content

Instantly share code, notes, and snippets.

@Trinea
Trinea / gist:3ced6dedaa6fceccc90dd299acfee114
Created August 5, 2017 17:09 — forked from mediavrog/gist:5625602
Filter out Intents you don"t want to show from a IntentChooser dialog. For example your own app, competing apps or just apps you have a share integration by SDK already :) Based on http://stackoverflow.com/questions/5734678/custom-filtering-of-intent-chooser-based-on-installed-android-package-name/8550043#8550043
// Usage:
// blacklist
String[] blacklist = new String[]{"com.any.package", "net.other.package"};
// your share intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "some text");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "a subject");
// ... anything else you want to add
// invoke custom chooser
@Trinea
Trinea / gist:8570347ec8d4b65cac20
Created July 9, 2014 10:01
textview dynamic size
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, unitTextSize);
@Trinea
Trinea / git submodule continue
Created May 12, 2014 13:17
git submodule continue
git submodule foreach 'git checkout release_anjuke7.1 || :'
Add '|| :' to avoid Stopping at a submodule;
@Trinea
Trinea / IsNamedProcess
Last active August 29, 2015 14:00
whether process of context is named with processName, can be used to avoid application onCreate multi times
/**
* whether this process is named with processName
*
* @param processName
* @return
*/
private static boolean isNamedProcess(Context context, String processName) {
if (TextUtils.isEmpty(processName)) {
return true;
}
@Trinea
Trinea / PackageUtils
Last active August 29, 2015 13:56
get system install location
/**
* get system install location<br/>
* can be set by System Menu Setting->Storage->Prefered install location
*
* @return
* @see {@link IPackageManager#getInstallLocation()}
*/
public static int getInstallLocation() {
CommandResult commandResult = ShellUtils.execCommand("LD_LIBRARY_PATH=/vendor/lib:/system/lib pm get-install-location",
false, true);
@Trinea
Trinea / CustomFonts
Created February 7, 2014 12:51
Custom fonts in Android the easy way
use
Typeface typeface = Typeface.createFromAsset(assetManager, filePath)
and cache it
from: https://github.com/chrisjenx/Calligraphy/blob/master/calligraphy/src/main/java/uk/co/chrisjenx/calligraphy/TypefaceUtils.java
@Trinea
Trinea / DigestUtils
Last active January 4, 2016 15:49
get md5 and sha1 of file
System.out.println(org.apache.commons.codec.digest.DigestUtils.md5Hex(new FileInputStream("E:\\trinea-android-demo.apk")));
System.out.println(org.apache.commons.codec.digest.DigestUtils.sha1Hex(new FileInputStream("E:\\trinea-android-demo.apk")));
System.out.println(org.apache.commons.codec.digest.DigestUtils.sha512Hex(new FileInputStream("E:\\trinea-android-demo.apk")));
download url: http://commons.apache.org/proper/commons-codec/download_codec.cgi
api guide: http://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/digest/DigestUtils.html
@Trinea
Trinea / GetDNSSetting
Last active June 4, 2017 05:15
get the current DNS servers for Android
Class<?> SystemProperties = Class.forName("android.os.SystemProperties");
Method method = SystemProperties.getMethod("get", new Class[] { String.class });
ArrayList<String> servers = new ArrayList<String>();
for (String name : new String[] { "net.dns1", "net.dns2", "net.dns3", "net.dns4", }) {
String value = (String) method.invoke(null, name);
if (value != null && !"".equals(value) && !servers.contains(value))
servers.add(value);
}
@Trinea
Trinea / SearchView setOnClickListener
Last active January 4, 2016 01:59
SearchView setOnClickListener
public static void setSearchViewOnClickListener(View v, OnClickListener listener) {
if (v instanceof ViewGroup) {
ViewGroup group = (ViewGroup)v;
int count = group.getChildCount();
for (int i = 0; i < count; i++) {
View child = group.getChildAt(i);
if (child instanceof LinearLayout || child instanceof RelativeLayout) {
setSearchViewOnClickListener(child, listener);
}