トラッキング コード

1/29/2012

NavigationBar / Virtual buttons in the System Bar

NavigationBar

NavigationBar is Virtual buttons in the System Bar.




Implement of NavigationBar

NavigationBar has been implemented as part of SystemUI / StatusBar.
Show PhoneStatusBar.java.

\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone
- PhoneStatusBar.java

try {
            boolean showNav = mWindowManager.hasNavigationBar();
            if (showNav) {
                mNavigationBarView =
                    (NavigationBarView) View.inflate(context, R.layout.navigation_bar, null);

                mNavigationBarView.setDisabledFlags(mDisabled);
            }
        } catch (RemoteException ex) {
            // no window manager? good luck with that
        }

It is just View!!

Layout file is
\frameworks\base\packages\SystemUI\res\layout
- navigation_bar.xml



Case of Tablet devices.

\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\tablet
- TabletStatusBar.java

try {
            // Sanity-check that someone hasn't set up the config wrong and asked for a navigation
            // bar on a tablet that has only the system bar
            if (mWindowManager.hasNavigationBar()) {
                throw new RuntimeException(
                        "Tablet device cannot show navigation bar and system bar");
            }
        } catch (RemoteException ex) {
        }

If Tablet devices has NavigationBar,occurs RuntimeException!!
Tablet devices do not implement NavigationBar.


NavigationBar is enable or Diseble ?

Show PhoneWindowManager#setInitialDisplaySize().


// Determine whether the status bar can hide based on the size
        // of the screen.  We assume sizes > 600dp are tablets where we
        // will use the system bar.
        int shortSizeDp = shortSize
                * DisplayMetrics.DENSITY_DEFAULT
                / DisplayMetrics.DENSITY_DEVICE;
        mStatusBarCanHide = shortSizeDp < 600;
        mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
                mStatusBarCanHide
                ? com.android.internal.R.dimen.status_bar_height
                : com.android.internal.R.dimen.system_bar_height);

        mHasNavigationBar = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_showNavigationBar);
        // Allow a system property to override this. Used by the emulator.
        // See also hasNavigationBar().
        String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
        if (! "".equals(navBarOverride)) {
            if      (navBarOverride.equals("1")) mHasNavigationBar = false;
            else if (navBarOverride.equals("0")) mHasNavigationBar = true;
        }
To see the value of com.android.internal.R.bool.config_showNavigationBar.
It is defined in following xml

 \frameworks\base\core\res\res\values - config.xml


<!-- Whether a software navigation bar should be shown. NOTE: in the future this may be
         autodetected from the Configuration. -->
    <bool name="config_showNavigationBar">false</bool>


Standard ICS is not shown as a NavigationBar.So, Check of device folder.

\device\samsung\tuna\overlay\frameworks\base\core\res\res\values
- config.xml
This value Will be displayed on GalaxyNexus.


Key Event of NavigationBar

If Buttom of home/back is touched, send inputEvent from Java Layer to Native Layer.
KeyButtonView#sendEvent
 - WindowManagerService#injectInputEventNoWait
   - InputManager#injectInputEvent
     - InputManager#nativeInjectInputEvent
       - android_server_InputManager_nativeInjectInputEvent
       - InputDispatcher#injectInputEvent




1/27/2012

Phone mode or Tablet mode in Ice Cream Sandwich ?

ICS has Phone UI Mode and Tablet UI Mode.
How to change Phone / Tablet in Android Frameworks ?


Definition of UI Mode

you can find in wake up Sequence.


ServerThread#run()
- WindowManagerService#displayReady
- PhoneWindowManagerService#setInitialDisplaySize


Check in PhoneWindowManagerService#setInitialDisplaySize.


// Determine whether the status bar can hide based on the size
        // of the screen.  We assume sizes > 600dp are tablets where we
        // will use the system bar.
        int shortSizeDp = shortSize
                * DisplayMetrics.DENSITY_DEFAULT
                / DisplayMetrics.DENSITY_DEVICE;
        mStatusBarCanHide = shortSizeDp < 600;


DisplayMetrics.DENSITY_DEFAULT is define in DisplayMetrics.java

