トラッキング コード

12/28/2013

How to use a Sensor of "TYPE_STEP_DETECTOR"

A sensor of this type triggers an event each time a step is taken by the user.

http://developer.android.com/reference/android/hardware/Sensor.html#TYPE_STEP_DETECTOR


Initialize Sensor

We have to get a Sensor's Object from SensorManager.
Set the type "Sensor.TYPE_STEP_DETECTOR".
public class StepCounterActivity extends Activity {
    private SensorManager mSensorManager;
    private Sensor mStepSensor;
    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTextView = (TextView) findViewById(R.id.text_step);

        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        mStepSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR);

    }

    protected void onResume() {
        super.onResume();
        mSensorManager.registerListener(mSensorEventListener, mStepSensor,
                SensorManager.SENSOR_DELAY_NORMAL);
    }

    protected void onPause() {
        super.onPause();
        mSensorManager.unregisterListener(mSensorEventListener);
    }


Create a SensorListener

We can get a trigger from onSensorChanged.

    private SensorEventListener mSensorEventListener = new SensorEventListener() {
        private int mStep;

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (event.values[0] == 1.0f) {
                mStep++;
            }
            mTextView.setText(Integer.toString(mStep));
        }
    };

12/27/2013

How to use a Sensor of "TYPE_STEP_COUNTER"

Android API 19 add Sensor of "TYPE_STEP_COUNTER".

http://developer.android.com/reference/android/hardware/Sensor.html#TYPE_STEP_COUNTER


Initialize Sensor

We have to get a Sensor's Object from SensorManager.
Set the type "Sensor.TYPE_STEP_COUNTER".
public class StepCounterActivity extends Activity {
    private SensorManager mSensorManager;
    private Sensor mStepSensor;
    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTextView = (TextView) findViewById(R.id.text_step);

        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        mStepSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);

    }

    protected void onResume() {
        super.onResume();
        mSensorManager.registerListener(mSensorEventListener, mStepSensor,
                SensorManager.SENSOR_DELAY_NORMAL);
    }

    protected void onPause() {
        super.onPause();
        mSensorManager.unregisterListener(mSensorEventListener);
    }


Create a SensorListener

We can get a step from onSensorChanged.
"event.values[0]" is a step counter.A sensor of this type returns the number of steps taken by the user since the last reboot while activated. The value is returned as a float (with the fractional part set to zero) and is reset to zero only on a system reboot.

    private SensorEventListener mSensorEventListener = new SensorEventListener() {
        private float mStepOffset;

        @Override
        public void onAccuracyChanged(Sensor sensor, int accuracy) {

        }

        @Override
        public void onSensorChanged(SensorEvent event) {
            if (mStepOffset == 0) {
                mStepOffset = event.values[0];
            }
            mTextView.setText(Float.toString(event.values[0] - mStepOffset));
        }
    };

12/21/2013

How to use the DrawerLayout like a slide menu of the "Google Play"

Android Developers Site

http://developer.android.com/training/implementing-navigation/nav-drawer.html


Creat a layout file

You shoud create a layout file using DrawerLayout in android.support.v4.widget.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- The main content view -->

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The navigation drawer -->

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#111"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp" />

</android.support.v4.widget.DrawerLayout>

Set in Activity

We set ActionBarDrawerToggle.
We call "setHomeButtonEnabled(true)" and "setDisplayHomeAsUpEnabled(true)", in order to enable the click of an icon on ActionBar.

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawerlayout);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mTitle = getTitle();
        mDrawerTitle = getText(R.string.drawer_open);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerToggle = new ActionBarDrawerToggle(
                this, /* host Activity */
                mDrawerLayout, /* DrawerLayout object */
                R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
                R.string.drawer_open, /* "open drawer" description */
                R.string.drawer_close /* "close drawer" description */
                ) {

                    /**
                     * Called when a drawer has settled in a completely closed
                     * state.
                     */
                    public void onDrawerClosed(View view) {
                        getActionBar().setTitle(mTitle);
                    }

                    /**
                     * Called when a drawer has settled in a completely open
                     * state.
                     */
                    public void onDrawerOpened(View drawerView) {
                        getActionBar().setTitle(mDrawerTitle);
                    }
                };

        // Set the drawer toggle as the DrawerListener
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);
    }

