NOTE:

NOTE: Of late, I have been getting requests for very trivial problems that many of you are facing in your day-to-day work. This blog is not to solve your "project" problems - surely not a "Support" site.
I just love to share my knowledge in my spare time and would appreciate any questions or feedback on the articles and code I have shared. I also do appreciate thought-provoking questions that would lead me to write more articles and share.
But please do not put your day-to-day trivial problems here. Even if you do, you most probably would not get a response here.
Thanks

Search This Blog

x

Monday 11 November 2013

Samsung Look Package - Some Fundamentals

Again, based on the fact that the Samsung SmartApp Challenge  that has already begun on the 5th of September and is going on currently with the last date of submission being 30th Nov 2013, which expects the use of the pen package and the look package, this is the promised article on the look package. Let us start from some fundamentals.

First, What is Look?

From the last 3 articles, we have seen that Samsung Mobile SDK is a SDK that brings 10 different small packages together into one SDK to ease the developers world. Look is a java package available as part of that same Samsung Mobile SDK. It is a package that provides specialized widgets for additional functions beyond what the Android Views already provide. And of course it builds on what the pen package already provides. In fact, Look requires that S Pen be used to access its features.

Next, then, what are the functions Look provides?

It supports
  • ·      WritingBuddy – This basically helps by giving an editor when a S Pen comes closer to an area that can take an input from the pen. The user can write in this editor, which would then by recognized by the WritingBuddy and converted into a digital format for further usage! 

Quite a useful feature considering that the S Pen would lead to a lot of apps that would take a written input but the UI should still be compact with out having large canvases occupying the UI for pen inputs. 

     
      This can be used with on any view layouts and in TextEdit. WritingBuddy recognizes numbers and alpahabets and even handwriting images which would lead to usages like signature recognition etc.

  • ·      AirButton – I see this feature as an advanced context sensitive menu! A set of items or images or what ever may be relevant to a particular context can be shown using an air button. 

The wow factor in this is you can creatively define the gravity, the direction and the display type making it look like a feature that was always needed but not invented till now!

Based on the user selection of a menu item / a recent item display there, the next set of actions can be invoked.


  • ·      SmartClip – As the name says, SmartClip is indeed a smart clipboard, which does not just capture the selected content, but also the metadata related to the content! This metadata is converted to text that can be searched on or sent to other applications for further use.  
This is certainly an interesting feature that can be used very imaginatively to provide seamless copy and paste options between various apps and also help in capturing related content.

This feature would look more magical especially when there is metadata available with the content captured. For example, if there are URLs that are part of the content that is captured, the SmartClip can capture data from the URL too and send it to the destination app.

  • ·      PointerIcon – This is a good to have feature – something that is taken for granted in many desktop apps but has found its way into a mobile through this package! 
This allows you to modify the look of the pointer when you place an S Pen on a view.


The Look Package Architecture

This diagram is taken from the Samsung documentation.

Lot of custom apps can be developed using the look package and as you see the look package is mainly an extension to the Android View package.

The Development environment

In order to develop an app that uses the look package and support all of the above-mentioned features, you need to download the complete Samsung Mobile SDK which can be downloaded independently or through an eclipse. Both ways of downloading the SDK and setting up the Development environment are described here. 


Once the SDK is downloaded, the contents of the SDK are as shown:

The libs folder has all the 10 different packages that I have detailed out in my earlier post. Each of the folders has the respective library jars along with the basic Samsung mobile SDK.

These jars are to be copied into the libs folder of your project trying to develop using a look feature.

Now, let us see a very simple example that changes the pointer icon when the pen hovers over a TextView. On the click of a button, the icon changes.

The 3 member variables created are:
private boolean mIsDefault = false;
private TextView mHoverTextView;
private SlookPointerIcon mPointerIcon = new SlookPointerIcon();
With in the onCreate() method,

//get a handle to the button
Button changeIcon = (Button)findViewById(R.id.btn_changeicon);
//get a handle to the text view
mHoverTextView = (TextView)findViewById(R.id.text_hoverarea);
// set the hover icon
mPointerIcon.setHoverIcon(mHoverTextView, getResources()
.getDrawable(R.drawable.ic_launcher));
//On click of the button, change the icon
changeIcon.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mIsDefault) {
mPointerIcon.setHoverIcon(mHoverTextView, getResources().getDrawable(R.drawable.ic_launcher)); mIsDefault = false;
((Button) v).setText("Turn off");
} else {
mPointerIcon.setHoverIcon(mHoverTextView, null); mIsDefault = true;
((Button) v).setText("Turn on");
}
  }
});
As simple as this, you can change the pointer icon!!
Similarly you can work with the WritingBuddy or the AirButton and the SmartClip. The samples in the downloaded SDK are a good guide to go by.


Tuesday 29 October 2013

Samsung Pen Package – Some Fundamentals

This is in continuation from my previous post. Samsung’s latest devices (Samsung Galaxy Note 3 and the Galaxy Note 10.1 (2014 edition) tablet) are unique with the introduction of the S Pen. The focus of the Samsung SmartApp Challenge that is currently open expects developers to use the pen and the look packages that are part of the Samsung Mobile SDK briefed in my earlier two posts.
In this post I would like to dive a bit deeper on the pen package and in a subsequent post on the look package. We will see what are they, as we go along.

S Pen is opening up a new horizon to Smartphones that support it. In fact I would not be surprised if Samsung soon open sources this project for encouraging wider adoption.

