Exemplo n.º 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
  }
  public String execute() {
    UserManager userMng = new UserManager();
    User user = new User();
    Branch branch = new Branch();
    Role role = new Role();
    HashUtil hashUtil = new HashUtil();

    branch.setId(bean.getBranchID());
    role.setId(bean.getRoleID());
    user.setFullName(bean.getFullName());
    user.setUserName(bean.getUsername());
    user.setPhoto(bean.getPhoto());
    user.setPass(hashUtil.md5(bean.getPass()));
    user.setBirthDate(bean.getBirthDate());
    user.setEmail(bean.getEmail());
    user.setGender(bean.getGender());
    user.setAddress(bean.getAddress());
    user.setBranch(branch);
    user.setRole(role);
    user.setActive(bean.isActive());

    boolean isExistUser = false;
    boolean isExistMail = false;

    isExistUser = userMng.checkExistRecord(bean.getUsername());
    isExistMail = userMng.checkExistUserEmail(bean.getEmail());

    if (isExistUser == false && isExistMail == false) {
      userMng.insert(user);
      addActionMessage("Insert User Successfully !!!");
      return SUCCESS;
    } else if (isExistMail == true) {
      addActionError("Email of this User already exists !!! Please enter another one!!!");
      return ERROR;
    } else {
      addActionError("User already exists !!!");
      return ERROR;
    }
  }