-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19420a1
commit a59a3d1
Showing
32 changed files
with
3,608 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
app/src/main/java/ysn/com/demo/cropimageview/CropActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package ysn.com.demo.cropimageview; | ||
|
||
import android.app.Activity; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.widget.LinearLayout; | ||
|
||
import java.util.Arrays; | ||
|
||
import ysn.com.view.cropimageview.CropImageView; | ||
import ysn.com.view.cropimageview.listener.OnCropMultiListener; | ||
import ysn.com.view.cropimageview.mode.CropMode; | ||
import ysn.com.view.cropimageview.mode.RotateAngle; | ||
import ysn.com.view.cropimageview.utils.FileUtils; | ||
import ysn.com.view.cropimageview.utils.Utils; | ||
|
||
/** | ||
* @Author yangsanning | ||
* @ClassName CropActivity | ||
* @Description 一句话概括作用 | ||
* @Date 2020/1/7 | ||
* @History 2020/1/7 author: description: | ||
*/ | ||
public class CropActivity extends AppCompatActivity implements View.OnClickListener, OnCropMultiListener { | ||
|
||
public static final int REQUEST_CODE_SELECT = 100; | ||
|
||
RecyclerView cropModeRecyclerView; | ||
RecyclerView angleRecyclerView; | ||
CropImageView cropImageView; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_crop); | ||
|
||
cropImageView = findViewById(R.id.crop_activity_crop_image_view); | ||
cropImageView.setOnCropMultiListener(this); | ||
|
||
initCropModeAdapter(); | ||
initAngleAdapter(); | ||
|
||
findViewById(R.id.crop_activity_select_image).setOnClickListener(this); | ||
findViewById(R.id.crop_activity_crop).setOnClickListener(this); | ||
} | ||
|
||
private void initCropModeAdapter() { | ||
StringAdapter cropModeAdapter = new StringAdapter(); | ||
cropModeAdapter.setOnItemClickListener((adapter, view, position) -> | ||
cropImageView.setCropMode(CropMode.getValue(position))); | ||
cropModeRecyclerView = findViewById(R.id.crop_activity_crop_mode_recycler_view); | ||
LinearLayoutManager layoutManager = new LinearLayoutManager(this); | ||
layoutManager.setOrientation(LinearLayout.HORIZONTAL); | ||
cropModeRecyclerView.setLayoutManager(layoutManager); | ||
cropModeRecyclerView.setAdapter(cropModeAdapter); | ||
cropModeAdapter.setNewData(Arrays.asList(getResources().getStringArray(R.array.crop_mode))); | ||
} | ||
|
||
private void initAngleAdapter() { | ||
int[] angles = getResources().getIntArray(R.array.angle_value); | ||
StringAdapter angleAdapter = new StringAdapter(); | ||
angleAdapter.setOnItemClickListener((adapter, view, position) -> | ||
cropImageView.rotateImage(RotateAngle.getValue(angles[position]))); | ||
angleRecyclerView = findViewById(R.id.crop_activity_angle_recycler_view); | ||
LinearLayoutManager layoutManager = new LinearLayoutManager(this); | ||
layoutManager.setOrientation(LinearLayout.HORIZONTAL); | ||
angleRecyclerView.setLayoutManager(layoutManager); | ||
angleRecyclerView.setAdapter(angleAdapter); | ||
angleAdapter.setNewData(Arrays.asList(getResources().getStringArray(R.array.angle))); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
switch (v.getId()) { | ||
case R.id.crop_activity_select_image: | ||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); | ||
intent.addCategory(Intent.CATEGORY_OPENABLE); | ||
intent.setType("image/*"); | ||
startActivityForResult(intent, REQUEST_CODE_SELECT); | ||
break; | ||
case R.id.crop_activity_crop: | ||
cropImageView.crop(FileUtils.getYsnUri(CropActivity.this, Bitmap.CompressFormat.PNG)); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public void onLoadSuccess() { | ||
|
||
} | ||
|
||
@Override | ||
public void onCropSuccess(Bitmap cropBitmap) { | ||
|
||
} | ||
|
||
@Override | ||
public void onCropSaveSuccess(Uri saveUri) { | ||
Intent intent = new Intent(); | ||
intent.setData(saveUri); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable e) { | ||
|
||
} | ||
|
||
|
||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, Intent result) { | ||
super.onActivityResult(requestCode, resultCode, result); | ||
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_SELECT) { | ||
cropImageView.load(result.getData(), true); | ||
} | ||
} | ||
} |
51 changes: 50 additions & 1 deletion
51
app/src/main/java/ysn/com/demo/cropimageview/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,62 @@ | ||
package ysn.com.demo.cropimageview; | ||
|
||
import android.Manifest; | ||
import android.annotation.SuppressLint; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.ImageView; | ||
import android.widget.Toast; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
import com.tbruyelle.rxpermissions2.RxPermissions; | ||
|
||
import io.reactivex.android.schedulers.AndroidSchedulers; | ||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
public static final int REQUEST_CODE_CROP = 2020; | ||
|
||
ImageView cropImageView; | ||
|
||
@SuppressLint("CheckResult") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
cropImageView = findViewById(R.id.main_activity_preview); | ||
|
||
new RxPermissions(this) | ||
.request(Manifest.permission.WRITE_EXTERNAL_STORAGE) | ||
.subscribeOn(AndroidSchedulers.mainThread()) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribe(granted -> { | ||
if (granted) { | ||
setViewClickListener(); | ||
} else { | ||
Toast.makeText(this, "权限不足", Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
} | ||
|
||
private void setViewClickListener() { | ||
findViewById(R.id.main_activity_preview).setOnClickListener(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
startActivityForResult(new Intent(this, CropActivity.class), REQUEST_CODE_CROP); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (resultCode == RESULT_OK) { | ||
if (requestCode == REQUEST_CODE_CROP && data != null) { | ||
cropImageView.setImageURI(data.getData()); | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/ysn/com/demo/cropimageview/StringAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ysn.com.demo.cropimageview; | ||
|
||
import com.chad.library.adapter.base.BaseQuickAdapter; | ||
import com.chad.library.adapter.base.BaseViewHolder; | ||
|
||
/** | ||
* @Author yangsanning | ||
* @ClassName StringAdapter | ||
* @Description 一句话概括作用 | ||
* @Date 2020/1/7 | ||
* @History 2020/1/7 author: description: | ||
*/ | ||
public class StringAdapter extends BaseQuickAdapter<String, BaseViewHolder> { | ||
|
||
public StringAdapter() { | ||
super(R.layout.item_string); | ||
} | ||
|
||
@Override | ||
protected void convert(BaseViewHolder helper, String item) { | ||
helper.setText(R.id.string_item_text, item); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:ysn="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context=".MainActivity"> | ||
|
||
<ysn.com.view.cropimageview.CropImageView | ||
android:id="@+id/crop_activity_crop_image_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" | ||
android:padding="15dp" | ||
ysn:civ_anim_duration="100" | ||
ysn:civ_anim_enabled="true" | ||
ysn:civ_bg_color="@android:color/transparent" | ||
ysn:civ_crop_enabled="true" | ||
ysn:civ_crop_mode="fit_image" | ||
ysn:civ_drag_point_padding="8dp" | ||
ysn:civ_drag_point_show="true" | ||
ysn:civ_drag_point_size="12dp" | ||
ysn:civ_gird_column_part="3" | ||
ysn:civ_gird_row_part="3" | ||
ysn:civ_grid_color="@android:color/white" | ||
ysn:civ_grid_line_mode="show_always" | ||
ysn:civ_grid_line_stroke="1dp" | ||
ysn:civ_grid_min_size="100dp" | ||
ysn:civ_grid_stroke="1dp" | ||
ysn:civ_img_src="@drawable/mm" | ||
ysn:civ_make_color="#AA1C1C1C" /> | ||
|
||
<RelativeLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:orientation="horizontal" | ||
android:padding="5dp"> | ||
|
||
<TextView | ||
android:id="@+id/crop_activity_select_image" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="12dp" | ||
android:text="选择图片" | ||
android:textColor="@color/text" | ||
android:textSize="18sp" /> | ||
|
||
<TextView | ||
android:id="@+id/crop_activity_crop" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentEnd="true" | ||
android:padding="12dp" | ||
android:text="裁剪" | ||
android:textColor="@color/text" | ||
android:textSize="18sp" /> | ||
</RelativeLayout> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="0.5dp" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginRight="10dp" | ||
android:background="@color/line" /> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/crop_activity_angle_recycler_view" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginRight="10dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="0.5dp" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginRight="10dp" | ||
android:background="@color/line" /> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/crop_activity_crop_mode_recycler_view" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginRight="10dp" /> | ||
|
||
<View | ||
android:layout_width="match_parent" | ||
android:layout_height="0.5dp" | ||
android:layout_marginLeft="10dp" | ||
android:layout_marginRight="10dp" | ||
android:background="@color/line" /> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context=".MainActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/main_activity_preview" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="15dp" | ||
android:src="@drawable/mm" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Hello World!" /> | ||
|
||
</FrameLayout> | ||
android:layout_alignParentBottom="true" | ||
android:layout_marginBottom="40dp" | ||
android:background="@color/colorPrimary" | ||
android:gravity="center" | ||
android:padding="10dp" | ||
android:text="点击图片进入裁剪" | ||
android:textColor="@android:color/white" | ||
android:textSize="18sp" /> | ||
</RelativeLayout> |
Oops, something went wrong.