12/06/2013

Add OpenGL with hardware rendering on JellybeanOnBeaglebone_WithSGX for Beagle Bone Black

If you would like to use OpenGL ES 2.0 with hardware rendering, you should add modification.


Mod egl.cfg
\device\ti\beagleboard\egl.cfg

0 0 android
0 1 POWERVR_SGX530_125 <- add line !!

Mod build.prop
\device\ti\beagleboard\beagleboard.mk

PRODUCT_PROPERTY_OVERRIDES := \
net.dns1=8.8.8.8 \
net.dns2=8.8.4.4 \
ro.opengles.version=131072 <- add line !!

Building JellybeanOnBeaglebone_WithSGX for Beagle Bone Black

Get the Files
  $ repo init -u git://gitorious.org/rowboat/manifest.git -m rowboat-jb-am335x.xml
  $ repo sync $

Toolchain Setup
Setup the tool-chain path to point to arm-eabi- tools in prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/
  $ export PATH=/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin:$PATH
Build Boot Loader (MLO/u-boot)
Change directory to u-boot
  $ cd u-boot
Execute following commands
  $ make CROSS_COMPILE=arm-eabi- distclean
  $ make CROSS_COMPILE=arm-eabi- am335x_evm_config
  $ make CROSS_COMPILE=arm-eabi- 
Build Android, Kernel and SGX
  $ make TARGET_PRODUCT=beagleboneblack OMAPES=4.x
Create Root Filesystem Tarball
Prepare the root filesystem as follows:
  $ cd 
  $ make TARGET_PRODUCT=beagleboneblack fs_tarball
Flash SD Card
Copy compiled Images to image folder and create a bootable SD card as follows.
  $ mkdir image_folder
  $ cd image_folder
  $ cp ../kernel/arch/arm/boot/uImage .
  $ cp ../u-boot/MLO .
  $ cp ../u-boot/u-boot.img .
  $ cp ../external/ti_android_utilities/am335x/u-boot-env/uEnv_beagleboneblack.txt .
  $ cp ../out/target/product/beagleboneblack/rootfs.tar.bz2 .
  $ cp ../external/ti_android_utilities/am335x/mk-mmc/mkmmc-android.sh .
  $ sudo ./mkmmc-android.sh YOUR_SD_CARD MLO u-boot.img uImage uEnv_beagleboneblack.txt rootfs.tar.bz2

12/05/2013

TI official image of Android On Beagle Bone Black

You can get 'release information' of Beagle Bone Black's Android.
http://downloads.ti.com/sitara_android/esd/TI_Android_DevKit/TI_Android_JB_4_2_2_DevKit_4_1_1/index_FDS.html

I got offical TI image Of Android 4.2.2, and install to beagle bone black.


$ wget http://downloads.ti.com/sitara_android/esd/TI_Android_DevKit/TI_Android_JB_4_2_2_DevKit_4_1_1/exports/TI_Android_JB_4.2.2_DevKit_4.1.1_beagleboneblack.tar.gz
$ tar xzvf TI_Android_JB_4.2.2_DevKit_4.1.1_beagleboneblack.tar.gz
$ cd beagleboneblack
$ sudo ./mkmmc-android.sh /dev/


copyed to log.
Assuming Default Locations for Prebuilt Images
All data on /dev/sdb now will be destroyed! Continue? [y/n]
y
[Unmounting all existing partitions on the device ]
umount: /dev/sdb: not mounted
umount: /dev/sdb2: not mounted
[Partitioning /dev/sdb...]
Disk /dev/sdb doesn't contain a valid partition table
DISK SIZE - 7851737088 bytes
CYLINDERS - 954
[Making filesystems...]
[Copying files...]
[Copying START_HERE folder to boot partition]
umount: /mnt: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[Copying all clips to data partition]
[Done]


Takes a long time to start Android...Please wait 10 minutes.