Beispiel #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_item);

    client = new YardSaleApplication(this);

    String itemId = getIntent().getStringExtra("item_id");
    ivItemPreview = (ImageView) findViewById(R.id.ivItemPreview);
    etEditItemDescription = (EditText) findViewById(R.id.etItemDescription);
    etEditItemPrice = (EditText) findViewById(R.id.etItemPrice);
    Button btnSaveItem = (Button) findViewById(R.id.btnSaveItem);

    ParseQuery getItemQuery = Item.getQuery();
    try {
      item = (Item) getItemQuery.get(itemId);
    } catch (ParseException e) {
      e.printStackTrace();
    }

    Picasso.with(this).load(item.getPhoto().getUrl()).into(ivItemPreview);
    etEditItemDescription.setText(item.getDescription());
    etEditItemPrice.setText("$" + item.getPrice().toString());
    etEditItemPrice.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
            String current = "";
            if (!s.toString().equals(current)) {
              etEditItemPrice.removeTextChangedListener(this);

              String cleanString = s.toString().replaceAll("[$,.]", "");

              double parsed = Double.parseDouble(cleanString);
              String formatted = NumberFormat.getCurrencyInstance().format((parsed / 100));

              current = formatted;
              etEditItemPrice.setText(formatted);
              etEditItemPrice.setSelection(formatted.length());

              etEditItemPrice.addTextChangedListener(this);
            }
          }

          @Override
          public void afterTextChanged(Editable s) {}
        });

    btnSaveItem.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            addItem(v);
          }
        });
  }
