package org.aplas.myshop; import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.GradientDrawable; import android.view.View; import android.widget.Adapter; import android.widget.CheckBox; import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.RelativeLayout; import android.widget.Spinner; import android.widget.TableLayout; import android.widget.TextView; import java.util.List; public class ElementTest extends org.aplas.myshop.ViewTest { private View component; private String compName; private String msgHeader; private String className; //private ArrayList testList = new ArrayList<>(); public ElementTest(View comp) { component =comp; compName = component.getContext().getResources().getResourceEntryName(component.getId()); className = component.getClass().getSimpleName(); msgHeader = "\n( "+compName+" - "+className+" ) "; } public void testIdName(String expected) { String msg = msgHeader + "Element Id Name is not suitable\n"; testItem(expected,compName,msg,1); } public void testWidth(int expected) { String msg = msgHeader + "Element width is not suitable\n"; testItem(expected,component.getLayoutParams().width,msg,1); } public void testHeight(int expected) { String msg = msgHeader + "Element height is not suitable\n"; testItem(expected,component.getLayoutParams().height,msg,1); } public void testWeight(float expected) { String msg = msgHeader + "Element height is not suitable\n"; testItem(expected,((LinearLayout.LayoutParams)component.getLayoutParams()).weight,msg,1); } public void testOrientation(int expected) { String msg = msgHeader + "Element orientation is not suitable\n"; testItem(expected,((LinearLayout)component).getOrientation(),msg,1); } public void testTopMargin(int expected) { String msg = msgHeader + "Element top margin is not suitable\n"; if (component.getLayoutParams().getClass().equals(RelativeLayout.LayoutParams.class)) { testItem(expected,((RelativeLayout.LayoutParams)component.getLayoutParams()).topMargin,msg,1); } else { testItem(expected, ((LinearLayout.LayoutParams) component.getLayoutParams()).topMargin, msg, 1); } } public void testBottomMargin(int expected) { String msg = msgHeader + "Element top margin is not suitable\n"; if (component.getLayoutParams().getClass().equals(RelativeLayout.LayoutParams.class)) { testItem(expected,((RelativeLayout.LayoutParams)component.getLayoutParams()).bottomMargin,msg,1); } else { testItem(expected, ((LinearLayout.LayoutParams) component.getLayoutParams()).bottomMargin, msg, 1); } } public void testPaddingLeft(int expected) { String msg = msgHeader + "Element left padding is not suitable\n"; testItem(expected,component.getPaddingLeft(),msg,1); } public void testPaddingRight(int expected) { String msg = msgHeader + "Element right padding is not suitable\n"; testItem(expected,component.getPaddingRight(),msg,1); } public void testPadding(int expected) { String msg = msgHeader + "Element padding is not suitable\n"; testItem(expected,component.getPaddingTop(),msg,1); testItem(expected,component.getPaddingBottom(),msg,1); testItem(expected,component.getPaddingLeft(),msg,1); testItem(expected,component.getPaddingRight(),msg,1); } public void testBgColor(int expected) { String msg = msgHeader + "Element Background color is not suitable\n"; testItem(expected,((ColorDrawable) component.getBackground()).getColor(),msg,1); } public void testBgGradientColor(int[] expected) { String msg = msgHeader + "Element Background gradient color is not suitable\n"; GradientDrawable draw = (GradientDrawable) component.getBackground(); //draw.getColors() testItem(expected[0],draw.getColors()[0],msg,1); testItem(expected[1],draw.getColors()[1],msg,1); testItem(expected[2],draw.getColors()[2],msg,1); } public void testTextString(String expected) { String msg = msgHeader + "Element text string is not suitable\n"; testItem(expected,((TextView)component).getText().toString(),msg,1); } public void testTextFace(Typeface expected) { String msg = msgHeader + "Element text font is not suitable\n"; testItem(expected,((TextView)component).getPaint().getTypeface(),msg,1); } public void testTextStyle(int expected) { String msg = msgHeader + "Element text style (bold/italic/normal) is not suitable\n"; testItem(expected,((TextView)component).getPaint().getTypeface().getStyle(),msg,1); } public void testTextColor(int expected) { String msg = msgHeader + "Element text color is not suitable\n"; testItem(expected,((TextView)component).getTextColors().getDefaultColor(),msg,1); } public void testTextSize(float expected) { String msg = msgHeader + "Element text size is not suitable\n"; /*if (className.equals("AppCompatSpinner")) { testItem(expected,((Spinner)component).get,msg,1); }*/ testItem(expected,((TextView)component).getTextSize(),msg,1); } public void testGravity(int expected) { String msg = msgHeader + "Element gravity orientation is not suitable\n"; if (className.equals("AppCompatSpinner")) { testItem(expected,((Spinner)component).getGravity(),msg,1); } else if (className.equals("AppCompatTextView")) { testItem(expected, ((TextView) component).getGravity(), msg, 1); } else if (className.equals("TableLayout")) { testItem(expected, ((LinearLayout)component).getGravity(), msg, 1); } } public void testAllCaps(boolean expected) { String msg = msgHeader + "Element all caps is not suitable\n"; testItem(expected,((TextView)component).isAllCaps(),msg,1); } public void testHintText(String expected) { String msg = msgHeader + "Element hint text is not suitable\n"; testItem(expected,((TextView)component).getHint().toString(),msg,1); } public void testInputType(int expected) { String msg = msgHeader + "Element input type is not suitable\n"; testItem(expected,((TextView)component).getInputType(),msg,1); } public void testIsEnabled(boolean expected) { String msg = msgHeader + "Element enabled value is not suitable\n"; testItem(expected,component.isEnabled(),msg,1); } public void testPromptText(String expected) { String msg = msgHeader + "Element prompt text is not suitable\n"; testItem(expected,((Spinner)component).getPrompt().toString(),msg,1); } public void testSpinnerMode(int expected) { String msg = msgHeader + "Element mode is not suitable\n"; if (expected==0) { testItem(expected,((Spinner)component).getDropDownVerticalOffset(),msg,1); } else { testItem(expected,((Spinner)component).getDropDownVerticalOffset()>0,msg,3); } } public void testSpinnerContent(List expected) { String msg = msgHeader + "Element spinner content is not suitable\n"; Adapter list = ((Spinner)component).getAdapter(); String res = ""; for (int i=0; i