示例#1
0
  public void setSyncText(SyncText sync) {
    this.syncText = sync;

    syncText.setOnTextChangeListener(
        new SyncText.OnTextChangeListener() {
          @Override
          public void onTextChange(
              final String currentText, final LinkedList<SyncTextDiff> diffs, int ver) {
            if (ver >= version) {
              updateText(diffs);
            }
          }
        });

    editText.addTextChangedListener(watcher);
  }
示例#2
0
 public String getText() {
   return editText.getText().toString();
 }
示例#3
0
 private void update() {
   if (syncText != null) {
     this.syncText.setPermissions(permissions);
     if ((permissions & PermissionManager.FLAG_WRITE) == PermissionManager.FLAG_WRITE) {
       editText.setVisibility(VISIBLE);
       overlay.setVisibility(GONE);
       editText.setInputType(inputType);
       editText.setEnabled(true);
       syncText.acceptSuggestions();
     } else if ((permissions & PermissionManager.FLAG_SUGGEST) == PermissionManager.FLAG_SUGGEST) {
       editText.setVisibility(VISIBLE);
       overlay.setVisibility(GONE);
       editText.setInputType(inputType);
       editText.setEnabled(true);
     } else if ((permissions & PermissionManager.FLAG_READ) == PermissionManager.FLAG_READ) {
       editText.setVisibility(VISIBLE);
       overlay.setVisibility(GONE);
       syncText.rejectSuggestions();
       editText.setInputType(EditorInfo.TYPE_NULL);
       editText.setEnabled(false);
     } else {
       editText.setVisibility(GONE);
       overlay.setVisibility(VISIBLE);
       syncText.rejectSuggestions();
       editText.setInputType(EditorInfo.TYPE_NULL);
       editText.setEnabled(false);
     }
   }
   if (!editable) {
     editText.disable();
   } else {
     editText.enable();
   }
 }
示例#4
0
  public void init(final Context context, AttributeSet attrs, int defStyleAttr) {
    FrameLayout.LayoutParams params =
        new FrameLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    textInputLayout = new TextInputLayout(context);
    textInputLayout.setLayoutParams(params);
    String hint = attrs.getAttributeValue(ANDROID_NS, "hint");
    if (hint != null) {
      textInputLayout.setHint(hint);
    }
    editText = new PermissionedEditText(context);
    editText.setSelectionListener(selectionListener);
    editText.setId(View.generateViewId());
    editText.setLayoutParams(params);
    int inputType = attrs.getAttributeIntValue(ANDROID_NS, "inputType", EditorInfo.TYPE_NULL);
    if (inputType != EditorInfo.TYPE_NULL) {
      editText.setInputType(inputType);
    }

    textInputLayout.addView(editText, params);
    addView(textInputLayout);

    overlay = new FrameLayout(context);
    overlay.setLayoutParams(
        new FrameLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
    //        overlay.setBackgroundColor(Color.BLACK);
    overlay.setBackgroundResource(R.drawable.permission_overlay_bg);
    overlay.setOnTouchListener(
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
              Toast.makeText(
                      getContext(), "This device does not have permission to view this field", 0)
                  .show();
            }
            return true;
          }
        });
    overlay.setVisibility(GONE);
    TextView overlayLabel = new TextView(context);
    overlayLabel.setTextSize(24);
    overlayLabel.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    overlayLabel.setText(hint + " Unavailable");

    overlay.addView(overlayLabel);
    addView(overlay);

    actionButton = new ImageView(context);
    IconDrawable drawable = new IconDrawable(context, MaterialIcons.md_check);
    drawable.color(Color.GREEN);
    actionButton.setImageDrawable(drawable);
    actionButton.setLayoutParams(new FrameLayout.LayoutParams(100, 100, Gravity.RIGHT));
    actionButton.setOnTouchListener(
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                {
                  ImageView view = (ImageView) v;
                  view.getDrawable().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
                  view.invalidate();
                  break;
                }
              case MotionEvent.ACTION_UP:
                if (permissionedTextListener != null) {
                  int aId = 0;
                  if (mPrimaryAction != null) {
                    aId = mPrimaryAction.id;
                  }
                  permissionedTextListener.onAction(aId, PermissionedTextLayout.this);
                }
              case MotionEvent.ACTION_CANCEL:
                {
                  ImageView view = (ImageView) v;
                  view.getDrawable().clearColorFilter();
                  view.invalidate();
                  break;
                }
            }
            return true;
          }
        });
    actionButton.setVisibility(GONE);
    addView(actionButton);
  }
示例#5
0
 public void setAutoCompleteAdapter(ArrayAdapter<String> adapter) {
   editText.setAdapter(adapter);
 }