/**
     * Standard quantized DPI for medium-density screens.
     */
    public static final int DENSITY_MEDIUM = 160;

    /**
     * The reference density used throughout the system.
     */
    public static final int DENSITY_DEFAULT = DENSITY_MEDIUM;

    /**
     * The device's density.
     * @hide becase eventually this should be able to change while
     * running, so shouldn't be a constant.
     */
    public static final int DENSITY_DEVICE = getDeviceDensity();

    private static int getDeviceDensity() {
        // qemu.sf.lcd_density can be used to override ro.sf.lcd_density
        // when running in the emulator, allowing for dynamic configurations.
        // The reason for this is that ro.sf.lcd_density is write-once and is
        // set by the init process when it parses build.prop before anything else.
        return SystemProperties.getInt("qemu.sf.lcd_density",
                SystemProperties.getInt("ro.sf.lcd_density", DENSITY_DEFAULT));
    }


Case of Crespo(Nexus s),
swWidth = 480
  ro.sf.lcd_density=240
  shortSizeDp = 480 * 160 / 240 = 320
Crespo has Phone UI mode.


Case of maguro(Galaxy Nexus),
swWidth = 720
  ro.sf.lcd_density=320
  shortSizeDp = 720 * 160 / 320 = 360
Maguro has Phone UI mode.


If you want to use Maguro with Tablet UI Mode, change lcd_density from 320 to 160.
swWidth = 720
  ro.sf.lcd_density=160
  shortSizeDp = 720 * 160 / 160 = 720



Check !!

\frameworks\base\policy\src\com\android\internal\policy\impl
- PhoneWindowManagerService.java

\frameworks\base\core\java\android\util
- DisplayMetrics.java

\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar
- all directory ( StatusBar / SystemBar)

1/21/2012

CPU Usage

how to display of CPU usage

Settings -> Developer Options -> Show CPU usage

Screen overlay showing current CPU usage.

Setting CPU Usage in frameworks

DevelopmentSettings#onPreferenceTreeClick
- writeCpuUsageOptions()
  - startService "com.android.systemui.LoadAverageService" of SysttemUI.
  - LoadAverageService#onCreate()
    - new LoadView extends ProcessStats
        - new Stats
    - WindowManager#addView() with Overlay layer of SECURE_SYSTEM_OVERLAY_LAYER
        - WindowManagerImpl#addView
            - ViewRootImpl#setView
                - IWindowSession#add
                    - Session#add
                        - WindowManagerService#addWindow


check sorce file

\packages\apps\Settings\src\com\android\settings
- DevelopmentSettings.java

\frameworks\base\packages\SystemUI\src\com\android\systemui
- LoadAverageService.java

\frameworks\base\policy\src\com\android\internal\policy\impl
- PhoneWindowManager.java

\frameworks\base\core\java\com\android\internal\os
- ProcessStats.java



Build speed up : out directory changed to SSD

Link:
New experimental build system feature: out/ directories in another location
http://groups.google.com/group/android-building/browse_thread/thread/ca6c1648aa52acb9

This should be useful when storing the build output on a physically
different volume. Additional benefits might come from using a
dedicated volume for that where journaling is disabled, and/or from
using an SSD.

To use it, set the OUT_DIR_COMMON_BASE environment to the directory
where the output directories will be created. A subdirectory will be
created there for each source tree. The name of the subdirectory
matches that of the source tree.

memo:
- we can change "out directory" with OUT_DIR_COMMON_BASE
- use SSD to build speed up.

but, This patch is commited in Master blanch, so is not in Android-4.0.3_r1 blanch.

check it !!
\build\core\envsetup.mk

# ---------------------------------------------------------------
# figure out the output directories

ifeq (,$(strip $(OUT_DIR)))
ifeq (,$(strip $(OUT_DIR_COMMON_BASE)))
OUT_DIR := $(TOPDIR)out
else
OUT_DIR := $(OUT_DIR_COMMON_BASE)/$(notdir $(PWD))
endif
endif

DEBUG_OUT_DIR := $(OUT_DIR)/debug

1/19/2012

Adding share action in ActionBar

See Gallery app



I introduce that how to add share action in ActionBar such as Galley app.


Creat menu resouce

You must to creat menu resouce with "android:actionProviderClass="android.widget.ShareActionProvider".

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/menu_share"
        android:title="share"
        android:icon="@android:drawable/ic_menu_share"
        android:showAsAction="ifRoom"
        android:actionProviderClass="android.widget.ShareActionProvider">
    </item>
</menu>

Adding Intent action

You must to add intent action with ShareActionProvider.class in onCreateOptionsMenu method.

