Skip to content

Instantly share code, notes, and snippets.

View namchuai's full-sized avatar

NamH namchuai

View GitHub Profile
public static int getApproxXToCenterText(String text, Typeface typeface, int fontSize, int widthToFitStringInto) {
Paint p = new Paint();
p.setTypeface(typeface);
p.setTextSize(fontSize);
float textWidth = p.measureText(text);
int xOffset = (int)((widthToFitStringInto-textWidth)/2f) - (int)(fontSize/2f);
return xOffset;
}
import 'dart:io' show Platform;
...
var horizontalTitleAlignment = Platform.isIOS
? CrossAxisAlignment.center
: CrossAxisAlignment.start;
@namchuai
namchuai / generate_dummy_list.dart
Created August 19, 2018 04:04
Generate a dummy list
final todos = List<Todo>.generate(
20,
(i) => Todo(
'Todo $i',
'A description of what needs to be done for Todo $i',
),
);
@namchuai
namchuai / circle.xml
Created August 16, 2018 02:54 — forked from gohilbhagirath90/circle.xml
list item with left side half circle android
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false" >
<solid android:color="@android:color/white" />
<size
android:height="50dp"
android:width="50dp" />
</shape>
public class MyWaitNotify {
String myMonitorObject = "";
boolean wasSignalled = false;
public void doWait() {
synchronized (myMonitorObject) {
while(!wasSignalled) {
try {
myMonitorObject.wait();
public class MyWaitNotify3 {
MonitorObject myMonitorObject = new MonitorObject();
boolean wasSignalled = false;
public void doWait() {
synchronized (myMonitorObject) {
while (!wasSignalled) {
try {
myMonitorObject.wait();
} catch (InterruptedException e) {
public class MyWaitNotify2 {
MonitorObject myMonitorObject = new MonitorObject();
boolean wasSignalled = false;
public void doWait() {
synchronized (myMonitorObject) {
if (!wasSignalled) {
try {
myMonitorObject.wait();
public class MonitorObject {
}
public class MyWaitNotify {
MonitorObject myMonitorObject = new MonitorObject();
public void doWait() {
synchronized(myMonitorObject) {
try {
myMonitor.wait();
protected MySignal sharedSignal = …
while (!sharedSignal.hasDataToProcess()) {
// do nothing… busy waiting
}
public class MySignal {
protected boolean hasDataToProcess = false;
public synchronized boolean hasDataToProcess() {
return this.hasDataToProcess;
}
public synchronized void setHasDataToProcess(boolean hasData) {
this.hasDataToProcess = hasData;
}