Skip to content

Instantly share code, notes, and snippets.

function dex-method-count() {
cat $1 | head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"'
}
function dex-method-count-by-package() {
dir=$(mktemp -d -t dex)
baksmali $1 -o $dir
for pkg in `find $dir/* -type d`; do
smali $pkg -o $pkg/classes.dex
count=$(dex-method-count $pkg/classes.dex)
@lidemin
lidemin / error
Created August 10, 2014 03:22
Android error code sheet
/*
import java files which contains static load resources files.
However in Android studio, it is not able to find the resource files right now.
http://stackoverflow.com/questions/7325579/java-lang-noclassdeffounderror-could-not-initialize-class-xxx
*/
java.lang.NoClassDefFoundError: Could not initialize class
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@lidemin
lidemin / StickyLocalBroadcastManager.java
Last active May 3, 2017 23:57
StickyLocalBroadcastManager
/**
* This is just a copy of Android LocalBroadcastManager from SupportLibrary.
*
* Add sticky broadcast support. PS: not sure it is the best way to do that.
*
*/
public class StickyLocalBroadcastManager {
private static class ReceiverRecord {
final IntentFilter filter;
@lidemin
lidemin / DLAppSession.java
Last active September 8, 2015 04:13
Android Utils
package com.damon.android;
/**
* Created by damon on 7/2/15.
*/
import android.content.Context;
import java.io.Serializable;
import java.util.ArrayList;
@lidemin
lidemin / GCMReceiver.java
Created February 6, 2015 08:14
Android Push Notification Bootstrap
/**
* Created by damon on 30/1/15.
*/
public class GCMReceiver extends WakefulBroadcastReceiver {
public static final String TAG = "GCMReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GCMService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
@lidemin
lidemin / BaseFragment.java
Last active August 29, 2015 14:14
LocalBroadcastManager enhancement
abstract public class BaseFragment extends Fragment {
/** Constant String representing class name for logs.*/
protected String _tag = ((Object) this).getClass().getSimpleName();
//broadcast manager
protected DLBroadcastManager broadcastManager;
protected BroadcastReceiver broadcastReceiver;
private IntentFilter intentFilter;
@lidemin
lidemin / DLRecyclerView.java
Created February 6, 2015 08:18
RecyclerView which can listen scroll to the bottom or end.
public class DLRecyclerView extends RecyclerView {
public interface OnScrollListener {
/**
* only works when layoutmanager is LinearLayoutManager
*/
public abstract void onScrollToEnd();
}
private OnScrollListener _onScrollListener;
@lidemin
lidemin / test.java
Created July 9, 2016 16:00
Just for testing.
@Override
public synchronized Bitmap getMosaicTile(String hexColor, int tileWidth, int tileHeight) throws Exception {
Bitmap newBmp = Bitmap.createBitmap(tileWidth, tileHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newBmp);
RectF rectF = new RectF(padding, padding, tileWidth - padding, tileHeight - padding);
paint.setColor(Color.parseColor("#" + hexColor));
canvas.drawRoundRect(rectF, radius, radius, paint);
return newBmp;
}
@lidemin
lidemin / CustomRecyclerViewAdapter.java
Created July 13, 2016 04:46
AS's live template for custom recyclerview adapter.
public class $objectclass$Adapter extends RecyclerView.Adapter<$objectclass$ViewHolder>{
List<$objectclass$> objList;
private Context context;
private LayoutInflater inflater;
public $objectclass$Adapter(Context context) {
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}