首页 > 系统 > Android > 正文

android 基于robotium 图像对比

2019-11-09 14:23:28
字体:
来源:转载
供稿:网友
/** * 确认View中的图片是否为指定的图片(只能对比资源文件中存在的图片) *  * @param view *            imageView对象或任意view(此时对比的是background) * @param pictureName *            开发定义图片名称 * @returns */@SupPRessWarnings("deprecation")public static boolean imageViewContainsPicture(Solo solo, View view, String pictureName) {   Activity activity = solo.getCurrentActivity();   int pictureId = activity.getapplicationContext().getResources().getIdentifier(pictureName, "drawable",         activity.getPackageName());   if (pictureId != 0) {      if (view instanceof ImageView) {         if (((ImageView) view).getDrawable().getCurrent().getConstantState().equals(               activity.getApplicationContext().getResources().getDrawable(pictureId).getConstantState())) {            return true;         }      } else {         DisplayMetrics dis = new DisplayMetrics();         activity.getWindowManager().getDefaultDisplay().getMetrics(dis);         Log.e(TAG, view.getBackground().getCurrent().getConstantState() + "");         Log.e(TAG, activity.getApplicationContext().getResources()               .getDrawableForDensity(pictureId, dis.densityDpi).getConstantState() + "");         // 对于不规则的四边形图像,比如说一个圆形图像,可能会失效         if (view.getBackground().getCurrent().getConstantState().equals(activity.getApplicationContext()               .getResources().getDrawableForDensity(pictureId, dis.densityDpi).getConstantState())) {            return true;         }      }   } else {      throw new RuntimeException("Util.imageViewContainsPicture()方法:资源文件中未找到图片id");   }   return false;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表