User is now able to crop custom images

This commit is contained in:
Michael Schättgen 2018-06-06 21:57:38 +02:00
parent 04e6e36811
commit d8bfe2e947
5 changed files with 36 additions and 5 deletions

View file

@ -32,6 +32,7 @@ dependencies {
implementation 'com.android.support:recyclerview-v7:27.1.1' implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1' implementation 'com.android.support:design:27.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.takisoft.fix:preference-v7:27.1.1.1' implementation 'com.takisoft.fix:preference-v7:27.1.1.1'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'me.dm7.barcodescanner:zxing:1.9' implementation 'me.dm7.barcodescanner:zxing:1.9'

View file

@ -15,6 +15,8 @@ public class TextDrawableHelper {
ColorGenerator generator = ColorGenerator.MATERIAL; ColorGenerator generator = ColorGenerator.MATERIAL;
int color = generator.getColor(s); int color = generator.getColor(s);
return TextDrawable.builder().buildRound(s.substring(0, 1).toUpperCase(), color); return TextDrawable.builder().beginConfig()
.width(100)
.height(100).endConfig().buildRect(s.substring(0, 1).toUpperCase(), color);
} }
} }

View file

@ -29,6 +29,7 @@ import com.esafirm.imagepicker.features.ImagePicker;
import com.esafirm.imagepicker.features.ReturnMode; import com.esafirm.imagepicker.features.ReturnMode;
import com.esafirm.imagepicker.model.Image; import com.esafirm.imagepicker.model.Image;
import de.hdodenhof.circleimageview.CircleImageView;
import me.impy.aegis.R; import me.impy.aegis.R;
import me.impy.aegis.crypto.KeyInfo; import me.impy.aegis.crypto.KeyInfo;
import me.impy.aegis.crypto.KeyInfoException; import me.impy.aegis.crypto.KeyInfoException;
@ -45,7 +46,8 @@ public class EditProfileActivity extends AegisActivity {
private boolean _edited = false; private boolean _edited = false;
private KeyProfile _profile; private KeyProfile _profile;
private ImageView _iconView; private CircleImageView _iconView;
private ImageView _saveImageButton;
private EditText _textName; private EditText _textName;
private EditText _textIssuer; private EditText _textIssuer;
@ -84,6 +86,7 @@ public class EditProfileActivity extends AegisActivity {
_iconView = findViewById(R.id.profile_drawable); _iconView = findViewById(R.id.profile_drawable);
_kropView = findViewById(R.id.krop_view); _kropView = findViewById(R.id.krop_view);
_saveImageButton = findViewById(R.id.iv_saveImage);
_textName = findViewById(R.id.text_name); _textName = findViewById(R.id.text_name);
_textIssuer = findViewById(R.id.text_issuer); _textIssuer = findViewById(R.id.text_issuer);
_textPeriod = findViewById(R.id.text_period); _textPeriod = findViewById(R.id.text_period);
@ -295,6 +298,14 @@ public class EditProfileActivity extends AegisActivity {
Bitmap bitmap = BitmapFactory.decodeFile(image.getPath(),bmOptions); Bitmap bitmap = BitmapFactory.decodeFile(image.getPath(),bmOptions);
_kropView.setBitmap(bitmap); _kropView.setBitmap(bitmap);
_kropView.setVisibility(View.VISIBLE); _kropView.setVisibility(View.VISIBLE);
_saveImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
_iconView.setImageBitmap(_kropView.getCroppedBitmap());
_kropView.setVisibility(View.GONE);
}
});
} }
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/>
</vector>

View file

@ -16,14 +16,14 @@
android:layout_height="250dp" android:layout_height="250dp"
android:background="@color/colorPrimary"> android:background="@color/colorPrimary">
<de.hdodenhof.circleimageview.CircleImageView
<ImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_drawable" android:id="@+id/profile_drawable"
android:layout_width="100dp" android:layout_width="100dp"
android:layout_height="100dp" android:layout_height="100dp"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:scaleType="centerCrop" /> />
<com.avito.android.krop.KropView <com.avito.android.krop.KropView
android:id="@+id/krop_view" android:id="@+id/krop_view"
@ -37,6 +37,14 @@
app:krop_offset="70dp" app:krop_offset="70dp"
app:krop_overlayColor="#aaffffff" > app:krop_overlayColor="#aaffffff" >
<ImageView
android:id="@+id/iv_saveImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="15dp"
android:src="@drawable/ic_check_black_24dp"
android:tint="?attr/iconColorPrimary" />
</com.avito.android.krop.KropView> </com.avito.android.krop.KropView>
</RelativeLayout> </RelativeLayout>