示例#1
0
  /**
   * 处理点击事件
   *
   * @param parent
   * @param view
   * @param position
   * @param id
   */
  protected void handleItemClick(AdapterView<?> parent, View view, int position, long id) {
    ImageItem item = mAdapter.getItem(position);
    ImageView selected = (ImageView) view.findViewById(R.id.isselected);
    if (mSelectTotal < ConstantKeys.MAX_SELECT_IMAGE_COUNT) {
      item.setSelected(!item.isSelected());
      if (item.isSelected()) {
        selected.setImageResource(R.drawable.ic_takephoto_album_img_selected);
        mSelectTotal++;
        setSendText(mSelectTotal);
        mSelectedMap.put(position, mDataList.get(position));

      } else if (!item.isSelected()) {
        selected.setImageResource(R.drawable.ic_takephoto_album_img_select_nor);
        mSelectTotal--;
        setSendText(mSelectTotal);
        mSelectedMap.remove(position);
      }
    } else if (mSelectTotal >= ConstantKeys.MAX_SELECT_IMAGE_COUNT) {
      if (item.isSelected() == true) {
        item.setSelected(!item.isSelected());
        selected.setImageResource(R.drawable.ic_takephoto_album_img_select_nor);
        mSelectTotal--;
        mSelectedMap.remove(position);
      } else {
        android.os.Message message = android.os.Message.obtain(mHandler, 0);
        message.sendToTarget();
      }
    }
  }
示例#2
0
  private void initView() {
    mGridView = (GridView) findViewById(R.id.gridview);
    mGridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
    for (ImageItem m : mDataList) {
      m.setStyle(ConstantKeys.ALBUM_IMAGE_GRIDVIEW_DISPLAYTYPE_SINGLE);
    }
    mAdapter.setData(mDataList);
    mGridView.setAdapter(mAdapter);
    mGridView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // mAdapter.notifyDataSetChanged();

            handleItemClick(parent, view, position, id);
          }
        });

    if (mName.length() > 12) {
      mName = mName.substring(0, 11) + "...";
    }

    mFinishTv = (TextView) findViewById(R.id.finish);
    mFinishTv.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            Iterator<Integer> iter = mSelectedMap.keySet().iterator();
            List<String> sendMessageList = new ArrayList<String>(); // 需要发送到服务器数据的集合列表
            List<MessageItem> messageItemList = new ArrayList<MessageItem>();
            while (iter.hasNext()) {
              int position = iter.next();
              ImageItem imgItem = mSelectedMap.get(position);
              if (imgItem != null && !TextUtils.isEmpty(imgItem.getImagePath())) {
                // 保存到数据库中
                MessageItem messageItem =
                    new MessageItem(
                        MessageItem.MESSAGE_TYPE_IMG,
                        mSpUtil.getNick(),
                        System.currentTimeMillis(),
                        imgItem.getImagePath(),
                        mSpUtil.getHeadIcon(),
                        false,
                        0,
                        0);
                mMsgDB.saveMsg(mSpUtil.getUserId(), messageItem);
                messageItemList.add(messageItem);
                // 保存到最近数据库中
                RecentItem recentItem =
                    new RecentItem(
                        MessageItem.MESSAGE_TYPE_IMG,
                        mSpUtil.getUserId(),
                        mSpUtil.getHeadIcon(),
                        mSpUtil.getNick(),
                        imgItem.getImagePath(),
                        0,
                        System.currentTimeMillis(),
                        0);
                mRecentDB.saveRecent(recentItem);
                Message message =
                    new Message(
                        MessageItem.MESSAGE_TYPE_IMG,
                        System.currentTimeMillis(),
                        messageItem.getMessage(),
                        "",
                        0);
                sendMessageList.add(mGson.toJson(message));
              }
            }

            // 更新界面

            MessageAdapter messageAdapter = MainActivity.getMessageAdapter();
            if (messageAdapter != null) {
              messageAdapter.upDateMsgByList(messageItemList);
            }
            if ("".equals(mSpUtil.getUserId())) {
              //                    Log.e("fff", "用户id为空2");
              T.show(ImageGridActivity.this, "注册百度push用户失败,不能将消息发送出去", 1);
              return;
            }
            // 发送push
            new SendMsgAsyncTask(sendMessageList, mSpUtil.getUserId()).send();

            // finish();
            Intent data = new Intent();
            data.putExtra("finish", true);
            setResult(RESULT_OK, data);
            ImageGridActivity.this.finish();
          }
        });
    mPreviewTv = (TextView) findViewById(R.id.preview);
    mPreviewTv.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {

            if (mSelectedMap != null && mSelectedMap.size() > 0) {
              Intent intent = new Intent(ImageGridActivity.this, PreviewActivity.class);
              startActivityForResult(intent, ConstantKeys.ALBUM_PREVIEW_BACK);

            } else {
              Toast.makeText(ImageGridActivity.this, getString(R.string.need_choose_images), 0)
                  .show();
              // Util.showToast(R.string.need_choose_images);
            }
          }
        });
  }