First, what is an S Pen?
Note that S Pen is an innovative stylus-type input device that comes with the Galaxy Note range of devices. It seems to have started off with the idea of making drawing or writing easy on smartphone where a finger touch doesn’t provide a great experience. It is not a capacitive stylus that typically phones came with but uses the Wacom’s EMR (Electro-Magnetic Resonance) patented Technology. For more on the technology behind the S Pen, you can read this article on the XDA Developers Forum or the ‘Android Authority’ post.
The tip of an S Pen allows for its usage in apps that need sensitivity to pressure applied and precision. The side buttons provide for press and release events based on which actions can be initiated.

In order to support developers to build apps for the S Pen, a pen package has been introduced as part of the Samsung Mobile SDK.

Next, what is the Pen package?
It is a package that allows developers to write applications that can take hand-written inputs. It allows the use of a pen, finger or any other kind of input tools or virtual pens to aid precise user input in the most natural way possible. It feels like you are actually writing or drawing on the device and would you call that a luxury? I am sure it is an understatement for thos who use their devices extensively for all day to day activities. J

The pen package enables to
  • ·      Draw using a pen/finger
  • ·      Change user preferences for pens, erasers and text
  • ·      Edit and save the inputs
  • ·      Undo or redo thus managing history of inputs
  • ·      Support both touch and hover events


A few words about the architecture of the pen package before we look at snippets of program using the package:



 This diagram is taken from the Samsung documentation.

As you can see the pen package is a layer over the Android platform using which many applications can be developed like the S-Note or S-Planner etc.

The pen core is organized into various packages with clear separation of responsibilities.  The relevant methods that can be used to develop apps have been made ‘public’ through what is shown as the ‘Pen API’.  It also provides a whole host of listeners that help in handling the touch, the hover, the zoom, the long press, the replay and the text change actions, to name a few.

The Engine provides the core of the package. It a way of managing the runtime objects and extensions to the Android view, line a canvas, text area, multi view, a context menu etc., that can take in inputs from the pen or a finger.

The Model module is literally the model of the pen package.  It gives APIs to save a pen document and retrieve it.  It could be a note that is to be saved and retrieved or a page with a set of strokes to be maintained in the history or even a image, a stroke or a text box with support for all text formatting – these could be persisted and retrieved.

The Setting module is one that helps in understand whether the device support s pen and manage the settings on the pen, eraser and text -  a small utility package.

The UI Control module consists of the various classes that help in managing the UI layouts and associated context menu.

The Plug-in module has a recognition class that allows for signature, text, shape and equation recognition that can be used for very interesting apps. The S pen Object Runtime allows developers to embed video clips or special text box as sandbox.

In order to start developing using the pen package, you need to download the Samsung Mobile SDK. It looks like that the programs need to be tested on a real device and are not supported on an emulator. I did try enabling on the emulator as given in the article on ‘Testing S Pen Apps on an Emulator’. However it seems that it works with what is called the S Pen SDK and not with the pen package, which is the focus of the developer challenge.

Now, unzip the Mobile SDK and you will find a folder by name libs. In libs, you find pen folder in which you have 2 jar files – “pen-v1.0.0.jar” and “sdk-v1.0.0.jar”.  Both of these need to be copied into your Android project libs folder and you are ready to create a pen based app.

You can start with a simple hello world program:

In the onCreate() method, you will have to check the support for the s pen feature first:

boolean isSpenFeatureEnabled = false;
Spen spenPackage = new Spen();
try {
      spenPackage.initialize(this);
      isSpenFeatureEnabled = spenPackage.isFeatureEnabled(Spen.DEVICE_PEN);
     } catch (SsdkUnsupportedException e) {
        //Handle the exception here   
        return;
     } catch (Exception e1) {
         Toast.makeText(mContext, "Cannot initialize Spen.",
         Toast.LENGTH_SHORT).show();
         e1.printStackTrace();
         finish();
     }

Once this basic and essential check is done, let us create a SpenSurfaceView and add it to a relative layout:

RelativeLayout spenViewLayout =
            (RelativeLayout) findViewById(R.id.spenViewLayout);
        mSpenSurfaceView = new SpenSurfaceView(mContext);
        if (mSpenSurfaceView == null) {
            Toast.makeText(mContext, "Cannot create new SpenView.",
                Toast.LENGTH_SHORT).show();
            finish();
        }
        spenViewLayout.addView(mSpenSurfaceView);

The next thing you need to do is a SpenNoteDoc which holds a SpenPageDoc within it and voila, you are ready with the first Spen app J

Display display = getWindowManager().getDefaultDisplay();
Rect rect = new Rect();
display.getRectSize(rect);
       
try {
     mSpenNoteDoc =
     new SpenNoteDoc(mContext, rect.width(), rect.height());
     } catch (IOException e) {
        Toast.makeText(mContext, "Cannot create new NoteDoc.",
        Toast.LENGTH_SHORT).show();
        e.printStackTrace();
        finish();
     } catch (Exception e) {
        e.printStackTrace();
        finish();
     }


        mSpenPageDoc = mSpenNoteDoc.appendPage();
        mSpenPageDoc.setBackgroundColor(0xFFD6E6F5);
        mSpenPageDoc.clearHistory();
        mSpenSurfaceView.setPageDoc(mSpenPageDoc, true);

Note that when you create a SpenNotedoc, you make it as big as the display size that is available.
Then you create a SpenPageDoc and append it to SpenNoteDoc and could optional set parameters like the background and clear the history, if any.
And finally in the onDestroy() method ensure that you clean up after yourself as shown:
    protected void onDestroy() {
        super.onDestroy();

        if(mSpenSurfaceView != null) {
            mSpenSurfaceView.close();
            mSpenSurfaceView = null;
        }

        if(mSpenNoteDoc != null) {
            try {
                mSpenNoteDoc.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            mSpenNoteDoc = null;
        }
    };

And you are done!!  With this you have created the first pen app with a canvas that takes the written input from a pen or a finger J