예제 #1
0
  /**
   * 生成MyViewGroup的子元素
   *
   * @param text
   */
  private void createView1(String text, String number) {

    if (etMess.getText().toString().equals(" ") || etMess.getText().toString().equals("")) {
    } else {
      TextView t = new TextView(this);
      t.setText(text);
      t.setTextColor(Color.BLACK);
      t.setGravity(Gravity.CENTER);
      t.setBackgroundResource(R.drawable.bg_sms_contact_btn);
      t.setHeight(60);
      t.setPadding(2, 0, 2, 0);
      t.setOnClickListener(new MyListener());
      t.setTag(number);
      mvg.addView(t, mvg.getChildCount() - 1);

      ContactBean cb = new ContactBean();
      cb.setDisplayName(text);
      cb.setPhoneNum(number);
      if (null == selectContactList) {
        selectContactList = new ArrayList<ContactBean>();
      }
      selectContactList.add(cb);
      queryListView.setVisibility(View.INVISIBLE);
    }
  }
예제 #2
0
 @Override
 public void onClick(View v) {
   mvg.removeView(v);
   String number = (String) v.getTag();
   for (ContactBean cb : selectContactList) {
     if (cb.getPhoneNum().equals(number)) {
       selectContactList.remove(cb);
       break;
     }
   }
   autoHeight(mvg.getChildAt(mvg.getChildCount() - 1));
 }
예제 #3
0
    @Override
    protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
      if (cursor != null && cursor.getCount() > 0) {

        list = new ArrayList<ContactBean>();
        cursor.moveToFirst();
        for (int i = 0; i < cursor.getCount(); i++) {
          cursor.moveToPosition(i);
          String name = cursor.getString(1);
          String number = cursor.getString(2);
          String sortKey = cursor.getString(3);
          int contactId = cursor.getInt(4);
          Long photoId = cursor.getLong(5);
          String lookUpKey = cursor.getString(6);

          ContactBean cb = new ContactBean();
          cb.setDisplayName(name);
          cb.setPhoneNum(number);
          cb.setSortKey(sortKey);
          cb.setContactId(contactId);
          cb.setPhotoId(photoId);
          cb.setLookUpKey(lookUpKey);

          list.add(cb);
        }
        if (list.size() > 0) {
          setAdapter(list);
        }
        cursor.close();
      }
    }
예제 #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.new_sms);

    queryListView = (ListView) findViewById(R.id.list);

    btn_return = (Button) findViewById(R.id.btn_return);
    btn_return.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            NewSMSActivity.this.finish();
          }
        });
    add_btn = (Button) findViewById(R.id.add_btn);
    add_btn.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {

            if (null == etMess || "".equals(etMess.getText().toString())) {
            } else {
              String phoneNum = etMess.getText().toString();
              if (isNum(etMess.getText().toString().trim())) {
                createView1(phoneNum, phoneNum);
                etMess.setText("");
              } else {
                etMess.setText("");
              }
            }

            if (null == selectContactList || selectContactList.size() < 1) {
              BaseIntentUtil.intentSysDefault(
                  NewSMSActivity.this, SelectContactsToSendActivity.class, null);
            } else {
              Gson gson = new Gson();
              String data = gson.toJson(selectContactList);
              Map<String, String> map = new HashMap<String, String>();
              map.put("data", data);
              BaseIntentUtil.intentSysDefault(
                  NewSMSActivity.this, SelectContactsToSendActivity.class, map);
            }
          }
        });

    fasong = (Button) findViewById(R.id.fasong);
    neirong = (EditText) findViewById(R.id.neirong);

    fasong.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {

            if (null == etMess || "".equals(etMess.getText().toString())) {
            } else {
              String phoneNum = etMess.getText().toString();
              if (isNum(etMess.getText().toString().trim())) {
                createView1(phoneNum, phoneNum);
                etMess.setText("");
              } else {
                etMess.setText("");
              }
            }

            if (null == selectContactList || selectContactList.size() < 1) {
              Toast.makeText(NewSMSActivity.this, "请输入发送目标", Toast.LENGTH_SHORT).show();
            } else {
              for (ContactBean cb : selectContactList) {
                Log.d("NewSMSActivity", "Send: " + cb.getPhoneNum());
                String nei = neirong.getText().toString();
                ContentValues values = new ContentValues();
                values.put(BODY, nei);
                values.put(ADDRESS, cb.getPhoneNum());
                values.put(TYPE, MESSAGE_TYPE_SENT);
                values.put(DATE, System.currentTimeMillis());
                values.put(READ, 1);

                IAsyncQueryFactory mAsyncQueryFactory =
                    new SMSAsyncQueryFactory(
                        NewSMSActivity.this,
                        new IAsyncQueryHandler() {
                          @Override
                          public void onQueryComplete(int token, Object cookie, Cursor cursor) {}

                          @Override
                          public void onDeleteComplete(int token, Object cookie, int result) {}

                          @Override
                          public void onUpdateComplete(int token, Object cookie, int result) {}

                          @Override
                          public void onInsertComplete(int token, Object cookie, Uri uri) {}
                        });
                IAsyncQuery query = mAsyncQueryFactory.getLocalAsyncQuery();
                query.startInsert(values);
                // 直接调用短信接口发短信
                SmsManager smsManager = SmsManager.getDefault();
                List<String> divideContents = smsManager.divideMessage(nei);
                for (String text : divideContents) {
                  smsManager.sendTextMessage(cb.getPhoneNum(), null, text, null, null);
                }
              }
              neirong.setText("");
              finish();
            }
          }
        });

    asyncQuery = new MyAsyncQueryHandler(getContentResolver());
    query();

    initMyGroupView();

    if (null != getIntent().getStringExtra("list")) {
      String data = getIntent().getStringExtra("list");
      Gson gson = new Gson();
      Type listRet = new TypeToken<List<ContactBean>>() {}.getType();
      selectContactList = gson.fromJson(data, listRet);
      for (ContactBean cb : selectContactList) {
        createView2(cb.getDisplayName().trim());
        final View child = mvg.getChildAt(mvg.getChildCount() - 1);
        autoHeight(child);
      }
    }
  }