Do you realize that fetching data from the web, for example a GET request, may actually block the GUI and then creates an error? I experienced that and would want to share my thoughts on resolving it. I have not implemented a sound solution but these are the things I have in my mind. There are two components to implement in the code:
1. Thread
2. Handler
Let's see if this works :)
Friday, November 27, 2009
Nonblocking mechanism for Android GUI
Email the blog author at: nicholaskeytholeong [at] gmail [dot] com
Wednesday, November 25, 2009
Saturday, November 21, 2009
Removing status and title bars in an Android app (suggested method)
I discovered that the status and title bars can be removed in an Android app by inserting one simple line in the manifest xml file. Feel free to try this out and let's discuss if this does not work for you.
<activity android:name=".YOUR_ACTIVITY_NAME"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".YOUR_ACTIVITY_NAME"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Email the blog author at: nicholaskeytholeong [at] gmail [dot] com
Labels:
Android
Thursday, November 19, 2009
Distinct intersecting values of two arrays
I have written two different methods that gives the same output. The output is a list of distinct intersecting values of two arrays. I am amazed with the different amount of time taken to solve this problem. It would be something interesting to investigate. Here are the suggested solutions:
import java.util.ArrayList;The output of these methods are as below (I'm telling you, you'll be amazed looking at the time taken for each method):
import java.util.HashSet;
import java.util.Set;
public class ArraysIntersection {
private void findIntersectionMethod1(int[] a, int[] b){
long start = System.nanoTime();
int indexA = 0;
int indexB = 0;
ArrayListunique = new ArrayList ();
while (indexA < a.length && indexB < b.length) {
if (a[indexA] == b[indexB]) {
if (!unique.contains(a[indexA])) {
unique.add(a[indexA]);
}
indexA++;
indexB++;
} else if (a[indexA] < b[indexB]) {
indexA++;
} else {
indexB++;
}
}
long elapsed = (System.nanoTime() - start);
System.out.println("Elapsed time (findIntersectionMethod1): " + elapsed + "ns");
System.out.println("Intersection of elements: " + unique);
}
private void findIntersectionMethod2(int[] arr1, int[] arr2){
long start = System.nanoTime();
ArrayListunique = new ArrayList ();
for (int i = 0; i < arr1.length; i++) {
for (int j = 0; j < arr2.length; j++) {
if (arr1[i] == arr2[j]) {
if (!unique.contains(arr1[i])) {
unique.add(arr1[i]);
}
}
}
}
long elapsed = (System.nanoTime() - start);
System.out.println("Elapsed time (findIntersectionMethod2): " + elapsed + "ns");
System.out.println("Intersection of elements: " + unique);
}
private void findIntersectionMethod3(int[] a, int[] b){
long start = System.nanoTime();
Setunique = new HashSet ();
int indexA = 0;
int indexB = 0;
while (indexA < a.length && indexB < b.length) {
if (a[indexA] == b[indexB]) {
unique.add(a[indexA]);
indexA++;
indexB++;
} else if (a[indexA] < b[indexB]) {
indexA++;
} else {
indexB++;
}
}
long elapsed = (System.nanoTime() - start);
System.out.println("Elapsed time (findIntersectionMethod3): " + elapsed + "ns");
System.out.println("Intersection of elements: " + unique);
}
public static void main(String[] args) {
int a[]={1, 1, 2, 4, 4, 7, 8, 8, 9, 14, 14, 20, 20, 20};
int b[]={1, 1, 1, 2, 2, 8, 8, 20};
ArraysIntersection arrIntersect = new ArraysIntersection();
arrIntersect.findIntersectionMethod1(a, b);
arrIntersect.findIntersectionMethod2(a, b);
arrIntersect.findIntersectionMethod3(a, b);
}
}
Elapsed time (findIntersectionMethod1): 455000nsI'm sure there are much better solutions to solve this interesting problem that I have not thought of.
Intersection of elements: [1, 2, 8, 20]
Elapsed time (findIntersectionMethod2): 15000ns
Intersection of elements: [1, 2, 8, 20]
Elapsed time (findIntersectionMethod3): 65000ns
Intersection of elements: [2, 8, 1, 20]
Email the blog author at: nicholaskeytholeong [at] gmail [dot] com
Labels:
Algorithms,
Java
Wednesday, November 18, 2009
Quizzie with improved user interface
This is Quizzie v1.1 with much better user interface. I hope you enjoy watching this video. Quizzie v1.0 is available here.
Email the blog author at: nicholaskeytholeong [at] gmail [dot] com
Remote log management and monitoring? There's an Android app for that
I'm thinking of writing an Android app using Splunk's API. Not sure if it's possible but I think it can be done. Here is my concept about the application.
We can actually see the outputs of the activities in Android by using adb logcat. What if I am able to pipe out the stream into a file and then push it to my local Splunk web server. hhhmmm interesting ...
"Remote log management and monitoring? There's an Android app for that"
:D
We can actually see the outputs of the activities in Android by using adb logcat. What if I am able to pipe out the stream into a file and then push it to my local Splunk web server. hhhmmm interesting ...
"Remote log management and monitoring? There's an Android app for that"
:D
Email the blog author at: nicholaskeytholeong [at] gmail [dot] com
Labels:
Splunk
Saturday, November 14, 2009
Jython in Android
I think it's possible. But why are there so limited references to use Jython in Android?
Email the blog author at: nicholaskeytholeong [at] gmail [dot] com
Subscribe to:
Posts (Atom)
