Пример #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    dbhelper = new DatabaseHelper(getApplicationContext());
    setContentView(R.layout.activity_main);

    beaconManager = new BeaconManager(getApplicationContext());
    beaconManager.connect(
        new BeaconManager.ServiceReadyCallback() {
          @Override
          public void onServiceReady() {
            beaconManager.startMonitoring(new Region("monitored region", null, null, null));
          }
        });

    dbhelper.addUser(new UserBean(1, "Player", 0));

    user = dbhelper.getUserByID(1);

    Log.i(APP_NAME, user.getUsername() + ", " + user.getLevel() + ", " + user.getId());

    Button run = (Button) findViewById(R.id.myRunButton);
    run.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            runaway();
          }
        });

    // set up listeners
    beaconManager.setMonitoringListener(
        new BeaconManager.MonitoringListener() {
          @Override
          public void onEnteredRegion(Region region, List<Beacon> list) {
            try {
              new HttpGetJsonTask()
                  .execute(
                      new URL("http://192.168.224.130:5000/monsters?userlevel=" + user.getLevel()));

            } catch (Exception e) {

            }
            showNotification(
                "You have entered a battle",
                "You have entered a battle with a monster click to fight and check it out.");
          }

          @Override
          public void onExitedRegion(Region region) {
            Toast.makeText(getApplicationContext(), "Exited a beacon", Toast.LENGTH_SHORT).show();
          }
        });
    // end of listeners
  }
Пример #2
0
  public void loadAccountSettings() {
    setContentView(R.layout.listview);
    ArrayList<EncounterBean> array = dbhelper.getAllEncounters();
    List<String> firstArray = new ArrayList();
    List<String> secondArray = new ArrayList();
    for (EncounterBean bean : array) {
      firstArray.add(bean.getMonsterID() + "");
      secondArray.add(bean.getNumWins() + "");
    }
    String[] first = new String[firstArray.size()];
    String[] second = new String[secondArray.size()];

    first = firstArray.toArray(first);
    second = secondArray.toArray(second);

    ArrayAdapter<String> adapter =
        new ArrayAdapter<String>(this, R.layout.listview, R.id.firstList, first);
    ArrayAdapter<String> adapter2 =
        new ArrayAdapter<String>(this, R.layout.listview, R.id.secondList, second);
  }