@Override
  public void call(String number) {
    // Woody Guo @ 2012/05/24
    if (number.equals(MAGIC_GENERATE_LOG_DATA)) {
      generateLog(true);
      mDialpad.setNumber(null);
      return;
    }
    if (number.equals(MAGIC_GENERATE_LOG_SDCARD)) {
      generateLog(false);
      mDialpad.setNumber(null);
      return;
    }
    // END

    // added by huizhang @2012/7/30
    if (number.equals(MAGIC_CALL_CIT)) {

      StartCit(true);
      mDialpad.setNumber(null);
      return;
    }
    // END

    CommonMethod.call(this, number);
  }
 @Override
 public void showDialpad(boolean show) {
   if (show) {
     mDialpad.show();
   } else {
     mDialpad.hide();
   }
 }
 @Override
 public void onFilterComplete(int count) {
   if ((count <= 0) && !TextUtils.isEmpty(mDialpad.getNumber())) {
     getListView().setVisibility(View.VISIBLE);
     // mLvMenus.setVisibility(View.VISIBLE);
   } else {
     // mLvMenus.setVisibility(View.GONE);
     getListView().setVisibility(View.VISIBLE);
   }
 }
  @Override
  public void loadAllContacts() { // called by beforetext changed.
    String number = mDialpad.getNumber();
    if (TextUtils.isEmpty(number)) { // enter first number, shold load contacts.
      log("loadAllContacts() loadDialpadItems...");
      final List<DialpadItem> items = PimEngine.getInstance(this).loadDialpadItems(false);

      mItemAdapter.setIsShowInFilterList(true);
      mItemAdapter.update(items, true);
    }
  }
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    {
      super.onListItemClick(l, v, position, id);
      DialpadItem item = (DialpadItem) l.getItemAtPosition(position);
      String number = item.getNumber();
      long contactId = item.getContactId();
      String name = item.getName();
      SharedPreferences mPrefs = getSharedPreferences("call_log_settings", Context.MODE_PRIVATE);

      int mClickOption = mPrefs.getInt("call_log_click_option", 0);

      log("onListItemClick: " + position + " " + number + "Clickoption = " + mClickOption);
      if (!TextUtils.isEmpty(number)) {
        if (mClickOption == 0) {
          CommonMethod.viewPimDetail(
              this,
              name,
              number,
              contactId,
              (item.getType() == DialpadItem.CALLLOG_TYPE
                  ? DetailEntry.LOG_DETAIL
                  : DetailEntry.CONTACT_DETAIL));
        } else {
          // Added by GanFeng 20120213, fix bug3391
          if ((null != mDialpad) && TextUtils.isEmpty(mDialpad.getNumber())) {
            long timeElapsed = Math.abs(System.currentTimeMillis() - mDialpad.getTimeStamp());
            if (timeElapsed < 1000) { // the elapsed time < 1S
              return;
            }
          }
          if ((null != mDialpad) && !TextUtils.isEmpty(mDialpad.getNumber())) {
            mDialpad.setNumber(null);
            mDialpad.showNumberUI();
          }
          call(number);
        }
      }
    }
  }
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    hideCaidan();

    switch (keyCode) {
      case KeyEvent.KEYCODE_CALL:
        {
          if (null != mDialpad) {
            String number = mDialpad.getNumber();
            if (!TextUtils.isEmpty(number)) {
              call(number);
            } else {
              number = getLastDialedNumber();
              if (!TextUtils.isEmpty(number)) {
                mDialpad.setNumber(number);
                mDialpad.show();
              }
            }
          }

          // break;
          return true;
        }

      case KeyEvent.KEYCODE_BACK:
        {
          if (mPopupWin != null) {
            mPopupWin.dismiss();
            mPopupWin = null;
            return true;
          }
        }

      default:
        break;
    }

    return super.onKeyDown(keyCode, event);
  }
 private void reloadDialpadItems() {
   String number = mDialpad.getNumber();
   if (TextUtils.isEmpty(number)) {
     categorizeCallLog(DialpadView.CALLLOG_TYPE_ALL);
     return;
   } else {
     final List<DialpadItem> items = PimEngine.getInstance(this).loadDialpadItems(false);
     // loge("reloadDialpadItems  items size=" + items.size());
     resetFilter();
     mItemAdapter.updateAndFilter(items, true, number, this);
     // filterNumber(number);
   }
 }
 public void setNumber(String number) {
   log("setNumber   number=" + number);
   mDialpad.setNumber(number);
   mDialpad.show();
 }
 @Override
 protected void onPause() {
   mDialpad.stopQueryLocation();
   super.onPause();
   mIsResume = false;
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dialpad_main_list);
    // setTitle(R.string.dialpad);

    PimStart.start(this.getApplicationContext());

    PimEngine pimEng = PimEngine.getInstance(this);
    pimEng.loadCallLogs(false);
    mPhotoLoader =
        new ContactPhotoLoader(
            this, R.drawable.ic_contact_list_picture, R.drawable.ic_contact_header_unknow);
    mNumLocationLoader = new NumberLocationLoader(this);
    final List<DialpadItem> logGroups = PimEngine.getInstance(this).loadDialpadItems(false);

    final int count = logGroups.size();
    if (count > 0) {
      final ArrayList<DialpadItem> newValues = new ArrayList<DialpadItem>(count);
      for (int i = 0; i < count; i++) {
        final DialpadItem item = logGroups.get(i);
        if (DialpadItem.CALLLOG_TYPE == item.getType()) {
          newValues.add(item);
        }
      }
      mItemAdapter =
          new DialpadListAdapter(this, newValues, mPhotoLoader, mNumLocationLoader, false);
    } else {
      mItemAdapter = new DialpadListAdapter(this, null, mPhotoLoader, mNumLocationLoader, false);
    }

    // mItemAdapter = new DialpadListAdapter(this, pimEng.loadCallLogItems(false),
    //        mPhotoLoader, mNumLocationLoader);
    setListAdapter(mItemAdapter);

    ListView lv = getListView();
    lv.setOnScrollListener(this);
    registerForContextMenu(lv);

    View dialpadView = findViewById(R.id.dialpad_keyboard);
    mDialpad = new DialpadView(dialpadView, this);

    Intent dialIntent = getIntent();
    if (null != dialIntent) {
      Uri telUri = dialIntent.getData();
      if (null != telUri) {
        mDialpad.setNumber(telUri.getSchemeSpecificPart());
        mDialpad.showNumberUI();
      }
    }

    mHandler = new Handler(Looper.myLooper(), this);

    /*IntentFilter intentFilter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL");
    intentFilter.addCategory("android.intent.category.DEFAULT");
    mOutgoingCallReceiver = new OutgoingCallReceiver();
    registerReceiver(mOutgoingCallReceiver, intentFilter);

    mCallListener = new CallListener();
    TelephonyManager telephonyMgr = (TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
    telephonyMgr.listen(mCallListener, PhoneStateListener.LISTEN_CALL_STATE);*/

    pimEng.addDataListenner(this);
  }