seo優化排名, seo搜索引擎 | All posts tagged 'google android'
點擊這裡→ 港元980即時開設最強網上商店,無任何隱藏成本

seo優化排名, seo搜索引擎

網路推廣,網站排名,網站推廣,搜索網站,seo服務

Google Android 手機程式設計 -- 設定 Android 中Proxy的方法和Android 的函式庫列表

clock 十一月 14, 2009 16:43 by author Administrator

設定 Android Proxy的方法     

在程式中設定

在系統中設定

Android 的函式庫列表

 

推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:

Google Android 手機程式設計--(附錄一: 範例程式的使用方法,Adb 除錯工具的使用)

clock 十一月 13, 2009 16:11 by author Administrator

附錄一: 範例程式的使用方法

Windows/preferences

 

附錄二  Adb 除錯工具的使用

 

推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:

Google Android 手機程式設計--電話功能(Telephony),衛星定位,藍芽功能

clock 十一月 11, 2009 16:41 by author Administrator

Android 的電話功能主要在android.telephony這個函式庫當中,提供播打與接收電話的功能,其中最重要的兩個物件是 IPhone PhoneNumberUtils.

撥打電話

當你想要在程式中呼叫播打電話的功能時,必需在 AndroidManifest.xml 檔案中將允許程式播打電話的權限打開,其指令如下:

<uses-permission id="android.permission.CALL_PHONE" />

要建立 IPhone 物件,必需透過 ServiceManager 類別,以下是取得 IPhone 的方法:

private static IPhone getPhoneInterface() throws DeadObjectException {

    IServiceManager sm = ServiceManagerNative.getDefault();

    IPhone phoneService = IPhone.Stub.asInterface(sm.getService("phone"));

    return phoneService;

}

一但取得 IPhone 物件後,即可使用 call dial 來撥打電話,然後使用 endCall 來結束通話。 

        void  call(String number) : Place a call to the numer.

        void  dial(String number) : Dial a number.

        void  endCall(boolean hangupOnly) : End call or go to the Home screen

 

dial call 之間的差別是 dial 會顯示一個撥號介面,其上填入 number 這個電話號碼 ( number null,則撥號介面中將不會有預設的號碼)

另一種撥打電話的方法是對一個電話網址 (例如: tel:0988077312) 送出  CALL_ACTION的動作,即可進行通話供能。

另外、你也可以使用 DataStateIntentReceiver PhoneStateIntentReceiver 進行電話事件的註冊,以便取得撥號狀態 (IDLE, RINING, OFF_HOOK)、服務狀態 (in service, out of service, emergency only, powered off, roaming, operator name )、訊號強度、語音留言、連線狀態 (disconnectedconnectingconnected)、資料進出狀態 (data in, data out) 等等。

取得電話資訊

 

您也可以透過 TelephonyProperties 中的屬性值,取得許多手機相關的資訊,例如手機的電話號碼、SIM 卡的資訊等等,其方法是使用 os.SystemProperties.get() 函數,傳入 TelephonyProperties 中的對應參數即可取得之,反之、若使用os.SystemProperties.put() 則可設定這些參數。

 

範例一:取得 IMEI 國際手機代碼

android.os.SystemProperties.get(PROPERTY_IMEI)

範例二:取得手機的電話號碼

android.os.SystemProperties.get(PROPERTY_LINE1_NUMBER)

範例三:取得手機的語音郵件號碼

android.os.SystemProperties.get(PROPERTY_LINE1_VOICE_MAIL_NUMBER)

範例四:取得電信公司的名稱

android.os.SystemProperties.get(PROPERTY_SIM_OPERATOR_ALPHA)

範例五:取得國家的代碼

android.os.SystemProperties.get(PROPERTY_SIM_OPERATOR_ISO_COUNTRY)

 

衛星定位

 

與衛星定位相關得兩個函式庫是android.location com.google.android.maps,目前還再草案狀態未定案

衛星定位的程式

android.location

預計將支援四種地圖相關資訊 (classkmlnmeatrack),其中的 LocationManager LocationProvider 是核心元件。

要取得 Location Manager 的方式必需透過 Context,方法如下:

LocationManager lm = Context.getSystemService(Context.LOCATION_SERVICE);

 

