Exemplo n.º 1
0
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // TODO Auto-generated method stub

    Object itemAdapter = parent.getAdapter();

    if (itemAdapter instanceof EmotionGvAdapter) {
      // 点击的是表情
      EmotionGvAdapter emotionGvAdapter = (EmotionGvAdapter) itemAdapter;

      if (position == emotionGvAdapter.getCount() - 1) {
        // 如果点击了最后一个回退按钮,则调用删除键事件
        msg.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));

      } else {

        // 如果点击了表情,则添加到输入框中
        String emotionName = (String) emotionGvAdapter.getItem(position);

        // 获取当前光标位置,在指定位置上添加表情图片文本
        int curPosition = msg.getSelectionStart();
        StringBuilder sb = new StringBuilder(msg.getText().toString());
        sb.insert(curPosition, emotionName);

        // 特殊文字处理,将表情等转换一下

        msg.setText(StringUtils.getEmotionContent(this, msg, sb.toString()));

        // 将光标设置到新增完表情的右侧
        msg.setSelection(curPosition + emotionName.length());
      }
    }
  }
Exemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.note_write_txt);
    a = 0;
    sound = (ImageView) findViewById(R.id.icon_audio);
    send = (ImageView) findViewById(R.id.note_write_send);
    emj = (ImageView) findViewById(R.id.emj);
    title = (EditText) findViewById(R.id.note_write_title);
    msg = (EditText) findViewById(R.id.note_write_msg);
    address = (TextView) findViewById(R.id.note_location_address);
    //	 2015.12.2
    player = new MediaPlayer();
    handler = new Handler();

    cancle = (TextView) findViewById(R.id.note_write_cancel);
    //		2015.12.8
    ll_emotion_dashboard = (LinearLayout) findViewById(R.id.ll_emotion_dashboard);
    vp_emotion_dashboard = (ViewPager) findViewById(R.id.vp_emotion_dashboard);

    Intent data = getIntent();
    Bundle bundle = getIntent().getExtras();
    final String sad = bundle.getString("picturePath1");

    //	    2015.12.2
    if (sad != null) {
      sound.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View arg0) {
              // TODO Auto-generated method stub

              String path = sad;

              try {
                player.setDataSource(path);
                player.prepare();

                a = player.getDuration();

                player.start();

              } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              } catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }

              handler.postDelayed(
                  new Runnable() {

                    @Override
                    public void run() {
                      // TODO Auto-generated method stub

                      player.reset();
                    }
                  },
                  a);
            }
          });
    }

    cancle.setOnClickListener(
        new OnClickListener() {

          public void onClick(View arg0) {
            finish();
          }
        });
    emj.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub
            ll_emotion_dashboard.setVisibility(
                ll_emotion_dashboard.getVisibility() == View.VISIBLE ? View.VISIBLE : View.GONE);
          }
        });
    initEmotion();

    msg.setText(StringUtils.getEmotionContent(this, msg, ""));
  }