public static void saveTweets(JSONArray alerts) throws JSONException {
    ActiveAndroid.beginTransaction();

    try {
      new Delete().from(Tweet.class).execute();

      JSONObject currentAlert;
      for (int i = 0; i < alerts.length(); i++) {
        currentAlert = alerts.getJSONObject(i);

        Tweet tweet = new Tweet();
        tweet.text = currentAlert.getString("text");
        tweet.user = currentAlert.getString("user");
        tweet.rtUser = currentAlert.getString("rt_user");
        tweet.date = currentAlert.getString("date");
        tweet.save();
      }

      ActiveAndroid.setTransactionSuccessful();

    } finally {

      ActiveAndroid.endTransaction();
    }
  }
  public static void saveAlerts(JSONArray alerts) throws JSONException {
    ActiveAndroid.beginTransaction();

    try {
      new Delete().from(Alert.class).execute();

      JSONObject currentAlert;
      for (int i = 0; i < alerts.length(); i++) {
        currentAlert = alerts.getJSONObject(i);

        Alert alert = new Alert();
        alert.alertId = currentAlert.getLong("id");
        alert.description = currentAlert.getString("alert");
        alert.date = currentAlert.getString("date");
        alert.username = currentAlert.getString("username");
        alert.latitude = currentAlert.getDouble("latitude");
        alert.longitude = currentAlert.getDouble("longitude");
        alert.line = currentAlert.getString("line");
        alert.city = currentAlert.getString("city");
        alert.station = currentAlert.getString("station");
        alert.transport = currentAlert.getString("transport");
        alert.icon = currentAlert.getString("transport_icon");
        alert.save();
      }

      ActiveAndroid.setTransactionSuccessful();

    } finally {

      ActiveAndroid.endTransaction();
    }
  }
  @Override
  protected Void doInBackground(Void... params) {
    /* Get all items from each machine */
    Reader reader = API.getData("machines/stock/");
    Machine machine =
        new GsonBuilder()
            .excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC)
            .create()
            .fromJson(reader, Machine.class);
    MachineData machines = machine.getMachineData();

    /* Store all items in the DB */
    ActiveAndroid.beginTransaction();
    try {
      List<ItemInfo> itemsList = new Select().from(ItemInfo.class).execute();
      for (ItemInfo item : itemsList) {
        item.delete();
      }
      for (ItemInfo item : machines.getBigItemInfo()) {
        item.save();
      }
      for (ItemInfo item : machines.getLittleItemInfo()) {
        item.save();
      }
      for (ItemInfo item : machines.getSnacktemInfo()) {
        item.save();
      }
      ActiveAndroid.setTransactionSuccessful();
    } finally {
      ActiveAndroid.endTransaction();
    }
    return null;
  }
