Wednesday 30 September 2015

How to Develop IME or SoftKeyboard or Custom Keyboard in Android?

Introduction:

BaseInputConnection
Defines the communication channel from an InputMethod back to the application that is receiving its input.
You use it to read text around the cursor, commit text to the text box, and send raw key events to the application.
Applications should extend this class rather than implementing the base interface InputConnection.

KeyboardView
An extension of View that renders a keyboard and responds to user input events.
The keyboard layout is specified by an instance of Keyboard, which you can define in an XML file.

Menifest:
In the Android system, an IME is an Android application that contains a IME service. The application's manifest file must declare the service, request the necessary permissions, provide an intent filter that matches the action action.view.InputMethod, and provide metadata that defines characteristics of the IME.
eg:-
<service android:name=".SimpleIME"
    android:label="@string/simple_ime"
    android:permission="android.permission.BIND_INPUT_METHOD"
    >
    <meta-data android:name="android.view.im" android:resource="@xml/method"/>
    <intent-filter>
        <action android:name="android.view.InputMethod" />
    </intent-filter>          
</service>

How can Design Keyboard Layout:
The layout of our keyboard contains only a KeyboardView.
<?xml version="1.0" encoding="UTF-8"?>
<android.inputmethodservice.KeyboardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/keyboard"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:keyPreviewLayout ="@layout/preview"
/>

Create a SoftKeyboard Class:

Create a new Java class and call it SoftKeyboard.java. The class should extend InputMethodService class and implement the OnKeyboardActionListener interface. The OnKeyboardActionListener interface contains the methods that are called when keys of the soft keyboard are tapped or pressed.

The SoftKeyboard class should have three member variables:

1.a KeyboardView referencing the view defined in the layout
2.a Keyboard instance that is assigned to the KeyboardView
3.a boolean telling us if the caps lock is enabled

After declaring these variables and adding the methods of the OnKeyboardActionListener interface, the SoftKeyboard class should look like this:

Switching among IME Subtypes:

You can allow users to switch easily among multiple IME subtypes by providing a switching key, such as the globe-shaped language icon, as part of the keyboard. Doing so greatly improves the keyboard's usability, and can help avoid user frustration. To enable such switching, perform the following steps:

Declare supportsSwitchingToNextInputMethod = "true" in the input method's XML resource files. Your declaration should look similar to the following snippet:
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
        android:settingsActivity="com.example.softkeyboard.Settings"
        android:icon="@drawable/ime_icon"
        android:supportsSwitchingToNextInputMethod="true">

Call the shouldOfferSwitchingToNextInputMethod() method.



Tuesday 29 September 2015

InputMethodSubtype:


This class is used to specify meta information of a subtype contained in an input method editor (IME). Subtype can describe locale (e.g. en_US, fr_FR...) and mode (e.g. voice, keyboard...), and is used for IME switch and settings. The input method subtype allows the system to bring up the specified subtype of the designated IME directly.

What is a Subtype
A subtype is a way to present multiple modes of operation for an Input Method Service. Commonly these different modes represent different languages, but they can also be totally different means of input such as voice input or handwriting recognition.

Before the introduction of Subtypes in Android Honeycomb (API version 11) an Input Method mapped directly to an implementation of InputMethodService.

  • The Documentation Provided by Android for Subtypes
  • The APIs surrounding Input Methods
  • InputMethodSubtype
  • InputMethodInfo
  • InputMethodManager
  • The Source code for the Android Latin IME
  • The Source code for Android

Monday 28 September 2015


 Difference between SOAP webservice and RESTFUL webservice"

At a very basic level , SOAP is a messaging protocol , REST is a design philosophy , not a protocol. When you base a WebService on a SOAP protocol , you basically comply with SOAP rules of creating a Service Request , posting the request to server , receiving the request at server , processing the request and returning the results as a SOAP message.SOAP does not talk about the exact manner in which client benefits from the service, nor about how to design the client itself ( apart from the message it is posting ), it only tells how a message from client can be sent to service and back.
REST is short for REpresentational State Transfer. It does not specify the rules to create a message and post it to server. You can do this by simple HTTP protocol. What REST specifies is the manner in which client and server manage their states so that they become useful to the client -server communication. Here , you are more focussed on designing the states of clients and servers rather than the messages they are exchanging.