Skip to content

Instantly share code, notes, and snippets.

@ikew0ng
ikew0ng / AndroidManifest.xml
Last active August 29, 2015 14:08
Replace Google Search Action on Navication Bar
<!-- target activity -->
<activity android:name="...">
<meta-data
android:name="com.android.systemui.action_assist_icon"
android:resource="@drawable/ic_assist"/>
<intent-filter>
<action android:name="android.intent.action.ASSIST"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
@ikew0ng
ikew0ng / ShowButton.java
Created July 27, 2014 09:37
利用OnPreDrawListener监听绘制前的时机,在这个点控件已经完全ready(完成可measure, layout),此时可以获取到动画所必须的参数,也保证动画的流畅。
btnMenu.setVisibility(View.VISIBLE);
btnClose.setVisibility(View.VISIBLE);
btnRefresh.setVisibility(View.VISIBLE);
btnMenu.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
btnMenu.getViewTreeObserver().removeOnPreDrawListener(this);
ViewGroup.MarginLayoutParams params =
(ViewGroup.MarginLayoutParams) btnClose.getLayoutParams();
int marginBottom = params.bottomMargin;
@ikew0ng
ikew0ng / ListViewUtils.java
Created June 6, 2014 08:04
Smoothly scroll listView to specified position.
public class ListViewUtils {
public static final int SCROLL_DURATION = 150;
private ListViewUtils() {}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void scrollListView(final ListView listView, final int position) {
if (CommonUtils.hasHoneycomb()) {
listView.smoothScrollToPositionFromTop(position, 0);
listView.postDelayed(new Runnable() {
@ikew0ng
ikew0ng / ClearBackStack.java
Created January 7, 2014 09:41
Clear fragment backStack
/**
* Remove all entries from the backStack of this fragmentManager.
*
* @param fragmentManager the fragmentManager to clear.
*/
private void clearBackStack(FragmentManager fragmentManager) {
if (fragmentManager.getBackStackEntryCount() > 0) {
FragmentManager.BackStackEntry entry = fragmentManager.getBackStackEntryAt(0);
mFragmentManager.popBackStack(entry.getId(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
@ikew0ng
ikew0ng / ThrowIfNotOnMainThread.java
Created December 23, 2013 06:19
检查方法是否运行于主线程
private void throwIfNotOnMainThread(){
if (Looper.myLooper() != Looper.getMainLooper()) {
throw new IllegalStateException("Must be invoked from the main thread.");
}
}
@ikew0ng
ikew0ng / ViewPagerUtils.java
Created October 1, 2013 14:20
获取ViewPager特定位置的Fragment
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
/**
* Created by Chaojun Wang on 5/6/14.
*/
public class ViewPagerUtils {
private ViewPagerUtils() {}
@ikew0ng
ikew0ng / ActionBarHeight.java
Created September 29, 2013 09:58
获得ActionBar高度
/**
* Get actionbar height
*/
public static int getActionBarHeight(Context context) {
TypedValue typedValue = new TypedValue();
if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
return typedValue.complexToDimensionPixelSize(typedValue.data, context.getResources()
.getDisplayMetrics());
}
return 0;
@ikew0ng
ikew0ng / AndroidManifest.xml
Last active May 22, 2018 13:34
动态替换launcher icon
<!-- activity -->
<activity
android:name=".ui.WelcomeActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize|stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
@ikew0ng
ikew0ng / SmartBarUtils.java
Last active December 11, 2015 18:19
反射禁用Smartbar的方法,注意必须开启actionbar才有效
package me.imid.fuubo.utils;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@SuppressLint("NewApi")
@ikew0ng
ikew0ng / gist:4547352
Created January 16, 2013 14:11
executeAsyncTask
/**
* 使用{@link AsyncTask.THREAD_POOL_EXECUTOR} 执行AsyncTask 这样可以避免android
* 4.0以上系统 每次只执行一个 asyncTask
*
* @param task
* @param params
*/
public static <Params, Progress, Result> void executeAsyncTask(
AsyncTask<Params, Progress, Result> task, Params... params) {
if (VERSION.SDK_INT >= 11) {