コード例 #1
0
  private void checkHashtag(String hashtag) {

    hashtag = hashtag.replace("#", "");
    hashtag = hashtag.replace(" ", "");

    if (hashtag.length() > 0) {

      if (hashtags.size() < 5.0) {

        Log.d("postText final ", hashtag);

        if (hashtags.size() == 0) {}
        hashtags.add(0, "#" + hashtag);

      } else {
        Toast.makeText(
                getActivity().getApplicationContext(),
                "Only 5 Hashtags allowed.",
                Toast.LENGTH_SHORT)
            .show();
      }

      postText.setText("");
      checkHeader();
    }
    adapter.notifyDataSetChanged();
  }
コード例 #2
0
  private void removeAllBadHashtags() {

    // Find the things to remove
    ArrayList<String> toDelete = new ArrayList<String>();
    for (String hashtag : hashtags) {
      if (shouldShowCaution(hashtag)) {
        toDelete.add(hashtag);
      }
    }
    hashtags.removeAll(toDelete);
    checkHeader();
    adapter.notifyDataSetChanged();
  }
コード例 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.post_list);
    listView = (ListView) findViewById(R.id.postList);

    final ArrayList<PostDataProvider> posts = getIntent().getParcelableArrayListExtra("posts");
    Log.d("facebook##", posts.size() + "");
    int i = 0;
    adapter = new PostAdapter(getApplicationContext(), R.layout.post_row);
    listView.setAdapter(adapter);

    for (PostDataProvider dataProvider : posts) {
      adapter.add(dataProvider);
      i++;
    }
    listView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {

          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getBaseContext(), position + " is selected", Toast.LENGTH_SHORT).show();
            selectedPost = posts.get(position);
            String currentId = selectedPost.getId();

            // Read access code from sharedpreference
            SharedPreferences prefs =
                getSharedPreferences(MainActivity.MY_PREFS_NAME, MODE_PRIVATE);
            String pageAccessTotken = prefs.getString("access_token", null);
            Log.d("facebook##", "access_token: " + pageAccessTotken);

            new GetTask()
                .execute(
                    "https://graph.facebook.com/"
                        + currentId
                        + "/insights/post_impressions_unique/lifetime?access_token="
                        + pageAccessTotken);
          }
        });
  }
