public void connect(View view) { TextView name = (TextView) findViewById(R.id.name); TextView ip = (TextView) findViewById(R.id.ip); Utils.name = name.toString().trim(); try { Server.connect(InetAddress.getByName(ip.toString()), 9876); } catch (UnknownHostException e) { toast(e.getMessage()); } }
public void voteCrumb(View view) { // change button text ImageButton voteButton = (ImageButton) findViewById(R.id.buttonVote); voteButton.setEnabled(false); if (hasVoted) { Intent msgIntent = new Intent(this, JSONRequest.class); msgIntent.putExtra(JSONRequest.IN_MSG, "unvote"); msgIntent.putExtra("queryID", "unvote"); msgIntent.putExtra( "jsonObject", "{\"username\":\"" + GlobalContainer.user.getInfo()[0] + "\",\"email\":\"" + GlobalContainer.user.getInfo()[1] + "\",\"crumbID\":\"" + crumbID + "\"}"); startService(msgIntent); ImageButton temp_voteButton = (ImageButton) findViewById(R.id.buttonVote); Resources res = getResources(); /** from an Activity */ temp_voteButton.setImageDrawable(res.getDrawable(R.drawable.newthumbup)); } else { ImageButton temp_voteButton = (ImageButton) findViewById(R.id.buttonVote); Resources res = getResources(); /** from an Activity */ temp_voteButton.setImageDrawable(res.getDrawable(R.drawable.newthumbdown)); Intent msgIntent = new Intent(this, JSONRequest.class); msgIntent.putExtra(JSONRequest.IN_MSG, "upvote"); msgIntent.putExtra("queryID", "upvote"); msgIntent.putExtra( "jsonObject", "{\"username\":\"" + GlobalContainer.user.getInfo()[0] + "\",\"email\":\"" + GlobalContainer.user.getInfo()[1] + "\",\"crumbID\":\"" + crumbID + "\"}"); startService(msgIntent); } // pass crumb back into database String comment = crumbComment.toString(); Intent intent = new Intent(this, MapsActivity.class); String id = getIntent().getStringExtra(MyCrumbsActivity.CRUMB_ID); // place into intent to pass back to MapsActivity intent.putExtra(MapsActivity.NAME, name); intent.putExtra(MapsActivity.COMMENT, comment); setResult(RESULT_OK, intent); // send result code }
// Receive the data from second activity when this is finished; Code similar from Hand In 1 protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == 0) { try { txtNote.setText(data.getCharSequenceExtra("note")); txt = txtNote.toString(); } catch (java.lang.RuntimeException e) { e.printStackTrace(); } } }
@Override public void onClick(View v) { TextView textView = (TextView) v; textView.setSelected(!textView.isSelected()); // 如果是选中的话 就是修改子体颜色 if (textView.isSelected()) { textView.setTextColor(getResources().getColor(R.color.white)); } // 设置 index currentIndex = position; /** 遍历所有的按钮 如果按下的按钮不是 选中的按钮 则把状态设置为没有选中 再把字体颜色设置为 默认颜色 */ for (int i = 0; i < mGridView.getChildCount(); i++) { if (!textView .toString() .equals(((LinearLayout) mGridView.getChildAt(i)).getChildAt(0).toString())) { ((LinearLayout) mGridView.getChildAt(i)).getChildAt(0).setSelected(false); ((TextView) ((LinearLayout) mGridView.getChildAt(i)).getChildAt(0)) .setTextColor(getResources().getColor(R.color.normal_dark_font)); } } }
/** * 显示弹出窗口 * * @param which 显示哪个弹出窗口 */ private void showPopwindow(int which) { switch (which) { case CLASSFICATION_POP: { int[] location = new int[2]; classificationTextView.getLocationOnScreen(location); if (choose_classfication_popupWindow == null) { initPopwindow(CLASSFICATION_POP); } Log.i("classificationTextView", classificationTextView.toString()); Log.i("choose_classfication_popupWindow", choose_classfication_popupWindow.toString()); choose_classfication_popupWindow.showAtLocation( addClassification, Gravity.NO_GRAVITY, location[0], location[1] + classificationTextView.getHeight()); } break; case ChooseGroup_POP: { int[] location = new int[2]; addShareGroupTextView.getLocationOnScreen(location); if (choose_group_popWindow == null) { initPopwindow(ChooseGroup_POP); } choose_group_popWindow.showAtLocation( chooseGroup, Gravity.NO_GRAVITY, location[0], location[1] + addShareGroupTextView.getHeight()); } default: break; } }