控制 Google Map 的顯示

com.google.android.maps

此函式庫支援 GoogleMap 應用程式的控制,您可以透過 MapView 物件顯示 GoogleMap,但前題是您的 Activity 必需繼承 MapActivity

 

接著您可以透過 MapView 中的getController() getOverlayController() 去控制MapView

 

GoogleMap 上重疊顯示

http://davanum.wordpress.com/2007/11/19/drawing-overlays-for-android-maps-aka-search-for-starbucks/

藍芽功能

藍芽裝置由於具有獨特的搜尋裝置等特性,因此、某些功能無法納入普通的 TCP/IP 網路功能之下,因此、需要特殊的函式庫支援,在 Android 中,採用的是開放原始碼的 bluez 函式庫 ( Android 中路徑為 org.bluez)

開放原始碼的藍芽函式庫 - BlueZ

搜尋藍芽裝置

檔案與物件交換

透過藍芽連上 Internet  自製視覺化元件

http://code.google.com/android/toolbox/custom-components.html

您可以經由繼承 view, layout,或任何從 View 衍生下來的元件以自製.

These steps provide a high level overview of what you need to know to get started in creating your own components:

1.Extend an existing View class or subclass with your own class.

2. Override some of the methods from the superclass: the superclass methods to override start with 'on', for example, onDraw(), onMeasure(), and onKeyDown().

This is similar to the on... events in Activity or ListActivity that you override for life cycle and other functionality hooks.

3. Use your new extension class: once completed, your new extension class can be used in place of the view upon which it was based, but now with the new functionality

 The CustomView sample in the API Demos provides an example of a customized component. The custom component is defined in the LabelView class.

推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:

Google Android 手機程式設計--影像與聲音功能

clock 十一月 10, 2009 14:10 by author Administrator

您可播放位於程式資源資料夾中的影音資源,也可以播放檔案系統中的影音檔,甚至播放網路上的影音檔案,但方法稍有差異。

播放內部影音資源 

MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1);

mp.prepare();

mp.start();

播放外部影音檔案

MediaPlayer mp = new MediaPlayer();

mp.setDataSource(PATH_TO_FILE);

mp.prepare();

mp.start();

播放網路上的影音檔案

ContentURI myURL = new ContentURI("http://myserver.com/link/to/my.mp3");

Intent intent = new Intent(Intent.VIEW_ACTION, myURL);

intent.setType("audio/*");

startActivity(intent);

擷取畫面

Bitmap copyWindowBitmap()

Return a copy of the bitmap holding the overall contents of the window this view is attached to.

void getAbsoluteLocationOnScreen(int[] location)

Computes the coordinates of this view on the screen.

錄音與錄影 

1. 啟動錄製功能

    recorder = new MediaRecorder();

    ContentValues values = new ContentValues(3);

 

    values.put(Video.MediaColumns.TITLE, SOME_NAME_HERE);

    values.put(Video.MediaColumns.TIMESTAMP, System.currentTimeMillis());

    values.put(Video.MediaColumns.MIME_TYPE, recorder.getMimeContentType());

   

    contentResolver = new ContentResolver();

   

    ContentURI base = Video.Media.INTERNAL_CONTENT_URI;

    ContentURI newUri = contentResolver.insert(base, values);

   

    if (newUri == null) {

        // need to handle exception here - we were not able to create a new

        // content entry

    }

   

    String path = contentResolver.getDataFilePath(newUri);

 

    // could use setPreviewDisplay() to display a preview to suitable View here

   

    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

    recorder.setVideoSize(176, 144); // QCIF

    recorder.setVideoFrameRate(15);

    recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);

    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    recorder.setOutputFile(path);

   

    recorder.prepare();

    recorder.start();

2. 停止錄製功能

recorder.stop();

recorder.release();

照相功能

 

 

 

推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:

Google Android 手機程式設計--第九章:二維繪圖功能,2D 動畫功能,3D 動畫OpenGL

clock 十一月 8, 2009 19:05 by author Administrator

Android 的繪圖相關物件

android.graphics.Camera

android.graphics.drawable.Drawable

 

Paint

  setStyle

  setColor

  setStrokeWidth(strokeWidth);

  setAntiAlias(true);

  setARGB(255, 255, 255, 255);

