Java Code Examples for com.avos.avoscloud.AVUser#getCurrentUser()

The following examples show how to use com.avos.avoscloud.AVUser#getCurrentUser() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContactFragment.java    From LoveTalkClient with Apache License 2.0 6 votes vote down vote up
private void deleteFriend(final AVUser user) {
	new MyAsyncTask(context) {

		@Override
		protected void doInBack() throws Exception {
			// TODO Auto-generated method stub
			AVUser curUser = AVUser.getCurrentUser();
			CloudService.removeFriendForBoth(curUser, user);
		}

		@Override
		protected void onSucceed() {
			Utils.toast("删除成功");
			userAdapter.remove(user);
		}
	};
}
 
Example 2
Source File: ChatHomeActivity.java    From PlayTogether with Apache License 2.0 6 votes vote down vote up
@Override
public void afterCreate()
{
	ActionBar actionBar = getSupportActionBar();
	if (actionBar != null) actionBar.setTitle("");
	User me = AVUser.getCurrentUser(User.class);
	if (me == null)
	{
		Toast.makeText(this, "请先进行登录,", Toast.LENGTH_SHORT).show();
		finish();
	}
	//初始化用户信息
	mTvUsername.setText(me.getUsername());
	AVFile avAvatar = me.getAvatar();
	if (avAvatar != null)
		PicassoUtils.displayFitImage(this, Uri.parse(avAvatar.getThumbnailUrl(true, Constant
						.AVATAR_WIDTH, Constant.AVATAR_HEIGHT)), mIvAvatar, null);
	//初始化事件
	initEvent();
	//初始化viewpager
	initViewPagerAndTabLayout();
}
 
Example 3
Source File: InvitationCategoryController.java    From PlayTogether with Apache License 2.0 6 votes vote down vote up
/**
	 * 保存用户的位置
	 *
	 * @param longitude
	 * @param latitude
	 */
	public void updateLocation(double longitude, double latitude)
	{
		User user = AVUser.getCurrentUser(User.class);
//		Logger.e(user.getLocation()+"");
		user.setLocation(new AVGeoPoint(latitude, longitude));
		mUserBll.updateLocation(user)
						.subscribeOn(Schedulers.io())
						.observeOn(AndroidSchedulers.mainThread())
						.subscribe(new Action1<Void>()
						{
							@Override
							public void call(Void aVoid)
							{
//						Logger.e("更新定位成功");
							}
						}, new Action1<Throwable>()
						{
							@Override
							public void call(Throwable throwable)
							{
//						Logger.e("更新定位失败:" + throwable.getMessage());
							}
						});
	}
 
Example 4
Source File: ChatActivity.java    From LoveTalkClient with Apache License 2.0 6 votes vote down vote up
public void initData(Intent intent) {
		mCurUser = AVUser.getCurrentUser();
		mDbHelper = new DBHelper(ctx, "chat.db", 1);
		int roomTypeInt = intent.getIntExtra(ROOM_TYPE, RoomType.Single.getValue());
		roomType = RoomType.fromInt(roomTypeInt);
		msgSize = PAGE_SIZE;
		if (roomType == RoomType.Single) {
			String chatUserId = intent.getStringExtra(CHAT_USER_ID);
			chatUser = DemoApplication.lookupUser(chatUserId);
			if (chatUser != null) {
				ChatService.withUserToWatch(chatUser, true);
				msgAgent = new MsgAgent(roomType, chatUser.getObjectId());
			} else {
				Log.d("test1", chatUserId);
			}


		} else {
//      String groupId = intent.getStringExtra(GROUP_ID);
//      Session session = ChatService.getSession();
//      group = session.getGroup(groupId);
//      chatGroup = App.lookupChatGroup(groupId);
//      msgAgent = new MsgAgent(roomType, groupId);
		}
	}
 
