Esempio n. 1
0
  private void makeNumPad(Context context) {
    textView = new TextView(context);
    textView.setBackgroundColor(0x00000000);
    TableLayout tableLayout = new TableLayout(context);

    tableLayout.setId(41);
    int numRows = 5;
    int numCols = 3;

    htKeys = new Hashtable<Button, String>();
    int[] bgRscs =
        new int[] {
          R.drawable.key1,
          R.drawable.key2,
          R.drawable.key3,
          R.drawable.key4,
          R.drawable.key5,
          R.drawable.key6,
          R.drawable.key7,
          R.drawable.key8,
          R.drawable.key9,
          R.drawable.key_star,
          R.drawable.key0,
          R.drawable.key_sharp,
          R.drawable.key_speed_dial,
          R.drawable.key_call,
          R.drawable.key_delete
        };

    String[] keyChars = new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#"};

    int cntKey = 0;
    int w = APPWIDTH / numCols;
    int h = w * 2 / 3;
    for (int i = 0; i < numRows; i++) {
      TableRow tr = new TableRow(context);
      for (int j = 0; j < numCols; j++) {
        TableRow.LayoutParams params = new TableRow.LayoutParams(j);
        Button btn = new Button(context);
        btn.setBackgroundResource(bgRscs[cntKey]);
        btn.setLayoutParams(params);
        btn.setAlpha(0.60f);

        if (i < numRows - 1) {
          if (i == 0 && j == 0) {
            btnVoiceMail = btn;
            btn.setOnLongClickListener(
                new View.OnLongClickListener() {

                  @Override
                  public boolean onLongClick(View arg0) {
                    if (isCalling) {
                      return false;
                    }

                    posture = xacPostureSenseFeatureMaker.calculatePosture();
                    if (posture != xacPostureSenseFeatureMaker.NONE) {
                      return false;
                    }

                    //								Log.d(LOGTAG, "voice mail!");
                    LauncherManager.vibrate(500);
                    CallManager.playNextVoiceMail();
                    wasLongClick = true;
                    return false;
                  }
                });
          }

          htKeys.put(btn, keyChars[cntKey]);
          btn.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  if (isCalling) {
                    return;
                  }

                  posture = xacPostureSenseFeatureMaker.calculatePosture();
                  if (posture != xacPostureSenseFeatureMaker.NONE) {
                    return;
                  }

                  Button btn = (Button) view;
                  if (btn == btnVoiceMail && wasLongClick) {
                    wasLongClick = false;
                    return;
                  }
                  strKeys += htKeys.get(btn);
                  textView.setText(
                      new StringBuffer(
                              new StringBuffer(strKeys)
                                  .reverse()
                                  .toString()
                                  .substring(0, Math.min(strKeys.length(), 10)))
                          .reverse()
                          .toString());
                }
              });
        } else {
          if (i == 4 && j == 1) {
            // phone call

            btn.setOnClickListener(
                new View.OnClickListener() {

                  @Override
                  public void onClick(View arg0) {
                    if (isCalling) {
                      return;
                    }
                    //								layoutCallScreen.setBackgroundResource(R.drawable.call_out);
                    RelativeLayout.LayoutParams paramsCallScreen =
                        new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.MATCH_PARENT,
                            RelativeLayout.LayoutParams.MATCH_PARENT);
                    //								paramsCallScreen.addRule(RelativeLayout.ABOVE, layoutViews.getId());
                    appLayout.addView(layoutCallScreen, paramsCallScreen);
                    isCalling = true;
                  }
                });

          } else if (i == 4 && j == 2) {
            // delete

            btn.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                    if (isCalling) {
                      return;
                    }

                    posture = xacPostureSenseFeatureMaker.calculatePosture();
                    if (posture != xacPostureSenseFeatureMaker.NONE) {
                      return;
                    }

                    if (strKeys.length() > 0) {
                      strKeys = strKeys.substring(0, strKeys.length() - 1);
                      textView.setText(
                          new StringBuffer(
                                  new StringBuffer(strKeys)
                                      .reverse()
                                      .toString()
                                      .substring(0, Math.min(strKeys.length(), 10)))
                              .reverse()
                              .toString());
                    }
                  }
                });
          }
        }

        tr.addView(btn, w, h);

        cntKey++;
      }
      tableLayout.addView(
          tr,
          new TableLayout.LayoutParams(
              TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    }

    RelativeLayout.LayoutParams paramsKeys =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    paramsKeys.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    layoutCall.addView(tableLayout, paramsKeys);

    //		textView.setBackgroundColor(0xFF000000);
    textView.setText("");
    textView.setTextColor(0xFFFFFFFF);
    textView.setTextSize(60);
    textView.setTypeface(LauncherManager.getTypeface(LauncherManager.NORMAL));
    RelativeLayout.LayoutParams paramsText =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, layoutCall.getMeasuredHeight() - h * numRows);
    paramsText.addRule(RelativeLayout.ABOVE, tableLayout.getId());
    paramsText.bottomMargin = 100;
    layoutCall.addView(textView, paramsText);
  }
Esempio n. 2
0
  private void dispatchButtons(Context context) {

    buttons = new ArrayList<Button>();

    btnCall = new Button(context);
    btnCall.setText("Call");
    btnCall.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            if (idxTab != CALLTAB) {
              clearViews(idxTab);
              idxTab = CALLTAB;
              updateViews(idxTab);
            }
          }
        });
    buttons.add(btnCall);

    btnLog = new Button(context);
    btnLog.setText("Log");
    btnLog.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            if (idxTab != LOGTAB) {
              clearViews(idxTab);
              idxTab = LOGTAB;
              updateViews(idxTab);
            }
          }
        });
    buttons.add(btnLog);

    btnContact = new Button(context);
    btnContact.setText("Contact");
    btnContact.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {}
        });
    buttons.add(btnContact);

    Button btnLast = null;
    int idBtn = 1;
    layoutViews.setId(1027);
    int w = APPWIDTH / buttons.size();
    int h = w * 2 / 3;
    for (Button btn : buttons) {
      btn.setId(1027 + idBtn);
      btn.setBackgroundColor(0xDD000000);
      btn.setTextColor(0xFFFFFFFF);
      btn.setTypeface(LauncherManager.getTypeface(LauncherManager.NORMAL));
      btn.setTextSize(20);

      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(w, h);
      if (idBtn > 1) {
        params.addRule(RelativeLayout.RIGHT_OF, btnLast.getId());
      }
      params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
      layoutViews.addView(btn, params);
      idBtn++;
      btnLast = btn;
    }

    // appLayout.addView(layoutViews);
  }