Commit 282ac0b1 authored by Grigory Fedorov's avatar Grigory Fedorov

First implementation of avatar select using jdamcd/android-crop library.

parent d1ffe032
......@@ -71,4 +71,6 @@ dependencies {
compile "org.igniterealtime.smack:smack-tcp:$smackVersion"
compile project('otr4j')
compile project('MemorizingTrustManager')
compile 'com.soundcloud.android:android-crop:1.0.0@aar'
}
......@@ -442,6 +442,9 @@
<activity
android:name="de.duenndns.ssl.MemorizingActivity"
/>
<activity android:name="com.soundcloud.android.crop.CropImageActivity" />
<receiver android:name=".receiver.GoAwayReceiver" />
<receiver android:name=".receiver.GoXaReceiver" />
<receiver android:name=".receiver.ComposingPausedReceiver" />
......
......@@ -12,6 +12,7 @@ import android.view.WindowManager;
import com.xabber.android.R;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.intent.EntityIntentBuilder;
......@@ -130,4 +131,11 @@ public class AccountInfoEditor extends ManagedActivity implements OnAccountChang
return super.onOptionsItemSelected(item);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
getFragmentManager().findFragmentById(R.id.fragment_container).onActivityResult(requestCode,
resultCode, data);
}
}
......@@ -14,6 +14,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.soundcloud.android.crop.Crop;
import com.xabber.android.R;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
......@@ -30,6 +31,7 @@ import org.jivesoftware.smackx.vcardtemp.packet.VCard;
import org.xmlpull.v1.XmlPullParserException;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
......@@ -200,21 +202,45 @@ public class AccountInfoEditorFragment extends Fragment implements OnVCardSaveLi
}
private void changeAvatar() {
Intent pickAvatar = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickAvatar, 1);
// Intent pickAvatar = new Intent(Intent.ACTION_PICK,
// android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// startActivityForResult(pickAvatar, 1);
Crop.pickImage(getActivity());
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
imageUri = data.getData();
avatar.setImageURI(imageUri);
public void onActivityResult(int requestCode, int resultCode, Intent result) {
LogManager.i(this, "onActivityResult");
// super.onActivityResult(requestCode, resultCode, data);
// if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
// imageUri = data.getData();
// avatar.setImageURI(imageUri);
// }
if (requestCode == Crop.REQUEST_PICK && resultCode == Activity.RESULT_OK) {
beginCrop(result.getData());
} else if (requestCode == Crop.REQUEST_CROP) {
handleCrop(resultCode, result);
}
}
private void beginCrop(Uri source) {
imageUri = Uri.fromFile(new File(getActivity().getCacheDir(), "cropped"));
Crop.of(source, imageUri).asSquare().start(getActivity());
}
private void handleCrop(int resultCode, Intent result) {
if (resultCode == Activity.RESULT_OK) {
avatar.setImageURI(Crop.getOutput(result));
} else if (resultCode == Crop.RESULT_ERROR) {
Toast.makeText(getActivity(), Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
}
}
public static byte[] getBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment