Exemple #1
0
 public SharesModel(ParseObject parseObject, Context context) {
   startDay = HelperClass.getStringFormatDate(parseObject.getDate("share_due_date"), context);
   shareOrder = parseObject.getInt("share_order");
   isShareDelivered = parseObject.getBoolean("share_status");
   jamId = parseObject.getString("shares_jamNo");
   shareOwnerId = parseObject.getString("share_owner_id");
   shareId = parseObject.getObjectId();
   sharePaidAmount = parseObject.getInt("share_paid_amount");
 }
  static float[] updateGraph() {
    long timeStep = 1445214540000L;
    float[] results = new float[numData];

    ParseQuery<ParseObject> query = ParseQuery.getQuery("data");
    query.whereEqualTo("flag", 1);
    try {
      ParseObject flagged = query.getFirst();
      timeStep = flagged.getLong("unixTimeStamp");
      flagged.put("flag", 0);
      flagged.saveInBackground();
      Log.d("Find Flag", flagged.getObjectId());
    } catch (ParseException e) {
      Log.d("Find Flag", "Error: " + e.getMessage());
    }
    query = ParseQuery.getQuery("data");
    query.orderByAscending("unixTimeStamp");
    query.whereGreaterThan("unixTimeStamp", timeStep);
    try {
      ParseObject nextFlag = query.getFirst();
      nextFlag.put("flag", 1);
      nextFlag.saveInBackground();
      Log.d("Set Next Flag", nextFlag.getObjectId() + " is " + nextFlag.getInt("flag"));
    } catch (ParseException e) {
      Log.d("Set Next Flag", "Error: " + e.getMessage());
    }
    query = ParseQuery.getQuery("data");
    query.orderByDescending("unixTimeStamp");
    query.whereLessThan("unixTimeStamp", timeStep);
    for (int i = 0; i < numData; i++) {
      try {
        ParseObject data = query.getFirst();
        results[numData - i - 1] = (float) data.getInt("Bg");
        query.whereLessThan("unixTimeStamp", data.getLong("unixTimeStamp"));
      } catch (ParseException e) {
        Log.d("Fill Results Array", "Failed");
      }
    }
    /*query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> data, ParseException e) {
            int i = 0;

            if (e == null) {
                Log.d("Blood Glucose", "Retrieved " + data.size() + " Blood Glucose Data Points");
                for(ParseObject person : data) {
                    results[i] = person.getInt("Bg");
                    i++;
                }
            }
            else {
                Log.d("Blood Glucose", "Error: " + e.getMessage());
            }
        }
    });*/
    return results;
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

      View v = convertView;

      if (v == null) {
        LayoutInflater vi;
        vi = LayoutInflater.from(getContext());
        v = vi.inflate(R.layout.item_userbookinghistory, null);
      }

      final ParseObject userbooking = (ParseObject) getItem(position);

      if (userbooking != null) {
        TextView tv_bookedTime = (TextView) v.findViewById(R.id.tv_hotel_booked_time);
        TextView tv_hotel_name = (TextView) v.findViewById(R.id.tv_hotel_name);
        TextView tv_status = (TextView) v.findViewById(R.id.tv_status);

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss");
        ParseObject hotel = userbooking.getParseObject("BookedHotel");

        Date reservationTime = userbooking.getDate("ReservationTime");
        tv_bookedTime.setText(formatter.format(reservationTime));

        tv_hotel_name.setText(hotel.getString("Name"));

        int status = userbooking.getInt("BookingState");
        String status_message = "";

        if (status == 1) {
          status_message = "Under Process";
        } else if (status == 2) {
          status_message = "Confirmed";
        } else if (status == -1) {
          status_message = "Canceled";
        } else if (status == -2) {
          status_message = "Not Confirmed";
        }

        tv_status.setText(status_message);
      }

      return v;
    }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LinearLayout newsView;
    ParseObject news = getItem(position);

    if (convertView == null) {
      LayoutInflater inflater =
          (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      newsView = (LinearLayout) inflater.inflate(R.layout.layout_news, parent, false);
    } else {
      newsView = (LinearLayout) convertView;
    }
    TextView tvTitle = (TextView) newsView.findViewById(R.id.tvType);

    switch (news.getInt("Type")) {
      case 0:
        tvTitle.setText("新貨");
        newsView.setBackgroundColor(getContext().getResources().getColor(R.color.new_blue));
        break;
      default:
      case 1:
        tvTitle.setText("公告");
        newsView.setBackgroundColor(getContext().getResources().getColor(R.color.declare_green));
        break;
      case 2:
        tvTitle.setText("活動");
        newsView.setBackgroundColor(getContext().getResources().getColor(R.color.activty_gray));
        break;
      case 3:
        tvTitle.setText("公休");
        newsView.setBackgroundColor(getContext().getResources().getColor(R.color.holiday_red));
        break;
    }

    TextView tvContent = (TextView) newsView.findViewById(R.id.tvNewsContent);
    tvContent.setText(news.getString("Content"));

    return newsView;
  }
  public static Board createBoard(ParseObject o) {
    if (o == null) {
      return null;
    }
    cache().put(o);

    Board board = new Board(o.getObjectId());
    if (o.has("category")) {
      board.setCategory(ParseHelper.createCategory(o.getParseObject("category")));
    }
    if (o.has("name")) {
      board.setName(o.getString("name"));
    }
    if (o.has("description")) {
      board.setDescription(o.getString("description"));
    }
    if (o.has("owner")) {
      board.setOwner(ParseHelper.createUser(o.getParseObject("owner")));
    }
    if (o.has("followers_count")) {
      board.setFollowersCount(o.getInt("followers_count"));
    }
    return board;
  }
