Ejemplo n.º 1
0
  public void searchContact(View view) {
    if (SearchName == null || SearchName.equals("")) {
      Toast.makeText(this, "Please Enter Name", Toast.LENGTH_SHORT).show();
      return;
    } else {
      /*Intent callIntent = new Intent(Intent.ACTION_CALL);
      callIntent.setData(Uri.parse("tel:0862335871"));
      startActivity(callIntent);*/
      searchName = SearchName.getText().toString();
      userDb = new UserDb(getApplicationContext());
      sqLiteDatabase = userDb.getReadableDatabase();
      Cursor cursor = userDb.getContact(searchName, sqLiteDatabase);
      if (cursor.moveToFirst()) {
        String mobile = cursor.getString(0);
        String email = cursor.getString(1);

        Phone.setText(mobile);
        Email.setText(email);

        /*//CALL THE PERSON ON SEARCH BUTTON
        Log.d("Hi","I want to call "+ mobile);
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:"+mobile));
        startActivity(callIntent);*/

        // SEND SOME EMERGENNCY MESSGAe
        /*String messageToSend = "this is a message";
        String number = "0877845450";
        SmsManager.getDefault().sendTextMessage(number, null, messageToSend, null, null);*/

        Email.setVisibility(View.VISIBLE);
        Phone.setVisibility(View.VISIBLE);
        CallButton.setVisibility(View.VISIBLE);
        EmailButton.setVisibility(View.VISIBLE);
        MapButton.setVisibility(View.VISIBLE);
        MessageButton.setVisibility(View.VISIBLE);
        TextMobile.setVisibility(View.VISIBLE);
        TextEmail.setVisibility(View.VISIBLE);
        // InstantSms.setVisibility(View.VISIBLE);

        /*Latitude.setVisibility(View.VISIBLE);
        Longitude.setVisibility(View.VISIBLE);
        AddressName.setVisibility(View.VISIBLE);
        Address.setVisibility(View.VISIBLE);*/

        /*Message.setVisibility(View.GONE);
        MessageButton.setVisibility(View.GONE);*/
      }
    }
  }
  @Timeout
  public void replicateUsers() throws IOException {

    logger.info("replicating users from MySQL to CouchDB");
    List<SecuredUser> users = userService.list();

    List<User> usersView = userDb.getUsersView().<User>createDocQuery().asDocs();
    Map<String, User> couchUsers = User.toMap(usersView);

    List<User> newOrModifiedUsers = new ArrayList<>();

    // Add new users to couchdb
    for (SecuredUser user : users) {
      String id = user.getId().toString();
      if (!couchUsers.containsKey(id)) {
        String mmsi = getMmsi(user);
        String name = getName(user);
        newOrModifiedUsers.add(new User(id, user.getUserName(), name, mmsi));
        logger.info("Adding user with id={} and name={}", user.getId(), name);
      } else {
        User couchUser = couchUsers.get(id);
        String mmsi = getMmsi(user);
        String name = getName(user);
        if (!Objects.equals(couchUser.getName(), name)
            || !Objects.equals(couchUser.getMmsi(), mmsi)
            || !Objects.equals(couchUser.getUserName(), user.getUserName())) {
          couchUser.setMmsi(mmsi);
          couchUser.setName(name);
          couchUser.setUserName(user.getUserName());
          logger.info("Updating user with id={} and name={}", id, name);
          newOrModifiedUsers.add(couchUser);
        }
      }
    }
    userDb.bulk(newOrModifiedUsers);

    // remove deleted users from couchdb
    Map<Long, SecuredUser> securedUsers =
        users.stream().collect(Collectors.toMap(SecuredUser::getId, u -> u));
    List<User> toRemove = new ArrayList<>();
    for (User user : couchUsers.values()) {
      if (!securedUsers.containsKey(Long.parseLong(user.getDocId()))) {
        toRemove.add(user);
        user.setDeleted();
        logger.info("Removing user with id={} and name={}", user.getDocId(), user.getName());
      }
    }

    userDb.bulk(toRemove);
  }
  public void initializeUserDatabase() {
    if (userDbUrl != null && userDbUrl.trim().length() != 0) {
      logger.info("Initializing CouchDB with url {}", userDbUrl);

      AsyncHttpClient httpClient = new AsyncHttpClient();

      // automaticly creates database if not already

      CouchDbConfig.Builder builder =
          new CouchDbConfig.Builder()
              .setHttpClient(httpClient)
              .setServerUrl(userDbUrl)
              .setDbName("embryo-user");

      if (dbUser != null
          && dbUser.trim().length() > 0
          && dbPassword != null
          && dbPassword.trim().length() > 0) {
        builder.setUser(dbUser).setPassword(dbPassword);
      }

      userDb = new UserDb(builder.build());

      userDb.cleanupViews();

      if (userCron != null) {
        timerService.createCalendarTimer(userCron, new TimerConfig(null, false));
      }
    } else {
      logger.info("embryo.couchDb.user.url not set");
    }
  }
Ejemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /*if(CheckNetwork.isInternetAvailable(MainActivity.this)) //returns true if internet available
    {

        //do something. loadwebview.
    }
    else
    {
        Toast.makeText(MainActivity.this,"No Internet Connection",Toast.LENGTH_LONG).show();
    }*/

    listView = (ListView) findViewById(R.id.listView);
    registerForContextMenu(listView);
    listAdapt = new ListAdapt(getApplicationContext(), R.layout.list_layout);
    listView.setAdapter(listAdapt);
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent launchNews = new Intent(MainActivity.this, Custom_NewsRead.class);
            startActivity(launchNews);
            view.setSelected(true);
          }
        });
    userDb = new UserDb(getApplicationContext());
    sqLiteDatabase = userDb.getReadableDatabase();
    cursor = userDb.viewList(sqLiteDatabase);

    if (cursor.moveToFirst()) {
      do {

        String website, websiteUrl;
        website = cursor.getString(0);
        websiteUrl = cursor.getString(1);
        Data data = new Data(website, websiteUrl);
        listAdapt.add(data);

      } while (cursor.moveToNext());
    }
  }
Ejemplo n.º 5
0
  public void call(View view) {
    Log.d("Hi", "this works");
    userDb = new UserDb(getApplicationContext());
    sqLiteDatabase = userDb.getReadableDatabase();
    Cursor cursor = userDb.getContact(searchName, sqLiteDatabase);

    Log.d("Hi", "going to move on the cursor");
    if (cursor.moveToFirst()) {
      Log.d("Hi", "we are in the cursor move to first");
      String mobile = cursor.getString(0);
      // String email = cursor.getString(1);
      // Phone.setText(mobile);

      Log.d("Hi", "I want to call " + mobile);
      Intent callIntent = new Intent(Intent.ACTION_CALL);
      callIntent.setData(Uri.parse("tel:" + mobile));
      startActivity(callIntent);
    }
  }
Ejemplo n.º 6
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterView.AdapterContextMenuInfo info =
       (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
   switch (item.getItemId()) {
     case R.id.id_edit:
       Intent intent = new Intent(this, Edit.class);
       this.startActivity(intent);
       overridePendingTransition(R.anim.right_animation, R.anim.left_animation);
       break;
     case R.id.id_remove:
       userDb = new UserDb(getApplicationContext());
       sqLiteDatabase = userDb.getReadableDatabase();
       userDb.deleteRow(NewsFeed.NewsFeedList.FeedName, sqLiteDatabase);
       Toast.makeText(getBaseContext(), "Website Removed ", Toast.LENGTH_LONG).show();
       /*listAdapt.remove(info.position);
       listAdapt.notifyDataSetChanged();
       return true;*/
     default:
       return super.onContextItemSelected(item);
   }
   return super.onContextItemSelected(item);
 }