トラッキング コード

12/12/2012

How to use ActivityLifecycleCallbacks in Application Class

Do you want to add same code in all your ActivityLifeCycle?
You must use ActivityLifecycleCallbacks.

ActivityLifecycleCallbacks is interface of Application.class.
Can handle the called lifeCycle of Activity.


Sample code:
public class MyApplication extends Application {

    @Override
 public void onCreate (){
  super.onCreate();
  registerActivityLifecycleCallbacks(new MyActivityLifecycleCallbacks());
 }
 
    @Override
    public void onTerminate (){
     super.onTerminate();
    }
    
    @Override
    public void onConfigurationChanged (Configuration newConfig){
     super.onConfigurationChanged(newConfig);
    }
    
    private static final class MyActivityLifecycleCallbacks implements ActivityLifecycleCallbacks {

  public void onActivityCreated(Activity activity, Bundle bundle) {
   Log.e("","onActivityCreated:" + activity.getLocalClassName());
  }

  public void onActivityDestroyed(Activity activity) {
   Log.e("","onActivityDestroyed:" + activity.getLocalClassName());
  }

  public void onActivityPaused(Activity activity) {
   Log.e("","onActivityPaused:" + activity.getLocalClassName());
  }

  public void onActivityResumed(Activity activity) {
   Log.e("","onActivityResumed:" + activity.getLocalClassName());
  }

  public void onActivitySaveInstanceState(Activity activity,
    Bundle outState) {
   Log.e("","onActivitySaveInstanceState:" + activity.getLocalClassName());
  }

  public void onActivityStarted(Activity activity) {
   Log.e("","onActivityStarted:" + activity.getLocalClassName());
  }

  public void onActivityStopped(Activity activity) {
   Log.e("","onActivityStopped:" + activity.getLocalClassName());
  }
    }
}

9/05/2012

How to use Camera Preview of Portrait

If Camera Preview's oientation is incorrect when the device is Portrait, you should read following developer's site.


http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)

Sample code:
 public void surfaceCreated(SurfaceHolder holder) {
      mCamera = Camera.open();
      setCameraDisplayOrientation();
 }

 private void setCameraDisplayOrientation(){
      int rotation = mWindowManager.getDefaultDisplay().getRotation();
      
      Camera.CameraInfo info = new Camera.CameraInfo();
      // camera id is ...
      Camera.getCameraInfo(0, info);
      int degrees = 0;
      switch (rotation) {
          case Surface.ROTATION_0: degrees = 0; break;
          case Surface.ROTATION_90: degrees = 90; break;
          case Surface.ROTATION_180: degrees = 180; break;
          case Surface.ROTATION_270: degrees = 270; break;
      }

      int result;
      if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
          result = (info.orientation + degrees) % 360;
          result = (360 - result) % 360;  // compensate the mirror
      } else {  // back-facing
          result = (info.orientation - degrees + 360) % 360;
      }
      mCamera.setDisplayOrientation(result);
 }

9/02/2012

How to handle "Screen ON/OFF and Keygurad"



You need to use BroadcastReceiver and IntentFilter.

  • Create BroadcastReceiver
  • Register BroadcastReceiver and IntentFilter
  • If you do not need, you must unregister.


Create BroadcastReceiver

If the device is Screen ON/OFF, Android frameworks call mReceiver#onReceive().

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(Intent.ACTION_SCREEN_OFF)) {
                // Screen is off
                Log.e("", "ACTION_SCREEN_OFF");
            }
            else if (action.equals(Intent.ACTION_SCREEN_ON)) {
                // Intent.ACTION_USER_PRESENT will be broadcast when the screen
                // is
                // unlocked.

                // if API Level 16
                /*
                 * if(mKeyguard.isKeyguardLocked()){ // the keyguard is
                 * currently locked. Log.e("","ACTION_SCREEN_ON : locked"); }
                 */
                if (mKeyguard.inKeyguardRestrictedInputMode()) {
                    // the keyguard is currently locked.
                    Log.e("", "ACTION_SCREEN_ON : locked");
                }
                else {
                    // unlocked
                    Log.e("", "ACTION_SCREEN_ON : unlocked");
                }

            }
            else if (action.equals(Intent.ACTION_USER_PRESENT)) {
                // The user has unlocked the screen. Enabled!
                Log.e("", "ACTION_USER_PRESENT");
            }

        }

    };


Register BroadcastReceiver and IntentFilter

Create IntentFilter with ACTION_SCREEN_ON(OFF), and register to use Activity(or Serivce)#registerReceiver().

        // get KeyGuardManager
        mKeyguard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);

        // IntetFilter with Action
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
        intentFilter.addAction(Intent.ACTION_SCREEN_ON);
        intentFilter.addAction(Intent.ACTION_USER_PRESENT);// Keyguard is GONE

        // register BroadcastReceiver and IntentFilter
        registerReceiver(mReceiver, intentFilter);


Unregister

If you do not need, you must unregister.

        // register BroadcastReceiver and IntentFilter
        unregisterReceiver(mReceiver);

8/30/2012

Never be called Application#onTerminate()


I checked up that Application(not Activity) has module of handling "stopped / resumed".
There was no explicit modules that are called from the frameworks.


So, What is Application#onTerminate()? Where is called in frameworks?
Are described in the Android Developers.

http://developer.android.com/reference/android/app/Application.html#onTerminate()

This method is for use in emulated process environments. It will never be called on a production Android device, where processes are removed by simply killing them; no user code (including this callback) is executed when doing so.

This Module will be present for what?

I do "grep" in Android frameworks, it is called from ActivityThread.java.

                case EXIT_APPLICATION:
                    if (mInitialApplication != null) {
                        mInitialApplication.onTerminate();
                    }
                    Looper.myLooper().quit();
                    break;


When ActivityThread#scheduleExit() send message, this process is called.

2 module in ActivityManagerService.java is called ActivityThread#scheduleExit()。


private final boolean attachApplicationLocked(IApplicationThread thread, int pid)
final void trimApplications()

Cord in module.
                    if (app.pid > 0 && app.pid != MY_PID) {
                        EventLog.writeEvent(EventLogTags.AM_KILL, app.pid,
                                app.processName, app.setAdj, "empty");
                        Process.killProcessQuiet(app.pid);
                    } else {
                        try {
                            app.thread.scheduleExit();
                        } catch (Exception e) {
                            // Ignore exceptions.
                        }
                    }
If the following case to call ActivityThread#scheduleExit().
  • PID is under "0"
  • PID is MY_PID(= System Process)


When Application is same "System Process", called ActivityThread#scheduleExit().
So, It is not application of "same System Process"...

7/18/2012

Starting for Android JUnit Test

If you would like to publish application to Google Market, I recommend that you test.
Android has test framework which helping you to test .

Check develoer's site!!

http://developer.android.com/tools/testing/index.html
The Android framework includes an integrated testing framework that helps you test all aspects of your application and the SDK tools include tools for setting up and running test applications. Whether you are working in Eclipse with ADT or working from the command line, the SDK tools help you set up and run your tests within an emulator or the device you are targeting.
If you aren't yet familiar with the Android testing framework, start by reading Testing Fundamentals. For a step-by-step introduction to Android testing, try the Activity Testing Tutorial.

How to set up Project for eclipse:

http://developer.android.com/tools/testing/testing_android.html

7/01/2012

Phone mode or Tablet mode in Android 4.1 Jelly Bean?




Android 4.1 Jelly Bean has Phone UI Mode and Tablet UI Mode, so same ICS.
How to change Phone / Tablet in Android Frameworks ?

If you have Android SDK Api 16, you can notice source code!!

Definition of UI Mode

Check in PhoneWindowManager#setInitialDisplaySize.

\sources\android-16\com\android\internal\policy\impl\PhoneWindowManager.java

        // SystemUI (status bar) layout policy
        int shortSizeDp = shortSize
                * DisplayMetrics.DENSITY_DEFAULT
                / DisplayMetrics.DENSITY_DEVICE;

        if (shortSizeDp < 600) {
            // 0-599dp: "phone" UI with a separate status & navigation bar
            mHasSystemNavBar = false;
            mNavigationBarCanMove = true;
        } else if (shortSizeDp < 720) {
            // 600-719dp: "phone" UI with modifications for larger screens
            mHasSystemNavBar = false;
            mNavigationBarCanMove = false;
        } else {
            // 720dp: "tablet" UI with a single combined status & navigation bar
            mHasSystemNavBar = true;
            mNavigationBarCanMove = false;
        }

        if (!mHasSystemNavBar) {
            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;
            }
        } else {
            mHasNavigationBar = false;
        } 
PhoneWindowManager has been changed from ICS.
Tablet UI mode need 720dp!!

4/01/2012

Getting the Factory Image 4.0.4(IMM76D) of Galaxy Nexus(maguro)




You can get the Factory Image of Galaxy Nexus.

Google Support for Nexus Phones and Flagship Devices.
 http://code.google.com/intl/ja/android/nexus/images.html


Example of 4.0.4 (IMM76D) maguro

wget https://dl.google.com/dl/android/aosp/yakju-imm76d-factory-c6e807a1.tgz
tar xvf ./yakju-imm76d-factory-c6e807a1.tgz
cd yakju-icl53f
./flash-all.sh

3/30/2012

3/11/2012

How to use Google Test on Android-4.0.3_r1

AOSP has Google Test project in extarnal/gtest directory.

I try to use Google Test in my Application.

Create Android.mk for Google Test

I was referring to the existing Android.mk in extarnal/gtest/test.

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

# Gtest depends on STLPort which does not build on host/simulator.

ifeq ($(BUILD_WITH_ASTL),true)
libgtest_test_includes := \
    bionic/libstdc++/include \
    external/astl/include \
    external/gtest/include \
 $(LOCAL_PATH)/../test \
 $(LOCAL_PATH)/..
libgtest_test_static_lib := libgtest_main libgtest libastl
libgtest_test_shared_lib :=
libgtest_test_host_static_lib := libgtest_main_host libgtest_host libastl_host
libgtest_test_host_shared_lib :=
else
# BUILD_WITH_ASTL could be undefined, force it to false (for the guard
# before the test-target call).
BUILD_WITH_ASTL := false
libgtest_test_includes := \
    bionic \
    external/stlport/stlport \
    external/gtest/include \
 $(LOCAL_PATH)/../test \
 $(LOCAL_PATH)/..
libgtest_test_static_lib := libgtest_main libgtest
libgtest_test_shared_lib := libstlport
libgtest_test_host_static_lib :=
libgtest_test_host_shared_lib :=
endif


LOCAL_MODULE_TAGS := TestAppGtest
LOCAL_C_INCLUDES := $(libgtest_test_includes)

LOCAL_SHARED_LIBRARIES := \
    libcutils \
    libutils \
    libandroid_runtime \
    $(libgtest_test_shared_lib) \
    $(libgtest_test_host_shared_lib)

LOCAL_STATIC_LIBRARIES := \
    $(libgtest_test_static_lib) \
    $(libgtest_test_host_static_lib)

# if LOCAL_SRC_FILES is .cc
#LOCAL_CPP_EXTENSION := .cc

# YOUR Source and Test Source
LOCAL_SRC_FILES := \
    sample1.cpp \
    sample1_unittest.cpp

LOCAL_MODULE := gtest_mytest
LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_APPS)

include $(BUILD_EXECUTABLE)


Building Google Test

I try to build an apllicaion with google test code.

I uploaded sample project.
https://docs.google.com/open?id=0BwdCdBWuE_7cb2ZzVGt3eHhSOEtEbGVxNnRCSkFJdw

$ cd "YOUR_BUILD_DIRECTORY"
$  . build/envsetup.sh
$ lunch "YOUR_BUILD_LUNCH"
$ make
$ cd packages/apps/
$ cd TestApp
$ mm -B


If building success , executable file is created.
target thumb C++: gtest_mytest <= packages/apps/TestApp/jni/test/sample1.cpp
target thumb C++: gtest_mytest <= packages/apps/TestApp/jni/test/sample1_unittest.cpp
target Executable: gtest_mytest (out/target/product/maguro/obj/EXECUTABLES/gtest_mytest_intermediates/LINKED/gtest_mytest)
target Symbolic: gtest_mytest (out/target/product/maguro/symbols/data/app/gtest_mytest)
target Strip: gtest_mytest (out/target/product/maguro/obj/EXECUTABLES/gtest_mytest_intermediates/gtest_mytest)
Install: out/target/product/maguro/data/app/gtest_mytest

Running Google Test

I try to run Google Test on Galaxy Nexus. My Galaxy Nexus is flashed Android-4.0.3_r1. Copy to executable file.
cd out/target/product/maguro/
$ adb push data/app/gtest_mytest /data/app
2870 KB/s (48728 bytes in 0.016s)
Running test using ADB.
$ adb shell
root@android:/ # cd data/app                                                   
root@android:/data/app # ./gtest_mytest    
Success to run, The test results are displayed.
root@android:/data/app # ./gtest_mytest                                        
Running main() from gtest_main.cc
[==========] Running 6 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 3 tests from FactorialTest
[ RUN      ] FactorialTest.Negative
[       OK ] FactorialTest.Negative
[ RUN      ] FactorialTest.Zero
[       OK ] FactorialTest.Zero
[ RUN      ] FactorialTest.Positive
[       OK ] FactorialTest.Positive
[----------] 3 tests from IsPrimeTest
[ RUN      ] IsPrimeTest.Negative
[       OK ] IsPrimeTest.Negative
[ RUN      ] IsPrimeTest.Trivial
[       OK ] IsPrimeTest.Trivial
[ RUN      ] IsPrimeTest.Positive
[       OK ] IsPrimeTest.Positive
[----------] Global test environment tear-down
[==========] 6 tests from 2 test cases ran.
[  PASSED  ] 6 tests.

3/10/2012

Create PreferenceActivity with header and Footer.







We can create PreferenceActivity with header and Fotter.

We shoud make following files and call method.
  1. Create Layout with ListView.
  2. Create Preference XML.
  3. Call setContentView() and addPreferencesFromResource() in onCreate().


Create Layout with ListView

Make layout xml file , to set PreferenceActivity#setContentView().
It must have ListView with android:id="@+id/android:list".

you shoud add android:layout_height="0.0dp"and android:layout_weight="1" to ListView, because to show footer in bottom


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <!-- Header  -->

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Header"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <!-- Show Preference in ListView  -->

    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0.0dp"
        android:layout_weight="1" >
    </ListView>

    <!-- Footer -->

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Footer"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

</LinearLayout>


Create Preference XML

Create Preference XML.
Sample.

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <CheckBoxPreference
        android:key="checkbox_preference"
        android:summary="summary_checkbox_preference"
        android:title="checkbox_preference" />

    <EditTextPreference
        android:dialogTitle="dialog_title_edittext_preference"
        android:key="edittext_preference"
        android:summary="summary_edittext_preference"
        android:title="title_edittext_preference" />

    <PreferenceScreen
        android:summary="intent_preference"
        android:title="intent_preference" >
        <intent
            android:action="android.intent.action.VIEW"
            android:data="http://www.android.com" />
    </PreferenceScreen>

</PreferenceScreen>


Call setContentView() and addPreferencesFromResource() in onCreate()

You must call setContentView(YOUR_LAYOUT_WIHT_HEADER_FOOTER_ID).

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        addPreferencesFromResource(R.xml.pref);
    }

3/06/2012

Add WPAN project in AOSP master

When I done "repo sync", added WPAN project in AOSP master.

From https://android.googlesource.com/platform/hardware/ti/wpan
* [new branch]      master     -> master

You need to read Android Building.
wpan project for Panda Bluetooth
http://groups.google.com/group/android-building/browse_thread/thread/b07552678a1829f0?pli=1


Wikipedia:http://en.wikipedia.org/wiki/Personal_area_network

WPAN is "Wireless Personal Area Network".This Network is smaller than WLAN.
Include Bluetooth,WiFi,ZigBee.

2/27/2012

Using a local mirror, repo sync speed up!

Create a local mirror of AOSP
Add repo init option "--mirror".

$ mkdir -p /mirror
$ cd /mirror
$ repo init -u https://android.googlesource.com/mirror/manifest --mirror
$ repo sync

Download time : about 4 hours and over.
volume : 10GB over


Get source from a local mirror

when get source from a local mirror, change repo init url with locla path.

$ mkdir -p android-4.0.3_r1
$ cd android-4.0.3_r1
$ repo init -u /mirror/platform/manifest.git -b android-4.0.3_r1
$ repo sync

I try to get android-4.0.3_r1 branch.

$ repo init -u ../aosp_mirror/platform/manifest.git/ -b android-4.0.3_r1
real 3m18.429s
user 8m21.260s
sys 0m54.990s

when get ICS soruce, time is 3m18s !!
(using SSD, not HDD!)

2/26/2012

Setting up ccache, Because build speed up

http://source.android.com/source/initializing.html#ccache

Put the following in your .bashrc or equivalent.

export USE_CCACHE=1

By default the cache will be stored in ~/.ccache. If your home directory is on NFS or some other non-local filesystem, you will want to specify the directory in your .bashrc as well.

export CCACHE_DIR= "path-to-your-cache-directory"

The suggested cache size is 50-100GB. You will need to run the following command once you have downloaded the source code.
prebuilt/linux-x86/ccache/ccache -M 50G



I measured the build time.

My builing pc spec

SSD:128G
memory:16G
CPU:Corei7 2600
OS:Ubuntu 10.04LTS

Build:1st time

Because creating ccache, do full build of android-4.0.3_r1.
$ . build/envsetup.sh
$ lunch full_maguro-userdebug
$ time make -j8

Time:
real 32m8.076s
user 249m16.350s
sys 13m3.600s

Building:2nd time

Because remove out directory, do "make clean".

$ make clean
$ time make -j8

Time:
real 14m30.814s
user 108m57.690s
sys 7m32.390s


Speed up

Build time speed up, to set Ccache enable!!
32m8.076s -> 14m30.814s

Removed sun-java6 from the Ubuntu Repository

I get new PC!

I try to build setup on Ubuntu 10.04.

$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

But, I can not install sun-java6-sdk!!
So,sun-java6-sdk removed from the Ubuntu Repository...

http://www.ubuntuupdates.org/package/canonical_partner/lucid/partner/base/sun-java6


I try to install "LffL Java PPA".
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:ferramroberto/java
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk

I cound build for AOSP!!

2/21/2012

Request that the visibility of the SystemBar be changed. For Tablet UI Mode of ICS

Tablet device has Systembar, which resides at the bottom of the screen to provide system navigation controls (Home, Back, and so forth).

If you would like to know NavigationBar for Phone device, Please read my post,
Request that the visibility of the NavigationBar be changed. For Phone UI Mode of ICS.

How to Request that the visibility of the SystemBar for Tablet

To request that the visibility of the SystemBar be changed, you can use View#setSystemUiVisibility().

  1. register Listener to View - View#setOnSystemUiVisibilityChangeListener
  2. set Visivility mode - View#setSystemUiVisibility

Visivility mode:
  • View.SYSTEM_UI_FLAG_LOW_PROFILE  - navigation icons may dim 

View.SYSTEM_UI_FLAG_HIDE_NAVIGATION is not used for Tablet.
Please read Android Developers Page.
http://developer.android.com/intl/ja/sdk/android-4.0.html "Controls for system UI visibility"

Example:


{
                   :
 View view;
 view = findViewById(R.id.linerLayout);
         view.setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener);
 view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
                   :
}

private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener = new OnSystemUiVisibilityChangeListener(){

 @Override
 public void onSystemUiVisibilityChange(int visibility) {
  Log.e("","call onSystemUiVisibilityChange = " + visibility);
 }
};


View.SYSTEM_UI_FLAG_LOW_PROFILE
SystemBar display area of ​​the intact, but appear dimmed.



If you want to know more process in Android Frameworks, check it!!
You can notice that TabletStatusBar do not has a NavigationBarView.

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

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

2/19/2012

How to use ListFragment




Android developers Page:
http://developer.android.com/intl/ja/reference/android/app/ListFragment.html


You need to create following files.
  1. Create Layout xml file, if need to use custom Screen Layout with ListView and more widget
  2. Row Layout xml file
  3. ListAdapter Class to make list data


Screen Layout

ListFragment has default ListView. this is mean that you do not should set view.
But, When ListView is no data, Application will display a screen similar to the following.
"Loading" continues to display.


Therefore, you should set custom layout.

Custom layout has ListView object with the id "@android:id/list"
and should has "empty list" with id "android:empty".

Example Layout:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:paddingLeft="8dp"
         android:paddingRight="8dp">

     <ListView android:id="@id/android:list"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="#00FF00"
               android:layout_weight="1"
               android:drawSelectorOnTop="false"/>

     <TextView android:id="@id/android:empty"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="#FF0000"
               android:text="No data"/>
 </LinearLayout>


You can customize the fragment layout by returning your own view hierarchy from onCreateView(LayoutInflater, ViewGroup, Bundle).



public class AppListFragment extends ListFragment {

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (container == null) {
            // We have different layouts, and in one of them this
            // fragment's containing frame doesn't exist.  The fragment
            // may still be created from its saved state, but there is
            // no reason to try to create its view hierarchy because it
            // won't be displayed.  Note this is not needed -- we could
            // just run the code below, where we would create and return
            // the view hierarchy; it would just never be used.
            return null;
        }
        

        return inflater.inflate(R.layout.list,null);
    }
}

2/17/2012

Disable Preinstall Application , Android 4.0.3



Can disable PreInstall Application in Settings->App->App info.
But limited PreInstall.

See Source in Android-4.0.3_r1.

packages\apps\Settings\src\com\android\settings\applications
- InstalledAppDetails.java

    private void initUninstallButtons() {
        mUpdatedSysApp = (mAppEntry.info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
        boolean enabled = true;
        if (mUpdatedSysApp) {
            mUninstallButton.setText(R.string.app_factory_reset);
        } else {
            if ((mAppEntry.info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                enabled = false;
                if (SUPPORT_DISABLE_APPS) {
                    try {
                        // Try to prevent the user from bricking their phone
                        // by not allowing disabling of apps signed with the
                        // system cert and any launcher app in the system.
                        PackageInfo sys = mPm.getPackageInfo("android",
                                PackageManager.GET_SIGNATURES);
                        Intent intent = new Intent(Intent.ACTION_MAIN);
                        intent.addCategory(Intent.CATEGORY_HOME);
                        intent.setPackage(mAppEntry.info.packageName);
                        List homes = mPm.queryIntentActivities(intent, 0);
                        if ((homes != null && homes.size() > 0) ||
                                (mPackageInfo != null && mPackageInfo.signatures != null &&
                                        sys.signatures[0].equals(mPackageInfo.signatures[0]))) {
                            // Disable button for core system applications.
                            mUninstallButton.setText(R.string.disable_text);
                        } else if (mAppEntry.info.enabled) {
                            mUninstallButton.setText(R.string.disable_text);
                            enabled = true;
                        } else {
                            mUninstallButton.setText(R.string.enable_text);
                            enabled = true;
                        }
                    } catch (PackageManager.NameNotFoundException e) {
                        Log.w(TAG, "Unable to get package info", e);
                    }
                }
            } else {
                mUninstallButton.setText(R.string.uninstall_text);
            }
        }
        // If this is a device admin, it can't be uninstall or disabled.
        // We do this here so the text of the button is still set correctly.
        if (mDpm.packageHasActiveAdmins(mPackageInfo.packageName)) {
            enabled = false;
        }
        mUninstallButton.setEnabled(enabled);
        if (enabled) {
            // Register listener
            mUninstallButton.setOnClickListener(this);
        }
    }


The following System applications can not be disabled.
- Update from Market.
- Application has Activity with Intent.CATEGORY_HOME.(= Launcher Application)
- Application has same signature of System. ( = System Application)



If you set to disable, Application Icon in App List do not show.

2/15/2012

Problem of Custom Notification's Background Color, Android 4.0.3


Show a screenshot above.
ICS has problem of notification's background color, white.


Conditions the problem:
  1. set RemoteViews when Notificaiton created
  2. Application's targetSdkVersion is lower than "9"(=GingerBread).



Cause of the problem

Show frameworks source in Android-4.0.3_r1.

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




private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) {
        StatusBarNotification sbn = entry.notification;
        RemoteViews remoteViews = sbn.notification.contentView;
        if (remoteViews == null) {
            return false;
        }
                     :
                     :
                     :
        applyLegacyRowBackground(sbn, content);

        entry.row = row;
        entry.content = content;
        entry.expanded = expanded;
        entry.largeIcon = largeIcon;

        return true;
    }

    void applyLegacyRowBackground(StatusBarNotification sbn, View content) {
        if (sbn.notification.contentView.getLayoutId() !=
                com.android.internal.R.layout.status_bar_latest_event_content) {
            int version = 0;
            try {
                ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(sbn.pkg, 0);
                version = info.targetSdkVersion;
            } catch (NameNotFoundException ex) {
                Slog.e(TAG, "Failed looking up ApplicationInfo for " + sbn.pkg, ex);
            }
            if (version > 0 && version < Build.VERSION_CODES.GINGERBREAD) {
                content.setBackgroundResource(R.drawable.notification_row_legacy_bg);
            } else {
                content.setBackgroundResource(R.drawable.notification_row_bg);
            }
        }
    }
Check to process of setting Notificaion Background Color.
if (version > 0 && version < Build.VERSION_CODES.GINGERBREAD) {
                content.setBackgroundResource(R.drawable.notification_row_legacy_bg);
            } else {
                content.setBackgroundResource(R.drawable.notification_row_bg);
            }


If TargetSdkVersion is lower than Build.VERSION_CODES.GINGERBREAD(APILevel9), set R.drawable.notification_row_legacy_bg!!


Check it!!

\frameworks\base\packages\SystemUI\res\drawable
- notification_row_legacy_bg.xml

\frameworks\base\packages\SystemUI\res\values\
- colors.xml

2/12/2012

How to use Tab mode on ActionBar



ActionBar provide tab navigation which used Fragment System.

Proccess in Activity#onCreate
  1. Set Navigation Mode to ActionBar.
  2. Create tab that is used Action#newTab().
  3. Set TabListener with Fragment to show tab selected.

If you do not want to show Title and Icon, you need to call actionBar.setDisplayShowTitleEnabled(false) and actionBar.setDisplayShowHomeEnabled(false).

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // setContentView(R.layout.main);
  // setup action bar for tabs
  ActionBar actionBar = getActionBar();
  actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  // hide Title and Icon
//  actionBar.setDisplayShowTitleEnabled(false);
//  actionBar.setDisplayShowHomeEnabled(false);

  Tab tab = actionBar.newTab();
  tab.setText("artist");
  tab.setTabListener(new TabListener(this, "artist", ArtistFragment.class) );
  actionBar.addTab(tab);

  tab = actionBar.newTab();
  tab.setText("album");
  tab.setTabListener(new TabListener(this, "album", AlbumFragment.class));
  actionBar.addTab(tab);

 }



Create TabListener with Fragment to show tab selected.

 private class TabListener implements
   ActionBar.TabListener {
  private Fragment mFragment;
  private final Activity mActivity;
  private final String mTag;
  private final Class mClass;

  /**
   * Constructor used each time a new tab is created.
   * 
   * @param activity
   *            The host Activity, used to instantiate the fragment
   * @param tag
   *            The identifier tag for the fragment
   * @param clz
   *            The fragment's Class, used to instantiate the fragment
   */
  public TabListener(Activity activity, String tag, Class clz) {
   mActivity = activity;
   mTag = tag;
   mClass = clz;
  }

  /* The following are each of the ActionBar.TabListener callbacks */

  public void onTabSelected(Tab tab, FragmentTransaction ft) {
   // Check if the fragment is already initialized
   if (mFragment == null) {
    // If not, instantiate and add it to the activity
    mFragment = Fragment.instantiate(mActivity, mClass.getName());
    ft.add(android.R.id.content, mFragment, mTag);
   } else {
    // If it exists, simply attach it in order to show it
    ft.attach(mFragment);
   }
  }

  public void onTabUnselected(Tab tab, FragmentTransaction ft) {
   if (mFragment != null) {
    // Detach the fragment, because another one is being attached
    ft.detach(mFragment);
   }
  }

  public void onTabReselected(Tab tab, FragmentTransaction ft) {
   // User selected the already selected tab. Usually do nothing.
  }
 }

Called the order

When Application launched,Called the order.
onCreate

onTabSelected of "artist"

ArtistFragment#onCreateView


Select Album Tab.
onTabUnselected of "artist"

onTabSelected of "album"

AlbumFragment#onCreateView


Reselect Album Tab.
onTabReselected of "album"

Launch Tablet Mode Android-4.0.3_r1 on Galaxy Nexus (maguro)

Disable config of config_showNavigationBar, because tablet device do not have NavigationBar.
If you want to know detail ,please read my Post.
Phone mode or Tablet mode in Ice Cream Sandwich ?
http://baroqueworksdev.blogspot.com/2012/01/phone-mode-or-tablet-mode-in-ice-cream.html
NavigationBar / Virtual buttons in the System Bar
http://baroqueworksdev.blogspot.com/2012/01/navigationbar.html


device/samsung/tuna/overlay/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">true</bool>
↓
<bool name="config_showNavigationBar">false</bool>

Change to LCD Density 160.

device/samsung/tuna
- device.mk
PRODUCT_PROPERTY_OVERRIDES += \
ro.sf.lcd_density=320
↓
ro.sf.lcd_density=160


building ROM
Obtaining 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
$ for i in *maguro-iml74k* ; do tar zxvf $i ; done
$ for i in ./extract-*-maguro.sh ; do $i ; done


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

Flashing a device
$ cd out/target/product/maguro
$ fastboot flashall -w


Launch device.
Tablet UI mode on Galaxy Nexus!!









2/11/2012

Building for maguro Android-4.0.3_r1

Building for devices
http://source.android.com/source/building-devices.html

I try to build for maguro Android-4.0.3_r1.
I successed boot of Android_4.0.3_r1 building Rom.

Obtaining 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
$ for i in *maguro-iml74k* ; do tar zxvf $i ; done
$ for i in ./extract-*-maguro.sh ; do $i ; done


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

Flashing a device
I try to flash only system.img and boot.img, but devices is reboot loop.
So, You shoud read Offical Pag "Building for devices".

flash command is
$ fastboot flashall -w


Do not use extract-files.sh ?

Yout want to know detail, you shoud read android-building thread.

Camera not working on ICS 4.03 / Maguro
http://groups.google.com/group/android-building/browse_thread/thread/a6bdd53547c0af62/b84f5731198d605a?lnk=gst&q=extract-files.sh&pli=1

extract-files.sh is my own private tool
anyway, used during development of the self-extractors, it's not meant
to be used by the general public, especially because of licensing
issues.

2/08/2012

Building for wingray Android_4.0.3_r1 - Motorola Xoom (US Wi-Fi)

wingray is building name of "Motorola Xoom (US Wi-Fi)".

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"

Get "proprietary binaries".
$ wget https://dl.google.com/dl/android/aosp/broadcom-wingray-iml74k-2c8a74c6.tgz
$ wget https://dl.google.com/dl/android/aosp/nvidia-wingray-iml74k-e5226417.tgz
$ for i in *wingray-iml74k* ; do tar zxvf $i ; done
$ for i in ./extract-*-wingray.sh ; do $i ; done

building the configuration that matches a device

running to build for wingray.

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

Create AOSP via recovery

This works on AOSP master branch, do not work Android-4.0.3_r1 etc.

If you want to know detail, you shoud read Android-building's thread.

https://groups.google.com/group/android-building/browse_thread/thread/1d0f4fea5a577f93/8c698abb96533a97?#8c698abb96533a97

# Create a directory to store all the temporary files
mkdir -p ~/aosp-ota-exp

# Download all the IML74K maguro binaries from
# https://code.google.com/android/nexus/drivers.html into ~/aosp-ota-exp
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


# download the ICL53F yakju factory image from
# https://code.google.com/android/nexus/images.html into ~/aosp-ota-exp
wget https://dl.google.com/dl/android/aosp/yakju-icl53f-factory-89fccaac.tgz

# download the matching stub target_files.zip directly from
wget https://dl.google.com/dl/android/aosp/stub-yakju-target_files-icl53f.zip

