当前位置: 首页 > news >正文

网站建设 职责谷歌可以做网站吗

网站建设 职责,谷歌可以做网站吗,站网站推广,做网站开视频网站一、什么是RemoteViewsRemoteViews翻译过来就是远程视图.顾名思义,RemoteViews不是当前进程的View,是属于SystemServer进程.应用程序与RemoteViews之间依赖Binder实现了进程间通信.二、RemoteViews的用法RemoteViews使用最多的场合是通知栏和桌面小插件. 以通知栏为例,讲解下它…一、什么是RemoteViewsRemoteViews翻译过来就是远程视图.顾名思义,RemoteViews不是当前进程的View,是属于SystemServer进程.应用程序与RemoteViews之间依赖Binder实现了进程间通信.二、RemoteViews的用法RemoteViews使用最多的场合是通知栏和桌面小插件. 以通知栏为例,讲解下它的用法.1、新建一个Notification这里要注意是在android3.0之前都是使用如下的形式构建一个Notification // 1.新建一个Notification对象 Notification mNotification new Notification(); // 2.添加属性,比如标题、内容、优先级、图片等 mNotification.tickerText 这是通知栏的标题; mNotification.icon R.drawable.ic_launcher; mNotification.flagsNotification.FLAG_NO_CLEAR; mNotification.setLatestEventInfo(this, 这是内容, 这是标题, null);1234567在3.0之后官方推荐使用建造者模式创建Notification.Notification mNotification new Notification.Builder(this) .setContentTitle(这是标题 ) .setContentText(这是内容) .setSmallIcon(R.drawable.ic_launcher) .build();12345Notification有很多属性,这里列举一些 - setContentTitle 设置标题 - setContentText 设置内容 - setLargeIcon 设置通知栏大图标 - setSmallIcon 设置通知栏小图标 - setContent 设置RemoteViews - setContentIntent 当通知条目被点击就执行这个被设置的Intent. - setDeleteIntent 当用户点击Clear All Notifications按钮区删除所有的通知的时候这个被设置的Intent被执行 - setLights 设置闪光灯 - setSound 设置声音 - setPriority 设置优先级 2、设置Notification的RemoteViews如果要给通知栏使用自定义布局就要使用RemoteViews了,传入包名和相应的布局.RemoteViews mRemoteViewsnew RemoteViews(com.example.remoteviewdemo, R.layout.remoteview_layout);1然后通过setContent()传入RemoteViews 对象即可.这里顺便讲一下PendingIntent,PendingIntent是”延迟意图”的意思,就是当满足某一条件时出触发这个Intent.通过PendingIntent的getActivity、getBroadcast、getService等分别构建一个打开对应组件的延迟Intent. 传入四个参数context、intent、requestCode(自定义)、flag.Intent intentnew Intent(MainActivity.this,MainActivity.class); PendingIntent mPendingIntentPendingIntent.getActivity(MainActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);12PendingIntent有4种flag. - FLAG_ONE_SHOT 只执行一次 - FLAG_NO_CREATE 若描述的Intent不存在则返回NULL值 - FLAG_CANCEL_CURRENT 如果描述的PendingIntent已经存在则在产生新的Intent之前会先取消掉当前的 - FLAG_UPDATE_CURRENT 总是执行,这个flag用的最多 3、获取通知管理者NotificationManager manager (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);14、弹出通知调用notify方法,传入一个id(自定义)和通知实例即可.manager.notify(1, mNotification);15、例子我用一个按钮弹出通知,点击这个通知时进入到该Activitypublic class MainActivity extends Activity { private NotificationManager manager; private Notification mNotification; Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //1.创建RemoteViews实例 RemoteViews mRemoteViewsnew RemoteViews(com.example.remoteviewdemo, R.layout.remoteview_layout); //2.构建一个打开Activity的PendingIntent Intent intentnew Intent(MainActivity.this,MainActivity.class); PendingIntent mPendingIntentPendingIntent.getActivity(MainActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); //3.创建一个Notification mNotification new Notification.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentIntent(mPendingIntent) .setContent(mRemoteViews) .build(); //4.获取NotificationManager manager (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Button button1 (Button) findViewById(R.id.button1); button1.setOnClickListener(new OnClickListener() { Override public void onClick(View v) { //弹出通知 manager.notify(1, mNotification); } }); } }1234567891011121314151617181920212223242526272829303132333435363738如下图6、改变RemoteViews的布局RemoteViews并不能直接获得控件实例,然后对控件进行操作.它提供了 setTextViewText(viewId, text)、setImageViewResource(viewId, srcId)等方法进行操作,传入控件id和相应的修改内容. 列举一下常用的属性 - setTextViewText(viewId, text) 设置文本 - setTextColor(viewId, color) 设置文本颜色 - setTextViewTextSize(viewId, units, size) 设置文本大小 - setImageViewBitmap(viewId, bitmap) 设置图片 - setImageViewResource(viewId, srcId) 根据图片资源设置图片 - setViewPadding(viewId, left, top, right, bottom) 设置Padding间距 - setOnClickPendingIntent(viewId, pendingIntent) 设置点击事件 我这里就以setTextViewText改变文本的属性来讲解改变RemoteViews的原理. 我在原来的代码上加上一个按钮点击改变内容Button button2 (Button) findViewById(R.id.button2); button2.setOnClickListener(new OnClickListener() { Override public void onClick(View v) { mRemoteViews.setTextViewText(R.id.remote_content, 改变了内容); manager.notify(1, mNotification); } });123456789看下效果三、RemoteViews的改变原理1.setTextViewText方法代码如下public class RemoteViews implements Parcelable, Filter { ...... public void setTextViewText(int viewId, CharSequence text) { setCharSequence(viewId, setText, text); } ...... }12345672.调用了setCharSequence方法public class RemoteViews implements Parcelable, Filter { ...... public void setCharSequence(int viewId, String methodName, CharSequence value) { addAction(new ReflectionAction(viewId, methodName, ReflectionAction.CHAR_SEQUENCE, value)); } ...... }12345673.在setCharSequence方法里调用了addAction方法,传入一个ReflectionAction实例ReflectionAction继承自Action,它是用反射调用的private final class ReflectionAction extends Action { ...... ReflectionAction(int viewId, String methodName, int type, Object value) { this.viewId viewId; this.methodName methodName; this.type type; this.value value; } ...... } 123456789104.看下addAction方法用了一个集合来保存Action实例,然后更新已使用内存的统计情况public class RemoteViews implements Parcelable, Filter { ...... private void addAction(Action a) { if (mActions null) { mActions new ArrayListAction(); } //添加Action mActions.add(a); // 更新已使用内存的统计情况 a.updateMemoryUsageEstimate(mMemoryUsageCounter); } ...... } 123456789101112131415这一步之后,会调用manager.notify(1, mNotification);1来更新,追踪这个notify方法.public class NotificationManager { ...... public void notify(String tag, int id, Notification notification) { ...... INotificationManager service getService(); try { service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id, stripped, idOut, UserHandle.myUserId()); ...... } ...... }12345678910111213145.上面会调用getService方法返回INotificationManager这个系统服务,它是在SystemServer进程添加的.然后该服务调用 enqueueNotificationWithTag方法最后层层调用到public class NotificationManagerService extends INotificationManager.Stub { ...... StatusBarNotification n new StatusBarNotification(pkg, id, tag, r.uid, r.initialPid, notification); try { mStatusBar.updateNotification(r.statusBarKey, n) } ...... } 123456789新建了StatusBarNotification实例,然后调用updateNotification方法. 这个方法会进入到public class PhoneStatusBar extends StatusBar { ...... public void updateNotification(IBinder key, StatusBarNotification notification) { ...... final RemoteViews contentView notification.notification.contentView; ...... contentView.reapply(mContext, oldEntry.content); ...... }123456789会调用StatusBarNotification 的notification.contentView返回RemoteViews 对象,然后调用reapply方法.6.回到RemoteViews 的reapply方法public class RemoteViews implements Parcelable, Filter { ...... public void reapply(Context context, View v, OnClickHandler handler) { RemoteViews rvToApply getRemoteViewsToApply(context); ...... rvToApply.performApply(v, (ViewGroup) v.getParent(), handler); } private void performApply(View v, ViewGroup parent, OnClickHandler handler) { if (mActions ! null) { handler handler null ? DEFAULT_ON_CLICK_HANDLER : handler; final int count mActions.size(); for (int i 0; i count; i) { Action a mActions.get(i); //调用apply方法 a.apply(v, parent, handler); } } } ...... }123456789101112131415161718192021222324最终调用apply方法,在这里加载新的布局,RemoteViews就是这么完成的.public class RemoteViews implements Parcelable, Filter { ...... public View apply(Context context, ViewGroup parent, OnClickHandler handler) { RemoteViews rvToApply getRemoteViewsToApply(context); View result; LayoutInflater inflater (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ...... //加载布局 result inflater.inflate(rvToApply.getLayoutId(), parent, false); rvToApply.performApply(result, parent, handler); return result; } ...... }12345678910111213141516总结RemoteViews运行在SystemServer进程,更新RemoteViews要通过Binder获取到对应的服务然后调用RemoteViews内部的apply方法加载更新布局.转载于:https://www.cnblogs.com/wxmdevelop/p/7099745.html
http://www.zqtcl.cn/news/883073/

