示例#1
0
 public static void init(Context context) {
   mPrefs = context.getSharedPreferences("preferences", Context.MODE_PRIVATE);
   long id = mPrefs.getLong("accountId", -1);
   AccountDataSource dataSource = new AccountDataSource(context);
   dataSource.open();
   if (id != -1) {
     mAccount = dataSource.getAccount(id);
   }
   mAccounts = dataSource.getAllAccounts();
   dataSource.close();
 }
 @Override
 public void onCompleted(Exception e, JsonObject result) {
   if (e != null) {
     mProgressDialog.dismiss();
     Toast.makeText(getActivity(), R.string.failed_to_load, Toast.LENGTH_SHORT).show();
     e.printStackTrace();
     return;
   }
   JsonObject data = result.get("json").getAsJsonObject().get("data").getAsJsonObject();
   Account a =
       new Account(
           mUsername.getText().toString(),
           data.get("modhash").getAsString(),
           data.get("cookie").getAsString());
   AccountDataSource dataSource = new AccountDataSource(getActivity());
   dataSource.open();
   dataSource.addAccount(a);
   dataSource.close();
   AccountManager.setAccount(a);
   mProgressDialog.dismiss();
   ((LogInActivity) getActivity()).onLoggedIn();
 }