Skip to content

Instantly share code, notes, and snippets.

@serso
Created August 6, 2015 10:15
Show Gist options
  • Save serso/7fa1a293b6754f9bd8e2 to your computer and use it in GitHub Desktop.
Save serso/7fa1a293b6754f9bd8e2 to your computer and use it in GitHub Desktop.
public class TestProguardActivity extends AppCompatActivity {
private final Executor background = Executors.newSingleThreadExecutor();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final TextView view = new TextView(this);
setContentView(view);
TestClass.testMethod(view);
view.append("Methods:\n");
AnotherTestClass.printMethods(view);
final AnotherTestClass o = new AnotherTestClass();
background.execute(new Runnable() {
@Override
public void run() {
o.waitForNotify(view);
}
});
view.postDelayed(new Runnable() {
@Override
public void run() {
synchronized (o) {
o.notify();
}
}
}, 5000);
}
}
final class TestClass {
public static void testMethod(TextView view) {
view.append("testMethod called\n\n");
}
}
final class AnotherTestClass {
public static void printMethods(TextView view) {
for (Method method : AnotherTestClass.class.getMethods()) {
view.append(method.getName());
view.append("\n");
}
}
public void waitForNotify(final TextView view) {
try {
final long waiting = System.currentTimeMillis();
synchronized (this) {
wait();
}
final long running = System.currentTimeMillis();
view.post(new Runnable() {
@Override
public void run() {
view.append("\n\nwaiting at " + waiting);
view.append("\nrunning at " + running + " after " + (running - waiting) + "ms");
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment