2010年12月7日星期二

Android VideoCamera Analysis

I wanted to know how to use camera recording. So I checked the file "VideoCamera" in android source code. The following was what it did.


1. If you want to start recording, you need Camera and MediaRecorder.
2. Decide when to open a camera device, how to set parameters of the camera and set the previewDisplay always before starting previewing.
3. Decide when to close a camera device.
4. Stop the camera and media recording in onPause() and resume them in onResume().
5. in callback method surfaceCreated, mSurfaceHolder is set.
6. in callback method surfaceDestroy, mSurfaceHolder is destroyed.
7. in callback method surfaceChanged, mSurfaceHolder is set again. But if the state of the Activity is Pausing, do nothing just return. Restart previewing and recording.


The following is an example.

vim+ctags+cscope+java

How to let cscope to support JAVA?
1. find . -name "*.java" >> cscope.files
2. cscope -b  (Refresh the database)
3. cscope

2010年12月5日星期日

Activity orientation | Activity Restart

The values of Orientation are ORIENTATION_PORTRAIT and
ORIENTATION_LANDSCAPE.


When orientation is changed, the default action is to restart the Activtiy.

If you don’t want your Activity to restart, you should do the following thing:


Config your Activity with the Activity Element
     android:configChanges="keyboardHidden|orientation"
Rewrite the callback method
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (this.getResources().getConfiguration().orientation ==
    Configuration.ORIENTATION_LANDSCAPE) {
    Log.d(TAG, "++ ORIENTATION_LANDSCAPE ++");
   
    } else if (this.getResources().getConfiguration().orientation
    == Configuration.ORIENTATION_PORTRAIT){
    Log.d(TAG, "++ ORIENTATION_PORTRAIT ++");
    }
}

2010年12月2日星期四

Android Bluetooth

Android Bluetooth

Bluetooth is a communication protocol designed for short-range, low-bandwidth, peer-to-peer communications.
Bluetooth devices and connections are only managed by the following classes:
l         BluetoothAdapter local Bluetooth adapter
l         BluetoothDevice remote Bluetooth device
l         BluetoothSocket
l         BluetoothServerSocket

Accessing the local BT adapter

BluetoothAdapter mBTAdapter = BluetoothAdapter.getDefaultAdapter();
In order to access the local BT adapter, you should include the Bluetooth manifest permission.
"android.permission.BLUETOOTH" />
"android.permission.BLUETOOTH_ADMIN" />

Managing BT Properties and State

The most useful properties are friendly name and MAC address:
mBTAdapter.getName()
mBTAdapter.getAddress()
The current BT Adpater’s state:
l         STATE_TURNING_ON
l         STATE_ON
l         STATE_TURNING_OFF
l         STATE_OFF

Turning on local BT Adapter

private static final int RQUEST_ENABLE_BT = 0;
Intent enalbeIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableIntent, RQUEST_ENABLE_BT);
A sub-activity will be pop-up. The result code of the sub-activity will be returned on the callback method onActivityResult(int requestCode, int resultCode, Intent data).

Being discoverable

The BT Discoverability is indicated by the scan mode.
There are three scan modes (getScanMode()).
SCAN_MODE_CONNECTABLE_DISCOVERABLE
SCAN_MODE_CONNECTABLE
SCAN_MODE_NONE
To turn on discovery you need to obtain permission from the user by starting an Activity:
String dis = BluetoothAdapter.ACTION_RQUEST_DISCOVERABLE;
Intent mDis = new Intent(dis);
StartActivityForResult(mDis, DISCOVERY_REQUEST);
To start discovery process, you should call function
mAdapter.startDiscovery();
To cancel discovery process, you should call function
mAdapter.cancelDiscovery();
To get the remote bluetooth device discovered, you should use the BroadcastReceiver,
registerReceiver(discoveryResult, new IntentFilter(BluetoothDevice.ACTION_FOUND));
BroadcastReceiver discoveryResult = new BroadcastReceiver(){
public void onReceiver(Context ct, Intent intent){
   String mRemoteDeviceName = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
   BluetoothDevice mRemoteDevice;
   mRemoteDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
}
}

Bluetooth Communications

The communication channel is a RFCOMM channel.
To establish the bidirectional communications, you should use the following classes:
l         BluetoothServerSocket  A bluetooth server socket is used to listen for incoming Bluetooth Socket connection request from remote Bluetooth Devices.
l         BluetoothSocket
The server socket is created by listenUsingRfcommWithServiceRecord method on mAdapter. The server socket is identified by a name and a UUID.
To start listening for connections call accept on the server.

Transmitting Data Using Bluetooth Sockets

Once a channel is established, the two peers can talk with each other by BluetoothSocket.

2010年11月7日星期日

Set Git Proxy


## Set a proxy for curl
$ export http_proxy="http://proxy.bupt.edu.cn:8080"
## Get the connect.c file and compile it
$ curl http://www.meadowy.org/~gotoh/ssh/connect.c > connect.c
$ gcc -o connect connect.c
## Write a bash file
$ cd ~/bin
$ vi http-proxy
    #!/bin/sh
    # FileName: http-proxy
    # This connects to an HTTP Proxy using connect.c
    connect -H http://proxy.bupt.edu.cn:8080 $@
$ chmod a+x http-proxy
## Run git config and you should change the name "kernel.org" to your interest site.
$ git config --global core.gitproxy "http-proxy for kernel.org"
## If your proxy needs an auth, write rc file for connect.
$ vi /etc/connectrc
    HTTP_PROXY_USER=useraccount
    HTTP_PROXY_PASSWORD=passwd

网络问题的检查 - Linux Network Check


One day, I encountered a problem that the STB had got the IP address, but it could not access the internet.
So, I decided to check the following:
1. DNS Configuration
cat /etc/resolv.conf

gateway 10.192.208.254
nameserver 10.194.128.15

2. Route Table

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0

You see, the Gateway was wrong. So, I used the command route to add a default gateway.
/sbin/route add default gw 192.168.1.1
3. Ping www.baidu.com. Ok. It worked.

2010年10月7日星期四

多个Gtalk实例同时运行

Gtalk是可以多实例运行的,方法如下:
1. 创建Gtalk的桌面快捷方式
2. 右键选择属性,选择快捷方式标签页
3. 修改Target一栏,如下:
"C:\Program Files\Google\Google Talk\googletalk.exe" /nomutex