Skip to content

Instantly share code, notes, and snippets.

@laaptu
laaptu / StaticHandler
Last active December 22, 2015 06:48
Creating static handlers on Android
CustomHandler customHandler = new CustomHandler(this);
customHandler.sendEmptyMessage(0);
static class CustomHandler extends Handler{
private final WeakReference<FriendListFragment> fragmentHolder;
public CustomHandler(FriendListFragment friendListFragment){
fragmentHolder = new WeakReference<FriendListFragment>(friendListFragment);
}
@laaptu
laaptu / CustomScrollView
Created September 5, 2013 08:03
Android View Pager or Horizontal Scroll View/List inside a vertical ScrollView http://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;
public class VerticalScrollView extends ScrollView {
public VerticalScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@laaptu
laaptu / AssetFileStringReader
Last active March 17, 2019 15:10
Android read file as string from asset
public String ReadFromfile(String fileName, Context context) {
StringBuilder ReturnString = new StringBuilder();
InputStream fIn = null;
InputStreamReader isr = null;
BufferedReader input = null;
try {
fIn = context.getResources().getAssets()
.open(fileName);
isr = new InputStreamReader(fIn);
input = new BufferedReader(isr);
@laaptu
laaptu / bitmap_not_stretch
Created September 6, 2013 07:19
Android stop background from stretching with content,meaning making width of background fixed http://stackoverflow.com/questions/5902230/how-to-implement-an-androidbackground-that-doesnt-stretch
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/dvdr"
android:tileMode="disabled" android:gravity="top" >
</bitmap>
@laaptu
laaptu / DisableChildViews
Created September 17, 2013 07:50
Method to disable or enable child view of a view group or view
/**
*http://stackoverflow.com/questions/5418510/disable-the-touch-events-for-all-the-views
* Enables/Disables all child views in a view group.
*
* @param viewGroup the view group
* @param enabled <code>true</code> to enable, <code>false</code> to disable
* the views.
*/
public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
int childCount = viewGroup.getChildCount();
@laaptu
laaptu / SmoothInterpolator
Created September 17, 2013 07:52
Android smooth interpolator as per Cyril Mottier
//as per cyrilmottier.com/2012/05/22/the-making-of-prixing-fly-in-app-menu-part-1/
public class SmoothInterpolator extends LinearInterpolator {
@Override
public float getInterpolation(float input) {
return (float) Math.pow(input - 1, 5) + 1;
}
}
@laaptu
laaptu / CollapseValueAnimator
Last active March 14, 2019 07:31
Android collapse animation by ValueAnimator
private void valueAnimateAndDelete(final View view,
final int deletePosition) {
final ViewGroup.LayoutParams lp = view.getLayoutParams();
final int originalHeight = view.getHeight();
ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 0);
animator.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator arg0) {
@laaptu
laaptu / CollapseAnimation
Created September 17, 2013 07:56
Android Collapse Animation by decreasing height
private void animateAndDelete(final View view, final int deletePosition) {
final int height = view.getMeasuredHeight();
Animation animation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime,
Transformation t) {
view.getLayoutParams().height = height
- (int) (height * interpolatedTime);
view.requestLayout();
@laaptu
laaptu / ListViewSmoothScrollToPosition
Created September 19, 2013 11:49
ListView smooth scroll to certain position
//Keep in mind the position should be actual size of ArrayList not ArrayList size -1
chatListAdapter.notifyDataSetChanged();
listView.getListView().postDelayed(new Runnable() {
@Override
public void run() {
listView.getListView().smoothScrollToPosition(
messageItemList.size());
public class ViewWeb extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView wv;
wv = (WebView) findViewById(R.id.webView1);
wv.loadUrl("file:///android_asset/aboutcertified.html"); // now it will not fail here
}
}