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

办公室装修公司费用360seo关键词优化

办公室装修公司费用,360seo关键词优化,制作好,网络推广网络营销公司装过Android版的Facebook、lastfm的同学是否对于这些应用的功能感到惊喜#xff0c;它们可以定期更新朋友的最新信息#xff0c;将最新近况和心情短语集成入联系人中。这些应用全部是以Android2.0后的账户和同步机制为基础的。Google的例程中给出了名为SampleSyncAdpater的例… 装过Android版的Facebook、lastfm的同学是否对于这些应用的功能感到惊喜它们可以定期更新朋友的最新信息将最新近况和心情短语集成入联系人中。这些应用全部是以Android2.0后的账户和同步机制为基础的。Google的例程中给出了名为SampleSyncAdpater的例子通过分析该例子可以学会Android中的Account验证、同步Adapter的使用。 详细例子代码可以看sdk samples中提供的源码现在拿2.2中的版本来简要说明。 首先是 class Authenticator extends AbstractAccountAuthenticator 该类是账户认证类打开手机的Setting里有AccountSync 一项Authenticator就是实现其中的账号功能的类。 [java]  view plain copy // in Authenticator.java       public Bundle addAccount(AccountAuthenticatorResponse response,           String accountType, String authTokenType, String[] requiredFeatures,           Bundle options) {           final Intent intent  new Intent(mContext, AuthenticatorActivity.class);           intent.putExtra(AuthenticatorActivity.PARAM_AUTHTOKEN_TYPE,               authTokenType);           intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,               response);           final Bundle bundle  new Bundle();           bundle.putParcelable(AccountManager.KEY_INTENT, intent);           return bundle;       }   其中addAccount方法用来定义需要增加账号时的操作如调用AuthenticatorActivity来进行账号的添加认证。 在AuthenticatorActivity.java中定义了handleLogin()此方法由login_activity.xml中的android:onClickhandleLogin定义与ui中的okbutton的关联。 [java]  view plain copy // in layout/login_activity.xml   Button               android:idid/ok_button               android:layout_widthwrap_content               android:layout_heightwrap_content               android:layout_gravitycenter_horizontal               android:minWidth100dip               android:textstring/login_activity_ok_button               android:onClickhandleLogin /   handleLogin()将ui中的用户名和密码取得并创建一个试图认证的线程通过网络去服务端验证。 NetworkUtilities.java中的 public static boolean authenticate(String username, String password, Handler handler, final Context context)方法展示了通过网络验证的具体流程。得到服务端验证结果后在sendResult()中通过handler.post调用来实现onAuthenticationResult()在AuthenticatorActivity中的运行。onAuthenticationResult()判断验证通过则结束AuthenticatorActivity否则报出用户名密码错让用户在AuthenticatorActivity中再次尝试验证。 [java]  view plain copy // AuthenticatorActivity.java中的handleLogin()方法       /**       * Handles onClick event on the Submit button. Sends username/password to       * the server for authentication.       *        * param view The Submit button for which this method is invoked       */       public void handleLogin(View view) {           if (mRequestNewAccount) {               mUsername  mUsernameEdit.getText().toString();           }           mPassword  mPasswordEdit.getText().toString();           if (TextUtils.isEmpty(mUsername) || TextUtils.isEmpty(mPassword)) {               mMessage.setText(getMessage());           } else {               showProgress();               // Start authenticating...               mAuthThread                    NetworkUtilities.attemptAuth(mUsername, mPassword, mHandler,                       AuthenticatorActivity.this);           }       }   [java]  view plain copy // NetworkUtilities中的authenticate()方法通过网络访问具体来实现服务端的验证sendResult()来使调用结果被AuthenticatorActivity的onAuthenticationResult()调用。       /**       * Connects to the Voiper server, authenticates the provided username and       * password.       *        * param username The users username       * param password The users password       * param handler The hander instance from the calling UI thread.       * param context The context of the calling Activity.       * return boolean The boolean result indicating whether the user was       *         successfully authenticated.       */       public static boolean authenticate(String username, String password,           Handler handler, final Context context) {           final HttpResponse resp;              final ArrayListNameValuePair params  new ArrayListNameValuePair();           params.add(new BasicNameValuePair(PARAM_USERNAME, username));           params.add(new BasicNameValuePair(PARAM_PASSWORD, password));           HttpEntity entity  null;           try {               entity  new UrlEncodedFormEntity(params);           } catch (final UnsupportedEncodingException e) {               // this should never happen.               throw new AssertionError(e);           }           final HttpPost post  new HttpPost(AUTH_URI);           post.addHeader(entity.getContentType());           post.setEntity(entity);           maybeCreateHttpClient();              try {               resp  mHttpClient.execute(post);               if (resp.getStatusLine().getStatusCode()  HttpStatus.SC_OK) {                   if (Log.isLoggable(TAG, Log.VERBOSE)) {                       Log.v(TAG, Successful authentication);                   }                   sendResult(true, handler, context);                   return true;               } else {                   if (Log.isLoggable(TAG, Log.VERBOSE)) {                       Log.v(TAG, Error authenticating  resp.getStatusLine());                   }                   sendResult(false, handler, context);                   return false;               }           } catch (final IOException e) {               if (Log.isLoggable(TAG, Log.VERBOSE)) {                   Log.v(TAG, IOException when getting authtoken, e);               }               sendResult(false, handler, context);               return false;           } finally {               if (Log.isLoggable(TAG, Log.VERBOSE)) {                   Log.v(TAG, getAuthtoken completing);               }           }       }          /**       * Sends the authentication response from server back to the caller main UI       * thread through its handler.       *        * param result The boolean holding authentication result       * param handler The main UI threads handler instance.       * param context The caller Activitys context.       */       private static void sendResult(final Boolean result, final Handler handler,           final Context context) {           if (handler  null || context  null) {               return;           }           handler.post(new Runnable() {               public void run() {                   ((AuthenticatorActivity) context).onAuthenticationResult(result);               }           });       }   [java]  view plain copy // AuthenticatorActivity.java中的onAuthenticationResult来根据验证结果来选择结束认证或重新尝试。       /**       * Called when the authentication process completes (see attemptLogin()).       */       public void onAuthenticationResult(boolean result) {           Log.i(TAG, onAuthenticationResult(  result  ));           // Hide the progress dialog           hideProgress();           if (result) {               if (!mConfirmCredentials) {                   finishLogin();               } else {                   finishConfirmCredentials(true);               }           } else {               Log.e(TAG, onAuthenticationResult: failed to authenticate);               if (mRequestNewAccount) {                   // Please enter a valid username/password.                   mMessage                       .setText(getText(R.string.login_activity_loginfail_text_both));               } else {                   // Please enter a valid password. (Used when the                   // account is already in the database but the password                   // doesnt work.)                   mMessage                       .setText(getText(R.string.login_activity_loginfail_text_pwonly));               }           }       }   Account的验证完毕后就生成了账号可以开始使用同步功能了。同步的主要逻辑在public class SyncAdapter extends AbstractThreadedSyncAdapter中实现。 [java]  view plain copy // SyncAdapter.java中的OnPerformSync方法主要的同步逻辑       Override       public void onPerformSync(Account account, Bundle extras, String authority,           ContentProviderClient provider, SyncResult syncResult) {           ListUser users;           ListStatus statuses;           String authtoken  null;            try {                // use the account manager to request the credentials                authtoken                    mAccountManager.blockingGetAuthToken(account,                       Constants.AUTHTOKEN_TYPE, true /* notifyAuthFailure */);                // fetch updates from the sample service over the cloud                users                    NetworkUtilities.fetchFriendUpdates(account, authtoken,                       mLastUpdated);               // update the last synced date.               mLastUpdated  new Date();               // update platform contacts.               Log.d(TAG, Calling contactManagers sync contacts);               ContactManager.syncContacts(mContext, account.name, users);               // fetch and update status messages for all the synced users.               statuses  NetworkUtilities.fetchFriendStatuses(account, authtoken);               ContactManager.insertStatuses(mContext, account.name, statuses);           } catch (final AuthenticatorException e) {               syncResult.stats.numParseExceptions;               Log.e(TAG, AuthenticatorException, e);           } catch (final OperationCanceledException e) {               Log.e(TAG, OperationCanceledExcetpion, e);           } catch (final IOException e) {               Log.e(TAG, IOException, e);               syncResult.stats.numIoExceptions;           } catch (final AuthenticationException e) {               mAccountManager.invalidateAuthToken(Constants.ACCOUNT_TYPE,                   authtoken);               syncResult.stats.numAuthExceptions;               Log.e(TAG, AuthenticationException, e);           } catch (final ParseException e) {               syncResult.stats.numParseExceptions;               Log.e(TAG, ParseException, e);           } catch (final JSONException e) {               syncResult.stats.numParseExceptions;               Log.e(TAG, JSONException, e);           }       }   onPerformSync中的执行流程中使用NetworkUtilities中的fetchFriendUpdates和fetchFriendStatuses来访问服务端的联系人更新并使用了例程中自己封装的ContactManager来读取、更新联系人信息。 那Account和SyncAdapter及其Service和xml定义之间是如何关联的呢 AndroidManifest.xml中定义了AccountAuthenticatorSyncAdapter及对应的Service和xml定义的关联。 [java]  view plain copy application       android:icondrawable/icon       android:labelstring/label       !-- The authenticator service --       service           android:name.authenticator.AuthenticationService           android:exportedtrue           intent-filter               action                   android:nameandroid.accounts.AccountAuthenticator /           /intent-filter           meta-data               android:nameandroid.accounts.AccountAuthenticator               android:resourcexml/authenticator /       /service       service           android:name.syncadapter.SyncService           android:exportedtrue           intent-filter               action                   android:nameandroid.content.SyncAdapter /           /intent-filter           meta-data               android:nameandroid.content.SyncAdapter               android:resourcexml/syncadapter /           meta-data               android:nameandroid.provider.CONTACTS_STRUCTURE               android:resourcexml/contacts /       /service       activity           android:name.authenticator.AuthenticatorActivity           android:labelstring/ui_activity_title           android:themeandroid:style/Theme.Dialog           android:excludeFromRecentstrue                      !--               No intent-filter here! This activity is only ever launched by               someone who explicitly knows the class name           --       /activity   /application   更详细的代码细节和执行流程可以去把SDK中的SampleSyncAdapter代码运行起来体会一下不过要实现整个流程必须搭建联系人的服务器端例程中在目录samplesyncadapter_server中也提供了简单的server端python代码需要搭建在google app engine上。搭建过程遇到一些问题由于对python不熟我弄了几天才解决好搭建成功其中遇到的一个model moudle找不到的问题需要你在model中新建一个__init__.py的空文件来说明是一个python模块如果你也遇到此问题希望对你有帮助。
http://www.hkea.cn/news/14448820/