Exemple #6
0
  public static void setPreferences(ParseObject userObject, final Context context) {
    PrefManager.with(context)
        .save(
            User.FIRST_NAME,
            userObject.getString(User.FIRST_NAME) != null
                ? userObject.getString(User.FIRST_NAME)
                : BuildConfig.FLAVOR);
    PrefManager.with(context)
        .save(
            User.LAST_NAME,
            userObject.getString(User.LAST_NAME) != null
                ? userObject.getString(User.LAST_NAME)
                : BuildConfig.FLAVOR);
    PrefManager.with(context)
        .save(
            PreferenceUtils.EMAIL,
            userObject.getString(PreferenceUtils.EMAIL) != null
                ? userObject.getString(PreferenceUtils.EMAIL)
                : BuildConfig.FLAVOR);
    PrefManager.with(context)
        .save(
            PreferenceUtils.AVATAR_URL,
            userObject.getString(PreferenceUtils.AVATAR_URL) != null
                ? userObject.getString(PreferenceUtils.AVATAR_URL)
                : BuildConfig.FLAVOR);
    PrefManager.with(context)
        .save(
            User.OBJECT_ID,
            userObject.getObjectId() != null ? userObject.getObjectId() : BuildConfig.FLAVOR);
    PrefManager.with(context).save(User.HAS_FITBIT, userObject.getBoolean(User.HAS_FITBIT));
    PrefManager.with(context).save(User.HAS_JAWBONE, userObject.getBoolean(User.HAS_JAWBONE));
    PrefManager.with(context).save(User.HAS_GOOGLEFIT, userObject.getBoolean(User.HAS_GOOGLEFIT));
    PrefManager.with(context).save(User.HAS_MISFIT, userObject.getBoolean(User.HAS_MISFIT));
    PrefManager.with(context).save(User.HAS_MOVES, userObject.getBoolean(User.HAS_MOVES));
    PrefManager.with(context)
        .save(
            User.MOVES_TOKEN,
            userObject.getString(User.MOVES_TOKEN) != null
                ? userObject.getString(User.MOVES_TOKEN)
                : BuildConfig.FLAVOR);
    PrefManager.with(context)
        .save(
            User.MOVES_REFRESH_TOKEN,
            userObject.getString(User.MOVES_REFRESH_TOKEN) != null
                ? userObject.getString(User.MOVES_REFRESH_TOKEN)
                : BuildConfig.FLAVOR);
    PrefManager.with(context)
        .save(
            User.UNITS,
            userObject.getString(User.UNITS) != null
                ? userObject.getString(User.UNITS)
                : context.getString(R.string.pref_units_imperial));
    try {
      String[] fitbitToken = userObject.getString(User.FITBIT_TOKEN).split(",");
      if (fitbitToken.length > 0) {
        PrefManager.with(context).save(FitbitClient.FITBIT_TOKEN, fitbitToken[0]);
        PrefManager.with(context).save(FitbitClient.FITBIT_TOKEN_SECRET, fitbitToken[1]);
        PrefManager.with(context).save(FitbitClient.FITBIT_TOKEN_RAW, fitbitToken[2]);
      }
    } catch (Exception ex) {
      if (ex.getMessage() != null) {
        Log.d(LOG_TAG, ex.getMessage());
      } else {
        Log.d(LOG_TAG, "Exception!", ex);
      }
    }
    if (userObject.getBoolean(User.HAS_MOVES)) {
      MoveApiClient.getBaseRestAdapter(context)
          .create(MoveApiClient.MovesConnector.class)
          .getUser(
              new Callback<MovesUser>() {
                @Override
                public void success(MovesUser movesUser, Response response) {
                  PrefManager.with(context)
                      .save(MoveApiClient.MOVES_FIRST_DATE, movesUser.getProfile().getFirstDate());
                }

                @Override
                public void failure(RetrofitError error) {}
              });
    }
    PrefManager.with(context)
        .save(
            MisfitClient.MISFIT_TOKEN,
            userObject.getString(MisfitClient.MISFIT_TOKEN) != null
                ? userObject.getString(MisfitClient.MISFIT_TOKEN)
                : BuildConfig.FLAVOR);
    PrefManager.with(context)
        .save(
            ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN,
            userObject.getString(User.JAWBONE_TOKEN) != null
                ? userObject.getString(User.JAWBONE_TOKEN)
                : BuildConfig.FLAVOR);
    PrefManager.with(context)
        .save(PreferenceUtils.WEEK_AVERAGE, String.valueOf(userObject.getInt(User.STEPS_AVERAGE)));
  }
  /** 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;
    }
Exemple #9
0
 public static void addShareNum(final ParseObject mQuestion) {
   int temp = mQuestion.getInt(Common.OBJECT_POST_SHARE_NUM);
   mQuestion.put(Common.OBJECT_POST_SHARE_NUM, temp + 1);
   mQuestion.saveInBackground();
 }
Exemple #10
0
 public static void likeComment(final ParseObject mComment, boolean add) {
   mComment.put(
       Common.OBJECT_COMMENT_LIKES,
       mComment.getInt(Common.OBJECT_COMMENT_LIKES) + ((add) ? 1 : -1));
   mComment.saveInBackground();
 }