Path

PathEffect

 

Matrix

  .setPolyToPoly(src, 0, dst, 0, src.length >> 1);

 

Paint.FontMetrics

mFontMetrics = mPaint.getFontMetrics();

整合練習 - 繪圖版範例

2D 動畫功能

Bitmap

createBitmap(int[] colors, int width, int height, boolean hasAlpha)

int         getPixel(int x, int y)

int         height()

void  setPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height)

int         width()

Canvas :

  setDevice()

  boolean     clipPath(Path path, ClipMode mode)

boolean      clipRect(float left, float top, float right, float bottom)

       Intersect the current clip with the specified rectangle, which is expressed in local coordinates.

void          drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)

void    drawBitmap(Bitmap bitmap, float left, float top, Paint paint)

void    drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint)

void    drawCircle(float cx, float cy, float radius, Paint paint)

void    drawColor(int color)

void    drawColor(int color, Mode mode)

void    drawLine(float startX, float startY, float stopX, float stopY, Paint paint)

void    drawOval(RectF oval, Paint paint)

void    drawPaint(Paint paint)

void    drawPath(Path path, Paint paint)

void    drawPoint(float x, float y, Paint paint)

void    drawPoints(float[] pts, int offset, int length, Paint paint)

void    drawPoints(float[] pts, Paint paint)

void    drawPosText(char[] text, int index, int count, float[] pos, Paint paint)

void    drawPosText(String text, float[] pos, Paint paint)

void    drawRGB(int r, int g, int b)

void    drawRect(RectF rect, Paint paint)

void    drawRect(float left, float top, float right, float bottom, Paint paint)

void    drawRect(Rect r, Paint paint)

void    drawRoundRect(RectF rect, float rx, float ry, Paint paint)

void    drawText(String text, int start, int end, float x, float y, Paint paint)

void    drawText(char[] text, int index, int count, float x, float y, Paint paint)

void    drawText(String text, float x, float y, Paint paint)

void    drawText(CharSequence text, int start, int end, float x, float y, Paint paint)

void    drawTextOnPath(String text, Path path, float hOffset, float vOffset, Paint paint)

void    drawTextOnPath(char[] text, int index, int count, Path path, float hOffset, float vOffset, Paint paint)

變形與轉換

Android 中二維的動畫功能主要在 android.view.animation 函式庫中,包含兩種動畫功能,第一種是二維轉換 (tweened animation) ,第二種是逐畫面的動畫(frame by frame animation)

二維轉換總共有四種基本轉換

1.    AlphaAnimation 透明度轉換 (transparency changes)

2.    RotateAnimation旋轉 (rotations)

3.    ScaleAnimation 縮放 (growing or shrinking)

4.    TranslateAnimation 位移 (position changes)

 

描述二維轉換的方式又可分為 1. 使用 XML 2. 使用 Java 程式 兩種方法。

 

(1)  使用 XML 描述二維轉換

<set android:shareInterpolator="true"

     android:interpolator="@android:anim/ease_in_interpolator">

 

    <translate android:fromXDelta="0"

               android:toXDelta="30"

               android:duration="800"

               android:fillAfter="true"/>

   

    <set android:duration="800"

         android:pivotX="50%"

         android:pivotY="50%" >

 

        <rotate android:fromDegrees="0"

                android:toDegrees="-90"

                android:fillAfter="true"

                android:startOffset="800"/>

   

        <scale android:fromXScale="1.0"

                android:toXScale="2.0"

                android:fromYScale="1.0"

                android:toYScale="2.0"

                android:startOffset="800" />

    </set>

 

    <translate android:toYDelta="-100"

               android:fillAfter="true"

               android:duration="800"

               android:startOffset="1600"/>

</set>

 

(2)  使用 Java 實作二維轉換

// Create root AnimationSet.

AnimationSet rootSet = new AnimationSet(true);

rootSet.setInterpolator(new EaseInInterpolator());

rootSet.setRepeatMode(Animation.NO_REPEAT);

 

// Create and add first child, a motion animation.

TranslateAnimation trans1 = new TranslateAnimation(0, 30, 0, 0);

trans1.setStartOffset(0);

trans1.setDuration(800);

