├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── lnyp │ │ └── imgdots │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── lnyp │ │ │ └── imgdots │ │ │ ├── activity │ │ │ ├── ImageBrowseActivity.java │ │ │ └── MainActivity.java │ │ │ ├── adapter │ │ │ └── ImgBrowsePagerAdapter.java │ │ │ ├── bean │ │ │ ├── ImgSimple.java │ │ │ └── PointSimple.java │ │ │ ├── utils │ │ │ └── UIUtil.java │ │ │ └── view │ │ │ └── ImageLayout.java │ └── res │ │ ├── drawable │ │ └── prod_point_img.xml │ │ ├── layout │ │ ├── activity_image_browse.xml │ │ ├── activity_main.xml │ │ ├── layout_img_browse.xml │ │ ├── layout_img_point.xml │ │ └── layout_imgview_point.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── left_bottom.png │ │ ├── left_top.png │ │ ├── right_bottom.png │ │ ├── rigth_top.png │ │ ├── test_1.jpg │ │ ├── test_2.jpg │ │ └── test_3.jpg │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── point_img.png │ │ ├── point_img1.png │ │ ├── point_img10.png │ │ ├── point_img11.png │ │ ├── point_img12.png │ │ ├── point_img13.png │ │ ├── point_img2.png │ │ ├── point_img3.png │ │ ├── point_img4.png │ │ ├── point_img5.png │ │ ├── point_img6.png │ │ ├── point_img7.png │ │ ├── point_img8.png │ │ └── point_img9.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── lnyp │ └── imgdots │ └── ExampleUnitTest.java ├── build.gradle ├── circle.yml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── imgs └── GIF.gif ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── bm │ │ └── library │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── bm │ └── library │ ├── Info.java │ ├── OnMatrixChangedListener.java │ ├── PhotoView.java │ └── RotateGestureDetector.java ├── newDots.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ImgDots 2 | [![GitHub version](https://badge.fury.io/gh/lihangleo2%2FImgdots.svg)](https://badge.fury.io/gh/lihangleo2%2FImgdots) 3 | 4 | 5 | 在图片的特定位置显示标签,标签可以点击 6 | 7 | 效果图: 8 | 9 | ![image](https://github.com/lihangleo2/Imgdots/blob/master/newDots.gif) 10 | 11 | 详细介绍: 12 | https://blog.csdn.net/leol_2/article/details/80225435 13 | 14 | 如果对你有所启发,请star下吧 15 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion '28.0.2' 6 | defaultConfig { 7 | applicationId "com.lnyp.imgdots" 8 | minSdkVersion 16 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(include: ['*.jar'], dir: 'libs') 23 | testCompile 'junit:junit:4.12' 24 | implementation 'com.android.support:appcompat-v7:28.0.0' 25 | compile 'com.apkfuns.logutils:library:1.0.6' 26 | compile 'com.github.bumptech.glide:glide:3.7.0' 27 | compile project(':library') 28 | } 29 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Java\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/lnyp/imgdots/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lnyp.imgdots; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/lnyp/imgdots/activity/ImageBrowseActivity.java: -------------------------------------------------------------------------------- 1 | package com.lnyp.imgdots.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.support.v4.view.ViewPager; 6 | import android.support.v7.app.AppCompatActivity; 7 | 8 | import com.lnyp.imgdots.R; 9 | import com.lnyp.imgdots.adapter.ImgBrowsePagerAdapter; 10 | import com.lnyp.imgdots.bean.ImgSimple; 11 | import com.lnyp.imgdots.bean.PointSimple; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class ImageBrowseActivity extends AppCompatActivity { 17 | 18 | private ViewPager viewPagerImgs; 19 | 20 | private List imgSimples; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | 26 | setContentView(R.layout.activity_image_browse); 27 | 28 | 29 | viewPagerImgs = (ViewPager) this.findViewById(R.id.viewPagerImgs); 30 | viewPagerImgs.setOffscreenPageLimit(2); 31 | 32 | initData(); 33 | 34 | PagerAdapter adapter = new ImgBrowsePagerAdapter(this, imgSimples); 35 | viewPagerImgs.setAdapter(adapter); 36 | 37 | } 38 | 39 | private void initData() { 40 | 41 | imgSimples = new ArrayList<>(); 42 | 43 | ImgSimple imgSimple1 = new ImgSimple(); 44 | imgSimple1.url = R.mipmap.test_1; 45 | imgSimple1.pic_with = 900; 46 | imgSimple1.pic_height = 1200; 47 | 48 | ArrayList pointSimples = new ArrayList<>(); 49 | PointSimple pointSimple1 = new PointSimple(); 50 | pointSimple1.pic_x = 900; 51 | pointSimple1.pic_y = 1200; 52 | pointSimple1.pointLeft_x = 320; 53 | pointSimple1.pointLeft_y = 30; 54 | pointSimple1.pointRight_x = 600; 55 | pointSimple1.pointRight_y = 380; 56 | pointSimples.add(pointSimple1); 57 | 58 | 59 | imgSimple1.pointSimples = pointSimples; 60 | 61 | 62 | ImgSimple imgSimple2 = new ImgSimple(); 63 | imgSimple2.url = R.mipmap.test_3; 64 | imgSimple2.pic_with = 566; 65 | imgSimple2.pic_height = 800; 66 | ArrayList pointSimples2 = new ArrayList<>(); 67 | PointSimple pointSimple7 = new PointSimple(); 68 | pointSimple7.pic_x = 566; 69 | pointSimple7.pic_y = 800; 70 | pointSimple7.pointLeft_x = 160; 71 | pointSimple7.pointLeft_y = 165; 72 | pointSimple7.pointRight_x = 400; 73 | pointSimple7.pointRight_y = 470; 74 | pointSimples2.add(pointSimple7); 75 | imgSimple2.pointSimples = pointSimples2; 76 | 77 | 78 | ImgSimple imgSimple3 = new ImgSimple(); 79 | imgSimple3.url = R.mipmap.test_2; 80 | imgSimple3.pic_with = 580; 81 | imgSimple3.pic_height = 435; 82 | ArrayList pointSimples3 = new ArrayList<>(); 83 | PointSimple pointSimple11 = new PointSimple(); 84 | pointSimple11.pic_x = 580; 85 | pointSimple11.pic_y = 435; 86 | pointSimple11.pointLeft_x = 300; 87 | pointSimple11.pointLeft_y = 50; 88 | pointSimple11.pointRight_x = 500; 89 | pointSimple11.pointRight_y = 250; 90 | pointSimples3.add(pointSimple11); 91 | 92 | 93 | 94 | imgSimple3.pointSimples = pointSimples3; 95 | imgSimples.add(imgSimple1); 96 | imgSimples.add(imgSimple2); 97 | imgSimples.add(imgSimple3); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/lnyp/imgdots/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.lnyp.imgdots.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | 8 | import com.lnyp.imgdots.R; 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | } 17 | 18 | public void btnClick(View view) { 19 | startActivity(new Intent(this, ImageBrowseActivity.class)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/lnyp/imgdots/adapter/ImgBrowsePagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lnyp.imgdots.adapter; 2 | 3 | import android.app.Activity; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.support.v4.view.ViewPager; 6 | import android.util.DisplayMetrics; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.LinearLayout; 11 | 12 | import com.lnyp.imgdots.R; 13 | import com.lnyp.imgdots.bean.ImgSimple; 14 | import com.lnyp.imgdots.bean.PointSimple; 15 | import com.lnyp.imgdots.view.ImageLayout; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | import static android.R.attr.width; 21 | 22 | public class ImgBrowsePagerAdapter extends PagerAdapter { 23 | 24 | List imgSimples; 25 | 26 | List views; 27 | 28 | Activity mContext; 29 | 30 | 31 | public ImgBrowsePagerAdapter(Activity context, List imgSimples) { 32 | 33 | this.mContext = context; 34 | this.imgSimples = imgSimples; 35 | 36 | this.views = new ArrayList<>(); 37 | 38 | DisplayMetrics dm = new DisplayMetrics(); 39 | context.getWindowManager().getDefaultDisplay().getMetrics(dm); 40 | 41 | } 42 | 43 | @Override 44 | public int getCount() { // 获得size 45 | return imgSimples.size(); 46 | } 47 | 48 | @Override 49 | public boolean isViewFromObject(View arg0, Object arg1) { 50 | return arg0 == arg1; 51 | } 52 | 53 | @Override 54 | public void destroyItem(ViewGroup container, int position, Object object) { 55 | 56 | ((ViewPager) container).removeView((View) object); 57 | } 58 | 59 | @Override 60 | public Object instantiateItem(ViewGroup container, int position) { 61 | 62 | LinearLayout view = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.layout_img_browse, null); 63 | ImageLayout layoutContent = (ImageLayout) view.findViewById(R.id.layoutContent); 64 | 65 | try { 66 | 67 | Integer imgUrl = imgSimples.get(position).url; 68 | int pic_with = imgSimples.get(position).pic_with; 69 | int pic_height = imgSimples.get(position).pic_height; 70 | ArrayList pointSimples = imgSimples.get(position).pointSimples; 71 | 72 | layoutContent.setPoints(pointSimples); 73 | layoutContent.setImgBg(pic_with,pic_height,imgUrl); 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | } 77 | 78 | ((ViewPager) container).addView(view); 79 | 80 | return view; 81 | } 82 | } -------------------------------------------------------------------------------- /app/src/main/java/com/lnyp/imgdots/bean/ImgSimple.java: -------------------------------------------------------------------------------- 1 | package com.lnyp.imgdots.bean; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class ImgSimple { 6 | 7 | public Integer url; 8 | public ArrayList pointSimples; 9 | public int pic_with; 10 | public int pic_height; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/lnyp/imgdots/bean/PointSimple.java: -------------------------------------------------------------------------------- 1 | package com.lnyp.imgdots.bean; 2 | 3 | /** 4 | * Created by lining on 2016/7/14. 5 | */ 6 | public class PointSimple { 7 | 8 | // 标记点相对于横向的宽度的比例 9 | // public int width_scale; 10 | // 标记点相对于横向的高度的比例 11 | // public int height_scale; 12 | public int pointLeft_x; 13 | public int pointLeft_y; 14 | public int pointRight_x; 15 | public int pointRight_y; 16 | public int pic_x; 17 | public int pic_y; 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/lnyp/imgdots/utils/UIUtil.java: -------------------------------------------------------------------------------- 1 | package com.lnyp.imgdots.utils; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageInfo; 5 | import android.content.pm.PackageManager; 6 | import android.os.Build; 7 | import android.telephony.TelephonyManager; 8 | import android.util.TypedValue; 9 | import android.view.WindowManager; 10 | 11 | import java.lang.reflect.Field; 12 | import java.util.Locale; 13 | import java.util.UUID; 14 | 15 | 16 | 17 | /** 18 | * Created by lihang Leo on 2016/12/10. 19 | */ 20 | public class UIUtil { 21 | 22 | private static final String TAG = UIUtil.class.getName(); 23 | 24 | /** 25 | * Dip to Px 26 | * 27 | * @param context 28 | * @param dipValue 29 | * @return 30 | */ 31 | public static int dip2px(Context context, float dipValue) { 32 | float scale = context.getResources().getDisplayMetrics().density; 33 | return (int) (dipValue * scale + 0.5f); 34 | } 35 | 36 | /** 37 | * Px To Dip 38 | * 39 | * @param context 40 | * @param pxValue 41 | * @return 42 | */ 43 | public static int px2dip(Context context, float pxValue) { 44 | float scale = context.getResources().getDisplayMetrics().density; 45 | return (int) (pxValue / scale + 0.5f); 46 | } 47 | 48 | //sp转px 49 | public static int Sp2Px(Context context, int sp) { 50 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics()); 51 | } 52 | 53 | 54 | public static int getWidth(Context context) { 55 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 56 | int width = wm.getDefaultDisplay().getWidth(); 57 | return width; 58 | } 59 | 60 | public static int getHeight(Context context) { 61 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 62 | int height = wm.getDefaultDisplay().getHeight(); 63 | return height; 64 | } 65 | 66 | //获取手机状态栏高度 67 | public static int getStatusBarHeight(Context context) { 68 | Class c = null; 69 | Object obj = null; 70 | Field field = null; 71 | int x = 0, statusBarHeight = 0; 72 | try { 73 | c = Class.forName("com.android.internal.R$dimen"); 74 | obj = c.newInstance(); 75 | field = c.getField("status_bar_height"); 76 | x = Integer.parseInt(field.get(obj).toString()); 77 | statusBarHeight = context.getResources().getDimensionPixelSize(x); 78 | } catch (Exception e1) { 79 | e1.printStackTrace(); 80 | } 81 | return statusBarHeight; 82 | } 83 | 84 | 85 | 86 | 87 | //获得独一无二的Psuedo ID 88 | public static String getDeviceId() { 89 | String serial = null; 90 | String m_szDevIDShort = "35" + 91 | Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + 92 | 93 | Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 + 94 | 95 | Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 + 96 | 97 | Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + 98 | 99 | Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 + 100 | 101 | Build.TAGS.length() % 10 + Build.TYPE.length() % 10 + 102 | 103 | Build.USER.length() % 10; //13 位 104 | 105 | try { 106 | serial = Build.class.getField("SERIAL").get(null).toString(); 107 | //API>=9 使用serial号 108 | return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString(); 109 | } catch (Exception exception) { 110 | //serial需要一个初始化 111 | serial = "serial"; // 随便一个初始化 112 | } 113 | //使用硬件信息拼凑出来的15位号码 114 | return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString(); 115 | } 116 | 117 | 118 | /** 119 | * 获取当前手机系统语言。 120 | * 121 | * @return 返回当前系统语言。例如:当前设置的是“中文-中国”,则返回“zh-CN” 122 | */ 123 | public static String getSystemLanguage() { 124 | return Locale.getDefault().getLanguage(); 125 | } 126 | 127 | /** 128 | * 获取当前系统上的语言列表(Locale列表) 129 | * 130 | * @return 语言列表 131 | */ 132 | public static Locale[] getSystemLanguageList() { 133 | return Locale.getAvailableLocales(); 134 | } 135 | 136 | /** 137 | * 获取当前手机系统版本号 138 | * 139 | * @return 系统版本号 140 | */ 141 | public static String getSystemVersion() { 142 | return Build.VERSION.RELEASE; 143 | } 144 | 145 | /** 146 | * 获取手机型号 147 | * 148 | * @return 手机型号 149 | */ 150 | public static String getSystemModel() { 151 | return Build.MODEL; 152 | } 153 | 154 | /** 155 | * 获取手机厂商 156 | * 157 | * @return 手机厂商 158 | */ 159 | public static String getDeviceBrand() { 160 | return Build.BRAND; 161 | } 162 | 163 | 164 | /** 165 | * get App versionCode 166 | * 167 | * @param context 168 | * @return 169 | */ 170 | public static String getVersionCode(Context context) { 171 | PackageManager packageManager = context.getPackageManager(); 172 | PackageInfo packageInfo; 173 | String versionCode = ""; 174 | try { 175 | packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); 176 | versionCode = packageInfo.versionCode + ""; 177 | } catch (PackageManager.NameNotFoundException e) { 178 | e.printStackTrace(); 179 | } 180 | return versionCode; 181 | } 182 | 183 | /** 184 | * get App versionName 185 | * 186 | * @param context 187 | * @return 188 | */ 189 | public static String getVersionName(Context context) { 190 | PackageManager packageManager = context.getPackageManager(); 191 | PackageInfo packageInfo; 192 | String versionName = ""; 193 | try { 194 | packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0); 195 | versionName = packageInfo.versionName; 196 | } catch (PackageManager.NameNotFoundException e) { 197 | e.printStackTrace(); 198 | } 199 | return versionName; 200 | } 201 | 202 | 203 | } 204 | -------------------------------------------------------------------------------- /app/src/main/java/com/lnyp/imgdots/view/ImageLayout.java: -------------------------------------------------------------------------------- 1 | package com.lnyp.imgdots.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.RectF; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.FrameLayout; 11 | import android.widget.ImageView; 12 | import android.widget.RelativeLayout; 13 | import android.widget.Toast; 14 | 15 | import com.bm.library.Info; 16 | import com.bm.library.OnMatrixChangedListener; 17 | import com.bm.library.PhotoView; 18 | import com.bumptech.glide.Glide; 19 | import com.lnyp.imgdots.R; 20 | import com.lnyp.imgdots.bean.PointSimple; 21 | import com.lnyp.imgdots.utils.UIUtil; 22 | 23 | import java.util.ArrayList; 24 | 25 | public class ImageLayout extends FrameLayout implements View.OnClickListener { 26 | 27 | ArrayList points; 28 | 29 | FrameLayout layouPoints; 30 | 31 | PhotoView imgBg; 32 | 33 | Context mContext; 34 | 35 | public ImageLayout(Context context) { 36 | this(context, null); 37 | } 38 | 39 | public ImageLayout(Context context, AttributeSet attrs) { 40 | this(context, attrs, 0); 41 | } 42 | 43 | public ImageLayout(Context context, AttributeSet attrs, int defStyleAttr) { 44 | super(context, attrs, defStyleAttr); 45 | 46 | initView(context, attrs); 47 | } 48 | 49 | 50 | private void initView(Context context, AttributeSet attrs) { 51 | 52 | mContext = context; 53 | 54 | View imgPointLayout = inflate(context, R.layout.layout_imgview_point, this); 55 | 56 | imgBg = (PhotoView) imgPointLayout.findViewById(R.id.imgBg); 57 | imgBg.enable(); 58 | imgBg.disableRotate(); 59 | imgBg.setOnClickListener(this); 60 | imgBg.setOnMatrixChangeListener(new OnMatrixChangedListener() { 61 | @Override 62 | public void onMatrixChanged(RectF rect) { 63 | Log.e("是不是有了",rect.toString()+""); 64 | Info info = PhotoView.getImageViewInfo(imgBg); 65 | int left = (int) info.getmImgRect().left; 66 | int top = (int) info.getmImgRect().top; 67 | int right = (int) info.getmImgRect().right; 68 | int bottom = (int) info.getmImgRect().bottom; 69 | addPoints(left,top,right,bottom); 70 | } 71 | }); 72 | 73 | 74 | layouPoints = (FrameLayout) imgPointLayout.findViewById(R.id.layouPoints); 75 | } 76 | 77 | @Override 78 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 79 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 80 | } 81 | 82 | @Override 83 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 84 | super.onSizeChanged(w, h, oldw, oldh); 85 | } 86 | 87 | public void setImgBg(int pic_with, int pic_height, Integer imgUrl) { 88 | 89 | ViewGroup.LayoutParams lp = imgBg.getLayoutParams(); 90 | lp.width = UIUtil.getWidth(getContext()); 91 | lp.height = UIUtil.getHeight(getContext()); 92 | imgBg.setLayoutParams(lp); 93 | 94 | 95 | ViewGroup.LayoutParams lp1 = layouPoints.getLayoutParams(); 96 | lp1.width = UIUtil.getWidth(getContext()); 97 | lp1.height = UIUtil.getHeight(getContext()); 98 | layouPoints.setLayoutParams(lp1); 99 | Glide.with(mContext).load(imgUrl).asBitmap().into(imgBg); 100 | 101 | // addPoints(UIUtil.getWidth(getContext()), UIUtil.getHeight(getContext())); 102 | 103 | } 104 | 105 | public void setPoints(ArrayList points) { 106 | 107 | this.points = points; 108 | } 109 | 110 | private void addPoints(int width, int height) { 111 | 112 | layouPoints.removeAllViews(); 113 | 114 | for (int i = 0; i < points.size(); i++) { 115 | 116 | int point_left_x = points.get(i).pointLeft_x; 117 | int point_left_y = points.get(i).pointLeft_y; 118 | int pic_with = points.get(i).pic_x; 119 | int pic_height = points.get(i).pic_y; 120 | 121 | int point_rigth_x = points.get(i).pointRight_x; 122 | int point_right_y = points.get(i).pointRight_y; 123 | 124 | int view_x = point_rigth_x - point_left_x; 125 | int view_y = point_right_y - point_left_y; 126 | 127 | 128 | RelativeLayout view = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.layout_img_point, this, false); 129 | RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.relative_point); 130 | relativeLayout.setTag(i); 131 | 132 | RelativeLayout.LayoutParams linlayout = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams(); 133 | linlayout.width = (width * view_x / pic_with); 134 | linlayout.height = UIUtil.getWidth(getContext()) * view_y / pic_with; 135 | 136 | 137 | LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); 138 | layoutParams.leftMargin = (int) (width * point_left_x / pic_with); 139 | layoutParams.topMargin = (int) (UIUtil.getWidth(getContext()) * point_left_y / pic_with); 140 | relativeLayout.setOnClickListener(this); 141 | layouPoints.addView(view, layoutParams); 142 | } 143 | } 144 | 145 | 146 | private void addPoints(int left, int top, int right, int bottom) { 147 | 148 | layouPoints.removeAllViews(); 149 | 150 | for (int i = 0; i < points.size(); i++) { 151 | 152 | int point_left_x = points.get(i).pointLeft_x; 153 | int point_left_y = points.get(i).pointLeft_y; 154 | int pic_with = points.get(i).pic_x; 155 | int pic_height = points.get(i).pic_y; 156 | int point_rigth_x = points.get(i).pointRight_x; 157 | int point_right_y = points.get(i).pointRight_y; 158 | 159 | 160 | //相对窗口宽度 161 | int screenWith = right - left; 162 | int screenHeight = bottom - top; 163 | 164 | 165 | int tempX = point_left_x * screenWith/ pic_with ; 166 | Log.e("我来看看是什么请撒",point_left_x+"==============="+pic_with+"`````````````"+screenWith); 167 | 168 | int tempY = point_left_y * screenHeight/ pic_height ; 169 | Log.e("我来看看是什么请撒",point_left_y+"==============="+pic_height+"`````````````"+screenHeight); 170 | 171 | //正确的坐标 左上角 172 | int trueX = left + tempX; 173 | int trueY = top + tempY; 174 | Log.e("这个Y轴是什么鬼",top+"----------------"+tempY); 175 | Log.e("我来看看是什么请撒",tempX+"==============="+tempY); 176 | 177 | //长宽 178 | int chaX = point_rigth_x - point_left_x; 179 | int chaY = point_right_y - point_left_y; 180 | 181 | int viewX = screenWith*chaX/pic_with; 182 | int viewY = screenHeight*chaY/pic_height; 183 | 184 | 185 | RelativeLayout view = (RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.layout_img_point, this, false); 186 | RelativeLayout relativeLayout = (RelativeLayout) view.findViewById(R.id.relative_point); 187 | relativeLayout.setTag(i); 188 | 189 | RelativeLayout.LayoutParams linlayout = (RelativeLayout.LayoutParams) relativeLayout.getLayoutParams(); 190 | linlayout.width = viewX; 191 | linlayout.height= viewY; 192 | 193 | 194 | LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); 195 | layoutParams.leftMargin = trueX; 196 | layoutParams.topMargin = trueY; 197 | relativeLayout.setOnClickListener(this); 198 | 199 | 200 | //左上角的点 201 | ImageView imageView_top_left = new ImageView(getContext()); 202 | LayoutParams leoParams_top_left = new LayoutParams(layoutParams.WRAP_CONTENT, layoutParams.WRAP_CONTENT); 203 | leoParams_top_left.leftMargin = trueX; 204 | leoParams_top_left.topMargin = trueY; 205 | imageView_top_left.setImageResource(R.mipmap.left_top); 206 | 207 | //左下角的点 208 | ImageView imageView_bottom_left = new ImageView(getContext()); 209 | LayoutParams leoParams_bottom_left = new LayoutParams(layoutParams.WRAP_CONTENT, layoutParams.WRAP_CONTENT); 210 | leoParams_bottom_left.leftMargin = trueX; 211 | leoParams_bottom_left.topMargin = trueY+viewY-60;//减去图片自身高度 212 | imageView_bottom_left.setImageResource(R.mipmap.left_bottom); 213 | 214 | 215 | //右上角的点 216 | ImageView imageView_top_right = new ImageView(getContext()); 217 | LayoutParams leoParams_top_right = new LayoutParams(layoutParams.WRAP_CONTENT, layoutParams.WRAP_CONTENT); 218 | leoParams_top_right.leftMargin = trueX+viewX-65; 219 | leoParams_top_right.topMargin = trueY; 220 | imageView_top_right.setImageResource(R.mipmap.rigth_top); 221 | 222 | 223 | //右下角的点 224 | ImageView imageView_bottom_right = new ImageView(getContext()); 225 | LayoutParams leoParams_bottom_right = new LayoutParams(layoutParams.WRAP_CONTENT, layoutParams.WRAP_CONTENT); 226 | leoParams_bottom_right.leftMargin = trueX+viewX-65; 227 | leoParams_bottom_right.topMargin = trueY+viewY-60; 228 | imageView_bottom_right.setImageResource(R.mipmap.right_bottom); 229 | 230 | 231 | layouPoints.addView(view, layoutParams); 232 | layouPoints.addView(imageView_top_left, leoParams_top_left); 233 | layouPoints.addView(imageView_bottom_left, leoParams_bottom_left); 234 | layouPoints.addView(imageView_top_right, leoParams_top_right); 235 | layouPoints.addView(imageView_bottom_right, leoParams_bottom_right); 236 | } 237 | } 238 | 239 | 240 | @Override 241 | public void onClick(View view) { 242 | switch (view.getId()) { 243 | case R.id.imgBg: 244 | Toast.makeText(getContext(), "点击了其他地方" + ((PhotoView) view).getScale(), Toast.LENGTH_SHORT).show(); 245 | // float f = ((PhotoView)view).getScale(); 246 | // addPoints((int) (UIUtil.getWidth(getContext())*f), (int) (UIUtil.getHeight(getContext())*f)); 247 | 248 | break; 249 | 250 | case R.id.relative_point: 251 | int pos = (int) view.getTag(); 252 | Toast.makeText(getContext(), "pos : " + pos, Toast.LENGTH_SHORT).show(); 253 | 254 | break; 255 | } 256 | 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/prod_point_img.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 10 | 13 | 16 | 19 | 22 | 25 | 28 | 31 | 34 | 37 | 40 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_image_browse.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 |