@Override
  public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info) {
    super.onCreateContextMenu(menu, view, info);
    final int viewId = view.getId();

    if (viewId == R.id.type) {
      for (final LogType typeOne : possibleLogTypes) {
        menu.add(viewId, typeOne.id, 0, typeOne.getL10n());
        Log.w("Adding " + typeOne + " " + typeOne.getL10n());
      }
    } else if (viewId == R.id.changebutton) {
      final int textId = ((TextView) findViewById(viewId)).getId();

      menu.setHeaderTitle(res.getString(R.string.log_tb_changeall));
      for (LogTypeTrackable logType : LogTypeTrackable.values()) {
        menu.add(textId, logType.id, 0, res.getString(logType.resourceId));
      }
    } else {
      final int realViewId = ((LinearLayout) findViewById(viewId)).getId();

      for (final cgTrackableLog tb : trackables) {
        if (tb.id == realViewId) {
          menu.setHeaderTitle(tb.name);
        }
      }
      for (LogTypeTrackable logType : LogTypeTrackable.values()) {
        menu.add(realViewId, logType.id, 0, res.getString(logType.resourceId));
      }
    }
  }
Beispiel #2
0
  private void selectTrackableAction(final View view) {
    final int realViewId = view.getId();
    final Builder alert = new AlertDialog.Builder(this);
    final TrackableLog trackableLog = actionButtons.get(realViewId);
    alert.setTitle(trackableLog.name);
    final List<LogTypeTrackable> tbLogTypeValues =
        LogTypeTrackable.getLogTypeTrackableForLogCache();
    final String[] tbLogTypes = getTBLogTypes(tbLogTypeValues);
    alert.setItems(
        tbLogTypes,
        new OnClickListener() {

          @Override
          public void onClick(final DialogInterface dialog, final int position) {
            final LogTypeTrackable logType = tbLogTypeValues.get(position);
            trackableLog.action = logType;
            Log.i(
                "Trackable "
                    + trackableLog.trackCode
                    + " ("
                    + trackableLog.name
                    + ") has new action: #"
                    + logType);
            updateTrackablesList();
            dialog.dismiss();
          }
        });
    alert.create().show();
  }
Beispiel #3
0
 private String[] getTBLogTypes() {
   final LogTypeTrackable[] logTypeValues = LogTypeTrackable.values();
   String[] logTypes = new String[logTypeValues.length];
   for (int i = 0; i < logTypes.length; i++) {
     logTypes[i] = res.getString(logTypeValues[i].resourceId);
   }
   return logTypes;
 }
Beispiel #4
0
  private void selectAllTrackablesAction() {
    final Builder alert = new AlertDialog.Builder(this);
    alert.setTitle(res.getString(R.string.log_tb_changeall));

    final List<LogTypeTrackable> tbLogTypeValues =
        LogTypeTrackable.getLogTypeTrackableForLogCache();
    final String[] tbLogTypes = getTBLogTypes(tbLogTypeValues);
    alert.setItems(
        tbLogTypes,
        new OnClickListener() {

          @Override
          public void onClick(final DialogInterface dialog, final int position) {
            final LogTypeTrackable logType = tbLogTypeValues.get(position);
            for (final TrackableLog tb : trackables) {
              tb.action = logType;
              Log.i("Trackable " + tb.trackCode + " (" + tb.name + ") has new action: #" + logType);
            }
            updateTrackablesList();
            dialog.dismiss();
          }
        });
    alert.create().show();
  }
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    final int group = item.getGroupId();
    final int id = item.getItemId();

    if (group == R.id.type) {
      setType(LogType.getById(id));

      return true;
    } else if (group == R.id.changebutton) {
      try {
        final LogTypeTrackable logType = LogTypeTrackable.findById(id);
        if (logType != null) {
          final LinearLayout inventView = (LinearLayout) findViewById(R.id.inventory);
          for (int count = 0; count < inventView.getChildCount(); count++) {
            final LinearLayout tbView = (LinearLayout) inventView.getChildAt(count);
            if (tbView == null) {
              return false;
            }

            final TextView tbText = (TextView) tbView.findViewById(R.id.action);
            if (tbText == null) {
              return false;
            }
            tbText.setText(res.getString(logType.resourceId) + " ▼");
          }
          for (cgTrackableLog tb : trackables) {
            tb.action = logType;
          }
          tbChanged = true;
          return true;
        }
      } catch (Exception e) {
        Log.e("cgeovisit.onContextItemSelected: " + e.toString());
      }
    } else {
      try {
        final LogTypeTrackable logType = LogTypeTrackable.findById(id);
        if (logType != null) {
          final LinearLayout tbView = (LinearLayout) findViewById(group);
          if (tbView == null) {
            return false;
          }

          final TextView tbText = (TextView) tbView.findViewById(R.id.action);
          if (tbText == null) {
            return false;
          }

          for (cgTrackableLog tb : trackables) {
            if (tb.id == group) {
              tbChanged = true;

              tb.action = logType;
              tbText.setText(res.getString(logType.resourceId) + " ▼");

              Log.i("Trackable " + tb.trackCode + " (" + tb.name + ") has new action: #" + id);
            }
          }

          return true;
        }
      } catch (Exception e) {
        Log.e("cgeovisit.onContextItemSelected: " + e.toString());
      }
    }

    return false;
  }