launcher 类分析

1.class LauncherSetting{//定义数据的类

    static final class Favorites implements BaseColumns {//一般通过内部类来实现BaseColumns
  •  
    • URI定义 
      • static final Uri CONTENT_URI = Uri.parse("content://" +              LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES + "?" + LauncherProvider.PARAMETER_NOTIFY + "=true");
    • 数据库中item项的定义 
      •  static final String ID = "_id";//定义ID
      •  static final String TITLE = "title";//定义title
}
}
2.public class LauncherProvider extends ContentProvider{//定义ContentProvider
  •    private static class DatabaseHelper extends SQLiteOpenHelper {//内部定义DatabaseHelper
}
}
 
 
  1.  function:
  Displays the shortcut creation dialog and launches, if necessary, the
  appropriate activity
通过一个AddAdpter加入到一个list中,创建menu中ADD的功能:
1.创建dialog
mAdapter = new AddAdapter(Launcher.this);
       AlertDialog.Builder builder=new  AlertDialog.Builder(this);
builder.setAdatper(mAddapter,this);
AlertDialog dialog = builder.create(); dialog.setOnCancelListener(this);
2.创建dialog的监听 主要监听以下动作:
  • AddAdapter.ITEM_SHORTCUT
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);//Pick an activity given an intent, returning the class selected
pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));//加入EXTRA_INTENT
  • AddAdapter.ITEM_APPWIDGET//打开所有widget的dialog
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appWidgetId);
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
ArrayList<AppWidgetProviderInfo> customInfo = new ArrayList<AppWidgetProviderInfo>();
pickIntent.putParcelableArrayListExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
通过上面四步就可以得到相应的widget dilaog
  • AddAdapter.ITEM_LIVE_FOLDER//打开folder的dialog
Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
pickIntent.putExtra(Intent.EXTRA_TITLE,getText(R.string.title_select_live_folder));
pickIntent.putExtra(Intent.EXTRA_INTENT, newIntent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
  • AddAdapter.ITEM_WALLPAPER//打开wallppaper的选择器diaog
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);//Action 为SET_wallpaper

startActivity(Intent.createChooser(pickWallpaper,getString(R.string.chooser_wallpaper)))选择器

 

 

launcher -->menu 的设计 以及相应的事件监听1.menu 的添加

menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add).setIcon(
    android.R.drawable.ic_menu_add).setAlphabeticShortcut('A');//Add item
menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
.setIcon(android.R.drawable.ic_menu_gallery)
.setAlphabeticShortcut('W');//wallpaper item add
menu.add(0, MENU_SEARCH, 0, R.string.menu_search).setIcon(
android.R.drawable.ic_search_category_default)
.setAlphabeticShortcut(SearchManager.MENU_KEY);//search item add
menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications)
.setIcon(com.android.internal.R.drawable.ic_menu_notifications)
.setAlphabeticShortcut('N');//notification item add
final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
menu.add(0, MENU_SETTINGS, 0,R.string.menu_settings).setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut(
'P').setIntent(settings);//setting item add 
 
search分析
  1. 启动Broswer去search你的内容可用以下代码:
Intent intent = new Intent(Intent.ACTION_SEARCH);// action search
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(SearchManager.QUERY, query);//query 为你要查询的东西
startActivity(Intent);
  2.Launcher的search中用SimpleCursorAdapter来实现AutoCompleteTextView的自动匹配动作。
  3.SimpleCursorAdapter是通过searchInfo来操作SearchRecentSuggestionsProvider的数据库,通过查询出来的curosr然后改变原来的cursor来布局到AutoCompleteTextView中去
posted @ 2012-12-24 16:07  GreyWolf  阅读(260)  评论(0编辑  收藏  举报