Example 5
Source File: MeFragment.java    From AndroidPlusJava with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void init() {
    super.init();
    mUser = AVUser.getCurrentUser(User.class);
    mUserName.setText(mUser.getUsername());
    if (mUser.getSlogan() != null) {
        mSlogan.setText(mUser.getSlogan());
    }
    GlideApp.with(this)
            .load(mUser.getAvatar())
            .transform(new CircleCrop())
            .transition(new DrawableTransitionOptions().crossFade())
            .placeholder(R.mipmap.ic_launcher_round)
            .into(mAvatar);

}
 
Example 6
Source File: MySpaceFragment.java    From LoveTalkClient with Apache License 2.0 6 votes vote down vote up
private void showSexChooseDialog() {
	AVUser user = AVUser.getCurrentUser();
	int checkItem = user.getInt("gender") == 0 ? 0 : 1;
	new AlertDialog.Builder(context)
			.setTitle(R.string.sex)
			.setSingleChoiceItems(genderStrings, checkItem,
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog,
											int which) {
							int gender;
							if (which == 0) {
								gender = 0;
							} else {
								gender = 1;
							}
							UserService.saveSex(gender, saveCallback);
							dialog.dismiss();
						}
					}).setNegativeButton(R.string.cancel, null).show();
}
 
Example 7
Source File: Utils.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public static void updateUserLocation() {
	PreferenceMap preferenceMap = PreferenceMap
			.getCurUserPrefDao(DemoApplication.context);
	AVGeoPoint lastLocation = preferenceMap.getLocation();
	String lastaddress = preferenceMap.getAddress();
	if (lastLocation != null) {
		final AVUser user = AVUser.getCurrentUser();
		final AVGeoPoint location = user.getAVGeoPoint("location");
		final String Address = user.getString("address");
		if (location == null
				|| !Utils.doubleEqual(location.getLatitude(),
				lastLocation.getLatitude())
				|| !Utils.doubleEqual(location.getLongitude(),
				lastLocation.getLongitude())) {
			user.put("location", lastLocation);
			user.put("address", lastaddress);
			user.saveInBackground(new SaveCallback() {
				@Override
				public void done(AVException e) {
					if (e != null) {
						e.printStackTrace();
					} else {
						log.v("lastLocation save "
								+ user.getAVGeoPoint("location"));
					}
				}
			});
		}
	}
}
 
Example 8
Source File: AddRequestService.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public static void createAddRequest(AVUser toUser) throws Exception {
	AVUser curUser = AVUser.getCurrentUser();
	AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
	q.whereEqualTo(AddRequest.FROM_USER, curUser);
	q.whereEqualTo(AddRequest.TO_USER, toUser);
	q.whereEqualTo(AddRequest.STATUS, AddRequest.STATUS_WAIT);
	int count = 0;
	try {
		count = q.count();
	} catch (AVException e) {
		e.printStackTrace();
		if (e.getCode() == AVException.OBJECT_NOT_FOUND) {
			count = 0;
		} else {
			throw e;
		}
	}
	if (count > 0) {
		throw new Exception(DemoApplication.context.getString(R.string.contact_alreadyCreateAddRequest));
	} else {
		AddRequest add = new AddRequest();
		add.setFromUser(curUser);
		add.setToUser(toUser);
		add.setStatus(AddRequest.STATUS_WAIT);
		add.save();
	}
}
 
Example 9
Source File: Utils.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public static void updateUserInfo() {
	AVUser user = AVUser.getCurrentUser();
	if (user != null) {
		user.fetchInBackground("friends", new GetCallback<AVObject>() {
			@Override
			public void done(AVObject avObject, AVException e) {
				if (e == null) {
					// User avUser = (User) avObject;
					// App.registerUserCache(avUser);
				}
			}
		});
	}
}
 
Example 10
Source File: AddRequestService.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public static List<AddRequest> findAddRequests() throws AVException {
	AVUser user = AVUser.getCurrentUser();
	AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
	q.include(AddRequest.FROM_USER);
	q.whereEqualTo(AddRequest.TO_USER, user);
	q.orderByDescending("createdAt");
	q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
	return q.find();
}
 
