Eros Live
          Find the Way
          posts - 15,comments - 0,trackbacks - 0

          在manifest的activity節(jié)點使用

          <activity android:windowSoftInputMode="adjustResize" . . . >

          當點擊EditText控件彈出軟鍵盤的時候,系統(tǒng)會自動調整控件的位置。

          代碼

          http://github.com/shaobin0604/miscandroidapps/tree/master/WindowSoftInputMode/

          參考

          posted @ 2010-08-25 18:42 Eros 閱讀(271) | 評論 (0)編輯 收藏

          AppWidget的初始化有兩種方式:

          1. 沒有提供Configure Activity, 則在 AppWidgetProvider#onUpdate 里初始化。
          2. 提供Configure Activity, 則在 Configure Activity 里初始化。

          目前遇到的問題是:

          在Launcher里可以預先配置桌面顯示的AppWidget,如果AppWidget有Configure Activity,則系統(tǒng)在AppWidget的初始化過程不會發(fā)送android.appwidget.action.APPWIDGET_CONFIGURE Intent,而只是加載appwidget-provider里配置的initialLayout。這樣第二種就不可用,只能用第一種方法。

          posted @ 2010-08-24 11:11 Eros 閱讀(431) | 評論 (0)編輯 收藏

          1.字體大小

          synchronized void
          setTextSize(WebSettings.TextSize t)

          Set the text size of the page.

          2.縮放比例

          void
          setSupportZoom(boolean support)

          Set whether the WebView supports zoom

          void
          setInitialScale(int scaleInPercent)

          Set the initial scale for the WebView.

          boolean
          zoomIn()

          Perform zoom in in the webview

          boolean
          zoomOut()

          Perform zoom out in the webview

          3.縮放控件

          void
          setBuiltInZoomControls(boolean enabled)

          Sets whether the zoom mechanism built into WebView is used.

          4.JavaScript支持

          synchronized void
          setJavaScriptEnabled(boolean flag)

          Tell the WebView to enable javascript execution.

          posted @ 2010-07-28 12:49 Eros 閱讀(389) | 評論 (0)編輯 收藏

          在程序里備份恢復數(shù)據(jù)

          public static boolean backupDatabase() {
              File dbFile = new File(Environment.getDataDirectory() + "/data/" + PKG + "/databases/" + DB_NAME);
           
              File exportDir = new File(Environment.getExternalStorageDirectory(), "pocket-voa");
              
              if (!exportDir.exists()) {
                  exportDir.mkdirs();
              }
              
              File file = new File(exportDir, dbFile.getName());
           
              try {
                  file.createNewFile();
                  copyFile(dbFile, file);
                  return true;
              } catch (IOException e) {
                  Log.e(TAG, "[backupDatabase] error", e);
                  return false;
              }
          }
           
          public static boolean restoreDatabase() {
              File dbFile = new File(Environment.getDataDirectory() + "/data/" + PKG + "/databases/" + DatabaseHelper.DB_NAME);
           
              File exportDbFile = new File(Environment.getExternalStorageDirectory() + "/pocket-voa/" + DatabaseHelper.DB_NAME);
              
              if (!exportDbFile.exists())
                  return false;
           
              try {
                  dbFile.createNewFile();
                  copyFile(exportDbFile, dbFile);
                  return true;
              } catch (IOException e) {
                  Log.e(TAG, "[restoreDatabase] error", e);
                  return false;
              }
          }
           
          private static void copyFile(File src, File dst) throws IOException {
              FileChannel inChannel = new FileInputStream(src).getChannel();
              FileChannel outChannel = new FileOutputStream(dst).getChannel();
              try {
                  inChannel.transferTo(0, inChannel.size(), outChannel);
              } finally {
                  if (inChannel != null)
                      inChannel.close();
                  if (outChannel != null)
                      outChannel.close();
              }
          }

          參考

          posted @ 2010-07-26 17:24 Eros 閱讀(344) | 評論 (0)編輯 收藏

           

          There are certain events that Android does not want to start up new processes for, so the device does not get too slow from all sorts of stuff all having to run at once. ACTION_SCREEN_ON is one of those. See this previous question for light blue advice on that topic.

          So, you need to ask yourself, "Self, do I really need to get control on those events?". The core Android team would like it if your answer was "no".

          posted @ 2010-07-22 19:59 Eros 閱讀(1175) | 評論 (0)編輯 收藏
               摘要: 1.海詞 http://api.dict.cn/ws.php?utf8=true&q=#{word} 返回格式XML<?xml version="1.0" encoding="UTF-8" ?> <dict> <key>word</key> <lang>ec</lang> <audio>...  閱讀全文
          posted @ 2010-07-15 15:45 Eros 閱讀(2037) | 評論 (0)編輯 收藏

          打開終端輸入

          adb devices

          出現(xiàn)如下內容

          ??????????? no permissions

          原因是啟動adb的時候需要有root權限。如果一開始忘記加了sudo, 就必須先終止adb。

          $ adb kill-server

          $ sudo adb start-server

          $ adb devices

          就可以看到設備信息了。

          參考

          posted @ 2010-07-07 15:44 Eros 閱讀(596) | 評論 (0)編輯 收藏
               摘要: 原理 關閉APN的原理是在APN信息表(content://telephony/carriers/current)的apn, type字段添加自定義的后綴(參考自APNDroid) 代碼 (取自 Quick Settings) package com.android.settings.widget; import android.content.ContentResolver;impo...  閱讀全文
          posted @ 2010-07-07 15:28 Eros 閱讀(724) | 評論 (0)編輯 收藏

          環(huán)境

          Ubuntu 9.10 64bit, sun-jdk-1.5(因需要編譯Android源代碼), Android SDK 2.1

          癥狀

          draw9patch 不能正確顯示出窗口,沒有菜單欄

          原因

          sun jdk 1.5 的BUG

          解決

          安裝 sun jdk 1.6

          參考

          1. http://resources2.visual-paradigm.com/index.php/tips-support/53-support/61-blank-screen.html
          2. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6585673
          3. https://bugs.launchpad.net/ubuntu/+bug/164004
          4. http://forums.visual-paradigm.com/posts/list/6719.html
          posted @ 2010-07-07 12:19 Eros 閱讀(274) | 評論 (0)編輯 收藏

          Install Ubuntu 9.10


          Links

          1. http://docs.google.com/fileview?id=0B7vaQCSPJU8PNjUzZmU1ZTItYTVlNi00ZDBmLWFhMzMtN2Q3NDA4MzljMjRm&hl=zh_CN
          2. http://ubuntuabc.com/123/?p=38

          Install JDK

          sudo apt-get install sun-java6-jdk

          sudo update-alternatives –config java


          posted @ 2010-07-02 19:58 Eros 閱讀(296) | 評論 (0)編輯 收藏

          1.NPR News

          http://code.google.com/p/npr-android-app/

          image

          2.Quick Settings

          Quick Settings is a highly customizable all-in-one settings applications for Android.

          http://code.google.com/p/quick-settings/

          image

          3.Quick Battery

          http://code.google.com/p/quick-settings/source/browse/#svn/trunk/quick-battery

          posted @ 2010-07-01 18:52 Eros 閱讀(145) | 評論 (0)編輯 收藏

          1.文本編輯器

           

          2.文本查看器

          JSON

          3.正則表達式

          在線測試工具

          4.字體

          YaHei Consolas

          http://www.box.net/shared/72dcnre8on

          設置字體大小為五號

          參考http://be-evil.org/post-178.html

          posted @ 2010-06-30 18:51 Eros 閱讀(142) | 評論 (0)編輯 收藏

          1.獲取屏幕的分辨率

          在 Activity 里使用如下代碼,寬度和高度的單位是像素

          Display display = getWindowManager().getDefaultDisplay();
          int screenWidth = display.getWidth();
          int screenHeight = display.getHeight();

          2.繪制文本

          使用 FontMetrics 類

          參考

          http://www.javaeye.com/topic/474526

          3.禁止自動橫豎屏切換

          在AndroidManifest.xml的Activity節(jié)點加入如下屬性

          android:screenOrientation="portrait"

          portrait是縱向,landscape是橫向

          4.Resources and Assets

          無論是使用Res\raw還是使用Asset存儲資源文件,文件大小UNCOMPRESS限制為1MB

          參考

          http://wayfarer.javaeye.com/blog/547174

          5.SDK 1.6 新增加SD卡寫入權限

          在AndroidManifest.xml加入以下代碼

          <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

          SDK1.6之前的項目自適應,無需此權限也可以寫入SD卡。

          6.在eclipse中查看Android Framework源代碼

          代碼下載

          1. SDK 1.5 http://www.box.net/shared/16au19tqlp
          2. SDK 1.6 http://www.box.net/shared/dh4dr9ir7j
          3. SDK 2.2 http://www.box.net/shared/dic2t0blj1

          參考

          http://www.javaeye.com/topic/534010

          7.給View注冊ContextMenu

          void setOnCreateContextMenuListener(View.OnCreateContextMenuListener l)

          Register a callback to be invoked when the context menu for this view is being built.

          8.給Preference設置Intent

          void setIntent(Intent intent)

          Sets an Intent to be used for startActivity(Intent) when this Preference is clicked.

          9.包含CheckBox的ListView

          ListView item中加入checkbox后onListItemClick 事件無法觸發(fā)。
          原因:checkbox的優(yōu)先級高于ListItem于是屏蔽了ListItem的單擊事件。
          解決方案:設置checkbox的android:focusable="false"

          10.取得當前的Locale

          Locale locale = context.getResources().getConfiguration().locale;

          11.使用android.text.format.Time類代替java.util.Calendar類

          The Time class is a faster replacement for the java.util.Calendar and java.util.GregorianCalendar classes. An instance of the Time class represents a moment in time, specified with second precision. It is modelled after struct tm, and in fact, uses struct tm to implement most of the functionality.

          12.調整WebView字體大小

          WebView.getSettings().setDefaultFontSize()
          WebView.getSettings().setDefaultZoom()

          13.View Animation總結

          參考

          14.檢查網絡狀態(tài)

          public static boolean isNetworkAvailable(Context context) {
              ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
              NetworkInfo info = cm.getActiveNetworkInfo();
              
              return (info != null && info.isConnected());
          }
           
           
          public static boolean isWifiConnected(Context context) { 
              return getNetworkState(context, ConnectivityManager.TYPE_WIFI) == State.CONNECTED;
          }
           
          public static boolean isMobileConnected(Context context) {
              return getNetworkState(context, ConnectivityManager.TYPE_MOBILE) == State.CONNECTED;
          }
           
          private static State getNetworkState(Context context, int networkType) {
              ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
              NetworkInfo info = cm.getNetworkInfo(networkType);
              
              return info == null ? null : info.getState();    
          }

          需要加入權限

          <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

          15.Parse JSON String

          參考

          1. http://www.androidcompetencycenter.com/2009/10/json-parsing-in-android/
          2. http://wiki.fasterxml.com/JacksonInFiveMinutes
          3. http://stackoverflow.com/questions/2818697/sending-and-parsing-json-in-android

          16.設置EditText的輸入模式

          url, password, email, 電話鍵盤等

          設置 android:inputType 屬性

          17.Crash Report

          1. http://code.google.com/p/acra/
          2. http://code.google.com/p/android-send-me-logs/

          18.用戶解鎖消息

          android.intent.action.USER_PRESENT

          只能在代碼里注冊Receiver

          19.屏幕消息

          android.intent.action.SCREEN_ON

          android.intent.action.SCREEN_OFF

          只能在代碼里注冊Receiver

          posted @ 2010-06-29 13:22 Eros 閱讀(503) | 評論 (0)編輯 收藏

          實現(xiàn)應用《cnBeta業(yè)界資訊》分批加載數(shù)據(jù)的效果

          image image image

          這里ListView底部的“顯示后10條”Button用到了ListView的方法

          public void addFooterView (View v)

          布局文件 main.xml

          <?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"
              >
              <ListView android:id="@+id/list" 
                  android:layout_width="fill_parent" 
                  android:layout_height="wrap_content" 
                  android:layout_weight="1"/>
          </LinearLayout>

          MainActivity.java

          package com.example.listviewwithheaderandfooter;
           
          import java.util.ArrayList;
          import java.util.List;
           
          import android.app.Activity;
          import android.app.ProgressDialog;
          import android.os.Bundle;
          import android.view.View;
          import android.widget.ArrayAdapter;
          import android.widget.Button;
          import android.widget.ListView;
           
          public class MainActivity extends Activity {
              static final String[] COUNTRIES = new String[] {
                  "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
                  "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
                  "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
                  "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
                  "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
                  "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory",
                  "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
                  "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
                  "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
                  "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
                  "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
                  "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
                  "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
                  "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
                  "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
                  "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
                  "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
                  "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
                  "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
                  "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
                  "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
                  "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
                  "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
                  "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
                  "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
                  "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
                  "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
                  "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
                  "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
                  "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
                  "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
                  "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
                  "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
                  "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
                  "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
                  "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
                  "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
                  "Ukraine", "United Arab Emirates", "United Kingdom",
                  "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
                  "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
                  "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
                };
              
              private List<String> mList = new ArrayList<String>();
           
              private ArrayAdapter<String> mAdapter;
              
              
              /** Called when the activity is first created. */
              @Override
              public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.main);
                  
                  ListView list = (ListView) findViewById(R.id.list);
                  
                  Button buttonHeader = new Button(this);
                  buttonHeader.setText("remove 1 entries");
                  buttonHeader.setOnClickListener(new View.OnClickListener() {
                      
                      @Override
                      public void onClick(View v) {
                          if (mList.size() > 0) {
                              mList.remove(mList.size() - 1);
                              mAdapter.notifyDataSetChanged();
                          }
                      }
                  });
                  list.addHeaderView(buttonHeader);
                  
                  Button buttonFooter = new Button(this);
                  buttonFooter.setText("add 1 entries");
                  
                  buttonFooter.setOnClickListener(new View.OnClickListener() {
                      
                      @Override
                      public void onClick(View v) {
                          // TODO Auto-generated method stub
                          final ProgressDialog dialog = new ProgressDialog(MainActivity.this);
                          dialog.setIndeterminate(true);
                          dialog.show();
                          new Thread() {
                              public void run() {
                                  int start = mList.size();
                                  int end = start + 1;
                                  if (end > COUNTRIES.length)
                                      end = COUNTRIES.length;
                                  
                                  for (; start < end; start++) {
                                      mList.add(COUNTRIES[start]);
                                  }
                                  
                                  runOnUiThread(new Runnable() {
                                      
                                      @Override
                                      public void run() {
                                          dialog.dismiss();
                                          mAdapter.notifyDataSetChanged();
                                      }
                                  });
                                  
                              }
                          }.start();
                          
                          
                      }
                  });
                  list.addFooterView(buttonFooter);
                  
                  mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mList);
                  
                  list.setAdapter(mAdapter);
              }
          }

          效果

          image image

          posted @ 2010-06-29 11:20 Eros 閱讀(2919) | 評論 (0)編輯 收藏
          主站蜘蛛池模板: 赣榆县| 沙坪坝区| 当阳市| 安宁市| 阳信县| 武义县| 东乡族自治县| 本溪市| 荃湾区| 崇文区| 昆山市| 延寿县| 苏尼特右旗| 澄迈县| 肥西县| 九江市| 科尔| 溆浦县| 湾仔区| 永兴县| 临安市| 贞丰县| 蒙阴县| 鄂温| 绥宁县| 微博| 郓城县| 绵竹市| 灵台县| 通辽市| 连江县| 青神县| 英吉沙县| 鄂州市| 平昌县| 毕节市| 蓝山县| 新蔡县| 湘潭县| 于都县| 铁岭县|