trans1.setFillAfter(true);

rootSet.addAnimation(trans1);

 

// Create a rotate and a size animation.

RotateAnimation rotate = new RotateAnimation(

       0,

       -90,

       RotateAnimation.RELATIVE_TO_SELF, 0.5f,

       RotateAnimation.RELATIVE_TO_SELF, 0.5f);

       rotate.setFillAfter(true);

       rotate.setDuration(800);

 

ScaleAnimation scale = new ScaleAnimation(

       1, 2, 1, 2, // From x, to x, from y, to y

       ScaleAnimation.RELATIVE_TO_SELF, 0.5f,

       ScaleAnimation.RELATIVE_TO_SELF, 0.5f);

       scale.setDuration(800);

       scale.setFillAfter(true);

 

// Add rotate and size animations to a new set,

// then add the set to the root set.

AnimationSet childSet = new AnimationSet(true);

childSet.setStartOffset(800);

childSet.addAnimation(rotate);

childSet.addAnimation(scale);

rootSet.addAnimation(childSet);

 

// Add a final motion animation to the root set.

TranslateAnimation trans2 = new TranslateAnimation(0, 0, 0, -100);

trans2.setFillAfter(true);

trans2.setDuration(800);

trans2.setStartOffset(1600);

rootSet.addAnimation(trans2);

 

// Start the animation.

animWindow.startAnimation(rootSet);

 

載入與啟動二維轉換

// Hook into the object to be animated.

TextView animWindow = (TextView)findViewById(R.id.anim);

 

// Load the animation from XML (XML file is res/anim/move_animation.xml).

Animation anim = AnimationUtils.loadAnimation(AnimationSample.this, R.anim.move_animation);

anim.setRepeatMode(Animation.NO_REPEAT);

 

// Play the animation.

animWindow.startAnimation(anim);

3D 動畫 OpenGL

Android 使用 OpenGL這個 3D 動畫遊戲引擎的嵌入式版本,稱為 OpenGL|ES,這和 J2ME 中的 JSR239 OpenGL ES API 大至上是相同的,但並不完全一樣。

OpenGL 的範例

Android 中使用 OpenGL 時,首先要先繼承 View 這個物件,然後在程式中取得 OpenGLContext 這個物件,接著在 onDraw() 這個函數中執行對應的繪圖的功能,以下是一個範例。

 

class GLView extends View

{

    public GLView(Context context)

    {

        mGLContext = new OpenGLContext(0);

    }

    @Override

    protected void onDraw(Canvas canvas) {

        GL10 gl = (GL10)(mGLContext.getGL());

        mGLContext.waitNative(canvas, this);

            gl.glViewport(0, 0, w, h);

            float ratio = (float)w / h;

            gl.glMatrixMode(gl.GL_PROJECTION);

            gl.glLoadIdentity();

            gl.glFrustumf(-ratio, ratio, -1, 1, 2, 12);

            gl.glDisable(gl.GL_DITHER);

            gl.glClearColor(1,1,1,1);

            gl.glEnable(gl.GL_SCISSOR_TEST);

            gl.glScissor(0, 0, w, h);

            gl.glClear(gl.GL_COLOR_BUFFER_BIT);

            gl.glMatrixMode(gl.GL_MODELVIEW);

            gl.glLoadIdentity();

            gl.glTranslatef(0, 0, -3.0f);

            gl.glScalef(0.5f, 0.5f, 0.5f);

            gl.glRotatef(mAngle, 0, 1, 0);

            gl.glRotatef(mAngle*0.25f,  1, 0, 0);

            gl.glColor4f(0.7f, 0.7f, 0.7f, 1.0f);

            gl.glEnableClientState(gl.GL_VERTEX_ARRAY);

            gl.glEnableClientState(gl.GL_COLOR_ARRAY);

            gl.glEnable(gl.GL_CULL_FACE);

            mCube.draw(gl);

            mAngle += 1.2f;

     mGLContext.waitGL();

          }

    }

 Android android.media.MediaPlayer 函式庫提供了影片與聲音的播放功能,另外也在android.media.MediaRecorder中提供了錄音與錄影的功能,但這些功能在模擬器當中將無法運作,只有真實的手機才會具備此功能。

推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:

Google Android 手機程式設計--第八章:網路函式庫

clock 十一月 7, 2009 13:55 by author Administrator

Android 的網路函式庫採用了標準的 java.net.* 中的網路函式庫,包含 Socket, URL, InetAddress, . 等物件,並且將 Android 所擴充的物件放在 android.net.* 中,以補充原先 java 網路函數上的不足,另外、Android 也從 apache當中取用了 httpClient 的函式庫以形成更完整的網路架構。

網路相關函式庫

Socket 程式設計

Apache HttpClient

Android 的網路函式庫

XMPP 網路服務協定

XMPP : ineXtensible Messaging and Presence Protocol

 

Totally *Unofficial* Android GTalk Client (Send/Receive XMPP Messages)

http://davanum.wordpress.com/2007/11/23/totally-unofficial-android-gtalk-client-sendreceive-xmpp-messages/

 

WebKit 瀏覽器的控制

Android 中所採用的瀏覽器是 WebKit,和 iPhone 中的一樣,要控置瀏覽器很簡單,只要 import android.webkit.WebView 後,呼叫 loadUrl() 函數載入網頁即可。

推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:

Google Android 手機程式設計--第七章:字串處理與XML, 資料儲存

clock 十一月 6, 2009 22:59 by author Administrator

自從全球資訊網 Web 被建立以後,文字型的資料處理就一直是程式設計師所必需具備的基本技巧,目前最常見的三種文字處理技術是:

1. 字串物件

2. Regular Expression 比對

3. XML 文件處理.

 

Android 中的字串相關函式庫

java.lang

java.text

Android.text Provides classes used to render or track text and text spans on the screen.

Android.text.method Provides classes that monitor or modify keypad input.

 

Android.text.style Provides classes used to view or change the style of a span of text in a View object.

android.text.util

 

正規表示式

java.util.regex

處理XML 文件

android.sax

javax.xml.parsers

org.json   

org.w3c.dom   

org.xml.sax  This package provides the core SAX APIs.

org.xml.sax.ext  This package contains interfaces to SAX2 facilities that conformant SAX drivers won't necessarily support.

org.xml.sax.helpers  This package contains "helper" classes, including support for bootstrapping SAX-based applications.

 

資料儲存

 

共用資料 – SharedPreference

 

1  SharedPreferences

Preference Android 中用來儲存資料最簡單的一種方法,我們可以使用 Context.getSharedPreferences() Activity.getPreferences() 取得儲存的變數,或對某一 Preference變數的 editor 物件進行 put 動作以儲存資料,但這些共用資料只能在同一個 Package 底下使用。

 

以下是使用 Preference 來設定一個小計算機中按鍵模式keypress 的範例程式:

public class Calc extends Activity {

public static final String PREFS_NAME = "MyPrefsFile";

     ...     

 

    @Override

    protected void onCreate(Bundle state){        

       super.onCreate(state);

   

    ...

   

       // Restore preferences

       SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

       boolean silent = settings.getBoolean("silentMode", false);

       setSilent(silent);

    }

   

    @Override

    protected void onStop(){

       super.onStop();

   

      // Save user preferences. We need an Editor object to

      // make changes. All objects are from android.context.Context

      SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

      SharedPreferences.Editor editor = settings.edit();

      editor.putBoolean("silentMode", mSilentMode);

 

      // Don't forget to commit your edits!!!

      editor.commit();

    }

}

檔案系統 - Files

 

2  Files

Context.openFileOutput() and Context.openFileInput()

If you have static files to package with your application at compile time, you can save your file in your project in res/raw/<mydatafile>, and then get it with Resources.openRawResource (R.raw.mydatafile).

資料庫- Sqlite

3  Sqlite

To create a database, use Context.createDatabase() and Context.openDatabase(), and read and write this data as appropriate.

資料提供者 – ContentProvider

4  Content Provider

Android 中要跨越應用存取資料,Content Provider 是唯一的方法,Content Provider 是可以被所有應用存取得一種物件。

推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:

Google Android 手機程式設計--第六章:事件處理

clock 十一月 5, 2009 15:24 by author Administrator

事件處理的基本概念