Example 11
Source File: LoveFragment.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
private void initView() {
	mContext = context;
	View fragmentView = getView();

	AVUser user = AVUser.getCurrentUser();
	userStr = user.getUsername();
	pass = user.getString("password");

	toQuery();
	container = (RelativeLayout) fragmentView.findViewById(R.id.container);
	status = (TextView) fragmentView.findViewById(R.id.txt_loveStatus);
	statusWord = (TextView) fragmentView.findViewById(R.id.txt_statusWord);
	loverPhone = (EditText) fragmentView.findViewById(R.id.edit_loverPhone);
	loverName = (EditText) fragmentView.findViewById(R.id.edit_loverName);
	toSay = (EditText) fragmentView.findViewById(R.id.edit_blog);
	bind = (Button) fragmentView.findViewById(R.id.btn_bind);
	writeBlog = (Button) fragmentView.findViewById(R.id.btn_toSay);
	myBlog = (Button) fragmentView.findViewById(R.id.btn_myBlog);
	itsBlog = (Button) fragmentView.findViewById(R.id.btn_itsBlog);
	changeLove = (Button) fragmentView.findViewById(R.id.changeLove);
	arrow = (ImageView) fragmentView.findViewById(R.id.img_arrow);

	bind.setOnClickListener(this);
	writeBlog.setOnClickListener(this);
	myBlog.setOnClickListener(this);
	itsBlog.setOnClickListener(this);
	changeLove.setOnClickListener(this);
}
 
Example 12
Source File: MySpaceFragment.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
private void refresh() {
	AVUser curUser = AVUser.getCurrentUser();
	usernameView.setText(curUser.getUsername());
	genderView.setText(genderStrings[curUser.getInt("gender")]);
	UserService.displayAvatar(getAvatarUrl(curUser), avatarView);
	mobileView.setText(curUser.getMobilePhoneNumber());
	emailView.setText(curUser.getEmail());
}
 
Example 13
Source File: MainActivity.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	setContentView(R.layout.activity_welcome);


	AVUser user = AVUser.getCurrentUser();
	if (user != null) {
		Utils.updateUserInfo();
		handler.sendEmptyMessageDelayed(GO_MAIN_MSG, DURATION);
	} else {
		handler.sendEmptyMessageDelayed(GO_LOGIN_MSG, DURATION);
	}
}
 
Example 14
Source File: PersonalCenterController.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
public void getUserInfo(String userId)
{
	User currentUser = AVUser.getCurrentUser(User.class);
	if (userId.equals(currentUser.getObjectId()))
	{
		mActivity.getUserInfoSuccess(currentUser);
		return;
	}
	mUserBll.getUserById(userId)
					.observeOn(AndroidSchedulers.mainThread())
					.subscribeOn(Schedulers.io())
					.subscribe(new Action1<User>()
					{
						@Override
						public void call(User user)
						{
							mActivity.getUserInfoSuccess(user);
						}
					}, new Action1<Throwable>()
					{
						@Override
						public void call(Throwable throwable)
						{
							throwable.printStackTrace();
							mActivity.getUserInfoFail("获取用户信息失败");
						}
					});
}
 
Example 15
Source File: PreferenceMap.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public static PreferenceMap getMyPrefDao(Context context) {
	AVUser user = AVUser.getCurrentUser();
	if (user == null) {
		throw new RuntimeException("user is null");
	}
	return new PreferenceMap(context, user.getObjectId());
}
 
Example 16
Source File: ArticleDetailActivity.java    From AndroidPlusJava with GNU General Public License v3.0 4 votes vote down vote up
private void initFavour() {
    User user = AVUser.getCurrentUser(User.class);
    isFavoured = user.isFavouredArticle(mArticle.getObjectId());
    mFavour.setSelected(isFavoured);
}
 
