@Test public void renderTest() throws NoSuchFieldException, IllegalAccessException { View mMock = Mockito.mock(View.class); OkBelowDescriptionButtonRenderer.Builder mBuilder = new OkBelowDescriptionButtonRenderer.Builder(); mBuilder.withOkButton("ok", null); mBuilder.withBorder(2, 0); OkBelowDescriptionButtonRenderer renderer = mBuilder.build(); ReflectionUtil.setField(OkBelowDescriptionButtonRenderer.class, renderer, "inflated", mMock); TextView okBtn = Mockito.mock(TextView.class); when(mMock.getWidth()).thenReturn(5); when(mMock.findViewById(R.id.txt_ok_btn)).thenReturn(okBtn); LinearLayout groupOk = Mockito.mock(LinearLayout.class); when(mMock.findViewById(R.id.group_ok)).thenReturn(groupOk); Context mContextMock = Mockito.mock(Context.class); when(mMock.getContext()).thenReturn(mContextMock); Resources resMock = Mockito.mock(Resources.class); when(mContextMock.getResources()).thenReturn(resMock); when(resMock.getDimension(R.dimen.button_padding)).thenReturn(0f); CoachmarkViewLayout layout = Mockito.mock(CoachmarkViewLayout.class); when(layout.calcDescriptionRect()).thenReturn(new RectF(0, 0, 0, 0)); renderer.render(layout); verify(okBtn, times(1)).setText("ok"); verify(groupOk, times(1)).setOnClickListener(any(View.OnClickListener.class)); verify(groupOk, times(1)).setBackground(any(GradientDrawable.class)); verify(mMock, times(1)).setLayoutParams(any(FrameLayout.LayoutParams.class)); ArgumentCaptor<Runnable> fooCaptor = ArgumentCaptor.forClass(Runnable.class); verify(mMock).post(fooCaptor.capture()); fooCaptor.getValue().run(); verify(layout).calcDescriptionRect(); verify(mMock).setX(-2.5F); verify(mMock).setY(0); verify(mMock).setVisibility(View.VISIBLE); }
@Override public View render(final CoachmarkViewLayout layout) { if (inflated == null) { LayoutInflater inflater = (LayoutInflater) layout.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflated = inflater.inflate(R.layout.ok_below_description_button_view, null); layout.addView(inflated); } TextView mTxtOkBtn = (TextView) inflated.findViewById(R.id.txt_ok_btn); LinearLayout mGroupOk = (LinearLayout) inflated.findViewById(R.id.group_ok); mTxtOkBtn.setText(mOkText); mGroupOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mListener == null || mListener.onClicked()) { layout.dismiss(); } } }); if (mBorder != 0) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setStroke(mBorder, mColor != null ? mColor : ContextCompat.getColor(layout.getContext(),R.color.default_border_color)); mGroupOk.setBackground(gradientDrawable); } FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); inflated.setLayoutParams(params); inflated.post(new Runnable() { @Override public void run() { RectF descriptionRectangle = layout.calcDescriptionRect(); inflated.setX(descriptionRectangle.centerX() - ((float) inflated.getWidth() / 2)); inflated.setY(descriptionRectangle.bottom + inflated.getContext().getResources().getDimension(R.dimen.button_padding)); inflated.setVisibility(View.VISIBLE); } }); return inflated; }
OkBelowDescriptionButtonRenderer implements ButtonRenderer { @Override public View render(final CoachmarkViewLayout layout) { if (inflated == null) { LayoutInflater inflater = (LayoutInflater) layout.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflated = inflater.inflate(R.layout.ok_below_description_button_view, null); layout.addView(inflated); } TextView mTxtOkBtn = (TextView) inflated.findViewById(R.id.txt_ok_btn); LinearLayout mGroupOk = (LinearLayout) inflated.findViewById(R.id.group_ok); mTxtOkBtn.setText(mOkText); mGroupOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mListener == null || mListener.onClicked()) { layout.dismiss(); } } }); if (mBorder != 0) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setStroke(mBorder, mColor != null ? mColor : ContextCompat.getColor(layout.getContext(),R.color.default_border_color)); mGroupOk.setBackground(gradientDrawable); } FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); inflated.setLayoutParams(params); inflated.post(new Runnable() { @Override public void run() { RectF descriptionRectangle = layout.calcDescriptionRect(); inflated.setX(descriptionRectangle.centerX() - ((float) inflated.getWidth() / 2)); inflated.setY(descriptionRectangle.bottom + inflated.getContext().getResources().getDimension(R.dimen.button_padding)); inflated.setVisibility(View.VISIBLE); } }); return inflated; } }
OkBelowDescriptionButtonRenderer implements ButtonRenderer { @Override public View render(final CoachmarkViewLayout layout) { if (inflated == null) { LayoutInflater inflater = (LayoutInflater) layout.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflated = inflater.inflate(R.layout.ok_below_description_button_view, null); layout.addView(inflated); } TextView mTxtOkBtn = (TextView) inflated.findViewById(R.id.txt_ok_btn); LinearLayout mGroupOk = (LinearLayout) inflated.findViewById(R.id.group_ok); mTxtOkBtn.setText(mOkText); mGroupOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mListener == null || mListener.onClicked()) { layout.dismiss(); } } }); if (mBorder != 0) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setStroke(mBorder, mColor != null ? mColor : ContextCompat.getColor(layout.getContext(),R.color.default_border_color)); mGroupOk.setBackground(gradientDrawable); } FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); inflated.setLayoutParams(params); inflated.post(new Runnable() { @Override public void run() { RectF descriptionRectangle = layout.calcDescriptionRect(); inflated.setX(descriptionRectangle.centerX() - ((float) inflated.getWidth() / 2)); inflated.setY(descriptionRectangle.bottom + inflated.getContext().getResources().getDimension(R.dimen.button_padding)); inflated.setVisibility(View.VISIBLE); } }); return inflated; } private  OkBelowDescriptionButtonRenderer(); }
OkBelowDescriptionButtonRenderer implements ButtonRenderer { @Override public View render(final CoachmarkViewLayout layout) { if (inflated == null) { LayoutInflater inflater = (LayoutInflater) layout.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflated = inflater.inflate(R.layout.ok_below_description_button_view, null); layout.addView(inflated); } TextView mTxtOkBtn = (TextView) inflated.findViewById(R.id.txt_ok_btn); LinearLayout mGroupOk = (LinearLayout) inflated.findViewById(R.id.group_ok); mTxtOkBtn.setText(mOkText); mGroupOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mListener == null || mListener.onClicked()) { layout.dismiss(); } } }); if (mBorder != 0) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setStroke(mBorder, mColor != null ? mColor : ContextCompat.getColor(layout.getContext(),R.color.default_border_color)); mGroupOk.setBackground(gradientDrawable); } FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); inflated.setLayoutParams(params); inflated.post(new Runnable() { @Override public void run() { RectF descriptionRectangle = layout.calcDescriptionRect(); inflated.setX(descriptionRectangle.centerX() - ((float) inflated.getWidth() / 2)); inflated.setY(descriptionRectangle.bottom + inflated.getContext().getResources().getDimension(R.dimen.button_padding)); inflated.setVisibility(View.VISIBLE); } }); return inflated; } private  OkBelowDescriptionButtonRenderer(); @Override View render(final CoachmarkViewLayout layout); }
OkBelowDescriptionButtonRenderer implements ButtonRenderer { @Override public View render(final CoachmarkViewLayout layout) { if (inflated == null) { LayoutInflater inflater = (LayoutInflater) layout.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflated = inflater.inflate(R.layout.ok_below_description_button_view, null); layout.addView(inflated); } TextView mTxtOkBtn = (TextView) inflated.findViewById(R.id.txt_ok_btn); LinearLayout mGroupOk = (LinearLayout) inflated.findViewById(R.id.group_ok); mTxtOkBtn.setText(mOkText); mGroupOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mListener == null || mListener.onClicked()) { layout.dismiss(); } } }); if (mBorder != 0) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setStroke(mBorder, mColor != null ? mColor : ContextCompat.getColor(layout.getContext(),R.color.default_border_color)); mGroupOk.setBackground(gradientDrawable); } FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); inflated.setLayoutParams(params); inflated.post(new Runnable() { @Override public void run() { RectF descriptionRectangle = layout.calcDescriptionRect(); inflated.setX(descriptionRectangle.centerX() - ((float) inflated.getWidth() / 2)); inflated.setY(descriptionRectangle.bottom + inflated.getContext().getResources().getDimension(R.dimen.button_padding)); inflated.setVisibility(View.VISIBLE); } }); return inflated; } private  OkBelowDescriptionButtonRenderer(); @Override View render(final CoachmarkViewLayout layout);  }