Android 所使用的事件處理方式,在視覺化介面上,是以傳統Java Listener 的方式,覆寫 Override 父類別中對映的事件函數的方式處理的,這和 VB 等設計方式很類似,在後面的文章中我們將使用一個簡單的按鈕控制示範這種覆寫處理法。 

然而、在自訂的事件方面,Android是以 訊息傳遞的方式,搭配控制作業系統排程的方式處理的,這是一個相當奇特的處理方式,也使得初學者很難理解這種概念,在

後面的文章中、我們將使用此種方式,設計一個小的電子鐘,以說明此種訊息傳遞的事件處理方式。

按鈕事件

 

滑鼠事件

 鍵盤事件

 

1  在程式中取得元件

取得上層元件

 

使用 R.id.. 可取得 layout 中用XML所定義的視覺化元件。

 

取得內層元件

 

使用 Activity.findViewById 可取得內層的元件,

 

TextView msgTextView = (TextView)findViewById(R.id.msg);

msgTextView.setText(R.string.push_me);

2  撰寫事件驅動函數

Listening for UI Notifications

Some UI notifications are automatically exposed and called by Android. For instance, Activity exposes overrideable methods onKeyDown and onKeyUp, and Widget exposes onFocusChanged(boolean, int). However, some important callbacks, such as button clicks, are not exposed natively, and must be registered for manually, as shown here

 

public class SendResult extends Activity

{

    /**

     * Initialization of the Screen after it is first created.  Must at least

     * call setContentView() to

     * describe what is to be displayed in the screen.

     */

    protected void onCreate(Bundle savedValues)

    {

        ...

 

        // Listen for button clicks.

        Button button = (Button)findViewById(R.id.corky);

        button.setOnClickListener(mCorkyListener);

    }

 

    // Create an anonymous class to act as a button click listener.

    private OnClickListener mCorkyListener = new OnClickListener()

    {

        public void onClick(View v)

        {

            // To send a result, simply call setResult() before your

            // activity is finished.

            setResult(RESULT_OK, "Corky!");

            finish();

        }

    };

 

3  一個簡單的按鈕範例

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<Button id="@+id/buttonHello"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="Press me to say hello !"

    />

</LinearLayout>

 

package test.widget;

 

import test.widget.R;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

 

public class ButtonTest extends Activity {

       Activity me;

       Button buttonHello;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle icicle) {

        super.onCreate(icicle);

        setContentView(R.layout.main);

        me = this;

        buttonHello = (Button) this.findViewById(R.id.buttonHello);

             buttonHello.setOnClickListener(buttonHelloListener);

    }

    private View.OnClickListener buttonHelloListener

= new View.OnClickListener() {

        public void onClick(View arg0) {

             me.showAlert("Title", "Hello!", "OK", true);

        }

       };   

}

時間事件

 

推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:

Google Android 手機程式設計--第五章:視覺化介面進階

clock 十一月 4, 2009 17:10 by author Administrator

視覺元件

取得銀幕大小

文字型元件

TextView

但是、若把 android:autoLink="all" 這行移除再執行,則會看到下列結果.

AutoCompleteTextView

 

圖片相關元件

Dialog

AlertDialog

DialogInterface      

  DatePickerDialog    

  ProgressDialog    

  TimePickerDialog 

資料綁定元件

GallaryGrid

ViewListView

PopupList

ScrollView

Spinner

TabHost

ViewFlipper

ViewSwitcher

 

XML 屬性的設定

統一的風格元件

1  在整個專案中使用統一的風格 (Theme)

 

Applying a Theme to your Application

If you do not explicitly specify a theme for your UI, Android will use the default theme defined by android.R.style.Theme. Many times you will want to use a different system theme (such as Theme.Dark) or create your own theme (as described in Style and Theme Resources).

 

To set your theme in XML, simply specify the desired theme in your AndroidManifest.xml file with the theme attribute. This can be used with the <application> tag (shown here) to specify a default theme for all of your activities, and/or with the <activity> to control the theme of a particular activity.

 
推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:

Google Android 手機程式設計--第四章:視覺化介面的基礎

clock 十一月 3, 2009 14:19 by author Administrator

Android 介面設計簡介

在上一章我們曾經談到, Android 平台的視覺化介面是使用 XML 的方式設計的,然而上一章我們只做了一個簡單的 HelloWorld 的表單,在本章、我們將介紹如何利用常用的元件設計出較實用的表單,並展示每個常用視覺元件的用途。