Example 17
Source File: QuestionDetailActivity.java    From AndroidPlusJava with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void init() {
    super.init();
    String serialized = getIntent().getStringExtra(Constant.EXTRA_QUESTION);
    try {
        //反序列化
        mQuestion = (Question) Question.parseAVObject(serialized);
    } catch (Exception e) {
        e.printStackTrace();
    }

    mQuestionTitle.setText(mQuestion.getTitle());
    if (mQuestion.getDescription() == null || mQuestion.getDescription().length() == 0) {
        mQuestionDescription.setVisibility(View.GONE);
    } else {
        mQuestionDescription.setVisibility(View.VISIBLE);
        mQuestionDescription.setText(mQuestion.getDescription());
    }

    User currentUser = AVUser.getCurrentUser(User.class);
    isFavorite = currentUser.isFavouredQuestion(mQuestion.getObjectId());
    mFavourQuestion.setSelected(isFavorite);

    //配置转场动画
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mQuestionTitle.setTransitionName(getString(R.string.question_title_transition));
        mQuestionDescription.setTransitionName(getString(R.string.question_des_transition));
        ChangeBounds changeBounds = new ChangeBounds();
        changeBounds.setPathMotion(new ArcMotion());
        getWindow().setSharedElementEnterTransition(changeBounds);
    }

    setSupportActionBar(mToolBar);
    ActionBar supportActionBar = getSupportActionBar();
    supportActionBar.setDisplayHomeAsUpEnabled(true);
    mCollapsingToolBar.setTitle(" ");

    String[] titles = getResources().getStringArray(R.array.answer_category);
    mViewPager.setAdapter(new QuestionDetailPagerAdapter(getSupportFragmentManager(), titles, mQuestion.getObjectId()));
    mTabLayout.setupWithViewPager(mViewPager);
}
 
Example 18
Source File: CloudService.java    From LoveTalkClient with Apache License 2.0 4 votes vote down vote up
public static void tryCreateAddRequest(AVUser toUser) throws AVException {
	AVUser user = AVUser.getCurrentUser();
	Map<String, Object> map = usersParamsMap(user, toUser);
	AVCloud.callFunction("tryCreateAddRequest", map);
}
 
Example 19
Source File: PersonalCenterHomeController.java    From PlayTogether with Apache License 2.0 4 votes vote down vote up
/**
 * 与作者聊天,需要先登录,然后创建会话
 */
public void chatWithAuthor(final User author)
{
	final List<User> members = new ArrayList<>();
	User user = AVUser.getCurrentUser(User.class);
	final String myName = user.getUsername();
	members.add(author);
	members.add(user);
	mChatBll.login(myName)//登录
					.subscribeOn(AndroidSchedulers.mainThread())
					.observeOn(AndroidSchedulers.mainThread())
					.flatMap(new Func1<AVIMClient, Observable<AVIMConversation>>()//创建会话
					{
						@Override
						public Observable<AVIMConversation> call(AVIMClient client)
						{
							return mConversationBll.createConversation(members, client,
											ChatConstant.TYPE_SINGLE_CHAT, myName + author.getUsername());

						}
					})
					.subscribe(new Action1<AVIMConversation>()
					{
						@Override
						public void call(AVIMConversation conversation)
						{
							Intent intent = new Intent(mFragment.getActivity(), ChatActivity.class);
							intent.putExtra(ChatActivity.EXTRA_CONVERSATION_ID, conversation
											.getConversationId());
							intent.putExtra(ChatActivity.EXTRA_CONVERSATION_NAME, author.getUsername());
							mFragment.getActivity().startActivity(intent);
						}
					}, new Action1<Throwable>()
					{
						@Override
						public void call(Throwable throwable)
						{
							throwable.printStackTrace();
						}
					});
}
 
Example 20
Source File: UserUtils.java    From AccountBook with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 校验用户是否已经登录。
 * @return true: 已登录 false: 未登录
 */
public static boolean checkLogin(){
    return null != AVUser.getCurrentUser(User.class);
}