[iOS SDK] Customizing text color of an UITabBarItem – the right way (iOS 7.0+)

After having a look at this good tutorial, i’ve noticed that some code has been declared deprecated in iOS 7.0+:

Old code (deprecated, but still works)

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
 [UIColor whiteColor], UITextAttributeTextColor,
 nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
 [UIColor redColor], UITextAttributeTextColor,
 nil] forState:UIControlStateHighlighted];

The most elegant solution for that is using NSForegroundColorAttributeName, and UIControlStateHighlighted.

iOS 7.0+ version of the previous code

 [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blueColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];

It may seem too silly, but believe me, it wasn’t that easy to find the right solution between that many incorrect answers that still use UITextAttributeTextColor, which is deprecated.

Happy coding!

[Android] OrmLite performance test: Insert vs Bulk-insert

1.- Parse a 800 Kb JSON file into an array
2.- Insert all the parsed entities into a table (Using OrmLite)
3.- Empty the table
4.- Perform the same insertion, but using Bulk-insert (one single transaction for all inserts, instead of a transaction for each)

Tested code:

protected void onCreate(Bundle savedInstanceState) {
strb = new StringBuilder();
mTxt1 = (TextView) findViewById(R.id.txt1);

long startMs = System.currentTimeMillis();
ArrayList points = parsePointsJson_v1(this);
long endMs = System.currentTimeMillis();

strb.append(points != null ? points.size() : "")
.append(points != null ? " points parsed" : " parse error")
.append(" - ").append(endMs-startMs).append(" milliseconds\n");

int insertCount=0;
final Dao poiDao = getHelper().getPointOfInterestDao();

startMs = System.currentTimeMillis();
for(PointOfInterest p : points){
endMs = System.currentTimeMillis();
.append(" normal insertions - ")
.append(endMs-startMs).append(" milliseconds\n\n");

startMs = System.currentTimeMillis();
endMs = System.currentTimeMillis();
strb.append("Empty Points table took: ").append(endMs-startMs).append(" milliseconds\n");

final ArrayList finalPoints = points;
TransactionManager.callInTransaction(poiDao.getConnectionSource(), new Callable(){
public Void call() throws Exception {
long start = System.currentTimeMillis();
int insertCount2 = 0;
for(PointOfInterest fp : finalPoints ){
long end = System.currentTimeMillis();
strb.append(" Bulk insert: ").append(insertCount2).append(" insertions. Took: ").append(end-start).append(" milliseconds\n");
return null;

}catch(SQLException e){
strb.append(" an exception ocurred while inserting: ").append( e.getMessage()).append(" ").append(insertCount).append(" insertions were made");
}catch(Exception e){
strb.append(" Exception bulk-inserting: "+ e.getMessage());


Results on some real devices:

HTC Sensation z710e

Samsung Galaxy SII
BQ Aquaris 5

A little compilation of the results:

[Android Wear] Enabling USB debugging on Wearables for ADB

As we do on Smartphones, we have to enable Developer Options in the Wearable to be able to access it with adb. To do so, go into Settings panel, then into “About”; Tap into “Compilation Number” 7 times. A toast should appear indicating that Development options are enabled. Then inside “Settings”, a new panel called “Development Options” will appear, and there we can enable “ADB Debugging” and “Bluetooth debugging”.

Now it is time to plug in the wearable into the USB port and execute “adb devices” in a terminal. The device might appear as unauthorized. To fix that, note that a permission dialog has appeared on your smartphone (not on the wearable) asking you for permission to let this computer install Apps into the Wearable. Accept it and execute “adb devices” again. The device should now appear just fine.

Captura de pantalla 2014-11-05 a la(s) 16.21.44