예제 #1
0
  public void newEditText(final String propertyName) {

    int top =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
    LayoutParams linearParams =
        new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setPadding(0, top, 0, 0);
    linearLayout.setLayoutParams(linearParams);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    ll.addView(linearLayout);

    TextInputLayout v = new TextInputLayout(context);
    LayoutParams textInputParams =
        new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    v.setLayoutParams(textInputParams);

    linearLayout.addView(v);

    final EditText editText = new EditText(context);

    int width =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 200, getResources().getDisplayMetrics());
    LayoutParams editTextParams = new LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT);

    editText.setLayoutParams(editTextParams);
    editText.setInputType(InputType.TYPE_CLASS_TEXT);

    v.setHint("Message");

    v.addView(editText);

    //        int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200,
    // getResources().getDisplayMetrics());
    //        LayoutParams editTextParams = new LayoutParams(width,
    // ViewGroup.LayoutParams.WRAP_CONTENT);
    //        final EditText editText = new EditText(context);
    //        editText.setId(View.generateViewId());
    //        editText.setInputType(InputType.TYPE_CLASS_TEXT);
    //        editText.setHint("Your Text");
    //
    //        editText.setLayoutParams(editTextParams);
    //
    //        linearLayout.addView(editText);

    ImageButton button = new ImageButton(context);
    button.setImageResource(R.drawable.send);
    LayoutParams buttonParams = new LayoutParams(100, ViewGroup.LayoutParams.WRAP_CONTENT);
    button.setLayoutParams(buttonParams);

    button.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            try {
              thing.setProperty(propertyName, editText.getText().toString());
              thing.updateSubscribedProperties(500);
            } catch (Exception e) {
              e.printStackTrace();
            }
            editText.clearFocus();
            editText.setText("");
          }
        });
    linearLayout.addView(button);
  }
예제 #2
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);
  }