Exemple #4
0
 @Override
 public final void run() {
   ActiveAndroid.beginTransaction();
   execute();
   ActiveAndroid.setTransactionSuccessful();
   ActiveAndroid.endTransaction();
 }
  @Background
  void fetchData() {
    TeamListResponse teams = connection.getTeams();
    MatchesListResponse matches = connection.getMatches();

    ActiveAndroid.beginTransaction();
    try {
      for (Team team : teams.getTeams()) {
        team.save();
      }

      for (Match match : matches.getMatches()) {
        Team awayTeam = match.getAwayTeam();
        match.setAwayTeam(awayTeam.getById());
        Team homeTeam = match.getHomeTeam();
        match.setHomeTeam(homeTeam.getById());
        match.save();
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      ActiveAndroid.setTransactionSuccessful();
    }
    ActiveAndroid.endTransaction();

    setupViewPager();
  }
    @Override
    protected Boolean doInBackground(String... params) {
      OAuth OAuth = new OAuth(context);
      Utils Utils = new Utils();

      Map<String, String> postParams = new HashMap<String, String>(1);
      postParams.put("client_id", Config.OAUTHCLIENTID);
      postParams.put("client_secret", Config.OAUTHCLIENTSECRET);
      JSONObject result = OAuth.call("StaticData", "", postParams);

      if (Config.DEBUG) Log.d("SyncStaticData", result.toString());

      try {
        // Save sync data
        JSONObject data = result.getJSONObject("data");

        JSONObject currentData;
        ActiveAndroid.beginTransaction();
        try {
          // Save countries
          new Delete().from(Country.class).execute();
          JSONArray countries = data.getJSONObject("country").getJSONArray("data");

          for (int i = 0; i < countries.length(); i++) {
            currentData = countries.getJSONObject(i);
            Country country = new Country();
            country.name = currentData.getString("name");
            country.countryId = currentData.getLong("id");
            country.save();
          }

          // Save cities
          new Delete().from(City.class).execute();
          JSONArray cities = data.getJSONObject("city").getJSONArray("data");

          for (int i = 0; i < cities.length(); i++) {
            currentData = cities.getJSONObject(i);
            City city = new City();
            city.name = currentData.getString("name");
            city.cityId = currentData.getLong("id");
            city.country_id = currentData.getLong("country_id");
            city.save();
          }

          ActiveAndroid.setTransactionSuccessful();
        } finally {
          ActiveAndroid.endTransaction();
        }
        return true;
      } catch (Exception e) {
        if (Config.DEBUG) Log.d("Sync", "Sync failed. Cause: " + e.toString());
        e.printStackTrace();
        return false;
      }
    }
Exemple #7
0
 @Subscribe
 public void onUsersLoaded(TaskEvent event) {
   if (event.getEvantType() == EventEnum.RELOAD) {
     ActiveAndroid.beginTransaction();
     try {
       new Delete().from(GitHubUser.class).execute();
       ActiveAndroid.setTransactionSuccessful();
     } finally {
       ActiveAndroid.endTransaction();
     }
   }
 }
Exemple #8
0
 @Subscribe
 public void onUsersLoaded(LoadUsersEvent event) {
   if (event.getUsers() != null) {
     ActiveAndroid.beginTransaction();
     try {
       for (GitHubUser user : event.getUsers()) {
         user.save();
       }
       ActiveAndroid.setTransactionSuccessful();
     } finally {
       ActiveAndroid.endTransaction();
     }
   }
 }
 public static void parse(Feed feed, String str) throws XmlPullParserException, IOException {
   try {
     ActiveAndroid.beginTransaction();
     XmlPullParser parser = Xml.newPullParser();
     parser.setInput(new StringReader(str));
     parser.nextTag();
     readFeed(feed, parser);
     ActiveAndroid.setTransactionSuccessful();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     ActiveAndroid.endTransaction();
   }
 }
  /**
   * 获得未同步的数据
   *
   * @param status
   * @return
   */
  public String getAsyncDataCount(String status) {

    String sql = "select count(*) from user_sign_info where status=? and adminId=? ";
    ActiveAndroid.execSQL(sql, new String[] {status, XiaoToonApplication.getAdminId()});

    return null;
  }
 @Override
 public void onCreate() {
   super.onCreate();
   ActiveAndroid.initialize(this);
   mObjectGraph = ObjectGraph.create();
   mObjectGraph.inject(this);
 }
  public void dasei(View v) {
    try {
      ActiveAndroid.beginTransaction();

      Item item = new Item();

      item.save();

      ActiveAndroid.setTransactionSuccessful();
    } finally {
      ActiveAndroid.endTransaction();
    }
    Intent intent = new Intent();
    intent.setAction(intent.ACTION_MAIN);
    intent.setClass(MainActivity.this, OtherActivity.class);
    startActivity(intent);
  }
  @Override
  public void onCreate() {
    super.onCreate();

    ActiveAndroid.initialize(this);

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
  }
  protected void initializeDB() {
    Configuration.Builder configurationBuilder = new Configuration.Builder(this);
    configurationBuilder.addModelClasses(Link.class);
    configurationBuilder.addModelClasses(FormResource.class);
    configurationBuilder.addModelClasses(EncounterType.class);
    configurationBuilder.addModelClasses(Encountercreate.class);
    configurationBuilder.addModelClasses(Obscreate.class);

    ActiveAndroid.initialize(configurationBuilder.create());
  }
Exemple #15
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_home);

    ActiveAndroid.initialize(this);

    // Intent intent = new Intent(this,Home.class);
    // startActivity(intent);

  }
  public void onCreate() {
    super.onCreate();

    if (IS_FIRST_RUN) {
      File f = new File("/data/data/com.ensureaway/databases/ensureaway.db");
      f.delete();
      f = new File("/data/data/com.ensureaway/databases/ensureaway.db-journal");
      f.delete();
      f = new File(f.getParent());
      f.delete();
    }
    ActiveAndroid.initialize(this);
    IS_FIRST_RUN = new Select().from(RunLog.class).execute().size() == 0;
    mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mAdminName = new ComponentName(this, AdminReceiver.class);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

    ActiveAndroid.initialize(this);

    Handler = new Handler();
    Handler.postDelayed(
        new Runnable() {
          @Override
          public void run() {

            Intent Intent = new Intent(MainActivity.this, Home.class);
            startActivity(Intent);
            finish();
          }
        },
        3000);
  }
 public StoreNewMachineItems(ActionBarActivity act, ViewPager pager) {
   ActiveAndroid.initialize(act);
   this.pager = pager;
   this.act = act;
 }
 public void clearSignData() {
   ActiveAndroid.execSQL(
       "delete from user_sign_info where status= ?  and adminId =?",
       new String[] {"2", XiaoToonApplication.getAdminId()});
 }
 public void onTerminate() {
   ActiveAndroid.dispose();
   super.onTerminate();
 }
Exemple #21
0
 public void onCreate() {
   super.onCreate();
   ActiveAndroid.initialize(this);
   courseService = new CourseService(this);
 }
    @Override
    protected Boolean doInBackground(String... params) {
      OAuth OAuth = new OAuth(context);
      Utils Utils = new Utils();

      Map<String, String> postParams = new HashMap<String, String>(1);
      postParams.put("access_token", Utils.getToken(context));
      JSONObject result = OAuth.call("synchronize", "", postParams);

      if (Config.DEBUG) Log.d("Sync", result.toString());

      try {
        // Save sync data
        JSONObject data = result.getJSONObject("data");

        JSONObject currentData;
        ActiveAndroid.beginTransaction();
        try {

          // Save user data
          new Delete().from(User.class).execute();
          JSONObject userData = data.getJSONObject("user");
          Log.d("User", "User data > " + userData);
          User user = new User();
          user.username = userData.getString("username");
          user.name = userData.getString("name");
          if (userData.isNull("name")) {
            user.name = "";
          }
          String email = "";
          if (!userData.isNull("email")) {
            email = userData.getString("email");
          }
          user.email = email;

          String twitter = "";
          if (!userData.isNull("twittername")) {
            twitter = userData.getString("twittername");
          }
          user.twittername = twitter;

          String aboutme = "";
          if (!userData.isNull("aboutme")) {
            aboutme = userData.getString("aboutme");
          }
          user.aboutme = aboutme;
          user.cityId = userData.getLong("city_id");
          user.save();

          // Save countries
          new Delete().from(Country.class).execute();
          JSONArray countries = data.getJSONObject("country").getJSONArray("data");

          for (int i = 0; i < countries.length(); i++) {
            currentData = countries.getJSONObject(i);
            Country country = new Country();
            country.name = currentData.getString("name");
            country.countryId = currentData.getLong("id");
            country.save();
          }

          // Save cities
          new Delete().from(City.class).execute();
          JSONArray cities = data.getJSONObject("city").getJSONArray("data");

          for (int i = 0; i < cities.length(); i++) {
            currentData = cities.getJSONObject(i);
            City city = new City();
            city.name = currentData.getString("name");
            city.cityId = currentData.getLong("id");
            city.country_id = currentData.getLong("country_id");
            city.save();
          }

          // Save Lines
          new Delete().from(Line.class).execute();
          JSONArray lines = data.getJSONObject("line").getJSONArray("data");
          for (int i = 0; i < lines.length(); i++) {
            currentData = lines.getJSONObject(i);
            Line line = new Line();
            line.name = currentData.getString("name");
            // line.cityId = currentData.getLong("city_id");
            line.lineId = currentData.getLong("id");
            line.transport_id = currentData.getInt("transport_id");
            line.save();
          }

          // Save Transports
          new Delete().from(Transport.class).execute();
          JSONArray transports = data.getJSONObject("transport").getJSONArray("data");
          for (int i = 0; i < transports.length(); i++) {
            currentData = transports.getJSONObject(i);
            Transport transport = new Transport();
            transport.transportId = currentData.getLong("id");
            transport.name = currentData.getString("name");
            transport.icon = currentData.getString("icon");
            transport.save();
          }

          // Save station
          new Delete().from(Station.class).execute();
          JSONArray stations = data.getJSONObject("station").getJSONArray("data");
          for (int i = 0; i < stations.length(); i++) {
            currentData = stations.getJSONObject(i);
            Station station = new Station();
            station.name = currentData.getString("name");
            station.longitude = currentData.getDouble("longitude");
            station.stationId = currentData.getLong("id");
            station.latitude = currentData.getDouble("latitude");
            // station.lineId = currentData.getLong("line_id");
            station.save();
          }

          // Save CitiesTransports
          new Delete().from(CitiesTransport.class).execute();
          JSONArray citiesTransports = data.getJSONObject("citiestransport").getJSONArray("data");
          for (int i = 0; i < citiesTransports.length(); i++) {
            currentData = citiesTransports.getJSONObject(i);
            CitiesTransport citiesTransport = new CitiesTransport();
            citiesTransport.transportId = currentData.getLong("transport_id");
            citiesTransport.cityId = currentData.getLong("city_id");
            citiesTransport.save();
          }

          // Save LineStations
          new Delete().from(LinesStation.class).execute();
          JSONArray lineStations = data.getJSONObject("linesstations").getJSONArray("data");
          for (int i = 0; i < lineStations.length(); i++) {
            currentData = lineStations.getJSONObject(i);
            LinesStation linesStation = new LinesStation();
            linesStation.lineId = currentData.getLong("line_id");
            linesStation.stationId = currentData.getLong("station_id");
            linesStation.save();
          }

          ActiveAndroid.setTransactionSuccessful();
        } finally {
          ActiveAndroid.endTransaction();
        }
        return true;
      } catch (Exception e) {
        if (Config.DEBUG) Log.d("Sync", "Sync failed. Cause: " + e.toString());
        e.printStackTrace();
        return false;
      }
    }