コード例 #1
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);
  }
コード例 #2
0
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    viewHolder = new ViewHolder(view);
    viewHolder.profileImageProgress.setVisibility(View.GONE);
    viewHolder.username.setText(username);
    final IconDrawable icon =
        new IconDrawable(getActivity(), FontAwesomeIcons.fa_camera)
            .colorRes(getActivity(), R.color.disableable_button_text)
            .sizeRes(getActivity(), R.dimen.fa_x_small);
    icon.setTintList(
        null); // IconDrawable is tinted by default, but we don't want it to be tinted here
    TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(
        viewHolder.changePhoto, icon, null, null, null);
    viewHolder.changePhoto.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            final PopupMenu popup = new PopupMenu(getActivity(), v);
            popup.getMenuInflater().inflate(R.menu.change_photo, popup.getMenu());
            popup.setOnMenuItemClickListener(
                new PopupMenu.OnMenuItemClickListener() {
                  public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                      case R.id.take_photo:
                        {
                          startActivityForResult(
                              helper.createCaptureIntent(getActivity()), CAPTURE_PHOTO_REQUEST);
                          break;
                        }
                      case R.id.choose_photo:
                        {
                          final Intent galleryIntent =
                              new Intent().setType("image/*").setAction(Intent.ACTION_GET_CONTENT);
                          startActivityForResult(galleryIntent, CHOOSE_PHOTO_REQUEST);
                          break;
                        }
                      case R.id.remove_photo:
                        {
                          executePhotoTask(
                              new DeleteAccountImageTask(getActivity(), username) {
                                @Override
                                protected void onSuccess(Void aVoid) throws Exception {
                                  hideLoading();
                                }

                                private void hideLoading() {
                                  if (null != viewHolder) {
                                    viewHolder.profileImageProgress.setVisibility(View.GONE);
                                  }
                                }
                              });
                          break;
                        }
                    }
                    return true;
                  }
                });
            popup.show();
          }
        });
    setData(account, formDescription);
  }