Android 當中的視覺化界面元件,可分為『容器』與『非容器』兩類,容器類繼承 ViewGroup 物件,非容器類則從 View 衍生出來,如下圖所示。

 

這些 Layout 可以套疊式的組成一棵元件樹,其中、父節點的 Layout 與子節點的 LayoutParams 之間有控制關系,舉例而言、若父節點是 RelativeLayout,則子節點的元件中可以指定 RelativeLayout.LayoutParams 中的屬性,以控制子節點在父節點中的排列狀況,如下圖所示:

各種排版元件 – Layout

容器類物件中專們用來排版者,稱為 Layout,以下是 Android Layout 物件的列表:

FrameLayout

Android 中的 FrameLayout Java Swing 中的 FrameLayout 完全不同,Android 中的 FrameLayout 代表只能放入單一視覺元件的容器,與 Swing 中區分『上、下、左、右、中』的 FrameLayout 完全是兩回事。

 

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<TextView 

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="Hello World, FrameLayoutTest"

    />

</FrameLayout>

AbsoluteLayout

<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

     <EditText id="@+id/title_edit"

        android:layout_x = "10px"

        android:layout_y = "10px"

        android:layout_width="200px"

        android:layout_height="wrap_content"/>

     <Button id="@+id/buttton"

        android:layout_x = "220px"

        android:layout_y = "10px"

        android:text="Send"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"/>

     <TextView 

        android:layout_x = "10px"

        android:layout_y = "50px"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="Hello World, AbsoluteLayoutTest"/>

</AbsoluteLayout>

LinearLayout

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

     <EditText id="@+id/title_edit"

        android:layout_width="200px"

        android:layout_height="wrap_content"/>

     <Button id="@+id/buttton"

        android:text="Send"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"/>

     <TextView 

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="Hello World, AbsoluteLayoutTest"/>

</LinearLayout>

RelativeLayout

 

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:padding="10dip">

 

    <TextView id="@+id/label"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:text="Hello!"/>

 

    <EditText id="@+id/entry"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_below="@id/label"/>

 

    <Button id="@+id/ok"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_below="@id/entry"

        android:layout_alignParentRight="true"

        android:layout_marginLeft="10dip"

        android:text="OK" />

 

    <Button id="@+id/entry"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_toLeft="@id/ok"

        android:layout_alignTop="@id/ok"

        android:text="Cancel" />

</RelativeLayout>

TableLayout

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"

            id="@+id/table_layout"

            android:layout_width="fill_parent"

            android:layout_height="wrap_content">

  <TableRow>

     <Button id="@+id/button1" android:text="Button1" />

     <Button id="@+id/button2" android:text="Button2" />

  </TableRow>

  <TableRow>

     <Button id="@+id/button3" android:text="Button3"

             android:layout_span="2"/>

  </TableRow>

</TableLayout>

 

由於視覺化介面的物件屬性與 XML 標記的屬性並不是11對映的,因此、Android 的程式設計人原有必要學會看 Android SDK 當中的原始函式庫說明文件,文件中的説明大至按照傳統 Java 的格式,然而、其中與傳統 Java 最大的當屬 XML 屬性了,在附錄D中,我們以 TableRow 這個物件為例介紹其文件的編寫方式,以利讀者看懂這些說明文件,順利成為 Google Phone/Android 的高手。

推薦給同仁

Tell a Friend 

您想要瞭解更多的免費小竅門以便提升你的網站排名嗎?
請馬上聯繫我們網站管理員:
MSN: chenlinwu@cmmail.com 
Email: info@rank-ad.com


第一個評分

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


開始建立您的網上業務,點擊進入http://www.rank-ad.com/

加入每二週免費網上推廣提示電郵訂閱,即時獲贈免費關鍵字廣告課程及提升網站流量

加入每二週免費網上推廣提示電郵訂閱, 即時獲贈免費關鍵字廣告課程及提升網站流量
Fo Xuan Henry

建立你的 Facebook 電子名片

Bookmark and Share

Twitter Updates:



© 版權所有 海神科技有限公司

© 版權所有 海神科技有限公司