life02

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  197 随笔 :: 3 文章 :: 37 评论 :: 0 Trackbacks

AnyCat 是android一个小的项目,虽然麻雀很小但是知识很多。别看小程序就没学习的地方,错也。现将学习总结如下:以下为AnyCat项目精髓之处。

转载请注明:QQ:273733055 ppwuyi@sohu.com

程序核心代码如下:
http://hi.baidu.com/adnroidorg/blog/item/b79194a4c424809bd14358ba.html

/****
*      result.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
*     result.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); //-----------广播接收者
*     result.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); //---------------加载进去
*     result.putExtra(Intent.EXTRA_SHORTCUT_NAME, info.loadLabel(mPackageManager));//------------获取名字 地址路径
*     result.putExtra(Intent.EXTRA_SHORTCUT_ICON, bd.getBitmap());//----------------加载进去
*/
sendBroadcast(result);  //注意这才是创建快接方式的核心地点

将装配好的Intent通过广播的形式发送到com.android.launcher.action.INSTALL_SHORTCUT;

不过中小功能的地方我们也学习到不少,现总结如下:
1. FrontDoorActivity.java  无学习要点。
2 .ActivityPickerActivity.java  学习到怎么获取系统应用程序的程序名和路径。
view.setTag(view.findViewById(android.R.id.text1));
final TextView textView = (TextView) view.getTag();

Intent queryIntent = new Intent(Intent.ACTION_MAIN); //过滤地址
List<ResolveInfo> list = mPackageManager.queryIntentActivities(queryIntent, 0); //返回符合 地址要求的列表

textView.setText(info.getInfo().loadLabel(mPackageManager)); //取出项目名
mPackageManager = getPackageManager();//获取包

//获取应用程序的图标
Drawable drawable = info.loadIcon(mPackageManager); //---------------------------读取程序图标
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bd = (BitmapDrawable) drawable;
result.putExtra(Intent.EXTRA_SHORTCUT_ICON, bd.getBitmap());//----------------加载进去
}
//获取链接应用程序的桥梁
Intent intent = new Intent();//准备
intent.setComponent(new ComponentName(info.activityInfo.applicationInfo.packageName,
info.activityInfo.name));  //这是核心

转载请注明:QQ:273733055 ppwuyi@sohu.com


3.CreateShortcutActivity.java  学习到很多东西
//获取单一的联系人
Intent intent = new Intent(Intent.ACTION_PICK, Phones.CONTENT_URI);  //显示联系人列表并重中选择一个联系人的URI链接方式
intent.putExtra(Contacts.Intents.UI.TITLE_EXTRA_KEY, getText(R.string.callShortcutActivityTitle)); //传递一个标题给联系人列表
startActivityForResult(intent, REQUEST_PHONE);//开启联系人选择的activity等待用户选择

//别样的构造函数
return new ShortcutEditorDialog(this, this, this); //注意这个this,this,this 应为实现了onClick,onCancel接口
public ShortcutEditorDialog(Context context, OnClickListener onClick, OnCancelListener onCancel){.....}

//很和谐的代码
int iconSize = (int) r.getDimension(android.R.dimen.app_icon_size);//获得当前系统快捷方式的图片的限制大小
Bitmap icon = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888); //建立一个空的BItMap
Canvas canvas = new Canvas(icon);//初始化画布 绘制的图像到icon上

// Copy in the photo
Paint photoPaint = new Paint(); //建立画笔
photoPaint.setDither(true); //获取跟清晰的图像采样
photoPaint.setFilterBitmap(true);//过滤一些
Rect src = new Rect(0, 0, photo.getWidth(), photo.getHeight());//创建一个指定的新矩形的坐标
Rect dst = new Rect(0, 0, iconSize, iconSize);//创建一个指定的新矩形的坐标
canvas.drawBitmap(photo, src, dst, photoPaint);//将photo 缩放或则扩大到 dst使用的填充区photoPaint

//再次被和谐的代码
Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);//设置画笔
textPaint.setTextSize(20.0f);//字体大小
textPaint.setTypeface(Typeface.DEFAULT_BOLD);//采用默认的宽度
textPaint.setColor(r.getColor(R.color.textColorIconOverlay));//采用的颜色
textPaint.setShadowLayer(3f, 1, 1, r.getColor(R.color.textColorIconOverlayShadow));//影音的设置
canvas.drawText(overlay, 2, 16, textPaint);//绘制上去 字,开始未知x,y采用那只笔绘制


4.ShortcutEditorDialog.java
唯一学习到了一点是 
mNameView.setError(getContext().getText(R.string.errorEmptyName));//显示输入框为空的告警
想看效果自己动手吧。
posted on 2012-03-21 15:03 life02 阅读(373) 评论(0)  编辑 收藏 引用 所属分类: Android开发

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理