# Extract the proprietary binaries
for i in ~/aosp-ota-exp/*maguro-iml74k* ; do tar zxvf $i ; done
for i in ./extract-*-maguro.sh ; do $i ; done 

# Extract the individual factory images
(cd ~/aosp-ota-exp ; tar zxvf yakju-icl53f-factory-89fccaac.tgz)
(cd ~/aosp-ota-exp/yakju-icl53f ; unzip image-yakju-icl53f.zip) 

# Patch the OTA-packaging tool
repo forall build -c 'git pull https://android.googlesource.com/platform/build refs/changes/64/31464/1' 

# Set up the build. Insert dummy files where the original files should be preserved
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
for i in  *maguro-iml74k* ; do tar zxvf $i ; done
for i in ./extract-*-maguro.sh ; do $i ; done 

. build/envsetup.sh
lunch full_maguro-userdebug
make installclean 
for i in vendor/firmware/bcm4330.hcd vendor/etc/sirfgps.conf vendor/lib/hw/gps.omap4.so vendor/lib/libinvensense_mpl.so vendor/firmware/libpn544_fw.so vendor/firmware/ducati-m3.bin ; do mkdir -p out/target/product/maguro/system/$(dirname $i) ; echo "DUMMY AOSP FILE" > out/target/product/maguro/system/$i ; done 

# Do the build (this is a dist build, not a plain build)
# Dist: out/dist/full-apps-eng.XXXXX.zip
# Dist: out/dist/full-emulator-eng.XXXXX.zip
# Dist: out/dist/full-target_files-eng.XXXXX.zip
# Dist: out/dist/full-symbols-eng.XXXXX.zip
time make -jX dist


# Create the OTA package and the custom cache partition
rm -rf ~/aosp-ota-exp/cache
mkdir -p ~/aosp-ota-exp/cache
build/tools/releasetools/ota_from_target_files -w -i ~/aosp-ota-exp/stub-yakju-target_files-icl53f.zip -k build/target/product/security/testkey out/dist/full_maguro-target_files-eng.*.zip ~/aosp-ota-exp/cache/aosp_update.zip 
make_ext4fs -s -l 209715200 -a cache ~/aosp-ota-exp/cache.img ~/aosp-ota-exp/cache 


# Flash the device
fastboot flash bootloader ~/aosp-ota-exp/yakju-icl53f/bootloader-maguro-primekk15.img
fastboot reboot-bootloader
fastboot flash radio ~/aosp-ota-exp/yakju-icl53f/radio-maguro-i9250xxkk6.img
fastboot reboot-bootloader
fastboot flash system ~/aosp-ota-exp/yakju-icl53f/system.img
fastboot flash boot
fastboot flash recovery
fastboot flash cache ~/aosp-ota-exp/cache.img 

# Boot into recovery (in the bootloader, navigate with volume up/down, and select with the power button)
# Get the recovery menu (hold power, press volume up)
# In recovery, apply /cache/aosp_update.zip, wipe the cache, and reboot.* 


Display About phone.
Android version is "4.0.3.0.2.0.1.0", count down???



Display Application list .
There is not GMS apps, Market etc.



WiFi work on. Connected to Google Top!!

2/07/2012

Don't work WIFI and Bluetooth on Galaxy Nexus ICS 4.0.3 ?

I don't try to build Android-4.0.3 for Galaxy Nexus.
Don't work WIFI and Bluetooth on Galaxy Nexus ICS 4.0.3 ?

Galaxy Nexus Android ICS and Bluetooth/Wifi drivers
https://groups.google.com/group/android-building/browse_thread/thread/d0294450823d093d/6470de50e54e600d?lnk=gst&q=android+4.0.3#6470de50e54e600d
We're still working on getting a license to distribute the Wifi/BT firmware
for Galaxy Nexus.

In the meantime, please try this and let me know if it works for you:
http://goo.gl/8jit8

2/05/2012

ScreenShot in ICS Android frameworks

Screenshot Proccess in Android Frameworks

Call interceptKeyBeforeQueueing from Navite Layer InputDispatcher 
InputManager#interceptKeyBeforeQueueing
 - PhoneWindowManager#interceptKeyBeforeQueueing
  - interceptKeyBeforeQueueing
    - interceptScreenshotChord()
      - mScreenshotChordLongPress#run
        - takeScreenshot()
            TakeScreenshotService of new Service in SystemUI
            - run()
              - GlobalScreenshot#takeScreenshot
                called Surface.screenshot to get Bitmap
                Animation and Save Screen Image!!


Check source!!


\frameworks\base\services\input
- InputDispatcher.cpp
- InputManager.cpp

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

\frameworks\base\packages\SystemUI\src\com\android\systemui\screenshot
- GlobalScreenshot.java
- TakeScreenshotService.java



2/04/2012

Request that the visibility of the NavigationBar be changed. For Phone UI Mode of ICS

Application can request that the visibility of the NavigationBar be changed.
But, be careful of timing be released from the Frameworks.

How to Request that the visibility of the NavigationBar

To request that the visibility of the NavigationBar be changed, you can use View#setSystemUiVisibility().

Android Developer: View#setSystemUiVisibility()

  1. register Listener to View - View#setOnSystemUiVisibilityChangeListener
  2. set Visivility mode - View#setSystemUiVisibility

Visivility mode:
  • View.SYSTEM_UI_FLAG_LOW_PROFILE  - navigation icons may dim 
  • View.SYSTEM_UI_FLAG_HIDE_NAVIGATION - hide navigation icons


Example:

{
                   :
 View view;
 view = findViewById(R.id.linerLayout);
         view.setOnSystemUiVisibilityChangeListener(mOnSystemUiVisibilityChangeListener);
 view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
                   :
}

private OnSystemUiVisibilityChangeListener mOnSystemUiVisibilityChangeListener = new OnSystemUiVisibilityChangeListener(){

 @Override
 public void onSystemUiVisibilityChange(int visibility) {
  Log.e("","call onSystemUiVisibilityChange = " + visibility);
 }
};



View.SYSTEM_UI_FLAG_LOW_PROFILE
NavigationBar display area of ​​the intact, but appear dimmed.




View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
Hide the display area of ​​the NavigationBar becomes completely, spread the display area of ​​the application.





Timing be released from the Frameworks

NavigationBar display specifiers will be released in the following use cases.
  • TouchDown on Screen
  • Show PowerDown Dialog(GlobalActions)
  • An application becomes active/inactive

Get the Factory Image of Galaxy Nexus

You can get the Factory Image of Galaxy Nexus.

Google Support for Nexus Phones and Flagship Devices.
 http://code.google.com/intl/ja/android/nexus/images.html


Example of 4.0.2 (ICL53F) maguro
wget https://dl.google.com/dl/android/aosp/yakju-icl53f-factory-89fccaac.tgz
tar xvf ./yakju-icl53f-factory-89fccaac.tgz
cd yakju-icl53f
./flash-all.sh

2/02/2012

is Displayed NavigationBar?

The following modules are available in the Frameworks.
PhoneWindowManager#hasNavigationBar()
WindoManagerService#hasNavigationBar()

Check whether there are sources that use this module!!
you can find ViewConfiguration class.

public class ViewConfiguration {
    private ViewConfiguration(Context context) {
             :
        if (!sHasPermanentMenuKeySet) {
            IWindowManager wm = Display.getWindowManager();
            try {
                sHasPermanentMenuKey = wm.canStatusBarHide() && !wm.hasNavigationBar();
                sHasPermanentMenuKeySet = true;
            } catch (RemoteException ex) {
                sHasPermanentMenuKey = false;
            }
        }
             :
    }

    public boolean hasPermanentMenuKey() {
        return sHasPermanentMenuKey;
    }
}

hasPermanentMenuKey() is check "Permanent Menu Key is available."
sHasPermanentMenuKey to determine the value under the following conditions.
wm.canStatusBarHide() : Phone UI or Tablet UI
wm.hasNavigationBar() : Navigation is enable /disable

Tablet UI is disable NavigationBar.
If NavigationBar is disable, sHasPermanentMenuKey is true.
If NavigationBar is enable, sHasPermanentMenuKey is false.

so, you can check using under cord.

//hasPermanentMenuKey == true -> NavigationBar is disable
//hasPermanentMenuKey == false  ->  NavigationBar is enable
boolean isNavigationBar = ! ViewConfiguration.get(this).hasPermanentMenuKey();

Enable NavigationBar on Emulator

How to Enable NavigationBar on Emulator

Standard ICS is not enable NavigationBar. but, Android Frameworkds is see Emulator settings.

        // 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;
        }


You can add "hw.mainkeys" from Edit AVD.


Procedure:
  1. add "Hardware Back/Home keys frome "New" button.
  2. change value to "no".


Start AVD!!


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