Archive
Amazing Cracked Screen
Hello everyone,
In this weekend I made a simple application just for fun – AmazingĀ Cracked Screen, the main purpose being to trick your friends and make fun of them! Basically, what does the application is to simulate a broken phone screen.
The application includes 6 different broken screens, and provides the ability to set up a delay time when the app should start, so you can manage to give the phone to your friend.
Just start the application, select the desired broken screen and have fun!
How to verify an RSS Feed if New Articles have been published.
Recently I built an rss app for a site that publishes daily IT News – ITMoldova.com. The main feature of application is to launch a service in background (at a given interval of time), and check if new articles have been published on http://itmoldova.com site. If it turns out that new articles have been published, then fire a notification message and notify the user about this, something like this: “4 New Articles Published on ITMoldova.com”.
The mechanism to identify if new articles have been published on the site (and how many) is pretty straightforward: when the application is installed and launched for the first time, it parses the Rss Feed and creates a new entry in the SharedPreferences with the value of <pubDate> element, of the first item from the rss list (pubDate = publication date). Then, everytime the service starts, it parses the RSS Feed and checks the value of first item from the rss list against the value stored in SharedPreferences, if the value stored in SharedPreferences is less than value returned by the service, then it means that there are new articles and it’s time to notify the user! Lastly, update the SharedPreferences with the most recent pubDate.
For the sake of simplicity and keeping things consistent, I will post here only snippets of most relevant code, but this will be good enough to give you an idea about how things works.
To compare the dates we need to convert them to milliseconds. The getTime() method of Date class can help us return the number of milliseconds of a given date:
Date date=new Date(); int timeMilliseconds=date.getTime();
Below is the implementation of verifyDates(String, String) method that will be used by the Service. The method takes 2 string parameters, the pubDate of rss item, and the pubDate stored in SharedPreferences.
public class Tools {
public int newArticles;
public boolean hasMoreArticles = true;
public void verifyDates(String rssPubDate, String sharedPrefLastPubDate) {
if (hasMoreArticles) {
SimpleDateFormat df = new SimpleDateFormat("dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
Date dLastPubDate = null;
Date dRssPubDate = null;
try {
dLastPubDate = df.parse(sharedPrefLastPubDate.substring(5));
dRssPubDate = df.parse(rssPubDate.substring(5));
} catch (ParseException e) {
Log.d("GREC", "Exception in verifayDates: " + e.getMessage());
e.printStackTrace();
}
//We want to count how many new articles were published.
if (dRssPubDate.getTime() > dLastPubDate.getTime()) {
newArticles++;
} else {
hasMoreArticles = false;
}
}
}
}
The service will parse the Rss Feed and do the comparison. Also, it will launch a status bar notification if it turns out that new articles were published.
public class RssService extends IntentService {
public RssService() {
super("ITMoldovaRssService");
}
@Override
protected void onHandleIntent(Intent intent) {
// Retrieve the date from SharedPreferences
String lastPubDate = getDateFromSharedPrefs();
// The AndroidFeedParser class helps us parse the Rss Feed.
AndroidFeedParser parser;
try {
parser = new AndroidFeedParser(new URL("http://itmoldova.com/feed/"));
List<Message> list = parser.parse();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
// Verify the pubDate of each item, against pubDate stored in SharedPreferences
tools.verifyDates(list.get(i).getDate(), lastPubDate);
}
// Get the last pubDate and save it to SharedPreferences.
lastPubDate = list.get(0).getDate();
saveToSharedPreferences(lastPubDate);
}
} catch (MalformedURLException e) {
Log.d("GREC", "Malformed URL Exception: " + e.getMessage());
e.printStackTrace();
}
if (tools.newArticles > 0) {
displayNotification();
} else {
Log.d("GREC", "No new articles ");
}
}
}
The service begins with parsing the Rss Feed and return the list of items:
List<Message> list = parser.parse();
then iterate through it comparing the publication date:
for (int i = 0; i < list.size(); i++) {
// Verify the pubDate of each item, against pubDate stored in SharedPreferences
tools.verifyDates(list.get(i).getDate(), lastPubDate);
}
and then ends getting the most recent publication date and saving it to SharedPreferences:
// Get the last pubDate and save it to SharedPreferences. lastPubDate = list.get(0).getDate(); saveToSharedPreferences(lastPubDate);
If it turns out that new articles were published, display a status bar notification.
if (tools.newArticles > 0) {
displayNotification();
}
How to parse an XML feed and how to display a status bar notification are some helper topics you may need to take a look in order to fully complete this task.
How to simulate an incoming call in Android
1. Start the Android Emulator
2. Open up the windows console by going to Start -> Run (or Windows + R shortcut) and type in “cmd”. Press Enter. This should open the dos console.
3. Type in “telnet” and press enter. This should open the Telnet Console.
(At this stage you may experience some problems, the console may display the error: ‘telnet’ is not recognized as an internal or external command, operable program or batch file. If this is the case, scroll down to see how to fix it, then return and continue the process)
4. Telnet Console being displayed, type in “o localhost 5554″. This will establish a connection with the emulator on port 5554 and open the Android Console. 5554 is the port number and you can see it on the title bar of the emulator window.
5. To simulate the call, type in “gsm call 099062274″
6. To cancel the call, type “gsm cancel 099062274″
7. Use “exit” to exit the Android Console, and “quit” to quit the Telnet client.
That’s it!
*How to fix the: ‘telnet’ is not recognized as an internal or external command, operable program or batch file error.
When trying to invoke the telnet program you may experience the above error. The cause of this could be that the Telnet Client is turned off on your computer.
To turn it on, follow these steps:
1. Go to Control Panel
2. Click on Programs
3. Under Programs and Features section, click on Turn Windows features on or off. This should bring you the Windows Features pop-up.
4. Find the Telnet Client, select it, click OK.





