예제 #1
0
		static void AddProfilePicture(Context context, string guid)
		{
			BitmapFactory.Options dimensions = new BitmapFactory.Options(); 
			Bitmap bitmap = BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.profile_1, dimensions);

			int big_width = 400;//(int)TypedValue.ApplyDimension (ComplexUnitType.Dip, 200, context.Resources.DisplayMetrics);
			int small_width = 80;//(int)TypedValue.ApplyDimension (ComplexUnitType.Dip, 80, context.Resources.DisplayMetrics);

			Bitmap big_profile = bitmap;

			// scalling
			int w = 1;
			int h = 1;
			float v = 0;
			if (bitmap.Width < bitmap.Height) {
				v = (float)(big_width+2) / (float)bitmap.Width;
			} else {
				v = (float)(big_width+2) / (float)bitmap.Height;
			}
			w = (int)((float)bitmap.Width * v);
			h = (int)((float)bitmap.Height * v);									
			big_profile = Bitmap.CreateScaledBitmap (bitmap, w,h, false);			

			// 
			int x = (big_profile.Width - big_width) / 2;
			int y = (big_profile.Height - big_width) / 2;
			// rounding errors
			if (big_profile.Width < big_width)
				big_width = bitmap.Width;
			if (big_profile.Height < big_width)
				big_width = bitmap.Height;
			big_profile = Bitmap.CreateBitmap (big_profile, x,y,big_width, big_width);
			Bitmap small_profile = global::Android.Media.ThumbnailUtils.ExtractThumbnail (big_profile, small_width, small_width);

			ProfilePicture pic = new ProfilePicture ();
			pic.Guid = guid;
			pic.Big = getBytes (big_profile).ToArray<byte> ();
			pic.Small = getBytes (small_profile).ToArray<byte> ();
			Database.Instance().SaveProfilePicture (pic);

		}
예제 #2
0
		public override void OnViewCreated (View view, Bundle savedInstanceState)
		{
			this.profile = Database.Instance ().GetProfileById (1);
			this.picture = Database.Instance ().GetPicture (profile.Guid);

			if (this.picture == null) {
				this.picture = new ProfilePicture ();
			}

			ImageView iv = view.FindViewById<ImageView> (Resource.Id.picture);

			if (this.picture.Big != null) {			
				iv.SetImageBitmap (Utils.BytesToBitmap (this.picture.Big));
			}
							
			iv.Click += delegate {                
				Intent intent = new Intent(MediaStore.ActionImageCapture);
				mImageCaptureUri = global::Android.Net.Uri.FromFile(new Java.IO.File(CreateDirectoryForPictures(), string.Format("myPhoto_{0}.jpg", System.Guid.NewGuid())));
				intent.PutExtra(MediaStore.ExtraOutput, mImageCaptureUri);
				intent.PutExtra("return-data", false);
				StartActivityForResult(intent, PICK_FROM_CAMERA);
			} ;

			EditText name = (view.FindViewById<EditText> (Resource.Id.name));
			name.Text = profile.Name == null ? "" : profile.Name;
			name.TextChanged += (object sender, global::Android.Text.TextChangedEventArgs e) => {
				profile.Name = e.Text.ToString();
				profile_dirty = true;
			};

			RadioGroup gender = (view.FindViewById<RadioGroup> (Resource.Id.radioGender));
			gender.Check (profile.Gender == Profile.GENDER_MALE ? Resource.Id.genderMale : Resource.Id.genderFemale);
			gender.CheckedChange += (object sender, RadioGroup.CheckedChangeEventArgs e) => {
				profile.Gender = e.CheckedId == Resource.Id.genderMale ? Profile.GENDER_MALE : Profile.GENDER_FEMALE;
				profile_dirty = true;
			};

			CheckBox meetMen = (view.FindViewById<CheckBox> (Resource.Id.meet_men));
			meetMen.Checked = (profile.ToMeet & Profile.GENDER_MALE)==Profile.GENDER_MALE;
			meetMen.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
				if (e.IsChecked) {
					profile.ToMeet |= Profile.GENDER_MALE;
				}
				else {
					profile.ToMeet &= ~Profile.GENDER_MALE;
				}
				profile_dirty = true;
			};

			CheckBox meetWomen = (view.FindViewById<CheckBox> (Resource.Id.meet_women));
			meetWomen.Checked = (profile.ToMeet & Profile.GENDER_FEMALE)==Profile.GENDER_FEMALE;
			meetWomen.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
				if (e.IsChecked) {
					profile.ToMeet |= Profile.GENDER_FEMALE;
				}
				else {
					profile.ToMeet &= ~Profile.GENDER_FEMALE;
				}
				profile_dirty = true;
			};
				
			EditText status = (view.FindViewById<EditText> (Resource.Id.status));
			status.Text = profile.Status == null ? "" : profile.Status;
			status.TextChanged += (object sender, global::Android.Text.TextChangedEventArgs e) => {
				profile.Status = e.Text.ToString();
				profile_dirty = true;
			};				

		}
예제 #3
0
		public void RefreshProfile(Profile profile)
		{
			if (profile == null)
				return;

			if (null != this.ProfileBroadcast) {
				this.ProfileBroadcast.RefreshProfile (profile);
			}
			if (null != this.UPDBroadcastListener) {
				this.UPDBroadcastListener.RefreshProfile (profile);
			}
			lock (this.MyPicture) {
				this.MyPicture = Database.Instance ().GetPicture (profile.Guid);
			}
			lock (this.MyProfile) {
				this.MyProfile = profile;
			}
		}	
예제 #4
0
		// request handler sends out a picture, this handles accepting the pciture
		private void HandleProfileMessage(MemoryStream data, string fromIp, TcpClient tcpClient)
		{
			if (Logging) {
				Database.Instance ().SaveLog ("Profile - HandleProfileMessage() " + fromIp);
			}

			MessageProfile m = ProtoBuf.Serializer.Deserialize<MessageProfile> (data);

			// look up the profile
			Profile profile = Database.Instance().GetProfileByGuid(m.Guid);
			if (profile == null) {
				profile = new Profile();
			}
			// and picture
			ProfilePicture pic = Database.Instance().GetPicture(m.Guid);
			if (pic == null) {
				pic = new ProfilePicture();
			}								

			profile.Guid = m.Guid;
			profile.Version = m.Version;
			profile.PicVersion = m.PicVersion;
			profile.Name = m.Name;
			profile.Gender = m.Gender;
			profile.ToMeet = m.ToMeet;
			profile.Status = m.Status;
			if (profile.Blocked < BLOCK_COUNT_LIMIT) {
				// change to show
				if (profile.State == Profile.STATE_PENDING || profile.State == Profile.STATE_HIDE) {
					profile.State = Profile.STATE_SHOW;
				}
				// if picture included
				if (null != m.Small) {
					pic.Guid = m.Guid;
					pic.Small = m.Small;
					pic.Big = m.Big;
					Database.Instance().SaveProfilePicture(pic);
				}
			}
			Database.Instance().SaveProfile(profile);

			// check for and clear out any old entry
			// this happens when some unistalls and reinstalls creating a new profile but on the same device					
			Profile old = Database.Instance().GetProfileByIpNotGuid(fromIp, m.Guid);
			if (null != old) {
				Database.Instance().DeleteProfile(old.Guid);
			}				

		}