Application Development

Configure the Development Environment

Development on Windows


Installation of JDK

Download JDK After Download follow the instructions to install the JDK, then configure the variables:


JAVA_HOME= D:\Program Files\Java\jdk1.6.0_18(Your JDK directory)
CLASSPATH=.;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\bin;
Path: Add to existing %JAVA_HOME%\bin;

After the installation is complete, check if JDK is installed successfully. Open cmd window, enter java -version.
You should see the following message if the installation is succesful:

Eclipse Installation

Download Eclipse Select download windows version. Unzip Eclipse directly after the download is complete and install it.

Installation and Configuration of ADT

Eclipse ADT is used to develop a plug-in Android applications. Open eclipse, select the menu bar help->Install New SoftWare->Add
Enter this address in the Location https://dl-ssl.google.com/android/eclipse/ and select local archive path.

Installation of Android SDK

Download AndroidSDK Choose suitable for your platform SDK package (in this case Windows) download. A compressed file is downloaded. Next, go to the Eclipse SDK configuration, open Eclipse select Windows> Preferences ... to open the Edit Properties window, select Android item in SDK Location then select the full path to the Android SDK unpacked files. Result should be as shown below:

Here is an example of a correct Windows Android Development Environment

Create an Android project

When you build environment is configured, it's time to create the first project:
1 .Choose File > New > Project
2 .Choose Android > Android Project, Click Next
3 .Create a new Android Project
At the end you should have an Android Project setup.


Linux Development Environment Setup


Download Linux SDK:http://pan.baidu.com/s/1pJ1hB7t, Password:epgk.

Download Linux NDK:http://pan.baidu.com/s/1kTCfiKJ,Password: 56w5.

Installation of JDK

Grant permission to modify the file


chmod  777  jdk-6u33-linux-x64.bin

Install


./jdk-6u33-linux-x64.bin

Configure the environment variables inside /etc/profile


sudo gedit /etc/profile

Add at the end of the file


JAVA_HOME=/home/test/AndroidTools/eclipse/jdk1.6.0_45 
JRE_HOME=/home/test/AndroidTools/eclipse/jdk1.6.0_45/jre
CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:/home/test/bin
export PATH JAVA_HOME JRE_HOME CLASSPATH

Then run the terminal source/etc/profile, so that the changes take effect immediately, run java -version so you can check if the environment variable configuration is correct. Run the java -version, which should output the following:

Installation of Eclipse

Download Eclipse Select the linux version for download. Unzip Eclipse directly after the download is complete.

Installation and Configuration of ADT

Eclipse ADT is used to develop a plug-in Android applications. Open eclipse, in the menu bar, select help-> Install New SoftWare-> Add
Enter the address https://dl-ssl.google.com/android/eclipse/ in the Location field. For local installation select archive storage path.

Installation of Android SDK

SDK and JDK similar configuration, easier than JDK configuration. Here an example with SDK directory under /home/test/ AndroidTools/android-sdk-linux configuration. First you have to extract the sdk directory. Then open the configuration file


sudo gedit /etc/profile 

After android configuration file should look like this:


JAVA_HOME=/home/test/AndroidTools/eclipse/jdk1.6.0_45   
ANDROID_HOME=/home/test/AndroidTools/android-sdk-linux
JRE_HOME=/home/test/AndroidTools/eclipse/jdk1.6.0_45/jre
CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:/home/test/bin:$ANDROID_HOME/tools
export PATH JAVA_HOME ANDROID_HOME JRE_HOME CLASSPATH

The references should now be updated. Save and reboot, sdk is configured. Then configure the Android SDK on Eclipse by following the steps mentioned for the Windows Environment.


Install Android NDK

This example has the NDK under android-ndk-r10 folder http://developer.android.com/ndk/downloads/index.html is the official website to download ndk, according to their own linux system selection, here is downloaded to /home/test/AndroidTools/path. After downloading unzip and configure the environment variables, open .bashrc configuration


$ vi .bashrc 

At the end configure the NDK path:


export NDK_HOME=/home/test/AndroidTools/android-ndk-r10  
export PATH=$NDK_HOME:$PATH

Refer to the configuration below and then change your building environment variables


$. .bashrc 

IWDS basic application development


Create a new Android project as shown below:

After the project is created you need to import IWDS jar package, you can directly link the two packages iwds-jar.jar, iwds.jar under the libs file into your new project. At the same time you need to put our used libiwds.so files copied into it. Right click in the Eclipse project root directory, select Properties -> Java Build Path -> Libraries, and then click Add External JARs ... choose the path pointing to jar, click OK, namely import was successful. (ADT17 and above need to manually import). libs file as shown below:

iwds jar package can have a good distribution after formally developed.

Demo DataTransactor data transmission between two devices (between the phone and watch)

1. First with two devices m_transactor.start start up DataTransactor.
2. Through onLinkConnected monitor the hardware connection status onChannelAvailable Monitoring Bluetooth data transmission channel. If the device is connected, the data transmission channel is active, you can transfer the data.
3. A device used m_transactor.send(m_weather) send data m_weather Object.
4. Another device onDataArrived(Object object) receives the Object sent.
5. After ending with m_transactor.stop shut down the DataTransactor.

Note: Application must be installed on both devices

Instantiation of DataTransactor:
 m_transactor = new DataTransactor(this, this, m_uuid);
Start with Close DataTransactor.

    @Override
    protected void onPause() {
        super.onPause();

        m_transactor.stop();

        IwdsLog.i(this, "onPause");
    }

    @Override
    protected void onResume() {
        super.onResume();

        m_transactor.start();

        IwdsLog.i(this, "onResume");
    }
Monitor the Bluetooth channel status, check if isAvailable is true in order to transmit data

    @Override
    public void onChannelAvailable(boolean isAvailable) {
        if (isAvailable) {
            IwdsLog.i(this, "Data channel is available.");

                /* when channel is available, send the data */
            m_transactor.send(m_weather);

        } else {
            IwdsLog.i(this, "Data channel is unavaiable.");
        }
    }

Download the Demo Code

Demo FileTransactionModel to send files between two devices.

This is the path of the sender /sdcard/Download/test.zip,and the path of the receiver /sdcard/iwds/
1. First start FileTransactionModel
2. Through the inter-connection state onLinkConnected monitor the devices, monitoring by onChannelAvailable Bluetooth data transmission channel. If the device is connected, the data transmission channel is active, you can transfer the data.
3. Send requestSendFile() to request a file.
4. The receiving end device in onRequestSendFile() to confirm whether to accept the document. Confirm receipt of the file with notifyConfirmForReceiveFile, received documents with notifyCancelForReceiveFile canceled.
5. The sender device sends a file when it receives ConfirmForReceiveFile, if it receives CancelForReceiveFile then the file is not sent.
6. After the file transfer, the sender and the receiver will trigger onSendResult, to notify the transmission success or failure. Receiving onFileArrived, notify that the file is received.

Note: application must be installed on both devices

Instantiation of FileTransactionModel:

   if (mFileTransactionModel == null)
                mFileTransactionModel = new FileTransactionModel(this, this, UUID);
Start by Closing FileTransactionModel

            case R.id.connect_button:
                Log.d(TAG, "MSG_CONNECTING.");
                mHandler.obtainMessage(MSG_CONNECTING).sendToTarget();
                mFileTransactionModel.start();
                mServiceConnected = true;
                break;
            case R.id.disconnect_button:
                Log.d(TAG, "MSG_DISCONNECTING.");
                mHandler.obtainMessage(MSG_DISCONNECTING).sendToTarget();
                mFileTransactionModel.stop();
                mServiceConnected = false;
                break;
Send the files you want to transfer:

        case R.id.send_button:
                Log.d(TAG, "MSG_SENDING.");
                mSendCounter = 0;
                mSendNum = getNumber(mIterationsEdit, Integer.MAX_VALUE);
                try {
                    mSendDataType = TYPE_FILE_INFO;
                    mFileTransactionModel.requestSendFile(FILE_PATH);
                    mIsResponse = false;
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                }
                mHandler.obtainMessage(MSG_SENDING).sendToTarget();
                break;
The receiving end with confirmation (the whole connection, transmission and receiving and other state can inherit FileTransactionModelCallback callback interface to real-time monitoring):

