This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener { | |
public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName(); | |
private int previousTotal = 0; // The total number of items in the dataset after the last load | |
private boolean loading = true; // True if we are still waiting for the last set of data to load. | |
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more. | |
int firstVisibleItem, visibleItemCount, totalItemCount; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compile 'com.android.support:percent:23.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConsumerThread extends Thread { | |
@Override | |
public void run() { | |
Looper.prepare(); // (1) | |
// Handler creation should be placed here | |
Looper.loop(); // (2) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by namchuai on 8/21/17. | |
* Use to convert from Unicode code point to UTF-16 | |
*/ | |
public class Converter { | |
private static final int BASE_HEX = 0x10000; | |
private static int mHexInput = 0x9FFFF; | |
public static void main(String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MySignal { | |
protected boolean hasDataToProcess = false; | |
public synchronized boolean hasDataToProcess() { | |
return this.hasDataToProcess; | |
} | |
public synchronized void setHasDataToProcess(boolean hasData) { | |
this.hasDataToProcess = hasData; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MySignal { | |
protected boolean hasDataToProcess = false; | |
public synchronized boolean hasDataToProcess() { | |
return this.hasDataToProcess; | |
} | |
public synchronized void setHasDataToProcess(boolean hasData) { | |
this.hasDataToProcess = hasData; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected MySignal sharedSignal = … | |
while (!sharedSignal.hasDataToProcess()) { | |
// do nothing… busy waiting | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MonitorObject { | |
} | |
public class MyWaitNotify { | |
MonitorObject myMonitorObject = new MonitorObject(); | |
public void doWait() { | |
synchronized(myMonitorObject) { | |
try { | |
myMonitor.wait(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyWaitNotify2 { | |
MonitorObject myMonitorObject = new MonitorObject(); | |
boolean wasSignalled = false; | |
public void doWait() { | |
synchronized (myMonitorObject) { | |
if (!wasSignalled) { | |
try { | |
myMonitorObject.wait(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyWaitNotify3 { | |
MonitorObject myMonitorObject = new MonitorObject(); | |
boolean wasSignalled = false; | |
public void doWait() { | |
synchronized (myMonitorObject) { | |
while (!wasSignalled) { | |
try { | |
myMonitorObject.wait(); | |
} catch (InterruptedException e) { |
OlderNewer