public boolean onCreateOptionsMenu(Menu menu){
     getMenuInflater().inflate(R.menu.menu, menu);
        mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_share).getActionProvider();

        // If you use more than one ShareActionProvider, each for a different action,
        // use the following line to specify a unique history file for each one.
        // mShareActionProvider.setShareHistoryFileName("custom_share_history.xml");

        // Set the share intent
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, "shareIntent Test");
        
        mShareActionProvider.setShareIntent(shareIntent);

        return true;
    }


1/18/2012

Using the App Icon for Navigation

What is the App Icon for Navigation?

You can see the App Icon for Navigation in Market App.



How to use the App Icon for Navigation

To enable the icon for up navigation, call setDisplayHomeAsUpEnabled(true) on your ActionBar.

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

When the user touches the icon, Android framework is called onOptionsItemSelected() method with the android.R.id.home ID in Activity Class.

    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case android.R.id.home:
            // app icon in action bar clicked;
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

1/16/2012

Adding the ActionBar

Developer site:
http://developer.android.com/intl/ja/guide/topics/ui/actionbar.html

Adding the Action Bar

Beginning with Android 3.0 (API level 11), the action bar is included in all activitie.
If yuu want to use Action Bar, you should add android:targetSdkVersion="11" in AndroidManifest.xml.


<manifest ...="">
    <uses-sdk android:minsdkversion="8" android:targetsdkversion="11">
</uses-sdk>
</manifest>


Creating an Options Menu

Creating a Menu Resource

you should define a menu and all its items in an XML menu resource, then inflate the menu resource (load it as a programmable object) in your application code.
To create a menu resource, create an XML file inside your project's res/menu/ directory.

example.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/item1"
        android:icon="@android:drawable/ic_menu_edit"
        android:title="btn1">
    </item>
    <item
        android:id="@+id/item2"
        android:icon="@android:drawable/ic_menu_add"
        android:title="btn2">
    </item>
</menu>


Creating an Options Menu

When Press the menu key, Android Framework is called onCreateOptionsMenu method in Activity class.
To inflate a menu resource.

@Override
    public boolean onCreateOptionsMenu(Menu menu){
      super.onCreateOptionsMenu(menu);
      getMenuInflater().inflate(R.menu.menu,menu);
      return true;
    }

Responding to user action

When User selected in menu item, Android Framework is called onOptionsItemSelected method in Activity class.


@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
        case R.id.item1:
         //action item1
            return true;
        case R.id.item2:
         //action item2
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

1/14/2012

Building for maguro ICS

maguro is building name of "Galaxy Nexus for GSM/HSPA+".

Reference WebPage

http://source.android.com/source/building-devices.html
http://code.google.com/intl/ja/android/nexus/drivers.html


Obtaining "proprietary binaries"

You need to obtain "proprietary binaries" which is not include the Android Open-Source Project.
To run the script for obtaining device's "proprietary binaries"

$ cd device/samsung/maguro
$ ./extract-files.sh

After running script, "vendor" drectory is generated in the root of the build environment.

vender/samsung/maguro/*

If you don't have Galaxy Nexus, need to get "proprietary binaries".

Example for getting Android-4.0.3 IML74K "proprietary binaries".
$ wget https://dl.google.com/dl/android/aosp/imgtec-maguro-iml74k-a796ffae.tgz
$ wget https://dl.google.com/dl/android/aosp/samsung-maguro-iml74k-de1cc439.tgz
$ tar zxvf imgtec-maguro-iml74k-a796ffae.tgz
$ tar zxvf samsung-maguro-iml74k-de1cc439.tgz
$ ./extract-imgtec-maguro.sh
$ ./extract-samsung-maguro.sh


building the configuration that matches a device

running to build for maguro.

$ . build/envsetup.sh
$ lunch full_maguro-userdebug
$ make

Building for Crespo ICS

Reference WebPage

http://source.android.com/source/building-devices.html
http://code.google.com/intl/ja/android/nexus/drivers.html


Obtaining "proprietary binaries"

You need to obtain "proprietary binaries" which is not include the Android Open-Source Project.
To run the script for obtaining device's "proprietary binaries"

$ cd device/samsung/crespo
$ ./extract-files.sh

After running script, "vendor" drectory is generated in the root of the build environment.

vender/samsung/crespo/*


building the configuration that matches a device

running to build for crespo.

$ . build/envsetup.sh
$ lunch full_crespo-userdebug
$ make