Skip to content

Instantly share code, notes, and snippets.

@jiangecho
jiangecho / nest fragment startActivity.md
Created October 28, 2015 07:38
nested fragment's onActivityResult is not called.

@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 December 26, 2015 09:47 — forked from lapastillaroja/README.md
Don't break the chain: use RxJava's compose() operator -> Android + Retrolambda + Observable.Transformer cannot find symbol method
@jiangecho
jiangecho / createObservableFromCallback.java
Created December 28, 2015 13:19
create an observable from callback.
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) {
/*
* 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 February 25, 2016 06:09 — forked from yqritc/gist:ccca77dc42f2364777e1
Equal column spacing for Android RecyclerView GridLayoutManager by using custom ItemDecoration

ItemOffsetDecoration

public class ItemOffsetDecoration extends RecyclerView.ItemDecoration {

    private int mItemOffset;

    public ItemOffsetDecoration(int itemOffset) {
        mItemOffset = itemOffset;
    }
@jiangecho
jiangecho / TrainFeedbackActivity.java
Created April 28, 2016 09:18
fix EditText in ScrollView scroll issue.
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 April 29, 2016 03:42
simulate user clicks on the content of webview
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);";
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);