Example #1
0
 /**
  * Post a new Comment. Called by the Post button on the menu
  *
  * @param v
  */
 public void postComment(View v) {
   EditText newCom = (EditText) findViewById(R.id.editText1);
   if (!newCom
       .getText()
       .toString()
       .trim()
       .equals("")) { // If there is text in the enter comment section
     if (theQuests.getOpenQuestion()
         == -1) { // If there are no open questions, enter the new comment as a new question
       pic.addQuestion("Anonymous", newCom.getText().toString());
     } else { // Otherwise, add it as an answer to the currently open question
       pic.getQuestions()
           .get(pic.getQuestions().size() - theQuests.getOpenQuestion() - 1)
           .addAnswer("Anonymous", newCom.getText().toString());
     }
   }
   newCom.setText("");
   InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
   imm.hideSoftInputFromWindow(v.getWindowToken(), 0); // Gets rid of the keyboard
   newCom.clearFocus();
 }
Example #2
0
  /**
   * Sets the Picture Item for this activity and updates all the elements accordingly.
   *
   * @param p
   */
  public void setPic(PictureItem p) {
    pic = p;
    ImageView image = (ImageView) findViewById(R.id.imageView1);
    image.setImageBitmap(pic.getPicture());
    image.setOnClickListener(
        new OnClickListener() {
          // Toggle whether the image gets the entire screen or not.
          @Override
          public void onClick(View v) {
            RelativeLayout relLay1 = (RelativeLayout) findViewById(R.id.RelativeLayout1);
            RelativeLayout relLay2 = (RelativeLayout) findViewById(R.id.RelativeLayout2);
            if (!imageOpen) { // The image is not already taking up the entire screen
              if (getResources().getConfiguration().orientation
                  == Configuration.ORIENTATION_LANDSCAPE) { // In Landscape
                relLay1.setLayoutParams(
                    new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 2f));
                relLay2.setLayoutParams(
                    new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 0f));

              } else { // In Portrait
                relLay1.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 2f));
                relLay2.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0f));
              }
              imageOpen = true;
            } else { // The image is already taking up the entire screen
              if (getResources().getConfiguration().orientation
                  == Configuration.ORIENTATION_LANDSCAPE) { // In Landscape
                relLay1.setLayoutParams(
                    new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
                relLay2.setLayoutParams(
                    new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));

              } else { // In Portrait
                relLay1.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
                relLay2.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
              }

              imageOpen = false;
            }
          }
        });
    TextView title = (TextView) findViewById(R.id.textView1);
    title.setText(pic.getTitle());
    TextView user = (TextView) findViewById(R.id.textView3);
    user.setText("By " + pic.getUser());
    ListView coms = (ListView) findViewById(R.id.listView1);
    TextView des = new TextView(this);
    des.setText(pic.getDescription());
    des.setTextSize(21);
    des.setTextColor(0xFFFFFFFF);
    coms.addHeaderView(des);
    coms.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            if (position != 0) {
              // QuestionAdapter quests = (QuestionAdapter) parent.getAdapter();
              theQuests.setOpenQuestion(position - 1);
              Button pushBut = (Button) findViewById(R.id.button1);
              if (theQuests.getOpenQuestion() == -1) {
                pushBut.setText("Post");
              } else {
                pushBut.setText("Reply");
              }
            }
          }
        });
    theQuests = new QuestionAdapter(this);
    theQuests.setQuestions(pic.getQuestions());
    coms.setAdapter(theQuests);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  }