相关文章:

  • 政务网站建设 紧急通知织梦模板首页修改教程
  • 天汇大厦网站建设公司个人备案可以做哪些网站
  • 网站版本功能列表公司网站制作
  • 网站 cms重庆人才网
  • 通桥小学的网站建设免费关键词搜索引擎工具
  • 网站建设代码走查如何防止网站挂黑链
  • 检测网站安全怎么做团购网站
  • 无锡网站商城建设房产网站排行
  • wordpress图片转内重庆百度快速优化
  • 家政门户网站源码四川工程信息造价网
  • 为了加强公司网站建设wordpress自定义工具栏
  • 婚恋网站排名前三北京装修公司加盟
  • 为什么建立网站wordpress 淘客
  • 国内三大oa系统网站百度搜索情况和反链接优化建议
  • 网站建设售后支持wordpress改浏览数数据库
  • 网站建设平台资讯北京网站建设方案外包
  • 做们作业网站网站备案系统登陆不上
  • 拉新app推广平台广州四楚seo顾问
  • 成都seo网站建设用wordpress做商城
  • 苏州网站建设风兰怎么用网页源码做网站
  • 建设文明网站包括那个网站可以做双色球号码对比的
  • 金融网站模版下载遵义市建设局网站官网
  • 四川省建设招标网站首页深圳网页设计与制作本科工资多少钱
  • 做外贸网站哪家公司好雅安做网站
  • 在线网站建设费用是多少怎么让公司地址在地图显示
  • 微信网站建设平台海南网站搭建
  • 上虞网站建设哪家好找做企业网站
  • 网站分站原理南京网站制作希丁哥
  • 如何做网站宣传片上海传媒公司介绍
  • 怎么修改网站标题关键词描述wordpress虚拟储存