@Override
    public void onRequestSendFile(FileInfo info) {
        mIsResponse = false;
        mRecvDataType = TYPE_FILE_INFO;
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.file_transfer);
        builder.setCancelable(false);
        builder.setMessage(FileTransactionActivity.this.getString(R.string.file_name) + ": " + info.name + "\n"
                + FileTransactionActivity.this.getString(R.string.file_size) + ": " + info.length + "bytes");
        builder.setPositiveButton(R.string.confirm,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,
                            int which) {
                        mFileTransactionModel.notifyConfirmForReceiveFile();
                        mRecvStartTime = System.currentTimeMillis();
                    }
                });
        builder.setNegativeButton(R.string.cancel,
                new DialogInterface.OnClickListener(){
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mFileTransactionModel.notifyCancelForReceiveFile();
                    }
        });
        builder.create().show();
    }

Download FileTransactionModelDemo

Demo iwds-ui-jar.jar and iwds-ui-with-res.jar application development Watch

1. Create a new Android ProjectDownload iwdsApiDemo

2. Now you need to import the packages iwds-ui-jar.jar,iwds-ui-with-res.jar into the lib folder in your project:

3. Inside Eclipse import iwds-ui-res-jar.

4. Reference iwdsApiDemo iwds-ui-res-jar source code, in Eclipse right project root directory, select Properties -> android, and then click Add and then select iwds-ui-res-jar, click OK.

How to use the Amazing Controls

1. AmazingDialog Controls


  private AmazingDialog dialog;
  /*Create a Dialog*/
  dialog = new AmazingDialog(mContext)
                .setContent(R.string.dialog_content)
                .setNegativeButton(0, new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        AmazingToast.showToast(mContext, "Click Cancel",
                                AmazingToast.LENGTH_SHORT,
                                AmazingToast.BOTTOM_CENTER);
                        dialog.dismiss();
                    }
                }).setPositiveButton(0, new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        AmazingToast.showToast(mContext, "Click OK",
                                AmazingToast.LENGTH_SHORT,
                                AmazingToast.BOTTOM_CENTER);
                        dialog.dismiss();
                    }
             });
  /*The dialog is displayed*/
  dialog.show();

as the picture below shows

2. AmazingprogressDialog Controls


  private AmazingDialog dialog;
  /*Create AmazingDialog*/
  progressDialog = new AmazingIndeterminateProgressDialog(mContext, getString(R.string.loading));
  progressDialog.setCancelable(true);
  /*Dialog box is displayed*/
  progressDialog.show();

as the picture shows

3. AmazingRingProgressView Controls


package com.ingenic.iwds.apidemo;

import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ingenic.iwds.widget.AmazingProgressBar;
import com.ingenic.iwds.widget.AmazingProgressBar2;
import com.ingenic.iwds.widget.AmazingRingProgressView;

public class ProgressFragment extends DemoFragment {

    private View mContentView;

    private AmazingProgressBar progressBar;
    private AmazingProgressBar2 progressBar2;
    private AmazingRingProgressView ringProgressView;

    private int mTotalProgress = 100;

    private int mCurrentProgress;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        mContentView = inflater.inflate(R.layout.amazing_progress, null);

        init();

        return mContentView;
    }

    /**
     * Init
     */
    private void init() {
        progressBar = (AmazingProgressBar) mContentView.findViewById(R.id.progressbar);
        progressBar2 = (AmazingProgressBar2) mContentView.findViewById(R.id.progressbar2);
        ringProgressView = (AmazingRingProgressView) mContentView
                .findViewById(R.id.ring_progressbar);
        ringProgressView.setPercentEnable(true);
        mHandler.sendEmptyMessageDelayed(0, 100);
    }

    /**
     * Progress Bar Handler
     */
    private Handler mHandler = new Handler() {

        public void handleMessage(android.os.Message msg) {// does not exceed maximum
            if (msg.what == 0 && mCurrentProgress < mTotalProgress) {
                    // Step value 1
                    mCurrentProgress ++;
                    // Setting the progress
                    ringProgressView.setProgress(mCurrentProgress);
                    mHandler.sendEmptyMessageDelayed(0, 10);
            }
        };

    };

    @Override
    public void onDestroyView() {
        if(null!=progressBar){
            progressBar.stop();
        }
        if(null!=progressBar2){
            progressBar2.stop();
        }
        super.onDestroyView();
    }

}

as the picture shows

4. For other controls implementation see iwdsApiDemo