Beispiel #2
0
  public static ParseObject getTema(String idString) {
    ParseObject tema = null;
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Tema");
    try {
      query.fromLocalDatastore();
      tema = query.get(idString);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return tema;
  }
Beispiel #3
0
 private void initializeData(String oid) {
   ParseQuery query = ParseQuery.getQuery("Classes");
   String assignment = new String();
   query.whereEqualTo("objectId", oid);
   try {
     ParseObject f = query.getFirst();
     assignment = f.getString("assignments");
   } catch (ParseException e) {
     Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
   }
   Log.e("Testing", assignment);
   String[] assignments = new String[1];
   if (assignment.length() < 10) {
     return;
   } else if (assignment.contains(",")) {
     assignments = assignment.split(",");
   } else {
     assignments = new String[1];
     assignments[0] = assignment;
   }
   ParseObject[] assignmentsList = new ParseObject[assignments.length];
   Log.e("Testing", Integer.toString(assignments.length));
   int z = 0;
   for (z = 0; z < assignments.length; z++) {
     ParseQuery<ParseObject> query3 = ParseQuery.getQuery("Assignments");
     Log.e("Testing", "a " + assignments[z]);
     Log.e("Testing", Integer.toString(z));
     try {
       ParseObject f = query3.get(assignments[z]);
       assignmentsList[z] = f;
     } catch (ParseException e) {
       Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
     }
   }
   courses = new ArrayList<>();
   for (ParseObject g : assignmentsList) {
     courses.add(
         new Assignments(g.getString("Assignment"), g.getString("Question"), g.getObjectId()));
   }
 }
 public User resolveById(String objectId) throws ParseException {
   ParseQuery<ParseObject> query = ParseQuery.getQuery(className);
   ParseObject parseObject = query.get(objectId);
   return new User(parseObject);
 }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final boolean customTitle = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    final Intent i = new Intent(this, BuganizerCreateParseUserActivity.class);

    setContentView(R.layout.bug_edit);

    if (customTitle) {
      getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_layout);
    }

    TextView tt = (TextView) findViewById(R.id.logout);
    tt.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Log.d("BuganizerParseEdit", "logout clicked ");
            ParseUser.logOut();
            startActivity(i);
          }
        });

    arrayPeople = new ArrayList<String>();

    mLinLayout = (LinearLayout) findViewById(R.id.EditVertLayout);

    Button bsave = (Button) findViewById(R.id.BugSave);
    Button bAddComment = (Button) findViewById(R.id.AddComment);
    Button bAddFriend = (Button) findViewById(R.id.AddUser);

    Log.d("BuganizerParseEdit", "hare krsna showing bug details ");

    Bundle extras = getIntent().getExtras();

    if (extras != null) {

      objectid = extras.getString(BuganizerParseConstants.objectid);
      Log.d("BuganizerParseEdit", "object id is  " + objectid);

      ParseQuery query = new ParseQuery("BugObject");
      try {
        pObject = query.get(objectid);
      } catch (ParseException e1) {
        e1.printStackTrace();
      }

      mAssTo = (TextView) findViewById(R.id.EditBugAssignedTo);
      mDetails = (TextView) findViewById(R.id.EditBugDetails);
      mTitle = (TextView) findViewById(R.id.EditBugTitle);
      mCreatedTS = (TextView) findViewById(R.id.EditBugCreatedTS);
      mPriority = (TextView) findViewById(R.id.EditBugPriority);
      mLayout = (LinearLayout) findViewById(R.id.EditVertLayout);

      String title = pObject.getString(BuganizerParseConstants.title);
      String body = pObject.getString(BuganizerParseConstants.body);
      String assto = pObject.getString(BuganizerParseConstants.assignedto);
      Date ts2 = pObject.getCreatedAt();
      int pri = pObject.getInt(BuganizerParseConstants.priority);

      acl = pObject.getACL();

      SimpleDateFormat dateFormatISO8601 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

      String ts = dateFormatISO8601.format(ts2);

      if (title != null) {
        mTitle.setText(title);
      }
      if (body != null) {
        mDetails.setText(body);
      }
      if (assto != null) {
        mAssTo.setText(assto);
      }
      if (ts != null) {
        mCreatedTS.setText(ts);
      }
      if (pri != 0) {
        mPriority.setText(Integer.toString(pri));
      } else {
        mPriority.setText("undefined");
      }

      if (acl != null) {
        Log.d("BuganizerParseEdit", "The bug has an ACL!");
        if (acl.getWriteAccess(ParseUser.getCurrentUser()) == true) {
          CheckBox chk = new CheckBox(this);
          chk.setChecked(true);
          chk.setText("Mark as private");
          mLayout.addView(chk, 5);
        }
      }
    }

    GetCommentsForBug();

    // fetch the comments first in the background
    ParseQuery query = new ParseQuery("CommentObject");
    query.whereEqualTo("bug", pObject);
    query.findInBackground(
        new FindCallback() {

          @Override
          public void done(List<ParseObject> objects, ParseException arg1) {

            // TODO Auto-generated method stub
            for (ParseObject ob : objects) {
              Log.d(
                  "BuganizerParseEdit",
                  "comments are : "
                      + ob.getString(BuganizerParseConstants.comments)
                      + " created at TS: "
                      + ob.getCreatedAt());
              AddCommentView(ob.getString(BuganizerParseConstants.comments), "", "", false);
            }
          }
        });

    bAddComment.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View view) {

            Log.d("BuganizerParseEdit", "Adding a new comment... ");
            final EditText bdetails = (EditText) findViewById(R.id.BugCommentAdd);
            String cmnt = bdetails.getText().toString();

            arrayPeople.add(cmnt);
            bdetails.setText("");
            AddCommentView(cmnt, "", "", false);
          }
        });

    bAddFriend.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View view) {

            Log.d("BuganizerParseEdit", "Adding a user to bug... ");
            Intent i2 = new Intent(BuganizerParseEdit.this, BuganizerListFriendsActivity.class);
            BuganizerParseEdit.this.startActivityForResult(i2, ACTIVITY_FRIEND_LIST_SHOW);
          }
        });

    bsave.setOnClickListener(
        new View.OnClickListener() {

          public void onClick(View view) {

            Intent mIntent = new Intent();
            Bundle bundle = new Bundle();

            for (String s : arrayPeople) Log.d("BuganizerParseEdit", "Comment: " + s);

            bundle.putString(BuganizerParseConstants.objectid, objectid);
            bundle.putStringArrayList(BuganizerParseConstants.comments, arrayPeople);

            mIntent.putExtras(bundle);
            setResult(RESULT_OK, mIntent);
            finish();
          }
        });
  }
    @Override
    protected Void doInBackground(Void... arg0) {
      if (isHoneycomb) {
        final ParseQuery query = new ParseQuery(Preferences.PARSE_TABLE_SMS);
        // Sort the Parse Object so only the username of the current
        // user can be accessed.
        query.whereEqualTo(Preferences.PARSE_USERNAME_ROW, Util.getUsernameString());
        // The most recent message added will be on top.
        query.orderByDescending("createdAt");
        // Only need to get one message from the server, each message
        // will be from a push
        query.setLimit(1);
        try {
          List<ParseObject> messageList = query.find();
          for (ParseObject messageObject : messageList) {
            // Open up the database
            // Get the parse object id
            String objectId = messageObject.objectId();
            // with the objectid you can query the server
            ParseObject message = query.get(objectId);
            // Get the time the message was added to the server
            Date time = message.createdAt();
            // Format the time to (Fri Jan 13 12:00)
            SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd hh:mm");
            String formatedTime = sdf.format(time);
            String timeDB = formatedTime.toString();
            String addressDB = message.getString("address");
            String bodyDB = message.getString("body");
            int readDB = message.getInt("read");
            int smsIdDB = message.getInt("smsId");
            String subjectDB = message.getString("subject");
            int threadIdDB = message.getInt("threadId");
            int typeDB = message.getInt("type");
            int onDeviceDB = message.getInt("onDevice");
            String usernameDB = message.getString("username");
            // Display the total message queryed for
            // logging
            String totalMessage =
                "Sent: "
                    + timeDB
                    + "\n"
                    + "Address: "
                    + addressDB
                    + "\n"
                    + "Message : "
                    + bodyDB
                    + "\n";
            Log.d(TAG, "New message is: " + totalMessage);
            // Get the MessageItem object so you can
            // create the db entry.
            MessageItem item =
                new MessageItem(
                    timeDB,
                    addressDB,
                    bodyDB,
                    readDB,
                    smsIdDB,
                    subjectDB,
                    threadIdDB,
                    typeDB,
                    onDeviceDB,
                    usernameDB);
            // Insert the MessageItem into the sms2honeycomb.db.
            dbAdapter.insertMessageItem(item);

            // TODO update the listadapter to display the new
            // message via an intent/ service?

            String intentString = "com.asa.texttotab.UPDATE_LIST";
            Intent updateIntent = new Intent();
            updateIntent.setAction(intentString);
            mContext.sendBroadcast(updateIntent);

            // TODO NOTICIFATIONS
          }
        } catch (ParseException e) {
          // TODO - Handle situation where querying server failed
          dbAdapter.close();
          Log.e(TAG, "querying server failed");
          e.printStackTrace();
        }
      } else {
        Log.e(TAG, "The device is not honeycomb is its a phone.");
        // If the device is not a tablet it is a phone so you pull from
        // the
        // server, but then send a sms message from the data recived.
        // We want to query the sms table
        final ParseQuery query = new ParseQuery(Preferences.PARSE_TABLE_SMS);
        // Sort the Parse Object so only the username of the current
        // user
        // can be accessed.
        query.whereEqualTo(Preferences.PARSE_USERNAME_ROW, Util.getUsernameString());
        // The most recent message added will be on top.
        query.orderByDescending("createdAt");
        // Only need to get one message from the server, each message
        // will be from a push
        query.setLimit(1);
        try {
          List<ParseObject> messageList = query.find();
          // For the ParseObjects quering get all that needs
          // to be done.
          for (ParseObject messageObject : messageList) {
            // Get the parse object id
            String objectId = messageObject.objectId();
            // with the objectid you can query the
            // server
            ParseObject message = query.get(objectId);
            // Get the time the message was created at
            // for
            // logging, do not need a time to send a
            // message.
            Date time = message.createdAt();
            String timeString = time.toString();
            // Get who the message is coming from
            // (phonenumber).
            String address = message.getString(Preferences.PARSE_SMS_ADDRESS);
            // Get the body of the message
            String body = message.getString(Preferences.PARSE_SMS_BODY);
            // Display the total message queryed for
            // logging
            String totalMessage =
                "Sent: " + timeString + "\n" + "To: " + address + "\n" + "Message : " + body + "\n";
            Log.d(TAG, "New message is: " + totalMessage);
            // get the smsmanager as sms
            SmsManager sms = SmsManager.getDefault();
            // If the message is over the 160 Char limit
            // it
            // will be choped up.
            if (body.length() > 160) {
              // Chops up the message
              sms.divideMessage(body);
              // Send the sms message in its parts
              sms.sendMultipartTextMessage(address, null, sms.divideMessage(body), null, null);
            } else {
              // Sends the message without cutting it
              sms.sendTextMessage(address, null, body, null, null);
            }
          }
        } catch (ParseException e) {
          // TODO - Handle situation where querying server failed
          e.printStackTrace();
        }
      }
      return null;
    }