Skip to content

Instantly share code, notes, and snippets.

@granoeste
granoeste / gist:3243388
Created August 3, 2012 01:56
[Android] Fillter in Logcat
tag:^(?!.*(DeskClock|dalvik|wpa|System.out)).*$
@granoeste
granoeste / _readme.txt
Created August 22, 2012 08:56
[Android] Do you want to close the activiy in the fragment?
Q.
I want to close the activiy in Fragment.
フラグメントでアクティビティをクローズしたい。
A.
Do not control the activity in the fragment!
フラグメントでアクティビティの操作をするな。
Controlled by the Activity using the callback.
コールバックでアクティビティの操作をするべきである。
@granoeste
granoeste / ListFragmentWithHeaderAndFooter.java
Last active October 11, 2015 03:48
[Android] ListView#getAdapter attention when addFooterView / addHeaderView
public class MyListFragment extends Fragment {
private LayoutInflater mLayoutInflater;
private ListView mListView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mLayoutInflater = getLayoutInflater(savedInstanceState);
return inflater.inflate(R.layout.fragment_list, container, false);
}
@granoeste
granoeste / SequenceOfMethods.java
Created October 4, 2012 09:23
[Android] SimpleCursorAdapter. Sequence of methods for the view.
public class MyCursorAdapter extends SimpleCursorAdapter
implements SimpleCursorAdapter.ViewBinder {
public MyListCursorAdapter(Context context) {
super(context,
android.R.layout.simple_list_item_2, null,
new String[] { Contacts.DISPLAY_NAME, Contacts.CONTACT_STATUS },
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
setViewBinder(this);
@granoeste
granoeste / addJavascriptInterface.md
Last active October 11, 2015 10:18
[Android] Security Considerations of JavascriptInterface of WebView

public void [addJavascriptInterface] (Object object, String name)

Since: API Level 1

Injects the supplied Java object into this WebView. The object is injected into the JavaScript context of the main frame, using the supplied name. This allows the Java object's public methods to be accessed from JavaScript. Note that that injected objects will not appear in JavaScript until the page is next (re)loaded. For example:

webView.addJavascriptInterface(new Object(), "injectedObject");  
webView.loadData("", "text/html", null);  
webView.loadUrl("javascript:alert(injectedObject.toString())");  
@granoeste
granoeste / attrs.xml
Created November 8, 2012 07:16
[Android] Attributes define in the Enum or Flag
<!-- Default text typeface. -->
<attr name="typeface">
<enum name="normal" value="0" />
<enum name="sans" value="1" />
<enum name="serif" value="2" />
<enum name="monospace" value="3" />
</attr>
<!-- Default text typeface style. -->
<attr name="textStyle">
@granoeste
granoeste / gist:4214069
Created December 5, 2012 09:05
[Android] getBroadcast
public String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
@granoeste
granoeste / CheckLauncherCategory.java
Last active December 11, 2015 06:48
[android] check Category is CATEGORY_LAUNCHER in an Activity
boolean isLauncher = intent.hasCategory(Intent.CATEGORY_LAUNCHER);
if (!isLauncher) {
Intent intent = new Intent(context, TopActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK
@granoeste
granoeste / gist:4631370
Created January 25, 2013 03:00
Java Templates for Android logging
// makeLogTag
${:importStatic(net.granoeste.commons.util.LogUtils.makeLogTag)}private static final String TAG = makeLogTag(${enclosing_type}.class);
// TRACE
${:importStatic(net.granoeste.commons.util.LogUtils.LOGV)}LOGV(TAG, "${enclosing_method}()"
// LOGV
${:importStatic(net.granoeste.commons.util.LogUtils.LOGV)}LOGV(TAG, ${cursor});
// LOGD
@granoeste
granoeste / activity_main.xml
Created March 23, 2013 02:48
[Android] What's " xmlns:tools="http://schemas.android.com/tools" " ?
<!--
xmlns:tools="http://schemas.android.com/tools" for Graphical Layout View.
-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"