PublishProfilePictureActivity.java

  1package eu.siacs.conversations.ui;
  2
  3import android.content.Intent;
  4import android.graphics.Bitmap;
  5import android.net.Uri;
  6import android.os.Bundle;
  7import android.util.Log;
  8import android.view.View;
  9import android.view.View.OnClickListener;
 10import android.widget.Button;
 11import android.widget.ImageView;
 12import android.widget.TextView;
 13import eu.siacs.conversations.R;
 14import eu.siacs.conversations.utils.PhoneHelper;
 15
 16public class PublishProfilePictureActivity extends XmppActivity {
 17	
 18	private static final int REQUEST_CHOOSE_FILE = 0xac23;
 19	
 20	private ImageView avatar;
 21	private TextView explanation;
 22	private Button cancelButton;
 23	private Button publishButton;
 24	
 25	private Uri avatarUri;
 26	
 27	@Override
 28	public void onCreate(Bundle savedInstanceState) {
 29		super.onCreate(savedInstanceState);
 30		setContentView(R.layout.activity_publish_profile_picture);
 31		this.avatar = (ImageView) findViewById(R.id.account_image);
 32		this.explanation = (TextView) findViewById(R.id.explanation);
 33		this.cancelButton = (Button) findViewById(R.id.cancel_button);
 34		this.publishButton = (Button) findViewById(R.id.publish_button);
 35		this.publishButton.setOnClickListener(new OnClickListener() {
 36			
 37			@Override
 38			public void onClick(View v) {
 39				if (avatarUri!=null) {
 40					xmppConnectionService.pushAvatar(null, avatarUri);
 41					finish();
 42				}
 43			}
 44		});
 45		this.cancelButton.setOnClickListener(new OnClickListener() {
 46			
 47			@Override
 48			public void onClick(View v) {
 49				finish();
 50			}
 51		});
 52		this.avatar.setOnClickListener(new OnClickListener() {
 53			
 54			@Override
 55			public void onClick(View v) {
 56				Intent attachFileIntent = new Intent();
 57				attachFileIntent.setType("image/*");
 58				attachFileIntent.setAction(Intent.ACTION_GET_CONTENT);
 59				Intent chooser = Intent.createChooser(attachFileIntent,
 60						getString(R.string.attach_file));
 61				startActivityForResult(chooser, REQUEST_CHOOSE_FILE);
 62			}
 63		});
 64	}
 65	
 66	@Override
 67	protected void onActivityResult(int requestCode, int resultCode,
 68			final Intent data) {
 69		super.onActivityResult(requestCode, resultCode, data);
 70		Log.d("xmppService","on activity result");
 71		if (resultCode == RESULT_OK) {
 72			if (requestCode == REQUEST_CHOOSE_FILE) {
 73				Log.d("xmppService","bla");
 74				this.avatarUri = data.getData();
 75			}
 76		}
 77	}
 78
 79	@Override
 80	protected void onBackendConnected() {
 81		Log.d("xmppService","on backend connected");
 82		if (this.avatarUri == null) {
 83			avatarUri = PhoneHelper.getSefliUri(getApplicationContext());
 84		}
 85		loadImageIntoPreview(avatarUri);
 86		String explainText = getString(R.string.publish_avatar_explanation,"daniel@gultsch.de");
 87		this.explanation.setText(explainText);
 88	}
 89	
 90	protected void loadImageIntoPreview(Uri uri) {
 91		Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare(uri, 384);
 92		this.avatar.setImageBitmap(bm);
 93		enablePublishButton();
 94	}
 95	
 96	protected void enablePublishButton() {
 97		this.publishButton.setEnabled(true);
 98		this.publishButton.setTextColor(getPrimaryTextColor());
 99	}
100
101}