相关文章:

  • 网站制作需要学什么搜狗网页版入口
  • html源码网seo搜索优化工程师招聘
  • 做的网站在小窗口中怎么保持中间广东省公共资源交易中心地址
  • 合肥做网站汇站网织梦网站广告代码教程
  • 复兴专业做网站wordpress搬家502
  • 代做毕网站淘宝权重查询
  • 有专做高端折扣女装的网站吗大连最好的做网站的公司
  • 网站需求嘉兴seo关键词优化
  • 自己开发微网站上海成品网站
  • 国外对企业网站开发的研究山西住房与城乡建设厅定额网站
  • 国家工信部网站备案postfix wordpress
  • 兴宁电子商务网站建设网站模板在线制作
  • 汕头整站优化营销推广网
  • 云服务器搭建网站教程加盟教育培训机构
  • 建筑网站设置工资单人换了怎么换太原做网站找谁
  • 网站做推广需要什么条件重庆网站推广哪家服务好
  • 怎样做理财网站wordpress做产品页教程视频
  • 官网模板建站塔山双喜北京网站建设兴田德润官网多少
  • 网站优化推广外包深圳专业网站建设定制
  • 网站开发aichengkeji元凤建盏简介
  • 移动端网站怎么制作asp做的网站如何发布
  • 做的网站用户密码在哪里找凡科申请的网站和qq空间一样吗
  • 如何自己做网站发布到服务器上面wordpress没有幻灯片
  • 闽侯县建设局网站企业建设网站例文
  • 家居类企业响应式网站搭建电商系统
  • 临沂哪里做网站比较好中国建设银行企业信息门户网站
  • 低价建网站提高网站订单转化率
  • 家居网站应该怎么做网站seo推广软件
  • 旅游网站建设报告关键词优化排名价格
  • 上海网站开发caiyiduo微信建微网站