編輯:關於Android編程
1、開發Android應用程序來使用硬件訪問服務
~/android-2.3_r1/packages/experimental/Freg
----AndroidManifest.java
----Android.mk
----src
----shy/luo/freg
----Freg.java
----res
----layout
----main.xml
----values
----string.xml
----drawable
----icon.png
Freg.java
package shy.luo.freg; import android.app.Activity; import android.os.ServiceManager; import android.os.Bundle; import android.os.IFregService; import android.os.RemoteException; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class Freg extends Activity implements OnClickListener { private final static String LOG_TAG = "shy.luo.freg.FregActivity"; private IFregService fregService = null; private EditText valueText = null; private Button readButton = null; private Button writeButton = null; private Button clearButton = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); fregService = IFregService.Stub.asInterface( ServiceManager.getService("freg")); valueText = (EditText)findViewById(R.id.edit_value); readButton = (Button)findViewById(R.id.button_read); writeButton = (Button)findViewById(R.id.button_write); clearButton = (Button)findViewById(R.id.button_clear); readButton.setOnClickListener(this); writeButton.setOnClickListener(this); clearButton.setOnClickListener(this); Log.i(LOG_TAG, "Freg Activity Created"); } @Override public void onClick(View v) { if(v.equals(readButton)) { try { int val = fregService.getVal(); String text = String.valueOf(val); valueText.setText(text); } catch (RemoteException e) { Log.e(LOG_TAG, "Remote Exception while reading value from freg service."); } } else if(v.equals(writeButton)) { try { String text = valueText.getText().toString(); int val = Integer.parseInt(text); fregService.setVal(val); } catch (RemoteException e) { Log.e(LOG_TAG, "Remote Exception while writing value to freg service."); } } else if(v.equals(clearButton)) { String text = ""; valueText.setText(text); } } }
Freg Value Please input a value... Read Write Clear
LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := Freg include $(BUILD_PACKAGE)
編譯成apk:
生成的Freg.apk位於out/target/product/generic/system/app中。<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PGJyPgo8L3A+CjxwPiAgICAgILTysPyjujwvcD4KPHA+PGltZyBzcmM9"/uploadfile/Collfiles/20140609/201406090910363.png" alt="\">
最後把Freg.apk重新打包進入system.img,位於out/target/product/gerneric中。
運行:
結果如下:
繪制曲線類:public class BaseFundChartView extends View { Paint linePaint; Paint text
我們知道,Android架構中上層應用是以java來編寫的,而底層則用C/C++編寫。一般而言,上層android工程師在開發過程中,不會或很少涉及到C/C++層,但項目
這篇博客我們來介紹一下模板方法模式(Template Method Pattern),也是行為型設計模式之一。在面向對象開發過程中,通常會遇到這樣的一個問題,我們知道一個
在學習新內容之前,我們先來弄清楚兩個問題:1 . 什麼是ViewGroup?ViewGroup是一種容器。它包含零個或以上的View及子View。2 . ViewGrou