コード例 #4
0
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle SavedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_new_photo, parent, false);
    header = (ViewGroup) inflater.inflate(R.layout.item_header, postHashtags, false);

    photoFile = null;
    videoFile = null;

    postHashtags = (ListView) v.findViewById(R.id.post_hashtags);

    postTags = (RelativeLayout) v.findViewById(R.id.post_tags);
    postVisual = (RelativeLayout) v.findViewById(R.id.post_visual);
    postImage = (ImageView) v.findViewById(R.id.post_image);
    postDeny = (ImageButton) v.findViewById(R.id.post_deny);
    postAccept = (ImageButton) v.findViewById(R.id.post_accept);

    adapter =
        new PostAdapter<String>(
            getActivity().getApplicationContext(),
            R.layout.item_list_hashtags,
            R.id.text1,
            hashtags,
            this);
    try {
      postHashtags.addHeaderView(header, null, false);
    } catch (Exception e) {
    }
    postHashtags.setAdapter(adapter);

    adapter.notifyDataSetChanged();

    cautionHeader = (LinearLayout) header.findViewById(R.id.post_caution_container);
    cautionHeader.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            removeAllBadHashtags();
          }
        });

    int[] rainbow =
        getActivity().getApplicationContext().getResources().getIntArray(R.array.colorPicker);
    Random rn = new Random();
    int picker = rn.nextInt(rainbow.length);

    /**
     * suggestedHeader = (RelativeLayout) header.findViewById(R.id.post_suggested);
     * suggestedHeader.setBackgroundColor(rainbow[rn.nextInt(rainbow.length)]);
     * suggestedHeader.setOnClickListener(new View.OnClickListener() { @Override public void
     * onClick(View v) {
     *
     * <p>hideKeyboard(); mCallback.onSuggestions(); } });*
     */

    // yep
    // Accept or deny photo
    Drawable dDeny = getResources().getDrawable(R.drawable.icon_exit_c);
    dDeny.setColorFilter(rainbow[picker], PorterDuff.Mode.SRC_ATOP);
    postDeny.setImageDrawable(dDeny);
    postDeny.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            mCallback.onTransitionFromPostion(getArguments().getBoolean("from_camera", true));
            photoFile = null;
            videoFile = null;
          }
        });

    Drawable dAccept = getResources().getDrawable(R.drawable.icon_checkmark_c);
    dAccept.setColorFilter(rainbow[picker], PorterDuff.Mode.SRC_ATOP);
    postAccept.setImageDrawable(dAccept);
    postAccept.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {

            Bitmap data = getArguments().getParcelable("image");
            String videoPath = getArguments().getString("video", null);
            if (data != null) {
              saveScaledPhoto(data, videoPath);
              hideImage();
            }
          }
        });

    postCancel = (Button) v.findViewById(R.id.post_cancel);
    postCancel.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            showImage();
          }
        });

    // Hashtags
    postText = ((EditText) v.findViewById(R.id.post_text));
    postText.setBackgroundColor(rainbow[picker]);
    postText.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) {}

          @Override
          public void afterTextChanged(Editable s) {

            if (postText.length() > 0 && s.toString().contains(" ")) {
              String hashing = String.valueOf(postText.getText());
              postText.setText("");
              checkHashtag(hashing);
            }
          }
        });
    postText.setOnEditorActionListener(
        new EditText.OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
              if (postText.length() > 0) {
                String hashing = String.valueOf(postText.getText());
                postText.setText("");
                checkHashtag(hashing);
                return true;
              }
            }
            return false;
          }
        });

    postText.setFocusableInTouchMode(true);
    postText.requestFocus();
    InputMethodManager imm =
        (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(postText, InputMethodManager.SHOW_IMPLICIT);
    postText.setCursorVisible(true);

    int[] rainbowa =
        getActivity().getApplicationContext().getResources().getIntArray(R.array.colorPicker);
    Random rna = new Random();
    int pickera = rn.nextInt(rainbow.length);

    postDoneContainer = ((LinearLayout) header.findViewById(R.id.post_done_container));
    postDoneContainer.setBackgroundColor(rainbow[rn.nextInt(rainbow.length)]);
    postDoneContainer.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {

            postDoneContainer.setEnabled(false);
            String hashing = String.valueOf(postText.getText());
            postText.setText("");
            checkHashtag(hashing);

            // Saving Hashtags
            ArrayList<String> cleanHashtags = cleanHashtags(hashtags);

            Hashtag hashtag = new Hashtag();

            for (int i = 0; i < cleanHashtags.size(); i++) {
              String hash = (String) cleanHashtags.get(i);
              hashtag.saveHashtag(hash); //
            }

            InputMethodManager imm =
                (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(postText.getWindowToken(), 0);

            // Saving Selfie
            Selfie selfie = new Selfie();

            ParseObject location = ParseUser.getCurrentUser().getParseObject("location");

            if (photoFile == null) {
              Toast.makeText(
                      getActivity(), "Error saving: Not going to save properly", Toast.LENGTH_LONG)
                  .show();
            }

            if (videoFile != null) {
              selfie.setNewSelfie(
                  photoFile, ParseUser.getCurrentUser(), location, cleanHashtags, videoFile);
            } else {
              selfie.setNewSelfie(
                  photoFile, ParseUser.getCurrentUser(), location, cleanHashtags, null);
            }

            // Save the meal and return
            selfie.saveInBackground(
                new SaveCallback() {

                  @Override
                  public void done(ParseException e) {
                    if (e == null) {
                    } else {
                      Log.d("Error saving: ", e.getMessage());
                    }
                  }
                });
            postDoneContainer.setEnabled(true);
            mCallback.onHideFragment();
          }
        });

    postHashtags.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            InputMethodManager imm =
                (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(postText.getWindowToken(), 0);
            postText.setCursorVisible(false);
            String hashing = String.valueOf(postText.getText());
            postText.setText("");
            checkHashtag(hashing);

            return false;
          }
        });

    v.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            InputMethodManager imm =
                (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(postText.getWindowToken(), 0);
            postText.setCursorVisible(false);
            String hashing = String.valueOf(postText.getText());
            postText.setText("");
            checkHashtag(hashing);
            return false;
          }
        });

    adapter.registerDataSetObserver(
        new DataSetObserver() {
          @Override
          public void onChanged() {
            super.onChanged();
            setPlaceholder();
          }
        });

    checkHeader();

    return v;
  }
コード例 #5
0
 public void run() {
   adapter.notifyDataSetChanged();
 }