├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── abner │ │ └── stickerdemo │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── abner │ │ │ └── stickerdemo │ │ │ ├── DisplayActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── model │ │ │ ├── BubblePropertyModel.java │ │ │ └── StickerPropertyModel.java │ │ │ ├── utils │ │ │ ├── CommonUtils.java │ │ │ ├── DensityUtils.java │ │ │ └── FileUtils.java │ │ │ └── view │ │ │ ├── BubbleInputDialog.java │ │ │ ├── BubbleTextView.java │ │ │ └── StickerView.java │ └── res │ │ ├── drawable │ │ └── fab_label_background.xml │ │ ├── layout │ │ ├── activity_display.xml │ │ ├── activity_main.xml │ │ ├── content_display.xml │ │ ├── content_main.xml │ │ └── view_input_dialog.xml │ │ ├── menu │ │ ├── menu_dislplay.xml │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ ├── bubble_7_rb.png │ │ ├── ic_add_white.png │ │ ├── ic_background.jpg │ │ ├── ic_cat.png │ │ ├── ic_launcher.png │ │ ├── icon_delete.png │ │ ├── icon_flip.png │ │ ├── icon_resize.png │ │ └── icon_top_enable.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── abner │ └── stickerdemo │ └── ExampleUnitTest.java ├── bubbleShot.jpg ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── license.txt ├── settings.gradle ├── stickerGIF.gif └── sticker_demo.apk /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | # built application files 3 | *.apk 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Android Studio 26 | .idea 27 | *.iml 28 | 29 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 30 | .gradle 31 | 32 | # Windows thumbnail db 33 | Thumbs.db 34 | 35 | # OSX files 36 | .DS_Store 37 | 38 | .settings/ 39 | 40 | /*/out 41 | /*/*/build 42 | **/build 43 | /*/*/production 44 | *.iws 45 | *.ipr 46 | *~ 47 | *.swp 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Android Gems](http://www.android-gems.com/badge/nimengbo/StickerView.svg?branch=master)](http://www.android-gems.com/lib/nimengbo/StickerView) 2 | 3 | # StickerView 4 | 5 | 单手操作图片控件 镜像、置顶、缩放、移动 6 | 7 | ![](https://github.com/nimengbo/StickerView/blob/master/stickerGIF.gif) 8 | 9 | 10 | 增加可以添加文字 11 | 12 | ![](https://github.com/nimengbo/StickerView/blob/master/bubbleShot.jpg) 13 | 14 | 15 | FloatingActionButton address : https://github.com/futuresimple/android-floating-action-button 16 | 17 | License 18 | ======= 19 | 20 | The MIT License (MIT) 21 | 22 | Copyright (c) 2015 nimengbo 23 | 24 | Permission is hereby granted, free of charge, to any person obtaining a copy 25 | of this software and associated documentation files (the "Software"), to deal 26 | in the Software without restriction, including without limitation the rights 27 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | copies of the Software, and to permit persons to whom the Software is 29 | furnished to do so, subject to the following conditions: 30 | 31 | The above copyright notice and this permission notice shall be included in all 32 | copies or substantial portions of the Software. 33 | 34 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 40 | SOFTWARE. -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.example.abner.stickerdemo" 9 | minSdkVersion 14 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.0' 26 | compile 'com.android.support:design:23.1.0' 27 | compile 'com.getbase:floatingactionbutton:1.10.1' 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 /Users/Abner/myData/mySoftware/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/example/abner/stickerdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo; 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 | 8 | 9 | 10 | 11 | 12 | 13 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/DisplayActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo; 2 | 3 | import android.net.Uri; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.Toolbar; 7 | import android.text.TextUtils; 8 | import android.view.Menu; 9 | import android.view.MenuItem; 10 | import android.widget.ImageView; 11 | 12 | public class DisplayActivity extends AppCompatActivity { 13 | 14 | private ImageView mDisplayImageView; 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_display); 20 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 21 | setSupportActionBar(toolbar); 22 | if (getSupportActionBar() != null) { 23 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 24 | } 25 | mDisplayImageView = (ImageView) findViewById(R.id.iv_dis); 26 | String compoundPath = getIntent().getStringExtra("image"); 27 | if (!TextUtils.isEmpty(compoundPath)) { 28 | mDisplayImageView.setImageURI(Uri.parse(compoundPath)); 29 | } 30 | } 31 | 32 | @Override 33 | public boolean onCreateOptionsMenu(Menu menu) { 34 | // Inflate the menu; this adds items to the action bar if it is present. 35 | getMenuInflater().inflate(R.menu.menu_dislplay, menu); 36 | return true; 37 | } 38 | 39 | @Override 40 | public boolean onOptionsItemSelected(MenuItem item) { 41 | // Handle action bar item clicks here. The action bar will 42 | // automatically handle clicks on the Home/Up button, so long 43 | // as you specify a parent activity in AndroidManifest.xml. 44 | int id = item.getItemId(); 45 | 46 | //noinspection SimplifiableIfStatement 47 | if (id == android.R.id.home) { 48 | onBackPressed(); 49 | } 50 | 51 | return super.onOptionsItemSelected(item); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo; 2 | 3 | import android.content.Intent; 4 | import android.graphics.Bitmap; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.os.Bundle; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.Toolbar; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.View; 13 | import android.widget.RelativeLayout; 14 | 15 | import com.example.abner.stickerdemo.utils.FileUtils; 16 | import com.example.abner.stickerdemo.view.BubbleInputDialog; 17 | import com.example.abner.stickerdemo.view.BubbleTextView; 18 | import com.example.abner.stickerdemo.view.StickerView; 19 | import com.getbase.floatingactionbutton.FloatingActionsMenu; 20 | 21 | import java.util.ArrayList; 22 | 23 | public class MainActivity extends AppCompatActivity { 24 | 25 | //气泡输入框 26 | private BubbleInputDialog mBubbleInputDialog; 27 | 28 | //当前处于编辑状态的贴纸 29 | private StickerView mCurrentView; 30 | 31 | //当前处于编辑状态的气泡 32 | private BubbleTextView mCurrentEditTextView; 33 | 34 | //存储贴纸列表 35 | private ArrayList mViews; 36 | 37 | private RelativeLayout mContentRootView; 38 | 39 | private FloatingActionsMenu mMultipleActions; 40 | 41 | private View mAddSticker; 42 | 43 | private View mAddBubble; 44 | 45 | @Override 46 | protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.activity_main); 49 | mContentRootView = (RelativeLayout) findViewById(R.id.rl_content_root); 50 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 51 | setSupportActionBar(toolbar); 52 | 53 | // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 54 | // fab.setOnClickListener(new View.OnClickListener() { 55 | // @Override 56 | // public void onClick(View view) { 57 | // addStickerView(); 58 | // } 59 | // }); 60 | mMultipleActions = (FloatingActionsMenu) findViewById(R.id.multiple_actions); 61 | mAddSticker = findViewById(R.id.action_add_sticker); 62 | mAddBubble = findViewById(R.id.action_add_bubble); 63 | mAddSticker.setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View v) { 66 | addStickerView(); 67 | mMultipleActions.collapse(); 68 | } 69 | }); 70 | mAddBubble.setOnClickListener(new View.OnClickListener() { 71 | @Override 72 | public void onClick(View v) { 73 | addBubble(); 74 | mMultipleActions.collapse(); 75 | } 76 | }); 77 | mViews = new ArrayList<>(); 78 | mBubbleInputDialog = new BubbleInputDialog(this); 79 | mBubbleInputDialog.setCompleteCallBack(new BubbleInputDialog.CompleteCallBack() { 80 | @Override 81 | public void onComplete(View bubbleTextView, String str) { 82 | ((BubbleTextView) bubbleTextView).setText(str); 83 | } 84 | }); 85 | 86 | } 87 | 88 | @Override 89 | public boolean onCreateOptionsMenu(Menu menu) { 90 | // Inflate the menu; this adds items to the action bar if it is present. 91 | getMenuInflater().inflate(R.menu.menu_main, menu); 92 | return true; 93 | } 94 | 95 | @Override 96 | public boolean onOptionsItemSelected(MenuItem item) { 97 | // Handle action bar item clicks here. The action bar will 98 | // automatically handle clicks on the Home/Up button, so long 99 | // as you specify a parent activity in AndroidManifest.xml. 100 | int id = item.getItemId(); 101 | 102 | //noinspection SimplifiableIfStatement 103 | if (id == R.id.action_complete) { 104 | mCurrentView.setInEdit(false); 105 | generateBitmap(); 106 | return true; 107 | } 108 | 109 | return super.onOptionsItemSelected(item); 110 | } 111 | 112 | //添加表情 113 | private void addStickerView() { 114 | final StickerView stickerView = new StickerView(this); 115 | stickerView.setImageResource(R.mipmap.ic_cat); 116 | stickerView.setOperationListener(new StickerView.OperationListener() { 117 | @Override 118 | public void onDeleteClick() { 119 | mViews.remove(stickerView); 120 | mContentRootView.removeView(stickerView); 121 | } 122 | 123 | @Override 124 | public void onEdit(StickerView stickerView) { 125 | if (mCurrentEditTextView != null) { 126 | mCurrentEditTextView.setInEdit(false); 127 | } 128 | mCurrentView.setInEdit(false); 129 | mCurrentView = stickerView; 130 | mCurrentView.setInEdit(true); 131 | } 132 | 133 | @Override 134 | public void onTop(StickerView stickerView) { 135 | int position = mViews.indexOf(stickerView); 136 | if (position == mViews.size() - 1) { 137 | return; 138 | } 139 | StickerView stickerTemp = (StickerView) mViews.remove(position); 140 | mViews.add(mViews.size(), stickerTemp); 141 | } 142 | }); 143 | RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); 144 | mContentRootView.addView(stickerView, lp); 145 | mViews.add(stickerView); 146 | setCurrentEdit(stickerView); 147 | } 148 | 149 | //添加气泡 150 | private void addBubble() { 151 | final BubbleTextView bubbleTextView = new BubbleTextView(this, 152 | Color.WHITE, 0); 153 | bubbleTextView.setImageResource(R.mipmap.bubble_7_rb); 154 | bubbleTextView.setOperationListener(new BubbleTextView.OperationListener() { 155 | @Override 156 | public void onDeleteClick() { 157 | mViews.remove(bubbleTextView); 158 | mContentRootView.removeView(bubbleTextView); 159 | } 160 | 161 | @Override 162 | public void onEdit(BubbleTextView bubbleTextView) { 163 | if (mCurrentView != null) { 164 | mCurrentView.setInEdit(false); 165 | } 166 | mCurrentEditTextView.setInEdit(false); 167 | mCurrentEditTextView = bubbleTextView; 168 | mCurrentEditTextView.setInEdit(true); 169 | } 170 | 171 | @Override 172 | public void onClick(BubbleTextView bubbleTextView) { 173 | mBubbleInputDialog.setBubbleTextView(bubbleTextView); 174 | mBubbleInputDialog.show(); 175 | } 176 | 177 | @Override 178 | public void onTop(BubbleTextView bubbleTextView) { 179 | int position = mViews.indexOf(bubbleTextView); 180 | if (position == mViews.size() - 1) { 181 | return; 182 | } 183 | BubbleTextView textView = (BubbleTextView) mViews.remove(position); 184 | mViews.add(mViews.size(), textView); 185 | } 186 | }); 187 | RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); 188 | mContentRootView.addView(bubbleTextView, lp); 189 | mViews.add(bubbleTextView); 190 | setCurrentEdit(bubbleTextView); 191 | } 192 | 193 | /** 194 | * 设置当前处于编辑模式的贴纸 195 | */ 196 | private void setCurrentEdit(StickerView stickerView) { 197 | if (mCurrentView != null) { 198 | mCurrentView.setInEdit(false); 199 | } 200 | if (mCurrentEditTextView != null) { 201 | mCurrentEditTextView.setInEdit(false); 202 | } 203 | mCurrentView = stickerView; 204 | stickerView.setInEdit(true); 205 | } 206 | 207 | /** 208 | * 设置当前处于编辑模式的气泡 209 | */ 210 | private void setCurrentEdit(BubbleTextView bubbleTextView) { 211 | if (mCurrentView != null) { 212 | mCurrentView.setInEdit(false); 213 | } 214 | if (mCurrentEditTextView != null) { 215 | mCurrentEditTextView.setInEdit(false); 216 | } 217 | mCurrentEditTextView = bubbleTextView; 218 | mCurrentEditTextView.setInEdit(true); 219 | } 220 | 221 | private void generateBitmap() { 222 | 223 | Bitmap bitmap = Bitmap.createBitmap(mContentRootView.getWidth(), 224 | mContentRootView.getHeight() 225 | , Bitmap.Config.ARGB_8888); 226 | Canvas canvas = new Canvas(bitmap); 227 | mContentRootView.draw(canvas); 228 | 229 | String iamgePath = FileUtils.saveBitmapToLocal(bitmap, this); 230 | Intent intent = new Intent(this, DisplayActivity.class); 231 | intent.putExtra("image", iamgePath); 232 | startActivity(intent); 233 | } 234 | 235 | } 236 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/model/BubblePropertyModel.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by Abner on 15/6/11. 7 | * QQ 230877476 8 | * Email nimengbo@gmail.com 9 | */ 10 | public class BubblePropertyModel implements Serializable { 11 | private static final long serialVersionUID = 6339777989485920188L; 12 | //气泡id 13 | private long bubbleId; 14 | //文本 15 | private String text; 16 | //x坐标 17 | private float xLocation; 18 | //y坐标 19 | private float yLocation; 20 | //角度 21 | private float degree; 22 | //缩放值 23 | private float scaling; 24 | //气泡顺序 25 | private int order; 26 | 27 | public long getBubbleId() { 28 | return bubbleId; 29 | } 30 | 31 | public void setBubbleId(long bubbleId) { 32 | this.bubbleId = bubbleId; 33 | } 34 | 35 | public String getText() { 36 | return text; 37 | } 38 | 39 | public void setText(String text) { 40 | this.text = text; 41 | } 42 | 43 | public float getxLocation() { 44 | return xLocation; 45 | } 46 | 47 | public void setxLocation(float xLocation) { 48 | this.xLocation = xLocation; 49 | } 50 | 51 | public float getyLocation() { 52 | return yLocation; 53 | } 54 | 55 | public void setyLocation(float yLocation) { 56 | this.yLocation = yLocation; 57 | } 58 | 59 | public float getDegree() { 60 | return degree; 61 | } 62 | 63 | public void setDegree(float degree) { 64 | this.degree = degree; 65 | } 66 | 67 | public float getScaling() { 68 | return scaling; 69 | } 70 | 71 | public void setScaling(float scaling) { 72 | this.scaling = scaling; 73 | } 74 | 75 | public int getOrder() { 76 | return order; 77 | } 78 | 79 | public void setOrder(int order) { 80 | this.order = order; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/model/StickerPropertyModel.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by Abner on 15/6/11. 7 | * QQ 230877476 8 | * Email nimengbo@gmail.com 9 | */ 10 | public class StickerPropertyModel implements Serializable { 11 | private static final long serialVersionUID = 3800737478616389410L; 12 | 13 | //贴纸id 14 | private long stickerId; 15 | //文本 16 | private String text; 17 | //x坐标 18 | private float xLocation; 19 | //y坐标 20 | private float yLocation; 21 | //角度 22 | private float degree; 23 | //缩放值 24 | private float scaling; 25 | //气泡顺序 26 | private int order; 27 | 28 | //水平镜像 1镜像 2未镜像 29 | private int horizonMirror; 30 | 31 | //贴纸PNG URL 32 | private String stickerURL; 33 | 34 | public int getHorizonMirror() { 35 | return horizonMirror; 36 | } 37 | 38 | public void setHorizonMirror(int horizonMirror) { 39 | this.horizonMirror = horizonMirror; 40 | } 41 | 42 | public String getStickerURL() { 43 | return stickerURL; 44 | } 45 | 46 | public void setStickerURL(String stickerURL) { 47 | this.stickerURL = stickerURL; 48 | } 49 | 50 | public long getStickerId() { 51 | return stickerId; 52 | } 53 | 54 | public void setStickerId(long stickerId) { 55 | this.stickerId = stickerId; 56 | } 57 | 58 | public String getText() { 59 | return text; 60 | } 61 | 62 | public void setText(String text) { 63 | this.text = text; 64 | } 65 | 66 | public float getxLocation() { 67 | return xLocation; 68 | } 69 | 70 | public void setxLocation(float xLocation) { 71 | this.xLocation = xLocation; 72 | } 73 | 74 | public float getyLocation() { 75 | return yLocation; 76 | } 77 | 78 | public void setyLocation(float yLocation) { 79 | this.yLocation = yLocation; 80 | } 81 | 82 | public float getDegree() { 83 | return degree; 84 | } 85 | 86 | public void setDegree(float degree) { 87 | this.degree = degree; 88 | } 89 | 90 | public float getScaling() { 91 | return scaling; 92 | } 93 | 94 | public void setScaling(float scaling) { 95 | this.scaling = scaling; 96 | } 97 | 98 | public int getOrder() { 99 | return order; 100 | } 101 | 102 | public void setOrder(int order) { 103 | this.order = order; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/utils/CommonUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo.utils; 2 | 3 | /** 4 | * Created by Abner on 15/2/12. 5 | * QQ 230877476 6 | * Email nimengbo@gmail.com 7 | */ 8 | public class CommonUtils { 9 | 10 | 11 | private static String TAG = "CommonUtils"; 12 | private static long lastClickTime; 13 | private static int lastClickViewId; 14 | private static final int KEY_PREVENT_TS = -20000; 15 | 16 | 17 | /** 18 | * 计算分享内容的字数,一个汉字=两个英文字母,一个中文标点=两个英文标点 注意:该函数的不适用于对单个字符进行计算,因为单个字符四舍五入后都是1 19 | * 20 | * @param c 21 | * @return 22 | */ 23 | public static long calculateLength(CharSequence c) { 24 | double len = 0; 25 | for (int i = 0; i < c.length(); i++) { 26 | int tmp = (int) c.charAt(i); 27 | if (tmp > 0 && tmp < 127) { 28 | len += 0.5; 29 | } else { 30 | len++; 31 | } 32 | } 33 | return Math.round(len); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/utils/DensityUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.example.abner.stickerdemo.utils; 5 | 6 | import android.content.Context; 7 | import android.content.res.Resources; 8 | import android.view.Display; 9 | import android.view.WindowManager; 10 | 11 | import java.lang.reflect.Field; 12 | 13 | 14 | public class DensityUtils { 15 | /** 16 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 17 | */ 18 | public static int dip2px(Context context, float dpValue) { 19 | final float scale = context.getResources().getDisplayMetrics().density; 20 | return (int) (dpValue * scale + 0.5f); 21 | } 22 | 23 | /** 24 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp 25 | */ 26 | public static int px2dip(Context context, float pxValue) { 27 | final float scale = context.getResources().getDisplayMetrics().density; 28 | return (int) (pxValue / scale + 0.5f); 29 | } 30 | 31 | /** 32 | * 获取屏幕宽度 33 | * 34 | * @param context 35 | * @return 36 | */ 37 | public static int getScreenWidth(Context context) { 38 | Display display = ((WindowManager) context 39 | .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 40 | // Point p = new Point(); 41 | // display.getSize(p);//need api13 42 | return display.getWidth(); 43 | } 44 | 45 | public static int getScreenHeight(Context context) { 46 | Display display = ((WindowManager) context 47 | .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 48 | // Point p = new Point(); 49 | // display.getSize(p);//need api13 50 | int height = display.getHeight(); 51 | return height; 52 | } 53 | 54 | /** 55 | * 获取状态栏高度 56 | * 57 | * @param context 58 | * @return 59 | */ 60 | public static int getStatusBarHeight(Context context) { 61 | Class c = null; 62 | Object obj = null; 63 | Field field = null; 64 | int x = 0, sbar = 38;//默认为38,貌似大部分是这样的 65 | 66 | try { 67 | c = Class.forName("com.android.internal.R$dimen"); 68 | obj = c.newInstance(); 69 | field = c.getField("status_bar_height"); 70 | x = Integer.parseInt(field.get(obj).toString()); 71 | sbar = context.getResources().getDimensionPixelSize(x); 72 | 73 | } catch (Exception e1) { 74 | e1.printStackTrace(); 75 | } 76 | return sbar; 77 | } 78 | 79 | public static int getNavigationBarHeight(Context context) { 80 | Resources resources = context.getResources(); 81 | int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); 82 | if (resourceId > 0) { 83 | return resources.getDimensionPixelSize(resourceId); 84 | } 85 | return 0; 86 | } 87 | 88 | /** 89 | * 计算分享内容的字数,一个汉字=两个英文字母,一个中文标点=两个英文标点 注意:该函数的不适用于对单个字符进行计算,因为单个字符四舍五入后都是1 90 | * 91 | * @param c 92 | * @return 93 | */ 94 | public static long calculateLength(CharSequence c) { 95 | double len = 0; 96 | for (int i = 0; i < c.length(); i++) { 97 | int tmp = (int) c.charAt(i); 98 | if (tmp > 0 && tmp < 127) { 99 | len += 0.5; 100 | } else { 101 | len++; 102 | } 103 | } 104 | return Math.round(len); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo.utils; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.os.Environment; 6 | 7 | import java.io.File; 8 | import java.io.FileNotFoundException; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | 12 | /** 13 | * Created by Abner on 15/9/22. 14 | * QQ 230877476 15 | * Email nimengbo@gmail.com 16 | * github https://github.com/nimengbo 17 | */ 18 | public class FileUtils { 19 | 20 | private static FileUtils instance = null; 21 | 22 | private static Context mContext; 23 | 24 | private static final String APP_DIR = "Abner"; 25 | 26 | private static final String TEMP_DIR = "Abner/.TEMP"; 27 | 28 | public static FileUtils getInstance(Context context) { 29 | if (instance == null) { 30 | synchronized (FileUtils.class) { 31 | if (instance == null) { 32 | mContext = context.getApplicationContext(); 33 | instance = new FileUtils(); 34 | } 35 | } 36 | } 37 | return instance; 38 | } 39 | 40 | /** 41 | * 保存图像到本地 42 | * 43 | * @param bm 44 | * @return 45 | */ 46 | public static String saveBitmapToLocal(Bitmap bm, Context context) { 47 | String path = null; 48 | try { 49 | File file = FileUtils.getInstance(context).createTempFile("IMG_", ".jpg"); 50 | FileOutputStream fos = new FileOutputStream(file); 51 | bm.compress(Bitmap.CompressFormat.JPEG, 100, fos); 52 | fos.flush(); 53 | fos.close(); 54 | path = file.getAbsolutePath(); 55 | } catch (FileNotFoundException e) { 56 | e.printStackTrace(); 57 | return null; 58 | } catch (IOException e) { 59 | e.printStackTrace(); 60 | return null; 61 | } 62 | 63 | return path; 64 | } 65 | 66 | /** 67 | * @param prefix 68 | * @param extension 69 | * @return 70 | * @throws java.io.IOException 71 | */ 72 | public File createTempFile(String prefix, String extension) 73 | throws IOException { 74 | File file = new File(getAppDirPath() + ".TEMP/" + prefix 75 | + System.currentTimeMillis() + extension); 76 | file.createNewFile(); 77 | return file; 78 | } 79 | 80 | /** 81 | * 得到当前应用程序内容目录,外部存储空间不可用时返回null 82 | * 83 | * @return 84 | */ 85 | public String getAppDirPath() { 86 | String path = null; 87 | if (getLocalPath() != null) { 88 | path = getLocalPath() + APP_DIR + "/"; 89 | } 90 | return path; 91 | } 92 | 93 | /** 94 | * 得到当前app的目录 95 | * 96 | * @return 97 | */ 98 | private static String getLocalPath() { 99 | String sdPath = null; 100 | sdPath = mContext.getFilesDir().getAbsolutePath() + "/"; 101 | return sdPath; 102 | } 103 | 104 | /** 105 | * 检查sd卡是否就绪并且可读写 106 | * 107 | * @return 108 | */ 109 | public boolean isSDCanWrite() { 110 | String status = Environment.getExternalStorageState(); 111 | if (status.equals(Environment.MEDIA_MOUNTED) 112 | && Environment.getExternalStorageDirectory().canWrite() 113 | && Environment.getExternalStorageDirectory().canRead()) { 114 | return true; 115 | } else { 116 | return false; 117 | } 118 | } 119 | 120 | private FileUtils() { 121 | // 创建应用内容目录 122 | if (isSDCanWrite()) { 123 | creatSDDir(APP_DIR); 124 | creatSDDir(TEMP_DIR); 125 | } 126 | } 127 | 128 | /** 129 | * 在SD卡根目录上创建目录 130 | * 131 | * @param dirName 132 | */ 133 | public File creatSDDir(String dirName) { 134 | File dir = new File(getLocalPath() + dirName); 135 | dir.mkdirs(); 136 | return dir; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/view/BubbleInputDialog.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo.view; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.os.Handler; 6 | import android.text.Editable; 7 | import android.text.TextUtils; 8 | import android.text.TextWatcher; 9 | import android.view.KeyEvent; 10 | import android.view.View; 11 | import android.view.inputmethod.EditorInfo; 12 | import android.view.inputmethod.InputMethodManager; 13 | import android.widget.EditText; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.example.abner.stickerdemo.R; 18 | import com.example.abner.stickerdemo.utils.CommonUtils; 19 | 20 | /** 21 | * Created by Abner on 15/6/12. 22 | * QQ 230877476 23 | * Email nimengbo@gmail.com 24 | */ 25 | public class BubbleInputDialog extends Dialog { 26 | private final String defaultStr; 27 | private EditText et_bubble_input; 28 | private TextView tv_show_count; 29 | private TextView tv_action_done; 30 | private static final int MAX_COUNT = 33; //字数最大限制33个 31 | private Context mContext; 32 | private BubbleTextView bubbleTextView; 33 | 34 | public BubbleInputDialog(Context context) { 35 | super(context, android.R.style.Theme_Translucent_NoTitleBar); 36 | mContext = context; 37 | defaultStr = context.getString(R.string.double_click_input_text); 38 | initView(); 39 | } 40 | 41 | public BubbleInputDialog(Context context, BubbleTextView view) { 42 | super(context, android.R.style.Theme_Translucent_NoTitleBar); 43 | mContext = context; 44 | defaultStr = context.getString(R.string.double_click_input_text); 45 | bubbleTextView = view; 46 | initView(); 47 | } 48 | 49 | public void setBubbleTextView(BubbleTextView bubbleTextView) { 50 | this.bubbleTextView = bubbleTextView; 51 | if (defaultStr.equals(bubbleTextView.getmStr())) { 52 | et_bubble_input.setText(""); 53 | } else { 54 | et_bubble_input.setText(bubbleTextView.getmStr()); 55 | et_bubble_input.setSelection(bubbleTextView.getmStr().length()); 56 | } 57 | } 58 | 59 | 60 | private void initView() { 61 | setContentView(R.layout.view_input_dialog); 62 | tv_action_done = (TextView) findViewById(R.id.tv_action_done); 63 | et_bubble_input = (EditText) findViewById(R.id.et_bubble_input); 64 | tv_show_count = (TextView) findViewById(R.id.tv_show_count); 65 | et_bubble_input.addTextChangedListener(new TextWatcher() { 66 | @Override 67 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 68 | 69 | } 70 | 71 | @Override 72 | public void onTextChanged(CharSequence s, int start, int before, int count) { 73 | long textLength = CommonUtils.calculateLength(s); 74 | tv_show_count.setText(String.valueOf(MAX_COUNT - textLength)); 75 | if (textLength > MAX_COUNT) { 76 | tv_show_count.setTextColor(mContext.getResources().getColor(R.color.red_e73a3d)); 77 | } else { 78 | tv_show_count.setTextColor(mContext.getResources().getColor(R.color.grey_8b8b8b)); 79 | } 80 | } 81 | 82 | @Override 83 | public void afterTextChanged(Editable s) { 84 | 85 | } 86 | }); 87 | et_bubble_input.setOnEditorActionListener(new TextView.OnEditorActionListener() { 88 | @Override 89 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 90 | if (actionId == EditorInfo.IME_ACTION_DONE) { 91 | done(); 92 | return true; 93 | } 94 | return false; 95 | } 96 | }); 97 | tv_action_done.setOnClickListener(new View.OnClickListener() { 98 | @Override 99 | public void onClick(View v) { 100 | done(); 101 | } 102 | }); 103 | } 104 | 105 | 106 | @Override 107 | public void show() { 108 | super.show(); 109 | Handler handler = new Handler(); 110 | handler.postDelayed(new Runnable() { 111 | @Override 112 | public void run() { 113 | InputMethodManager m = (InputMethodManager) et_bubble_input.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 114 | m.toggleSoftInput(0, InputMethodManager.SHOW_FORCED); 115 | } 116 | }, 500); 117 | 118 | } 119 | 120 | @Override 121 | public void dismiss() { 122 | super.dismiss(); 123 | InputMethodManager m = (InputMethodManager) et_bubble_input.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 124 | m.hideSoftInputFromWindow(et_bubble_input.getWindowToken(), 0); 125 | } 126 | 127 | public interface CompleteCallBack { 128 | void onComplete(View bubbleTextView, String str); 129 | } 130 | 131 | private CompleteCallBack mCompleteCallBack; 132 | 133 | public void setCompleteCallBack(CompleteCallBack completeCallBack) { 134 | this.mCompleteCallBack = completeCallBack; 135 | } 136 | 137 | private void done() { 138 | if (Integer.valueOf(tv_show_count.getText().toString()) < 0) { 139 | Toast.makeText(mContext, mContext.getString(R.string.over_text_limit), Toast.LENGTH_SHORT).show(); 140 | return; 141 | } 142 | dismiss(); 143 | if (mCompleteCallBack != null) { 144 | String str; 145 | if (TextUtils.isEmpty(et_bubble_input.getText())) { 146 | str = ""; 147 | } else { 148 | str = et_bubble_input.getText().toString(); 149 | } 150 | mCompleteCallBack.onComplete(bubbleTextView, str); 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/view/BubbleTextView.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Matrix; 9 | import android.graphics.Paint; 10 | import android.graphics.PaintFlagsDrawFilter; 11 | import android.graphics.PointF; 12 | import android.graphics.Rect; 13 | import android.support.v4.view.MotionEventCompat; 14 | import android.text.TextPaint; 15 | import android.text.TextUtils; 16 | import android.util.AttributeSet; 17 | import android.util.DisplayMetrics; 18 | import android.util.Log; 19 | import android.util.TypedValue; 20 | import android.view.MotionEvent; 21 | import android.widget.ImageView; 22 | 23 | import com.example.abner.stickerdemo.R; 24 | import com.example.abner.stickerdemo.model.BubblePropertyModel; 25 | import com.example.abner.stickerdemo.utils.DensityUtils; 26 | 27 | 28 | /** 29 | * Created by Abner on 15/6/7. 30 | * QQ 230877476 31 | * Email nimengbo@gmail.com 32 | */ 33 | public class BubbleTextView extends ImageView { 34 | 35 | private static final String TAG = "BubbleTextView"; 36 | 37 | 38 | private Bitmap deleteBitmap; 39 | private Bitmap flipVBitmap; 40 | private Bitmap topBitmap; 41 | private Bitmap resizeBitmap; 42 | private Bitmap mBitmap; 43 | private Bitmap originBitmap; 44 | private Rect dst_delete; 45 | private Rect dst_resize; 46 | private Rect dst_flipV; 47 | private Rect dst_top; 48 | 49 | 50 | private int deleteBitmapWidth; 51 | private int deleteBitmapHeight; 52 | private int resizeBitmapWidth; 53 | private int resizeBitmapHeight; 54 | private int flipVBitmapWidth; 55 | private int flipVBitmapHeight; 56 | 57 | //置顶 58 | private int topBitmapWidth; 59 | private int topBitmapHeight; 60 | private Paint localPaint; 61 | private int mScreenwidth, mScreenHeight; 62 | private static final float BITMAP_SCALE = 0.7f; 63 | private PointF mid = new PointF(); 64 | private OperationListener operationListener; 65 | private float lastRotateDegree; 66 | 67 | //是否是第二根手指放下 68 | private boolean isPointerDown = false; 69 | //手指移动距离必须超过这个数值 70 | private final float pointerLimitDis = 20f; 71 | private final float pointerZoomCoeff = 0.09f; 72 | 73 | private final float moveLimitDis = 0.5f; 74 | /** 75 | * 对角线的长度 76 | */ 77 | private float lastLength; 78 | private boolean isInResize = false; 79 | 80 | private Matrix matrix = new Matrix(); 81 | /** 82 | * 是否在四条线内部 83 | */ 84 | private boolean isInSide; 85 | 86 | private float lastX, lastY; 87 | /** 88 | * 是否在编辑模式 89 | */ 90 | private boolean isInEdit = true; 91 | 92 | private float MIN_SCALE = 0.5f; 93 | 94 | private float MAX_SCALE = 1.5f; 95 | 96 | private double halfDiagonalLength; 97 | 98 | private float oringinWidth = 0; 99 | 100 | private DisplayMetrics dm; 101 | 102 | /** 103 | * 文字部分 104 | */ 105 | private final String defaultStr; 106 | //显示的字符串 107 | private String mStr = ""; 108 | 109 | //字号默认16sp 110 | private final float mDefultSize = 16; 111 | private float mFontSize = 16; 112 | //最大最小字号 113 | private final float mMaxFontSize = 25; 114 | private final float mMinFontSize = 14; 115 | 116 | //字离旁边的距离 117 | private final float mDefaultMargin = 20; 118 | private float mMargin = 20; 119 | 120 | //绘制文字的画笔 121 | private TextPaint mFontPaint; 122 | 123 | private Canvas canvasText; 124 | 125 | private Paint.FontMetrics fm; 126 | //由于系统基于字体的底部来绘制文本,所有需要加上字体的高度。 127 | private float baseline; 128 | 129 | boolean isInit = true; 130 | 131 | //双指缩放时的初始距离 132 | private float oldDis; 133 | 134 | //是否按下 135 | private boolean isDown = false; 136 | //是否移动 137 | private boolean isMove = false; 138 | //是否抬起手 139 | private boolean isUp = false; 140 | //是否在顶部 141 | private boolean isTop = true; 142 | 143 | private boolean isInBitmap; 144 | 145 | private final int fontColor; 146 | 147 | private final long bubbleId; 148 | 149 | 150 | public BubbleTextView(Context context, AttributeSet attrs) { 151 | super(context, attrs); 152 | defaultStr = getContext().getString(R.string.double_click_input_text); 153 | this.fontColor = Color.BLACK; 154 | bubbleId = 0; 155 | init(); 156 | } 157 | 158 | public BubbleTextView(Context context) { 159 | super(context); 160 | defaultStr = getContext().getString(R.string.double_click_input_text); 161 | this.fontColor = Color.BLACK; 162 | bubbleId = 0; 163 | init(); 164 | } 165 | 166 | public BubbleTextView(Context context, AttributeSet attrs, int defStyleAttr) { 167 | super(context, attrs, defStyleAttr); 168 | defaultStr = getContext().getString(R.string.double_click_input_text); 169 | this.fontColor = Color.BLACK; 170 | bubbleId = 0; 171 | init(); 172 | } 173 | 174 | /** 175 | * @param context 176 | * @param fontColor 177 | * @param bubbleId some fuck id 178 | */ 179 | public BubbleTextView(Context context, int fontColor, long bubbleId) { 180 | super(context); 181 | defaultStr = getContext().getString(R.string.double_click_input_text); 182 | this.fontColor = fontColor; 183 | this.bubbleId = bubbleId; 184 | init(); 185 | } 186 | 187 | 188 | private void init() { 189 | dm = getResources().getDisplayMetrics(); 190 | dst_delete = new Rect(); 191 | dst_resize = new Rect(); 192 | dst_flipV = new Rect(); 193 | dst_top = new Rect(); 194 | localPaint = new Paint(); 195 | localPaint.setColor(getResources().getColor(R.color.red_e73a3d)); 196 | localPaint.setAntiAlias(true); 197 | localPaint.setDither(true); 198 | localPaint.setStyle(Paint.Style.STROKE); 199 | localPaint.setStrokeWidth(2.0f); 200 | mScreenwidth = dm.widthPixels; 201 | mScreenHeight = dm.heightPixels; 202 | mFontSize = mDefultSize; 203 | mFontPaint = new TextPaint(); 204 | mFontPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mFontSize, dm)); 205 | mFontPaint.setColor(fontColor); 206 | mFontPaint.setTextAlign(Paint.Align.CENTER); 207 | mFontPaint.setAntiAlias(true); 208 | fm = mFontPaint.getFontMetrics(); 209 | 210 | baseline = fm.descent - fm.ascent; 211 | isInit = true; 212 | mStr = defaultStr; 213 | } 214 | 215 | @Override 216 | protected void onDraw(Canvas canvas) { 217 | if (mBitmap != null) { 218 | 219 | 220 | float[] arrayOfFloat = new float[9]; 221 | matrix.getValues(arrayOfFloat); 222 | float f1 = 0.0F * arrayOfFloat[0] + 0.0F * arrayOfFloat[1] + arrayOfFloat[2]; 223 | float f2 = 0.0F * arrayOfFloat[3] + 0.0F * arrayOfFloat[4] + arrayOfFloat[5]; 224 | float f3 = arrayOfFloat[0] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat[1] + arrayOfFloat[2]; 225 | float f4 = arrayOfFloat[3] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat[4] + arrayOfFloat[5]; 226 | float f5 = 0.0F * arrayOfFloat[0] + arrayOfFloat[1] * this.mBitmap.getHeight() + arrayOfFloat[2]; 227 | float f6 = 0.0F * arrayOfFloat[3] + arrayOfFloat[4] * this.mBitmap.getHeight() + arrayOfFloat[5]; 228 | float f7 = arrayOfFloat[0] * this.mBitmap.getWidth() + arrayOfFloat[1] * this.mBitmap.getHeight() + arrayOfFloat[2]; 229 | float f8 = arrayOfFloat[3] * this.mBitmap.getWidth() + arrayOfFloat[4] * this.mBitmap.getHeight() + arrayOfFloat[5]; 230 | 231 | 232 | canvas.save(); 233 | 234 | //先往文字上绘图 235 | mBitmap = originBitmap.copy(Bitmap.Config.ARGB_8888, true); 236 | canvasText.setBitmap(mBitmap); 237 | canvasText.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG)); 238 | canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG)); 239 | float left = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, dm); 240 | float scalex = arrayOfFloat[Matrix.MSCALE_X]; 241 | float skewy = arrayOfFloat[Matrix.MSKEW_Y]; 242 | float rScale = (float) Math.sqrt(scalex * scalex + skewy * skewy); 243 | 244 | float size = rScale * 0.75f * mDefultSize; 245 | if (size > mMaxFontSize) { 246 | mFontSize = mMaxFontSize; 247 | } else if (size < mMinFontSize) { 248 | mFontSize = mMinFontSize; 249 | } else { 250 | mFontSize = size; 251 | } 252 | mFontPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mFontSize, dm)); 253 | String[] texts = autoSplit(mStr, mFontPaint, mBitmap.getWidth() - left * 3); 254 | float height = (texts.length * (baseline + fm.leading) + baseline); 255 | float top = (mBitmap.getHeight() - height) / 2; 256 | //基于底线开始画的 257 | top += baseline; 258 | for (String text : texts) { 259 | if (TextUtils.isEmpty(text)) { 260 | continue; 261 | } 262 | canvasText.drawText(text, mBitmap.getWidth() / 2, top, mFontPaint); //坐标以控件左上角为原点 263 | top += baseline + fm.leading; //添加字体行间距 264 | } 265 | canvas.drawBitmap(mBitmap, matrix, null); 266 | 267 | //删除在右上角 268 | dst_delete.left = (int) (f3 - deleteBitmapWidth / 2); 269 | dst_delete.right = (int) (f3 + deleteBitmapWidth / 2); 270 | dst_delete.top = (int) (f4 - deleteBitmapHeight / 2); 271 | dst_delete.bottom = (int) (f4 + deleteBitmapHeight / 2); 272 | //拉伸等操作在右下角 273 | dst_resize.left = (int) (f7 - resizeBitmapWidth / 2); 274 | dst_resize.right = (int) (f7 + resizeBitmapWidth / 2); 275 | dst_resize.top = (int) (f8 - resizeBitmapHeight / 2); 276 | dst_resize.bottom = (int) (f8 + resizeBitmapHeight / 2); 277 | //置顶在左上角 278 | dst_top.left = (int) (f1 - topBitmapWidth / 2); 279 | dst_top.right = (int) (f1 + topBitmapWidth / 2); 280 | dst_top.top = (int) (f2 - topBitmapHeight / 2); 281 | dst_top.bottom = (int) (f2 + topBitmapHeight / 2); 282 | //水平镜像在右下角 283 | // dst_flipV.left = (int) (f5 - topBitmapWidth / 2); 284 | // dst_flipV.right = (int) (f5 + topBitmapWidth / 2); 285 | // dst_flipV.top = (int) (f6 - topBitmapHeight / 2); 286 | // dst_flipV.bottom = (int) (f6 + topBitmapHeight / 2); 287 | if (isInEdit) { 288 | 289 | canvas.drawLine(f1, f2, f3, f4, localPaint); 290 | canvas.drawLine(f3, f4, f7, f8, localPaint); 291 | canvas.drawLine(f5, f6, f7, f8, localPaint); 292 | canvas.drawLine(f5, f6, f1, f2, localPaint); 293 | 294 | canvas.drawBitmap(deleteBitmap, null, dst_delete, null); 295 | canvas.drawBitmap(resizeBitmap, null, dst_resize, null); 296 | // canvas.drawBitmap(flipVBitmap, null, dst_flipV, null); 297 | canvas.drawBitmap(topBitmap, null, dst_top, null); 298 | } 299 | 300 | canvas.restore(); 301 | } 302 | } 303 | 304 | public void setText(String text) { 305 | // if (TextUtils.isEmpty(text)) { 306 | // mStr = defaultStr; 307 | // mFontSize = mDefultSize; 308 | // mMargin = mDefaultMargin; 309 | // } else { 310 | mStr = text; 311 | // } 312 | invalidate(); 313 | } 314 | 315 | @Override 316 | public void setImageResource(int resId) { 317 | matrix.reset(); 318 | //使用拷贝 不然会对资源文件进行引用而修改 319 | setBitmap(BitmapFactory.decodeResource(getResources(), resId)); 320 | } 321 | 322 | public void setImageResource(int resId, BubblePropertyModel model) { 323 | matrix.reset(); 324 | //使用拷贝 不然会对资源文件进行引用而修改 325 | setBitmap(BitmapFactory.decodeResource(getResources(), resId), model); 326 | } 327 | 328 | public void setBitmap(Bitmap bitmap, BubblePropertyModel model) { 329 | mFontSize = mDefultSize; 330 | originBitmap = bitmap; 331 | mBitmap = originBitmap.copy(Bitmap.Config.ARGB_8888, true); 332 | canvasText = new Canvas(mBitmap); 333 | setDiagonalLength(); 334 | initBitmaps(); 335 | int w = mBitmap.getWidth(); 336 | int h = mBitmap.getHeight(); 337 | oringinWidth = w; 338 | 339 | mStr = model.getText(); 340 | float scale = model.getScaling() * mScreenwidth / mBitmap.getWidth(); 341 | if (scale > MAX_SCALE) { 342 | scale = MAX_SCALE; 343 | } else if (scale < MIN_SCALE) { 344 | scale = MIN_SCALE; 345 | } 346 | float degree = (float) Math.toDegrees(model.getDegree()); 347 | matrix.postRotate(-degree, w >> 1, h >> 1); 348 | matrix.postScale(scale, scale, w >> 1, h >> 1); 349 | float midX = model.getxLocation() * mScreenwidth; 350 | float midY = model.getyLocation() * mScreenwidth; 351 | float offset = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 22, dm); 352 | midX = midX - (w * scale) / 2 - offset; 353 | midY = midY - (h * scale) / 2 - offset; 354 | matrix.postTranslate(midX, midY); 355 | invalidate(); 356 | } 357 | 358 | public void setBitmap(Bitmap bitmap) { 359 | mFontSize = mDefultSize; 360 | originBitmap = bitmap; 361 | mBitmap = originBitmap.copy(Bitmap.Config.ARGB_8888, true); 362 | canvasText = new Canvas(mBitmap); 363 | setDiagonalLength(); 364 | initBitmaps(); 365 | int w = mBitmap.getWidth(); 366 | int h = mBitmap.getHeight(); 367 | oringinWidth = w; 368 | float topbarHeight = DensityUtils.dip2px(getContext(), 50); 369 | //Y坐标为 (顶部操作栏+正方形图)/2 370 | matrix.postTranslate(mScreenwidth / 2 - w / 2, (mScreenwidth) / 2 - h / 2); 371 | invalidate(); 372 | } 373 | 374 | private void setDiagonalLength() { 375 | halfDiagonalLength = Math.hypot(mBitmap.getWidth(), mBitmap.getHeight()) / 2; 376 | } 377 | 378 | private void initBitmaps() { 379 | 380 | float minWidth = mScreenwidth / 8; 381 | if (mBitmap.getWidth() < minWidth) { 382 | MIN_SCALE = 1f; 383 | } else { 384 | MIN_SCALE = 1.0f * minWidth / mBitmap.getWidth(); 385 | } 386 | 387 | if (mBitmap.getWidth() > mScreenwidth) { 388 | MAX_SCALE = 1; 389 | } else { 390 | MAX_SCALE = 1.0f * mScreenwidth / mBitmap.getWidth(); 391 | } 392 | topBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_top_enable); 393 | deleteBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_delete); 394 | flipVBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_flip); 395 | resizeBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_resize); 396 | 397 | deleteBitmapWidth = (int) (deleteBitmap.getWidth() * BITMAP_SCALE); 398 | deleteBitmapHeight = (int) (deleteBitmap.getHeight() * BITMAP_SCALE); 399 | 400 | resizeBitmapWidth = (int) (resizeBitmap.getWidth() * BITMAP_SCALE); 401 | resizeBitmapHeight = (int) (resizeBitmap.getHeight() * BITMAP_SCALE); 402 | 403 | flipVBitmapWidth = (int) (flipVBitmap.getWidth() * BITMAP_SCALE); 404 | flipVBitmapHeight = (int) (flipVBitmap.getHeight() * BITMAP_SCALE); 405 | 406 | topBitmapWidth = (int) (topBitmap.getWidth() * BITMAP_SCALE); 407 | topBitmapHeight = (int) (topBitmap.getHeight() * BITMAP_SCALE); 408 | 409 | } 410 | 411 | private long preClicktime; 412 | 413 | private final long doubleClickTimeLimit = 200; 414 | 415 | @Override 416 | public boolean onTouchEvent(MotionEvent event) { 417 | int action = MotionEventCompat.getActionMasked(event); 418 | boolean handled = true; 419 | isInBitmap = false; 420 | switch (action) { 421 | case MotionEvent.ACTION_DOWN: 422 | if (isInButton(event, dst_delete)) { 423 | if (operationListener != null) { 424 | operationListener.onDeleteClick(); 425 | } 426 | isDown = false; 427 | } else if (isInResize(event)) { 428 | isInResize = true; 429 | lastRotateDegree = rotationToStartPoint(event); 430 | midPointToStartPoint(event); 431 | lastLength = diagonalLength(event); 432 | isDown = false; 433 | } else if (isInButton(event, dst_flipV)) { 434 | PointF localPointF = new PointF(); 435 | midDiagonalPoint(localPointF); 436 | matrix.postScale(-1.0F, 1.0F, localPointF.x, localPointF.y); 437 | isDown = false; 438 | invalidate(); 439 | } else if (isInButton(event, dst_top)) { 440 | //置顶 441 | bringToFront(); 442 | if (operationListener != null) { 443 | operationListener.onTop(this); 444 | } 445 | isDown = false; 446 | } else if (isInBitmap(event)) { 447 | isInSide = true; 448 | lastX = event.getX(0); 449 | lastY = event.getY(0); 450 | isDown = true; 451 | isMove = false; 452 | isPointerDown = false; 453 | isUp = false; 454 | isInBitmap = true; 455 | 456 | long currentTime = System.currentTimeMillis(); 457 | Log.d(TAG, (currentTime - preClicktime) + ""); 458 | if (currentTime - preClicktime > doubleClickTimeLimit) { 459 | preClicktime = currentTime; 460 | } else { 461 | if (isInEdit && operationListener != null) { 462 | operationListener.onClick(this); 463 | } 464 | } 465 | 466 | } else { 467 | handled = false; 468 | } 469 | break; 470 | case MotionEvent.ACTION_POINTER_DOWN: 471 | if (spacing(event) > pointerLimitDis) { 472 | oldDis = spacing(event); 473 | isPointerDown = true; 474 | midPointToStartPoint(event); 475 | } else { 476 | isPointerDown = false; 477 | } 478 | isInSide = false; 479 | isInResize = false; 480 | break; 481 | case MotionEvent.ACTION_MOVE: 482 | //双指缩放 483 | if (isPointerDown) { 484 | float scale; 485 | float disNew = spacing(event); 486 | if (disNew == 0 || disNew < pointerLimitDis) { 487 | scale = 1; 488 | } else { 489 | scale = disNew / oldDis; 490 | //缩放缓慢 491 | scale = (scale - 1) * pointerZoomCoeff + 1; 492 | } 493 | float scaleTemp = (scale * Math.abs(dst_flipV.left - dst_resize.left)) / oringinWidth; 494 | if (((scaleTemp <= MIN_SCALE)) && scale < 1 || 495 | (scaleTemp >= MAX_SCALE) && scale > 1) { 496 | scale = 1; 497 | } else { 498 | lastLength = diagonalLength(event); 499 | } 500 | matrix.postScale(scale, scale, mid.x, mid.y); 501 | invalidate(); 502 | } else if (isInResize) { 503 | matrix.postRotate((rotationToStartPoint(event) - lastRotateDegree) * 2, mid.x, mid.y); 504 | lastRotateDegree = rotationToStartPoint(event); 505 | 506 | float scale = diagonalLength(event) / lastLength; 507 | 508 | if (((diagonalLength(event) / halfDiagonalLength <= MIN_SCALE)) && scale < 1 || 509 | (diagonalLength(event) / halfDiagonalLength >= MAX_SCALE) && scale > 1) { 510 | scale = 1; 511 | if (!isInResize(event)) { 512 | isInResize = false; 513 | } 514 | } else { 515 | lastLength = diagonalLength(event); 516 | } 517 | matrix.postScale(scale, scale, mid.x, mid.y); 518 | 519 | invalidate(); 520 | } else if (isInSide) { 521 | //TODO 移动区域判断 不能超出屏幕 522 | float x = event.getX(0); 523 | float y = event.getY(0); 524 | //判断手指抖动距离 加上isMove判断 只要移动过 都是true 525 | if (!isMove && Math.abs(x - lastX) < moveLimitDis 526 | && Math.abs(y - lastY) < moveLimitDis) { 527 | isMove = false; 528 | } else { 529 | isMove = true; 530 | } 531 | matrix.postTranslate(x - lastX, y - lastY); 532 | lastX = x; 533 | lastY = y; 534 | invalidate(); 535 | } 536 | break; 537 | case MotionEvent.ACTION_CANCEL: 538 | case MotionEvent.ACTION_UP: 539 | isInResize = false; 540 | isInSide = false; 541 | isPointerDown = false; 542 | isUp = true; 543 | break; 544 | 545 | } 546 | if (handled && operationListener != null) { 547 | operationListener.onEdit(this); 548 | } 549 | // //判断是不是做了点击动作 必须在编辑状态 且在图片内 并且是双击 550 | // if (isDoubleClick && isDown && !isPointerDown && !isMove && isUp && isInBitmap && isInEdit && operationListener != null) { 551 | // operationListener.onClick(this); 552 | // } 553 | return handled; 554 | } 555 | 556 | public BubblePropertyModel calculate(BubblePropertyModel model) { 557 | float[] v = new float[9]; 558 | matrix.getValues(v); 559 | // translation is simple 560 | float tx = v[Matrix.MTRANS_X]; 561 | float ty = v[Matrix.MTRANS_Y]; 562 | Log.d(TAG, "tx : " + tx + " ty : " + ty); 563 | // calculate real scale 564 | float scalex = v[Matrix.MSCALE_X]; 565 | float skewy = v[Matrix.MSKEW_Y]; 566 | float rScale = (float) Math.sqrt(scalex * scalex + skewy * skewy); 567 | Log.d(TAG, "rScale : " + rScale); 568 | // calculate the degree of rotation 569 | float rAngle = Math.round(Math.atan2(v[Matrix.MSKEW_X], v[Matrix.MSCALE_X]) * (180 / Math.PI)); 570 | Log.d(TAG, "rAngle : " + rAngle); 571 | 572 | float minX = (dst_top.centerX() + dst_resize.centerX()) / 2; 573 | float minY = (dst_top.centerY() + dst_resize.centerY()) / 2; 574 | 575 | Log.d(TAG, "midX : " + minX + " midY : " + minY); 576 | 577 | model.setDegree((float) Math.toRadians(rAngle)); 578 | model.setBubbleId(bubbleId); 579 | //TODO 占屏幕百分比 580 | float precentWidth = (mBitmap.getWidth() * rScale) / mScreenwidth; 581 | model.setScaling(precentWidth); 582 | Log.d(TAG, " x " + (minX / mScreenwidth) + " y " + (minY / mScreenwidth)); 583 | model.setxLocation(minX / mScreenwidth); 584 | model.setyLocation(minY / mScreenwidth); 585 | model.setText(mStr); 586 | return model; 587 | } 588 | 589 | 590 | /** 591 | * 是否在四条线内部 592 | * 593 | * @return 594 | */ 595 | private boolean isInBitmap(MotionEvent event) { 596 | float[] arrayOfFloat1 = new float[9]; 597 | this.matrix.getValues(arrayOfFloat1); 598 | //左上角 599 | float f1 = 0.0F * arrayOfFloat1[0] + 0.0F * arrayOfFloat1[1] + arrayOfFloat1[2]; 600 | float f2 = 0.0F * arrayOfFloat1[3] + 0.0F * arrayOfFloat1[4] + arrayOfFloat1[5]; 601 | //右上角 602 | float f3 = arrayOfFloat1[0] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat1[1] + arrayOfFloat1[2]; 603 | float f4 = arrayOfFloat1[3] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat1[4] + arrayOfFloat1[5]; 604 | //左下角 605 | float f5 = 0.0F * arrayOfFloat1[0] + arrayOfFloat1[1] * this.mBitmap.getHeight() + arrayOfFloat1[2]; 606 | float f6 = 0.0F * arrayOfFloat1[3] + arrayOfFloat1[4] * this.mBitmap.getHeight() + arrayOfFloat1[5]; 607 | //右下角 608 | float f7 = arrayOfFloat1[0] * this.mBitmap.getWidth() + arrayOfFloat1[1] * this.mBitmap.getHeight() + arrayOfFloat1[2]; 609 | float f8 = arrayOfFloat1[3] * this.mBitmap.getWidth() + arrayOfFloat1[4] * this.mBitmap.getHeight() + arrayOfFloat1[5]; 610 | 611 | float[] arrayOfFloat2 = new float[4]; 612 | float[] arrayOfFloat3 = new float[4]; 613 | //确定X方向的范围 614 | arrayOfFloat2[0] = f1;//左上的左 615 | arrayOfFloat2[1] = f3;//右上的右 616 | arrayOfFloat2[2] = f7;//右下的右 617 | arrayOfFloat2[3] = f5;//左下的左 618 | //确定Y方向的范围 619 | arrayOfFloat3[0] = f2;//左上的上 620 | arrayOfFloat3[1] = f4;//右上的上 621 | arrayOfFloat3[2] = f8; 622 | arrayOfFloat3[3] = f6; 623 | return pointInRect(arrayOfFloat2, arrayOfFloat3, event.getX(0), event.getY(0)); 624 | } 625 | 626 | /** 627 | * 判断点是否在一个矩形内部 628 | * 629 | * @param xRange 630 | * @param yRange 631 | * @param x 632 | * @param y 633 | * @return 634 | */ 635 | private boolean pointInRect(float[] xRange, float[] yRange, float x, float y) { 636 | //四条边的长度 637 | double a1 = Math.hypot(xRange[0] - xRange[1], yRange[0] - yRange[1]); 638 | double a2 = Math.hypot(xRange[1] - xRange[2], yRange[1] - yRange[2]); 639 | double a3 = Math.hypot(xRange[3] - xRange[2], yRange[3] - yRange[2]); 640 | double a4 = Math.hypot(xRange[0] - xRange[3], yRange[0] - yRange[3]); 641 | //待检测点到四个点的距离 642 | double b1 = Math.hypot(x - xRange[0], y - yRange[0]); 643 | double b2 = Math.hypot(x - xRange[1], y - yRange[1]); 644 | double b3 = Math.hypot(x - xRange[2], y - yRange[2]); 645 | double b4 = Math.hypot(x - xRange[3], y - yRange[3]); 646 | 647 | double u1 = (a1 + b1 + b2) / 2; 648 | double u2 = (a2 + b2 + b3) / 2; 649 | double u3 = (a3 + b3 + b4) / 2; 650 | double u4 = (a4 + b4 + b1) / 2; 651 | 652 | //矩形的面积 653 | double s = a1 * a2; 654 | double ss = Math.sqrt(u1 * (u1 - a1) * (u1 - b1) * (u1 - b2)) 655 | + Math.sqrt(u2 * (u2 - a2) * (u2 - b2) * (u2 - b3)) 656 | + Math.sqrt(u3 * (u3 - a3) * (u3 - b3) * (u3 - b4)) 657 | + Math.sqrt(u4 * (u4 - a4) * (u4 - b4) * (u4 - b1)); 658 | return Math.abs(s - ss) < 0.5; 659 | 660 | 661 | } 662 | 663 | 664 | private boolean isInButton(MotionEvent event, Rect rect) { 665 | int left = rect.left; 666 | int right = rect.right; 667 | int top = rect.top; 668 | int bottom = rect.bottom; 669 | return event.getX(0) >= left && event.getX(0) <= right && event.getY(0) >= top && event.getY(0) <= bottom; 670 | } 671 | 672 | private boolean isInResize(MotionEvent event) { 673 | int left = -20 + this.dst_resize.left; 674 | int top = -20 + this.dst_resize.top; 675 | int right = 20 + this.dst_resize.right; 676 | int bottom = 20 + this.dst_resize.bottom; 677 | return event.getX(0) >= left && event.getX(0) <= right && event.getY(0) >= top && event.getY(0) <= bottom; 678 | } 679 | 680 | private void midPointToStartPoint(MotionEvent event) { 681 | float[] arrayOfFloat = new float[9]; 682 | matrix.getValues(arrayOfFloat); 683 | float f1 = 0.0f * arrayOfFloat[0] + 0.0f * arrayOfFloat[1] + arrayOfFloat[2]; 684 | float f2 = 0.0f * arrayOfFloat[3] + 0.0f * arrayOfFloat[4] + arrayOfFloat[5]; 685 | float f3 = f1 + event.getX(0); 686 | float f4 = f2 + event.getY(0); 687 | mid.set(f3 / 2, f4 / 2); 688 | } 689 | 690 | private void midDiagonalPoint(PointF paramPointF) { 691 | float[] arrayOfFloat = new float[9]; 692 | this.matrix.getValues(arrayOfFloat); 693 | float f1 = 0.0F * arrayOfFloat[0] + 0.0F * arrayOfFloat[1] + arrayOfFloat[2]; 694 | float f2 = 0.0F * arrayOfFloat[3] + 0.0F * arrayOfFloat[4] + arrayOfFloat[5]; 695 | float f3 = arrayOfFloat[0] * this.mBitmap.getWidth() + arrayOfFloat[1] * this.mBitmap.getHeight() + arrayOfFloat[2]; 696 | float f4 = arrayOfFloat[3] * this.mBitmap.getWidth() + arrayOfFloat[4] * this.mBitmap.getHeight() + arrayOfFloat[5]; 697 | float f5 = f1 + f3; 698 | float f6 = f2 + f4; 699 | paramPointF.set(f5 / 2.0F, f6 / 2.0F); 700 | } 701 | 702 | 703 | /** 704 | * 在滑动过车中X,Y是不会改变的,这里减Y,减X,其实是相当于把X,Y当做原点 705 | * 706 | * @param event 707 | * @return 708 | */ 709 | private float rotationToStartPoint(MotionEvent event) { 710 | 711 | float[] arrayOfFloat = new float[9]; 712 | matrix.getValues(arrayOfFloat); 713 | float x = 0.0f * arrayOfFloat[0] + 0.0f * arrayOfFloat[1] + arrayOfFloat[2]; 714 | float y = 0.0f * arrayOfFloat[3] + 0.0f * arrayOfFloat[4] + arrayOfFloat[5]; 715 | double arc = Math.atan2(event.getY(0) - y, event.getX(0) - x); 716 | return (float) Math.toDegrees(arc); 717 | } 718 | 719 | /** 720 | * 触摸点到矩形中点的距离 721 | * 722 | * @param event 723 | * @return 724 | */ 725 | private float diagonalLength(MotionEvent event) { 726 | float diagonalLength = (float) Math.hypot(event.getX(0) - mid.x, event.getY(0) - mid.y); 727 | return diagonalLength; 728 | } 729 | 730 | /** 731 | * Determine the space between the first two fingers 732 | */ 733 | private float spacing(MotionEvent event) { 734 | if (event.getPointerCount() == 2) { 735 | float x = event.getX(0) - event.getX(1); 736 | float y = event.getY(0) - event.getY(1); 737 | return (float) Math.sqrt(x * x + y * y); 738 | } else { 739 | return 0; 740 | } 741 | } 742 | 743 | public interface OperationListener { 744 | void onDeleteClick(); 745 | 746 | void onEdit(BubbleTextView bubbleTextView); 747 | 748 | void onClick(BubbleTextView bubbleTextView); 749 | 750 | void onTop(BubbleTextView bubbleTextView); 751 | } 752 | 753 | public void setOperationListener(OperationListener operationListener) { 754 | this.operationListener = operationListener; 755 | } 756 | 757 | public void setInEdit(boolean isInEdit) { 758 | this.isInEdit = isInEdit; 759 | invalidate(); 760 | } 761 | 762 | /** 763 | * 自动分割文本 764 | * 765 | * @param content 需要分割的文本 766 | * @param p 画笔,用来根据字体测量文本的宽度 767 | * @param width 指定的宽度 768 | * @return 一个字符串数组,保存每行的文本 769 | */ 770 | private String[] autoSplit(String content, Paint p, float width) { 771 | int length = content.length(); 772 | float textWidth = p.measureText(content); 773 | if (textWidth <= width) { 774 | return new String[]{content}; 775 | } 776 | 777 | int start = 0, end = 1, i = 0; 778 | int lines = (int) Math.ceil(textWidth / width); //计算行数 779 | String[] lineTexts = new String[lines]; 780 | while (start < length) { 781 | if (p.measureText(content, start, end) > width) { //文本宽度超出控件宽度时 782 | lineTexts[i++] = (String) content.subSequence(start, end); 783 | start = end; 784 | } 785 | if (end == length) { //不足一行的文本 786 | lineTexts[i] = (String) content.subSequence(start, end); 787 | break; 788 | } 789 | end += 1; 790 | } 791 | return lineTexts; 792 | } 793 | 794 | public String getmStr() { 795 | return mStr; 796 | } 797 | } 798 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/abner/stickerdemo/view/StickerView.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Matrix; 8 | import android.graphics.Paint; 9 | import android.graphics.PointF; 10 | import android.graphics.Rect; 11 | import android.support.v4.view.MotionEventCompat; 12 | import android.util.AttributeSet; 13 | import android.util.DisplayMetrics; 14 | import android.util.Log; 15 | import android.view.MotionEvent; 16 | import android.widget.ImageView; 17 | 18 | import com.example.abner.stickerdemo.R; 19 | import com.example.abner.stickerdemo.model.StickerPropertyModel; 20 | 21 | 22 | /** 23 | * 表情贴纸 24 | */ 25 | public class StickerView extends ImageView { 26 | private static final String TAG = "StickerView"; 27 | 28 | private Bitmap deleteBitmap; 29 | private Bitmap flipVBitmap; 30 | private Bitmap topBitmap; 31 | private Bitmap resizeBitmap; 32 | private Bitmap mBitmap; 33 | private Rect dst_delete; 34 | private Rect dst_resize; 35 | private Rect dst_flipV; 36 | private Rect dst_top; 37 | private int deleteBitmapWidth; 38 | private int deleteBitmapHeight; 39 | private int resizeBitmapWidth; 40 | private int resizeBitmapHeight; 41 | //水平镜像 42 | private int flipVBitmapWidth; 43 | private int flipVBitmapHeight; 44 | //置顶 45 | private int topBitmapWidth; 46 | private int topBitmapHeight; 47 | private Paint localPaint; 48 | private int mScreenwidth, mScreenHeight; 49 | private static final float BITMAP_SCALE = 0.7f; 50 | private PointF mid = new PointF(); 51 | private OperationListener operationListener; 52 | private float lastRotateDegree; 53 | 54 | //是否是第二根手指放下 55 | private boolean isPointerDown = false; 56 | //手指移动距离必须超过这个数值 57 | private final float pointerLimitDis = 20f; 58 | private final float pointerZoomCoeff = 0.09f; 59 | /** 60 | * 对角线的长度 61 | */ 62 | private float lastLength; 63 | private boolean isInResize = false; 64 | 65 | private Matrix matrix = new Matrix(); 66 | /** 67 | * 是否在四条线内部 68 | */ 69 | private boolean isInSide; 70 | 71 | private float lastX, lastY; 72 | /** 73 | * 是否在编辑模式 74 | */ 75 | private boolean isInEdit = true; 76 | 77 | private float MIN_SCALE = 0.5f; 78 | 79 | private float MAX_SCALE = 1.2f; 80 | 81 | private double halfDiagonalLength; 82 | 83 | private float oringinWidth = 0; 84 | 85 | //双指缩放时的初始距离 86 | private float oldDis; 87 | 88 | private final long stickerId; 89 | 90 | private DisplayMetrics dm; 91 | 92 | //水平镜像 93 | private boolean isHorizonMirror = false; 94 | 95 | public StickerView(Context context, AttributeSet attrs) { 96 | super(context, attrs); 97 | stickerId = 0; 98 | init(); 99 | } 100 | 101 | public StickerView(Context context) { 102 | super(context); 103 | stickerId = 0; 104 | init(); 105 | } 106 | 107 | public StickerView(Context context, AttributeSet attrs, int defStyleAttr) { 108 | super(context, attrs, defStyleAttr); 109 | stickerId = 0; 110 | init(); 111 | } 112 | 113 | private void init() { 114 | 115 | dst_delete = new Rect(); 116 | dst_resize = new Rect(); 117 | dst_flipV = new Rect(); 118 | dst_top = new Rect(); 119 | localPaint = new Paint(); 120 | localPaint.setColor(getResources().getColor(R.color.red_e73a3d)); 121 | localPaint.setAntiAlias(true); 122 | localPaint.setDither(true); 123 | localPaint.setStyle(Paint.Style.STROKE); 124 | localPaint.setStrokeWidth(2.0f); 125 | dm = getResources().getDisplayMetrics(); 126 | mScreenwidth = dm.widthPixels; 127 | mScreenHeight = dm.heightPixels; 128 | 129 | } 130 | 131 | @Override 132 | protected void onDraw(Canvas canvas) { 133 | if (mBitmap != null) { 134 | 135 | 136 | float[] arrayOfFloat = new float[9]; 137 | matrix.getValues(arrayOfFloat); 138 | float f1 = 0.0F * arrayOfFloat[0] + 0.0F * arrayOfFloat[1] + arrayOfFloat[2]; 139 | float f2 = 0.0F * arrayOfFloat[3] + 0.0F * arrayOfFloat[4] + arrayOfFloat[5]; 140 | float f3 = arrayOfFloat[0] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat[1] + arrayOfFloat[2]; 141 | float f4 = arrayOfFloat[3] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat[4] + arrayOfFloat[5]; 142 | float f5 = 0.0F * arrayOfFloat[0] + arrayOfFloat[1] * this.mBitmap.getHeight() + arrayOfFloat[2]; 143 | float f6 = 0.0F * arrayOfFloat[3] + arrayOfFloat[4] * this.mBitmap.getHeight() + arrayOfFloat[5]; 144 | float f7 = arrayOfFloat[0] * this.mBitmap.getWidth() + arrayOfFloat[1] * this.mBitmap.getHeight() + arrayOfFloat[2]; 145 | float f8 = arrayOfFloat[3] * this.mBitmap.getWidth() + arrayOfFloat[4] * this.mBitmap.getHeight() + arrayOfFloat[5]; 146 | 147 | canvas.save(); 148 | canvas.drawBitmap(mBitmap, matrix, null); 149 | //删除在右上角 150 | dst_delete.left = (int) (f3 - deleteBitmapWidth / 2); 151 | dst_delete.right = (int) (f3 + deleteBitmapWidth / 2); 152 | dst_delete.top = (int) (f4 - deleteBitmapHeight / 2); 153 | dst_delete.bottom = (int) (f4 + deleteBitmapHeight / 2); 154 | //拉伸等操作在右下角 155 | dst_resize.left = (int) (f7 - resizeBitmapWidth / 2); 156 | dst_resize.right = (int) (f7 + resizeBitmapWidth / 2); 157 | dst_resize.top = (int) (f8 - resizeBitmapHeight / 2); 158 | dst_resize.bottom = (int) (f8 + resizeBitmapHeight / 2); 159 | //垂直镜像在左上角 160 | dst_top.left = (int) (f1 - flipVBitmapWidth / 2); 161 | dst_top.right = (int) (f1 + flipVBitmapWidth / 2); 162 | dst_top.top = (int) (f2 - flipVBitmapHeight / 2); 163 | dst_top.bottom = (int) (f2 + flipVBitmapHeight / 2); 164 | //水平镜像在左下角 165 | dst_flipV.left = (int) (f5 - topBitmapWidth / 2); 166 | dst_flipV.right = (int) (f5 + topBitmapWidth / 2); 167 | dst_flipV.top = (int) (f6 - topBitmapHeight / 2); 168 | dst_flipV.bottom = (int) (f6 + topBitmapHeight / 2); 169 | if (isInEdit) { 170 | 171 | canvas.drawLine(f1, f2, f3, f4, localPaint); 172 | canvas.drawLine(f3, f4, f7, f8, localPaint); 173 | canvas.drawLine(f5, f6, f7, f8, localPaint); 174 | canvas.drawLine(f5, f6, f1, f2, localPaint); 175 | 176 | canvas.drawBitmap(deleteBitmap, null, dst_delete, null); 177 | canvas.drawBitmap(resizeBitmap, null, dst_resize, null); 178 | canvas.drawBitmap(flipVBitmap, null, dst_flipV, null); 179 | canvas.drawBitmap(topBitmap, null, dst_top, null); 180 | } 181 | 182 | canvas.restore(); 183 | } 184 | } 185 | 186 | @Override 187 | public void setImageResource(int resId) { 188 | setBitmap(BitmapFactory.decodeResource(getResources(), resId)); 189 | } 190 | 191 | public void setBitmap(Bitmap bitmap) { 192 | matrix.reset(); 193 | mBitmap = bitmap; 194 | setDiagonalLength(); 195 | initBitmaps(); 196 | int w = mBitmap.getWidth(); 197 | int h = mBitmap.getHeight(); 198 | oringinWidth = w; 199 | float initScale = (MIN_SCALE + MAX_SCALE) / 2; 200 | matrix.postScale(initScale, initScale, w / 2, h / 2); 201 | //Y坐标为 (顶部操作栏+正方形图)/2 202 | matrix.postTranslate(mScreenwidth / 2 - w / 2, (mScreenwidth) / 2 - h / 2); 203 | invalidate(); 204 | } 205 | 206 | 207 | private void setDiagonalLength() { 208 | halfDiagonalLength = Math.hypot(mBitmap.getWidth(), mBitmap.getHeight()) / 2; 209 | } 210 | 211 | private void initBitmaps() { 212 | //当图片的宽比高大时 按照宽计算 缩放大小根据图片的大小而改变 最小为图片的1/8 最大为屏幕宽 213 | if (mBitmap.getWidth() >= mBitmap.getHeight()) { 214 | float minWidth = mScreenwidth / 8; 215 | if (mBitmap.getWidth() < minWidth) { 216 | MIN_SCALE = 1f; 217 | } else { 218 | MIN_SCALE = 1.0f * minWidth / mBitmap.getWidth(); 219 | } 220 | 221 | if (mBitmap.getWidth() > mScreenwidth) { 222 | MAX_SCALE = 1; 223 | } else { 224 | MAX_SCALE = 1.0f * mScreenwidth / mBitmap.getWidth(); 225 | } 226 | } else { 227 | //当图片高比宽大时,按照图片的高计算 228 | float minHeight = mScreenwidth / 8; 229 | if (mBitmap.getHeight() < minHeight) { 230 | MIN_SCALE = 1f; 231 | } else { 232 | MIN_SCALE = 1.0f * minHeight / mBitmap.getHeight(); 233 | } 234 | 235 | if (mBitmap.getHeight() > mScreenwidth) { 236 | MAX_SCALE = 1; 237 | } else { 238 | MAX_SCALE = 1.0f * mScreenwidth / mBitmap.getHeight(); 239 | } 240 | } 241 | 242 | topBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_top_enable); 243 | deleteBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_delete); 244 | flipVBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_flip); 245 | resizeBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_resize); 246 | 247 | deleteBitmapWidth = (int) (deleteBitmap.getWidth() * BITMAP_SCALE); 248 | deleteBitmapHeight = (int) (deleteBitmap.getHeight() * BITMAP_SCALE); 249 | 250 | resizeBitmapWidth = (int) (resizeBitmap.getWidth() * BITMAP_SCALE); 251 | resizeBitmapHeight = (int) (resizeBitmap.getHeight() * BITMAP_SCALE); 252 | 253 | flipVBitmapWidth = (int) (flipVBitmap.getWidth() * BITMAP_SCALE); 254 | flipVBitmapHeight = (int) (flipVBitmap.getHeight() * BITMAP_SCALE); 255 | 256 | topBitmapWidth = (int) (topBitmap.getWidth() * BITMAP_SCALE); 257 | topBitmapHeight = (int) (topBitmap.getHeight() * BITMAP_SCALE); 258 | } 259 | 260 | @Override 261 | public boolean onTouchEvent(MotionEvent event) { 262 | int action = MotionEventCompat.getActionMasked(event); 263 | boolean handled = true; 264 | switch (action) { 265 | case MotionEvent.ACTION_DOWN: 266 | if (isInButton(event, dst_delete)) { 267 | if (operationListener != null) { 268 | operationListener.onDeleteClick(); 269 | } 270 | } else if (isInResize(event)) { 271 | isInResize = true; 272 | lastRotateDegree = rotationToStartPoint(event); 273 | midPointToStartPoint(event); 274 | lastLength = diagonalLength(event); 275 | } else if (isInButton(event, dst_flipV)) { 276 | //水平镜像 277 | PointF localPointF = new PointF(); 278 | midDiagonalPoint(localPointF); 279 | matrix.postScale(-1.0F, 1.0F, localPointF.x, localPointF.y); 280 | isHorizonMirror = !isHorizonMirror; 281 | invalidate(); 282 | } else if (isInButton(event, dst_top)) { 283 | //置顶 284 | bringToFront(); 285 | if (operationListener != null) { 286 | operationListener.onTop(this); 287 | } 288 | } else if (isInBitmap(event)) { 289 | isInSide = true; 290 | lastX = event.getX(0); 291 | lastY = event.getY(0); 292 | } else { 293 | handled = false; 294 | } 295 | break; 296 | case MotionEvent.ACTION_POINTER_DOWN: 297 | if (spacing(event) > pointerLimitDis) { 298 | oldDis = spacing(event); 299 | isPointerDown = true; 300 | midPointToStartPoint(event); 301 | } else { 302 | isPointerDown = false; 303 | } 304 | isInSide = false; 305 | isInResize = false; 306 | break; 307 | case MotionEvent.ACTION_MOVE: 308 | //双指缩放 309 | if (isPointerDown) { 310 | float scale; 311 | float disNew = spacing(event); 312 | if (disNew == 0 || disNew < pointerLimitDis) { 313 | scale = 1; 314 | } else { 315 | scale = disNew / oldDis; 316 | //缩放缓慢 317 | scale = (scale - 1) * pointerZoomCoeff + 1; 318 | } 319 | float scaleTemp = (scale * Math.abs(dst_flipV.left - dst_resize.left)) / oringinWidth; 320 | if (((scaleTemp <= MIN_SCALE)) && scale < 1 || 321 | (scaleTemp >= MAX_SCALE) && scale > 1) { 322 | scale = 1; 323 | } else { 324 | lastLength = diagonalLength(event); 325 | } 326 | matrix.postScale(scale, scale, mid.x, mid.y); 327 | invalidate(); 328 | } else if (isInResize) { 329 | 330 | matrix.postRotate((rotationToStartPoint(event) - lastRotateDegree) * 2, mid.x, mid.y); 331 | lastRotateDegree = rotationToStartPoint(event); 332 | 333 | float scale = diagonalLength(event) / lastLength; 334 | 335 | if (((diagonalLength(event) / halfDiagonalLength <= MIN_SCALE)) && scale < 1 || 336 | (diagonalLength(event) / halfDiagonalLength >= MAX_SCALE) && scale > 1) { 337 | scale = 1; 338 | if (!isInResize(event)) { 339 | isInResize = false; 340 | } 341 | } else { 342 | lastLength = diagonalLength(event); 343 | } 344 | matrix.postScale(scale, scale, mid.x, mid.y); 345 | 346 | invalidate(); 347 | } else if (isInSide) { 348 | float x = event.getX(0); 349 | float y = event.getY(0); 350 | //TODO 移动区域判断 不能超出屏幕 351 | matrix.postTranslate(x - lastX, y - lastY); 352 | lastX = x; 353 | lastY = y; 354 | invalidate(); 355 | } 356 | break; 357 | case MotionEvent.ACTION_CANCEL: 358 | case MotionEvent.ACTION_UP: 359 | isInResize = false; 360 | isInSide = false; 361 | isPointerDown = false; 362 | break; 363 | 364 | } 365 | if (handled && operationListener != null) { 366 | operationListener.onEdit(this); 367 | } 368 | return handled; 369 | } 370 | 371 | /** 372 | * 计算图片的角度等属性 373 | * 374 | * @param model 375 | * @return 376 | */ 377 | public StickerPropertyModel calculate(StickerPropertyModel model) { 378 | float[] v = new float[9]; 379 | matrix.getValues(v); 380 | // translation is simple 381 | float tx = v[Matrix.MTRANS_X]; 382 | float ty = v[Matrix.MTRANS_Y]; 383 | Log.d(TAG, "tx : " + tx + " ty : " + ty); 384 | // calculate real scale 385 | float scalex = v[Matrix.MSCALE_X]; 386 | float skewy = v[Matrix.MSKEW_Y]; 387 | float rScale = (float) Math.sqrt(scalex * scalex + skewy * skewy); 388 | Log.d(TAG, "rScale : " + rScale); 389 | // calculate the degree of rotation 390 | float rAngle = Math.round(Math.atan2(v[Matrix.MSKEW_X], v[Matrix.MSCALE_X]) * (180 / Math.PI)); 391 | Log.d(TAG, "rAngle : " + rAngle); 392 | 393 | PointF localPointF = new PointF(); 394 | midDiagonalPoint(localPointF); 395 | 396 | Log.d(TAG, " width : " + (mBitmap.getWidth() * rScale) + " height " + (mBitmap.getHeight() * rScale)); 397 | 398 | float minX = localPointF.x; 399 | float minY = localPointF.y; 400 | 401 | Log.d(TAG, "midX : " + minX + " midY : " + minY); 402 | model.setDegree((float) Math.toRadians(rAngle)); 403 | //TODO 占屏幕百分比 404 | float precentWidth = (mBitmap.getWidth() * rScale) / mScreenwidth; 405 | model.setScaling(precentWidth); 406 | model.setxLocation(minX / mScreenwidth); 407 | model.setyLocation(minY / mScreenwidth); 408 | model.setStickerId(stickerId); 409 | if (isHorizonMirror) { 410 | model.setHorizonMirror(1); 411 | } else { 412 | model.setHorizonMirror(2); 413 | } 414 | return model; 415 | } 416 | 417 | /** 418 | * 是否在四条线内部 419 | * 图片旋转后 可能存在菱形状态 不能用4个点的坐标范围去判断点击区域是否在图片内 420 | * 421 | * @return 422 | */ 423 | private boolean isInBitmap(MotionEvent event) { 424 | float[] arrayOfFloat1 = new float[9]; 425 | this.matrix.getValues(arrayOfFloat1); 426 | //左上角 427 | float f1 = 0.0F * arrayOfFloat1[0] + 0.0F * arrayOfFloat1[1] + arrayOfFloat1[2]; 428 | float f2 = 0.0F * arrayOfFloat1[3] + 0.0F * arrayOfFloat1[4] + arrayOfFloat1[5]; 429 | //右上角 430 | float f3 = arrayOfFloat1[0] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat1[1] + arrayOfFloat1[2]; 431 | float f4 = arrayOfFloat1[3] * this.mBitmap.getWidth() + 0.0F * arrayOfFloat1[4] + arrayOfFloat1[5]; 432 | //左下角 433 | float f5 = 0.0F * arrayOfFloat1[0] + arrayOfFloat1[1] * this.mBitmap.getHeight() + arrayOfFloat1[2]; 434 | float f6 = 0.0F * arrayOfFloat1[3] + arrayOfFloat1[4] * this.mBitmap.getHeight() + arrayOfFloat1[5]; 435 | //右下角 436 | float f7 = arrayOfFloat1[0] * this.mBitmap.getWidth() + arrayOfFloat1[1] * this.mBitmap.getHeight() + arrayOfFloat1[2]; 437 | float f8 = arrayOfFloat1[3] * this.mBitmap.getWidth() + arrayOfFloat1[4] * this.mBitmap.getHeight() + arrayOfFloat1[5]; 438 | 439 | float[] arrayOfFloat2 = new float[4]; 440 | float[] arrayOfFloat3 = new float[4]; 441 | //确定X方向的范围 442 | arrayOfFloat2[0] = f1;//左上的x 443 | arrayOfFloat2[1] = f3;//右上的x 444 | arrayOfFloat2[2] = f7;//右下的x 445 | arrayOfFloat2[3] = f5;//左下的x 446 | //确定Y方向的范围 447 | arrayOfFloat3[0] = f2;//左上的y 448 | arrayOfFloat3[1] = f4;//右上的y 449 | arrayOfFloat3[2] = f8;//右下的y 450 | arrayOfFloat3[3] = f6;//左下的y 451 | return pointInRect(arrayOfFloat2, arrayOfFloat3, event.getX(0), event.getY(0)); 452 | } 453 | 454 | /** 455 | * 判断点是否在一个矩形内部 456 | * 457 | * @param xRange 458 | * @param yRange 459 | * @param x 460 | * @param y 461 | * @return 462 | */ 463 | private boolean pointInRect(float[] xRange, float[] yRange, float x, float y) { 464 | //四条边的长度 465 | double a1 = Math.hypot(xRange[0] - xRange[1], yRange[0] - yRange[1]); 466 | double a2 = Math.hypot(xRange[1] - xRange[2], yRange[1] - yRange[2]); 467 | double a3 = Math.hypot(xRange[3] - xRange[2], yRange[3] - yRange[2]); 468 | double a4 = Math.hypot(xRange[0] - xRange[3], yRange[0] - yRange[3]); 469 | //待检测点到四个点的距离 470 | double b1 = Math.hypot(x - xRange[0], y - yRange[0]); 471 | double b2 = Math.hypot(x - xRange[1], y - yRange[1]); 472 | double b3 = Math.hypot(x - xRange[2], y - yRange[2]); 473 | double b4 = Math.hypot(x - xRange[3], y - yRange[3]); 474 | 475 | double u1 = (a1 + b1 + b2) / 2; 476 | double u2 = (a2 + b2 + b3) / 2; 477 | double u3 = (a3 + b3 + b4) / 2; 478 | double u4 = (a4 + b4 + b1) / 2; 479 | 480 | //矩形的面积 481 | double s = a1 * a2; 482 | //海伦公式 计算4个三角形面积 483 | double ss = Math.sqrt(u1 * (u1 - a1) * (u1 - b1) * (u1 - b2)) 484 | + Math.sqrt(u2 * (u2 - a2) * (u2 - b2) * (u2 - b3)) 485 | + Math.sqrt(u3 * (u3 - a3) * (u3 - b3) * (u3 - b4)) 486 | + Math.sqrt(u4 * (u4 - a4) * (u4 - b4) * (u4 - b1)); 487 | return Math.abs(s - ss) < 0.5; 488 | 489 | 490 | } 491 | 492 | 493 | /** 494 | * 触摸是否在某个button范围 495 | * 496 | * @param event 497 | * @param rect 498 | * @return 499 | */ 500 | private boolean isInButton(MotionEvent event, Rect rect) { 501 | int left = rect.left; 502 | int right = rect.right; 503 | int top = rect.top; 504 | int bottom = rect.bottom; 505 | return event.getX(0) >= left && event.getX(0) <= right && event.getY(0) >= top && event.getY(0) <= bottom; 506 | } 507 | 508 | /** 509 | * 触摸是否在拉伸区域内 510 | * 511 | * @param event 512 | * @return 513 | */ 514 | private boolean isInResize(MotionEvent event) { 515 | int left = -20 + this.dst_resize.left; 516 | int top = -20 + this.dst_resize.top; 517 | int right = 20 + this.dst_resize.right; 518 | int bottom = 20 + this.dst_resize.bottom; 519 | return event.getX(0) >= left && event.getX(0) <= right && event.getY(0) >= top && event.getY(0) <= bottom; 520 | } 521 | 522 | /** 523 | * 触摸的位置和图片左上角位置的中点 524 | * 525 | * @param event 526 | */ 527 | private void midPointToStartPoint(MotionEvent event) { 528 | float[] arrayOfFloat = new float[9]; 529 | matrix.getValues(arrayOfFloat); 530 | float f1 = 0.0f * arrayOfFloat[0] + 0.0f * arrayOfFloat[1] + arrayOfFloat[2]; 531 | float f2 = 0.0f * arrayOfFloat[3] + 0.0f * arrayOfFloat[4] + arrayOfFloat[5]; 532 | float f3 = f1 + event.getX(0); 533 | float f4 = f2 + event.getY(0); 534 | mid.set(f3 / 2, f4 / 2); 535 | } 536 | 537 | /** 538 | * 计算对角线交叉的位置 539 | * 540 | * @param paramPointF 541 | */ 542 | private void midDiagonalPoint(PointF paramPointF) { 543 | float[] arrayOfFloat = new float[9]; 544 | this.matrix.getValues(arrayOfFloat); 545 | float f1 = 0.0F * arrayOfFloat[0] + 0.0F * arrayOfFloat[1] + arrayOfFloat[2]; 546 | float f2 = 0.0F * arrayOfFloat[3] + 0.0F * arrayOfFloat[4] + arrayOfFloat[5]; 547 | float f3 = arrayOfFloat[0] * this.mBitmap.getWidth() + arrayOfFloat[1] * this.mBitmap.getHeight() + arrayOfFloat[2]; 548 | float f4 = arrayOfFloat[3] * this.mBitmap.getWidth() + arrayOfFloat[4] * this.mBitmap.getHeight() + arrayOfFloat[5]; 549 | float f5 = f1 + f3; 550 | float f6 = f2 + f4; 551 | paramPointF.set(f5 / 2.0F, f6 / 2.0F); 552 | } 553 | 554 | 555 | /** 556 | * 在滑动旋转过程中,总是以左上角原点作为绝对坐标计算偏转角度 557 | * 558 | * @param event 559 | * @return 560 | */ 561 | private float rotationToStartPoint(MotionEvent event) { 562 | 563 | float[] arrayOfFloat = new float[9]; 564 | matrix.getValues(arrayOfFloat); 565 | float x = 0.0f * arrayOfFloat[0] + 0.0f * arrayOfFloat[1] + arrayOfFloat[2]; 566 | float y = 0.0f * arrayOfFloat[3] + 0.0f * arrayOfFloat[4] + arrayOfFloat[5]; 567 | double arc = Math.atan2(event.getY(0) - y, event.getX(0) - x); 568 | return (float) Math.toDegrees(arc); 569 | } 570 | 571 | /** 572 | * 触摸点到矩形中点的距离 573 | * 574 | * @param event 575 | * @return 576 | */ 577 | private float diagonalLength(MotionEvent event) { 578 | float diagonalLength = (float) Math.hypot(event.getX(0) - mid.x, event.getY(0) - mid.y); 579 | return diagonalLength; 580 | } 581 | 582 | /** 583 | * 计算双指之间的距离 584 | */ 585 | private float spacing(MotionEvent event) { 586 | if (event.getPointerCount() == 2) { 587 | float x = event.getX(0) - event.getX(1); 588 | float y = event.getY(0) - event.getY(1); 589 | return (float) Math.sqrt(x * x + y * y); 590 | } else { 591 | return 0; 592 | } 593 | } 594 | 595 | public interface OperationListener { 596 | void onDeleteClick(); 597 | 598 | void onEdit(StickerView stickerView); 599 | 600 | void onTop(StickerView stickerView); 601 | } 602 | 603 | public void setOperationListener(OperationListener operationListener) { 604 | this.operationListener = operationListener; 605 | } 606 | 607 | public void setInEdit(boolean isInEdit) { 608 | this.isInEdit = isInEdit; 609 | invalidate(); 610 | } 611 | } 612 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/fab_label_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_display.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 57 | 58 | 65 | 66 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_display.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_input_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 18 | 19 | 33 | 34 | 49 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_dislplay.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/bubble_7_rb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xhdpi/bubble_7_rb.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_add_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xhdpi/ic_add_white.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xhdpi/ic_background.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_cat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xhdpi/ic_cat.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/icon_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xhdpi/icon_delete.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/icon_flip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xhdpi/icon_flip.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/icon_resize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xhdpi/icon_resize.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/icon_top_enable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xhdpi/icon_top_enable.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 10 | 11 | 15 | 16 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/test/java/com/example/abner/stickerdemo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.example.abner.stickerdemo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /bubbleShot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/bubbleShot.jpg -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.3.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Sep 22 14:04:25 CST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 nimengbo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /stickerGIF.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/stickerGIF.gif -------------------------------------------------------------------------------- /sticker_demo.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nimengbo/StickerView/a49d88664d27fe1de0832ba49d6ec4cc3664f748/sticker_demo.apk --------------------------------------------------------------------------------