Skip to content

Instantly share code, notes, and snippets.

@ishitcno1
ishitcno1 / MainActivity.java
Last active June 18, 2018 11:40
ObservableScrollView. Load more data when scroll to bottom.
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends Activity implements ObservableScrollView.ScrollViewListener {
private ObservableScrollView mScrollView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Display display = getWindowManager().getDefaultDisplay();
int width = 0;
int height = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
Point size = new Point();
display.getSize(size);
width = size.x;
height = size.y;
} else {
// Before API level 13
@ishitcno1
ishitcno1 / files.txt
Created January 22, 2014 08:42
Read line by line from a file and operate in bash.
line one
line two
line three
@ishitcno1
ishitcno1 / methods.java
Created January 27, 2014 01:34
Android get layout inflater.
// inside activities
LayoutInflater inflater = getLayoutInflater();
// outside activities
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
@ishitcno1
ishitcno1 / MainActivity.java
Last active January 4, 2016 16:09
ObservableListView. Load more data when scroll to bottom.
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements ObservableListView.ListViewListener {
private ObservableListView mListView;
@ishitcno1
ishitcno1 / files.java
Created February 18, 2014 03:48
Android make a call.
// Start dial app
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:1234-12345678"));
startActivity(intent);
// Make a call directly
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:1234-12345678"));
startActivity(intent);
@ishitcno1
ishitcno1 / ImageTextButton.java
Created March 4, 2014 06:28
Android image text button.
public class ImageTextButton extends LinearLayout {
public ImageTextButton(Context context) {
this(context, null);
}
public ImageTextButton(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.ImageTextButton, 0, 0);
String titleText = a.getString(R.styleable.ImageTextButton_title);
@ishitcno1
ishitcno1 / fragment_test.xml
Created March 5, 2014 11:05
Android listview empty and loading.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ishitcno1
ishitcno1 / ImageTextButton.java
Created March 5, 2014 11:28
Android custom button with image and text.
public class ImageTextButton extends LinearLayout {
public ImageTextButton(Context context) {
this(context, null);
}
public ImageTextButton(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.ImageTextButton, 0, 0);
String titleText = a.getString(R.styleable.ImageTextButton_title);
@ishitcno1
ishitcno1 / DialogFragment.java
Created March 7, 2014 02:56
A custom DialogFragment that is positioned above given "source" component. Ref: http://stackoverflow.com/questions/9698410/position-of-dialogfragment-in-android
/**
* A custom DialogFragment that is positioned above given "source" component.
*
* @author Jonik, http://stackoverflow.com/a/20419231/56285
*/
public class ConfirmBox extends DialogFragment {
private View source;
public ConfirmBox() {
}