Skip to content

Instantly share code, notes, and snippets.

@jiangecho
jiangecho / nest fragment startActivity.md
Created Oct 28, 2015
nested fragment's onActivityResult is not called.
View nest fragment startActivity.md

@Override public void startActivityForResult(final Intent _intent, final int _requestCode) { final FragmentManager fragmentManager = getActivity().getSupportFragmentManager();

final Fragment f = new Fragment() {
	@Override
	public void onAttach(Context context) {
		super.onAttach(context);
		startActivityForResult(_intent, _requestCode);

}

@jiangecho
jiangecho / README.md
Created Dec 26, 2015 — forked from lapastillaroja/README.md
Don't break the chain: use RxJava's compose() operator -> Android + Retrolambda + Observable.Transformer cannot find symbol method
View README.md
@jiangecho
jiangecho / createObservableFromCallback.java
Created Dec 28, 2015
create an observable from callback.
View createObservableFromCallback.java
public Observable<String> doAmazingThingObservable(int param) {
return Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
doAmazingThing(param, new CallBack() {
@Override
public void onGotResult(String result) {
if (result == null) {
View MultiSwipeRefreshLayout.java
/*
* Copyright 2014 Google Inc. All rights reserved.
*/*from w ww . jav a2s . c om*/
* 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
@jiangecho
jiangecho / gist:4dace1e25bf5c9b90143
Created Feb 25, 2016 — forked from yqritc/gist:ccca77dc42f2364777e1
Equal column spacing for Android RecyclerView GridLayoutManager by using custom ItemDecoration
View gist:4dace1e25bf5c9b90143

ItemOffsetDecoration

public class ItemOffsetDecoration extends RecyclerView.ItemDecoration {

    private int mItemOffset;

    public ItemOffsetDecoration(int itemOffset) {
        mItemOffset = itemOffset;
 }
@jiangecho
jiangecho / TrainFeedbackActivity.java
Created Apr 28, 2016
fix EditText in ScrollView scroll issue.
View TrainFeedbackActivity.java
feedbackEditText.setOnTouchListener((v, event) -> {
if (v.getId() == R.id.feedbackEditText) {
ViewParent parent = v.getParent();
while (!(parent instanceof ScrollView)) {
parent = parent.getParent();
}
parent.requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
@jiangecho
jiangecho / SplashActivity.java
Created Apr 29, 2016
simulate user clicks on the content of webview
View SplashActivity.java
int X_MAX = 412;
int Y_MAX = 50;
int x, y;
x = random.nextInt(X_MAX);
y = random.nextInt(Y_MAX);
// String htmlEventJs = "var ev = document.createEvent(\"HTMLEvents\"); " +
// "var el = document.elementFromPoint(%d,%d); " +
// "ev.initEvent('click',true,true);" +
// " el.dispatchEvent(ev);";
View MainActivityCallMe.java
private PopupWindow popTrainMenu() {
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.train_popwindow_menu, null);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Log.v("zxy", "width=" + width + ",height=" + height);
PopupWindow popWindow = new PopupWindow(view, 2 * width / 5, ViewGroup.LayoutParams.WRAP_CONTENT, true);