コード例 #1
0
ファイル: MainActivity.java プロジェクト: Red680812/MyObdDemo
  private void addTableRow(String key, String val) {
    TableLayout tl = (TableLayout) findViewById(R.id.data_table);
    TableRow tr = new TableRow(this);
    MarginLayoutParams params =
        new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(TABLE_ROW_MARGIN, TABLE_ROW_MARGIN, TABLE_ROW_MARGIN, TABLE_ROW_MARGIN);
    tr.setLayoutParams(params);
    tr.setBackgroundColor(Color.BLACK);
    TextView name = new TextView(this);
    name.setGravity(Gravity.RIGHT);
    name.setText(key + ": ");
    TextView value = new TextView(this);
    value.setGravity(Gravity.LEFT);
    value.setText(val);
    tr.addView(name);
    tr.addView(value);
    tl.addView(
        tr, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    /*
     * TODO remove this hack
     *
     * let's define a limit number of rows
     */
    if (tl.getChildCount() > 10) tl.removeViewAt(0);
  }
コード例 #2
0
ファイル: GpsMainActivity.java プロジェクト: pari-m/gpslogger
  /** Displays a human readable summary of the preferences chosen by the user on the main form */
  private void ShowPreferencesSummary() {
    Utilities.LogDebug("GpsMainActivity.ShowPreferencesSummary");
    try {
      TextView txtLoggingTo = (TextView) findViewById(R.id.txtLoggingTo);
      TextView txtFrequency = (TextView) findViewById(R.id.txtFrequency);
      TextView txtDistance = (TextView) findViewById(R.id.txtDistance);
      TextView txtAutoEmail = (TextView) findViewById(R.id.txtAutoEmail);

      if (!AppSettings.shouldLogToKml() && !AppSettings.shouldLogToGpx()) {
        txtLoggingTo.setText(R.string.summary_loggingto_screen);

      } else if (AppSettings.shouldLogToGpx() && AppSettings.shouldLogToKml()) {
        txtLoggingTo.setText(R.string.summary_loggingto_both);
      } else {
        txtLoggingTo.setText((AppSettings.shouldLogToGpx() ? "GPX" : "KML"));
      }

      if (AppSettings.getMinimumSeconds() > 0) {
        String descriptiveTime =
            Utilities.GetDescriptiveTimeString(
                AppSettings.getMinimumSeconds(), getApplicationContext());

        txtFrequency.setText(descriptiveTime);
      } else {
        txtFrequency.setText(R.string.summary_freq_max);
      }

      if (AppSettings.getMinimumDistanceInMeters() > 0) {
        if (AppSettings.shouldUseImperial()) {
          int minimumDistanceInFeet =
              Utilities.MetersToFeet(AppSettings.getMinimumDistanceInMeters());
          txtDistance.setText(
              ((minimumDistanceInFeet == 1)
                  ? getString(R.string.foot)
                  : String.valueOf(minimumDistanceInFeet) + getString(R.string.feet)));
        } else {
          txtDistance.setText(
              ((AppSettings.getMinimumDistanceInMeters() == 1)
                  ? getString(R.string.meter)
                  : String.valueOf(AppSettings.getMinimumDistanceInMeters())
                      + getString(R.string.meters)));
        }
      } else {
        txtDistance.setText(R.string.summary_dist_regardless);
      }

      if (AppSettings.isAutoEmailEnabled()) {
        String autoEmailResx;

        if (AppSettings.getAutoEmailDelay() == 0) {
          autoEmailResx = "autoemail_frequency_whenistop";
        } else {

          autoEmailResx =
              "autoemail_frequency_"
                  + String.valueOf(AppSettings.getAutoEmailDelay()).replace(".", "");
        }

        String autoEmailDesc =
            getString(getResources().getIdentifier(autoEmailResx, "string", getPackageName()));

        txtAutoEmail.setText(autoEmailDesc);
      } else {
        TableRow trAutoEmail = (TableRow) findViewById(R.id.trAutoEmail);
        trAutoEmail.setVisibility(View.INVISIBLE);
      }

      onFileName(Session.getCurrentFileName());
    } catch (Exception ex) {
      Utilities.LogError("ShowPreferencesSummary", ex);
    }
  }
コード例 #3
0
ファイル: MainActivity.java プロジェクト: jreznot/diy-remote
    @Override
    protected void onPostExecute(List<Action> actions) {
      if (actions == null) {
        statusLabel.setText("Unable to get actions");
        return;
      }

      // all is ok, replace start pane
      LinearLayout contentPane = (LinearLayout) findViewById(R.id.contentPane);
      contentPane.removeView(startPane);

      LinearLayout buttonsLayout = new LinearLayout(getApplicationContext());
      buttonsLayout.setGravity(Gravity.CENTER);

      TableLayout buttonsTable = new TableLayout(getApplicationContext());
      TableRow currentTableRow = new TableRow(getApplicationContext());

      TableRow.LayoutParams buttonMarginParams =
          new TableRow.LayoutParams(
              TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
      int marginPx =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics());
      buttonMarginParams.setMargins(marginPx, marginPx, marginPx, marginPx);

      for (final Action action : actions) {
        ImageButton actionButton = new ImageButton(getApplicationContext());
        int drawableId = getResources().getIdentifier(action.icon, "drawable", getPackageName());
        actionButton.setImageDrawable(getResources().getDrawable(drawableId));
        actionButton.setContentDescription(action.description);
        actionButton.setLayoutParams(buttonMarginParams);
        actionButton.setBackgroundResource(R.drawable.button);
        actionButton.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                new PerformActionAsyncTask().execute(action.name);
              }
            });

        currentTableRow.addView(actionButton);
        if (currentTableRow.getChildCount() == 3) {
          buttonsTable.addView(currentTableRow);
          currentTableRow = new TableRow(getApplicationContext());
        }
      }

      if (currentTableRow.getChildCount() > 0) {
        buttonsTable.addView(currentTableRow);
      }

      buttonsLayout.addView(buttonsTable);

      LinearLayout.LayoutParams params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
      contentPane.addView(buttonsLayout, params);

      runStatusUpdateTimer();
    }