Skip to content

Instantly share code, notes, and snippets.

View orhanobut's full-sized avatar

Orhan Obut orhanobut

View GitHub Profile
@orhanobut
orhanobut / gist:9267654
Last active October 17, 2022 20:44
how to find square root of an integer with binary search
public static int sqr(int a){
if (a < 1) return 0;
int low = 1;
int h = a;
while (low < h){
@orhanobut
orhanobut / gist:8665372
Created January 28, 2014 10:34
Up down animation for dialog fragment
// Slide up animation
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="100%"
android:interpolator="@android:anim/accelerate_interpolator"
android:toXDelta="0" />
public class MainActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SpannableString spannable = new SpannableString("aasdfasasdfasdfasdf span span");
spannable.setSpan(
new LineBackgroundSpan() {
@Override public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom,
class MyApplication extends Application {
Override public void onCreate(){
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
public class StethoUtils {
private StethoUtils() {
// no instance
}
public static void init(Context context) {
// no-op
}
public class MyApplication extends Application {
@Override public void onCreate(){
super.onCreate();
StethoUtils.init(this);
}
}
public class StethoUtils {
private StethoUtils() {
// no instance
}
public static void init(Context context) {
Stetho.initializeWithDefaults(context);
}
@RunWith(AndroidJUnit4.class)
public class GooglePlacesApiTest {
private GoogleApiClient apiClient;
@Before public void setup() throws InterruptedException {
Context context = InstrumentationRegistery.getContext();
final CountDownLatch latch = new CountDownLatch(1);
apiClient = new GoogleApiClient.Builder(context)
.addApi(Places.GEO_DATA_API)
@RunWith(AndroidJUnit4.class)
public class GooglePlacesApiTest {
GoogleApiClient apiClient;
@Before public void setup() throws InterruptedException {
Context context = InstrumentationRegistery.getContext();
apiClient = new GoogleApiClient.Builder(context)
.addApi(Places.GEO_DATA_API)
Thread thread = new Thread(new Runnable() {
@Override public void run() {
// your long task
textView.setText("Task 4 Result"); //update view
}
});
thread.start();