コード例 #1
0
 public static void tryCreateVar(@Nonnull final Context context) {
   final CalculatorDisplay display = Locator.getInstance().getDisplay();
   final CalculatorDisplayViewState viewState = display.getViewState();
   if (viewState.isValid()) {
     final String varValue = viewState.getText();
     if (!Strings.isEmpty(varValue)) {
       if (CalculatorVarsFragment.isValidValue(varValue)) {
         if (context instanceof SherlockFragmentActivity) {
           VarEditDialogFragment.showDialog(
               VarEditDialogFragment.Input.newFromValue(varValue),
               ((SherlockFragmentActivity) context).getSupportFragmentManager());
         } else {
           final Intent intent = new Intent(context, CalculatorVarsActivity.class);
           intent.putExtra(CalculatorVarsFragment.CREATE_VAR_EXTRA_STRING, varValue);
           Android.addIntentFlags(intent, false, context);
           context.startActivity(intent);
         }
       } else {
         getNotifier().showMessage(R.string.c_value_is_not_a_number, MessageType.error);
       }
     } else {
       getNotifier().showMessage(R.string.empty_var_error, MessageType.error);
     }
   } else {
     getNotifier().showMessage(R.string.not_valid_result, MessageType.error);
   }
 }
コード例 #2
0
  public PacketExtension parseExtension(XmlPullParser parser)
      throws XmlPullParserException, IOException, XMPPException {
    String hash = null;
    String version = null;
    String node = null;
    if (parser.getEventType() == XmlPullParser.START_TAG
        && parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT)) {
      hash = parser.getAttributeValue(null, "hash");
      version = parser.getAttributeValue(null, "ver");
      node = parser.getAttributeValue(null, "node");
    } else {
      throw new XMPPException("Malformed Caps element");
    }

    parser.next();

    if (!(parser.getEventType() == XmlPullParser.END_TAG
        && parser.getName().equalsIgnoreCase(EntityCapsManager.ELEMENT))) {
      throw new XMPPException("Malformed nested Caps element");
    }

    if (version != null && node != null) {
      return new CapsExtension(node, version, Strings.getNotEmpty(hash, ""));
    } else {
      throw new XMPPException("Caps element with missing attributes");
    }
  }
コード例 #3
0
 @Nonnull
 public PropertyView setValue(@Nullable CharSequence value) {
   final TextView valueView = getValueTextView();
   valueView.setText(value);
   valueView.setVisibility(Strings.isEmpty(value) ? GONE : VISIBLE);
   return this;
 }
コード例 #4
0
 private void commitText(@NotNull InputConnection ic, @Nullable CharSequence text, int position) {
   ic.commitText(text, position);
   if (!Strings.isEmpty(text)) {
     history.addState(
         new KeyboardInputHistoryState(AndroidKeyboardUtils.getTextFromInputConnection(ic), 0));
   }
 }
コード例 #5
0
 @Override
 public void onClick(@Nonnull IConstant data, @Nonnull Context context) {
   final String text = data.getValue();
   if (!Strings.isEmpty(text)) {
     if (text == null) throw new AssertionError();
     Locator.getInstance().getClipboard().setText(text);
   }
 }
コード例 #6
0
 @Override
 public void onClick(@Nonnull IConstant data, @Nonnull Context context) {
   final String text =
       Locator.getInstance().getEngine().getVarsRegistry().getDescription(data.getName());
   if (!Strings.isEmpty(text)) {
     if (text == null) throw new AssertionError();
     Locator.getInstance().getClipboard().setText(text);
   }
 }
コード例 #7
0
 @Override
 public void handlePaste() {
   final ClipboardManager clipboardManager =
       (ClipboardManager) inputMethodService.getSystemService(Context.CLIPBOARD_SERVICE);
   final CharSequence text = clipboardManager.getText();
   if (!Strings.isEmpty(text)) {
     commitText(text, 1);
   }
 }
コード例 #8
0
 private static void copy(@Nonnull AFunction target, @Nonnull IFunction source) {
   target.name = source.getName();
   target.content = source.getContent();
   target.description = Strings.getNotEmpty(source.getDescription(), "");
   target.system = source.isSystem();
   if (source.isIdDefined()) {
     target.id = source.getId();
   }
   target.parameterNames = new ArrayList<String>(source.getParameterNames());
 }
コード例 #9
0
  @Nonnull
  @Override
  protected List<LabeledMenuItem<IConstant>> getMenuItemsOnLongClick(@Nonnull IConstant item) {
    final List<LabeledMenuItem<IConstant>> result =
        new ArrayList<LabeledMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));

    if (item.isSystem()) {
      result.remove(LongClickMenuItem.edit);
      result.remove(LongClickMenuItem.remove);
    }

    if (Strings.isEmpty(
        Locator.getInstance().getEngine().getVarsRegistry().getDescription(item.getName()))) {
      result.remove(LongClickMenuItem.copy_description);
    }

    if (Strings.isEmpty(item.getValue())) {
      result.remove(LongClickMenuItem.copy_value);
    }

    return result;
  }
コード例 #10
0
  @Override
  public int translateKeyDown(int unicodeChar) {
    if (!Strings.isEmpty(typedText)) {
      char accent = typedText.charAt(typedText.length() - 1);
      int composed = KeyEvent.getDeadChar(accent, unicodeChar);

      if (composed != 0) {
        unicodeChar = composed;
        typedText.setLength(typedText.length() - 1);
      }
    }

    return unicodeChar;
  }
コード例 #11
0
 private void writeToFile(@Nonnull String stackTrace, @Nonnull String fileName) {
   try {
     BufferedWriter bos = null;
     try {
       bos = new BufferedWriter(new FileWriter(localPath + "/" + fileName));
       bos.write(stackTrace);
       bos.flush();
     } finally {
       if (bos != null) {
         bos.close();
       }
     }
   } catch (Exception e) {
     // unable to save to the file - strange
     Log.e(TAG, Strings.fromStackTrace(e.getStackTrace()));
   }
 }
コード例 #12
0
  @NotNull
  public static String inClause(@NotNull List<?> objects) {
    final StringBuilder result = new StringBuilder(3 * objects.size());

    result.append("(");
    if (objects.size() == 1) {
      result.append("?");
    } else if (objects.size() > 1) {
      result.append("?");
      result.append(Strings.repeat(", ?", objects.size() - 1));
    } else {
      result.append("'foo'");
    }
    result.append(")");

    return result.toString();
  }
コード例 #13
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Bundle bundle = getArguments();
    if (bundle != null) {
      final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
      if (!Strings.isEmpty(varValue)) {
        VarEditDialogFragment.showDialog(
            VarEditDialogFragment.Input.newFromValue(varValue), getFragmentManager());

        // in order to stop intent for other tabs
        bundle.remove(CREATE_VAR_EXTRA_STRING);
      }
    }

    setHasOptionsMenu(true);
  }
コード例 #14
0
  public static void tryCreateFunction(@Nonnull final Context context) {
    final CalculatorDisplay display = Locator.getInstance().getDisplay();
    final CalculatorDisplayViewState viewState = display.getViewState();

    if (viewState.isValid()) {
      final String functionValue = viewState.getText();
      if (!Strings.isEmpty(functionValue)) {

        FunctionEditDialogFragment.showDialog(
            FunctionEditDialogFragment.Input.newFromDisplay(viewState), context);

      } else {
        getNotifier().showMessage(R.string.empty_function_error, MessageType.error);
      }
    } else {
      getNotifier().showMessage(R.string.not_valid_result, MessageType.error);
    }
  }
コード例 #15
0
    @Nonnull
    public AFunction create() throws AFunction.Builder.CreationException {
      final AFunction result;
      if (id != null) {
        result = new AFunction(id);
      } else {
        result = new AFunction();
      }

      result.name = name;
      try {
        result.content = Locator.getInstance().getCalculator().prepareExpression(value).toString();
      } catch (CalculatorParseException e) {
        throw new CreationException(e);
      }
      result.system = system;
      result.description = Strings.getNotEmpty(description, "");
      result.parameterNames = new ArrayList<String>(parameterNames);

      return result;
    }
コード例 #16
0
  public static void tryPlot() {
    final CalculatorPlotter plotter = Locator.getInstance().getPlotter();
    final CalculatorDisplay display = Locator.getInstance().getDisplay();
    final CalculatorDisplayViewState viewState = display.getViewState();

    if (viewState.isValid()) {
      final String functionValue = viewState.getText();
      final Generic expression = viewState.getResult();
      if (!Strings.isEmpty(functionValue) && expression != null) {
        if (plotter.isPlotPossibleFor(expression)) {
          plotter.plot(expression);
        } else {
          getNotifier().showMessage(R.string.cpp_plot_too_many_variables, MessageType.error);
        }
      } else {
        getNotifier().showMessage(R.string.cpp_plot_empty_function_error, MessageType.error);
      }
    } else {
      getNotifier().showMessage(R.string.not_valid_result, MessageType.error);
    }
  }
コード例 #17
0
  public void uncaughtException(Thread t, Throwable e) {
    try {

      final Date time = new Date();

      final String stackTrace = getStackTrace(e);

      if (stackTrace != null) {
        if (localPath != null) {
          writeToFile(stackTrace, String.valueOf(time.getTime()) + ".stacktrace");
        }

        if (url != null) {
          sendToServer(stackTrace, time);
        }
      }
    } catch (Throwable anyException) {
      Log.e(TAG, Strings.fromStackTrace(anyException.getStackTrace()));
    } finally {
      defaultUEH.uncaughtException(t, e);
    }
  }