Sunday, November 30, 2014

Pasteboard in iOS interprocess Communication


On iOS, the class is UIPasteBoard, and on Mac, it is NSPasteBoard. These both are pretty much the same, but on iOS, the APIs are modern and cleaner. 
Programmatically writing into pasteboard is nearly as invoking Edit > Copy in GUI application. 

NSImage *image; 
NSPasteBoard *pasteboard = [NSPasteBoard generalPasteboard];
[pasteboard clearContents];
[pasteboard writeObjects:@[image]];

The receive of contents in the pasteboard is bit more involved and it is like below 

NSPasteBoard *pasteboard = [NSPasteBoard generalPasteboard];
if([pasteboard canReadObjectForClasses:@[[NSImage image] options:nil])
{
NSArray *contents = [pasteboard readObjectsForClasses:@[[NSImage class]] options:nil];
NSImage *image = [contents firstObject];
}


What makes Pasteboard compelling as a mechanism for transferring data is the notion of simultaneously providing multiple representations of content copied into pasteboard. For e.g. a selection of text may be copied as a Rich text or a normal text and the receiver can be accordingly configured to take it. For e.g. a rich text editor will be able to take the formatted text. 

References:
http://nshipster.com/inter-process-communication/

What is Chromebook - vs Microsoft Windows, Apple iPad



Chrome book is laptop with the Chrome OS installed within. The iPad is not having a keypad hardware causing it most of the time inconvenient to use for kids especially. 
Like mentioned in an article, Chromebook is for creating and iPad is for consuming. 
Chromebook is completely web based, meaning if there is no network, it can’t really function very well. 


Chrome book is basically available for multiple hardware vendors such as Acer, Dell, Samsung Microsoft 
Many of the schools in US are said to be ditching the iPad and going behind the Chromebooks. 

Some of the apps we used to are not supported in Chromebook such as Microsoft office, But these days many of the desktop apps are having their web versions, so it is not a big deal. 

References:


Apple Or Google ?

(Picture Courtesy http://www.pocket-lint.com/)

- Based on many articles read it is very much obvious that for any solution it is must to have interoperability between devices, Google is achieving it highly using the cloud model, by providing centralised cloud store for settings, preferences, data which can be accessed via a number of mediums such as handhelds, desktops.  This is a good reminder for us to concentrate our apps in this as well. We rarely integrate with the cloud services and take advantage of the cloud platforms offered by the giants, such as iCloud, Google Drive, One Drive. There are plenty of APIs now  available for such integrations. 

- Apple is driving the user base with its superior hardwares, while i think cloud based services of Apple is not really any weaker than Google’s but it falls short in terms of number of devices it can reach. A simple example may be Google apps are available on iOS and a user with Google account can use apple device without much problems, while the other way is not really true, in the sense that iTunes accounts are restricted only to Apple devices. Not sure this can really change, and it has been like this from many years, and still Apple is strong! 

- Samsung’s flexible display “YOUM”  OLED Displayes could drastically change the user experience possibly the form factor of the devices, With this, Apple’s superior quality devices could get a good competition. Of course Apple will have definitely something in their kit to counter this. 

- Also read the article that Chromebooks are taking over the iPads in education area. This is again due to the price affordability may be especially in education area. There are two advantages being told for Chromebooks that 1. Chromebooks have hardware keyboards , 2) Chromebooks is completely web driven, not the App driven.  . The second point just tells the ability to use the content outside the current device or in otherwords ability to use in multiple devices. This is merely possible in Apple devices too i think.


Even though the article is more saying Google is overtaking the market share etc,  in my thinking, it is just wait and see, Apple is also coming up with counter technologies for everything that others are introducing, best examples being WatchKit, CarKit, HealthKit, HomeKit etc the recent additions to the iOS platform. 

References:
http://www.pocket-lint.com/news/131520-which-cloud-storage-service-is-right-for-you-icloud-vs-google-drive-vs-onedrive-vs-dropbox
https://www.edsurge.com/n/2014-06-30-3-reasons-why-chromebook-beats-ipad-in-1-1-programs
http://www.in.techradar.com//articleshow/42913485.cms

Android Changing Name of application

Yet another simple stuff which i did not know as a beginner was, how to change the name of application,

The application name is basically defined within the application element in the AndroidManifest.xml file

        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/AppTheme"
         >

the label field represents the label that is shown on the Device. We just need to change it, in this case, the name is taken from string/app_name resource. To edit it, just change in the resource string file.

References:
http://developer.android.com/guide/topics/manifest/application-element.html

Android Adding Application icon

Inorder to add application icon which is renderable in multiple device densities, the icon asset in various dimension needs to be provided in the resource folder

        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/AppTheme"


By default android project has the icon name ic_launcher, this is kept in the res folder under density specific folders.

We just needs to replace these files with the one required.

Also found a very useful website which can create the resource with different densities for icons.

http://android-ui-utils.googlecode.com/hg/asset-studio/dist/icons-launcher.html

Just provide icon to it and the complete set can be downloaded. So easy!

References:
http://romannurik.github.io/AndroidAssetStudio/
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/icons-launcher.html

Saturday, November 29, 2014

Android Reading raw Resource file

As part of a project, i had to read a resource file from raw folder. This was a login response json file.

First right clicked on the Resources folder and selected the resource directory like in the below screenshot



From this, selected the resource type as raw.


Doing this, the raw folder appeared under resources. 

Right clicked on the raw again and then selected add file and selected a text file as the file was a json file 


This created an empty file and pasted the json file contents into this. Did a compile once so that R.java file is getting this resource Id 

After this from the code did the below 

Utils.readRawTextFile(contextRef,R.raw.login_response);

public static String readRawTextFile(Context ctx, int resId)
    {
        InputStream inputStream = ctx.getResources().openRawResource(resId);

        InputStreamReader inputreader = new InputStreamReader(inputStream);
        BufferedReader buffreader = new BufferedReader(inputreader);
        String line;
        StringBuilder text = new StringBuilder();

        try {
            while (( line = buffreader.readLine()) != null) {
                text.append(line);
                text.append('\n');
            }
        } catch (IOException e) {
            return null;
        }
        return text.toString();
    }


Thats all, the file is read from the resouces folder. 





Android Studio - Changing Run Configurations

When i imported an eclipse project into Android Studio, and ran it, it started by default launching in simulator even though i had the device connected.

This configuration can be altered using the Run -> Edit Configurations Menu,
In this the Target Device can be selected to Emulator or Device or Show Chooser dialog. This configuration is given like in below screenshot

 References:
http://stackoverflow.com/questions/16585055/android-studio-doesnt-start-with-connected-device