实训第三周(1)
李晨晨:
本周我用高德定位SDK实现了定位。
1.首先是账号的申请和key值的获取,可以根据其网站的指示文档申请。
重点是SHA1安全码,要和自己的Android Studio的对应;PackageName要和自己项目的包名对应。否则会报错。
我用的方式为远程构建,所以要在build.gradle(Module:app)中加入
- // 高德地图,定位相关
- compile 'com.amap.api:map2d:latest.integration'
- compile 'com.amap.api:location:latest.integration'
- compile 'com.amap.api:search:latest.integration'
2.然后是选择位置并发送位置的selectLocActivity及相应的布局文件:
初始化主要的是initPoiList方法(初始化周围位置列表)和initMap(初始化上方的地图显示界面);其他的当位置移动和滑动地图时通过高德接口的监听器实现。
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setStatusBarColor(R.color.app_blue_color);
- setContentView(R.layout.activity_select_location);
- ButterKnife.bind(this);
- mMapView.onCreate(savedInstanceState);
- initPoiList();
- initMap();
- }
3.initPoiList,主要为mRecyclerView的内容,初始化位置循环列表,并对条目绑定OnClickListener,当选定条目时,取消上一次勾选,勾选当前条目,并将地图中心移到当前条目所表示的位置。
- private void initPoiList(){
- mLayoutManager = new LinearLayoutManager(this);
- mRecyclerView.setLayoutManager(mLayoutManager);
- mPointList = new ArrayList<>();
- mAdapter = new RecycleViewAdapter<LocationPoint>(this,mPointList) {
- @Override
- public int setItemLayoutId(int position) {
- return R.layout.item_round_poi;
- }
- @Override
- public void bindView(RViewHolder holder, int position) {
- LocationPoint point = mPointList.get(position);
- holder.setText(R.id.tv_poi_name,point.getName());
- holder.setText(R.id.tv_poi_address,point.getAddress());
- if (point.isSelected()){
- holder.getImageView(R.id.iv_selected).setVisibility(View.VISIBLE);
- }else {
- holder.getImageView(R.id.iv_selected).setVisibility(View.INVISIBLE);
- }
- }
- };
- mAdapter.setItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(RViewHolder holder, int position) {
- // 清除原来已选的
- mPointList.get(mCurrentSelect).setSelected(false);
- mAdapter.notifyItemChanged(mCurrentSelect);
- // 更新当前已选点
- mCurrentSelect = position;
- mPointList.get(position).setSelected(true);
- mAdapter.notifyItemChanged(position);
- // 刷新地图
- LatLonPoint point = mPointList.get(position).getPoint();
- setMapCenter(point.getLatitude(),point.getLongitude());
- }
- });
- mRecyclerView.setAdapter(mAdapter);
- }
设置地图中心方法:
- private void setMapCenter(double latitude, double longitude) {
- // 设置地图中心点
- mCenterPoint = new LatLng(latitude, longitude);
- // 将地图移动到当前位置
- CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(mCenterPoint, mZoomLevel);
- mAMap.animateCamera(cameraUpdate);
- }
4.initMap方法:
- private void initMap(){
- mAMap = mMapView.getMap();
- // 初始位置,广州市中心
- setMapCenter(23.13023, 113.253171);
- // 地图中心发生变化监听
- <strong>mAMap.setOnCameraChangeListener(this);</strong>
- // 缩放控件
- UiSettings settings = mAMap.getUiSettings();
- settings.setZoomGesturesEnabled(true);
- settings.setMyLocationButtonEnabled(false);
- settings.setZoomControlsEnabled(false);
- mLocationClient = new AMapLocationClient(getApplicationContext());
- //mLocationClient.setApiKey("9f06a419f114f90a8a0156fd37a5ebf3");
- AMapLocationClientOption option = new AMapLocationClientOption();
- option.setGpsFirst(false);
- option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
- // 单次定位
- option.setOnceLocation(true);
- mLocationClient.setLocationOption(option);
- <strong> mLocationClient.setLocationListener(this);</strong>
- mLocationClient.startLocation();
- }
onCameraChangeListener重写:
当地图镜头移动时,如果与原中心点距离超过10米,刷新POI列表(searchRoundPoi),并将地图中心设置为当前位置。
- /**地图镜头被移动*****/
- @Override
- public void onCameraChange(CameraPosition cameraPosition) {
- }
- @Override
- public void onCameraChangeFinish(CameraPosition cameraPosition) {
- mZoomLevel = cameraPosition.zoom;
- // 判断是否已经定位成功
- if (mLocation != null){
- // 若移动后,与原中心点距离超过10米,刷新 POI 列表
- float distance = AMapUtils.
- calculateLineDistance(mCenterPoint,cameraPosition.target);
- if (distance >= 10.0f){
- setMapCenter(cameraPosition.target.latitude,cameraPosition.target.longitude);
- searchRoundPoi(new LatLonPoint(cameraPosition.target.latitude,
- cameraPosition.target.longitude));
- }
- }
- }
searchRoundPoi方法:
- private void searchRoundPoi(LatLonPoint point){
- mProgressBar.setVisibility(View.VISIBLE);
- // 清除原有数据
- mPointList.clear();
- mAdapter.notifyDataSetChanged();
- // 关键字 类型 区域
- PoiSearch.Query query = new PoiSearch.Query("","",mLocation.getCityCode());
- query.setPageNum(1);
- query.setPageSize(50);
- // 位置点周边1000米范围搜索
- PoiSearch search = new PoiSearch(this,query);
- PoiSearch.SearchBound bound = new PoiSearch.SearchBound(point,1000);
- search.setBound(bound);
- search.setOnPoiSearchListener(this);
- search.searchPOIAsyn();
- }
- /**我的位置发生移动**/
- @Override
- public void onLocationChanged(AMapLocation location) {
- if (location != null) {
- if (location.getErrorCode() == 0) {
- // 保存当前定位点
- mLocation = location;
- // 移动到定位点
- setMapCenter(location.getLatitude(), location.getLongitude());
- // 显示位置点
- drawLocationPoint();
- // 搜索并显示周边POI点列表
- searchRoundPoi(new LatLonPoint(location.getLatitude(),location.getLongitude()));
- }else {
- //显示错误信息ErrCode是错误码,errInfo是错误信息,详见错误码表。
- Log.e("AmapError","location Error, ErrCode:"
- + location.getErrorCode() + ", errInfo:"
- + location.getErrorInfo());
- }
- }
- }
drawLocationPoint方法:
- private void drawLocationPoint(){
- mLocationMarker = new MarkerOptions();
- BitmapDescriptor descriptor = BitmapDescriptorFactory.fromResource(R.mipmap.ic_my_loc);
- mLocationMarker.icon(descriptor);
- mLocationMarker.position(mCenterPoint);
- mAMap.addMarker(mLocationMarker);
- }
- @OnClick(R.id.iv_back_btn)
- public void backOnClick(){
- this.finish();
- }
- @OnClick(R.id.tv_btn_send)
- public void send(){
- if (!mPointList.isEmpty() && mCurrentSelect != -1){
- Intent intent = new Intent();
- intent.putExtra("location",mPointList.get(mCurrentSelect).getPoint());
- intent.putExtra("address",mPointList.get(mCurrentSelect).getAddress());
- setResult(RESULT_OK,intent);
- finish();
- }else {
- ToastUtils.showMessage(this,"位置获取失败,请稍后再试~");
- }
- }
- @Override
- protected void onResume() {
- super.onResume();
- mMapView.onResume();
- }
- @Override
- protected void onPause() {
- super.onPause();
- mMapView.onPause();
- if (mLocationClient.isStarted()){
- mLocationClient.stopLocation();
- }
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mMapView.onDestroy();
- mLocationClient.onDestroy();
- }
6.具体效果图:
仝心:
本周我完成了将所有的字符存入数据库的操作,并对这些字符添加了一些手机传感器获得的参数的影响。
首先是存储所有手绘字符,在这里定义了一个int类型的计数器count,用于记录这是存储的第几个字符,字符的顺序按照ASC码的排序逐个绘制,同时数据库中添加了一项name,用于记录字符的count。每次点击“下一页”时,count计数加一,用于显示要绘制的字符的TextView按照ASC码的顺序刷新一次。
- ContentValues values = new ContentValues();
- char letter = (char)('!'+count);
- String str = ""+letter;
- values.put("id",str);
- values.put("content",s);
- values.put("name",count);
- ImageSQLiteHelper dbHelper = new ImageSQLiteHelper(CreateActivity.this,"my_nn_database");
- SQLiteDatabase db = dbHelper.getWritableDatabase();
- db.insert("array",null,values);
- s="";
- class nextListener implements View.OnClickListener{
- @Override
- public void onClick(View view) {
- count++;
- char letter = (char)('!'+ count);
- tv.setText(""+letter);
- resumeCanvas();
- }
- }
接下来通过手机的加速度计获得了手机的抖动程度,重力传感器获得了手机的偏向,通过按下和抬起的时间差记录触键时间,通过传入随机数在每次输出时对原始字符图片进行一些随机偏移。这些作用效果叠加起来构成了输出效果。
- SensorEventListener sensorListener = new SensorEventListener() {
- //传感器改变时,一般是通过这个方法里面的参数确定传感器状态的改变
- @Override
- public void onSensorChanged(SensorEvent sensorEvent) {
- if (sensorEvent.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
- {
- accelerometerValues = sensorEvent.values.clone();
- float[] values = sensorEvent.values;//获取传感器的数据
- //float max = sensor.getMaximumRange();//获取最大值范围
- if (values.length >= 3) {
- float x = values[0];//右侧面向上时为g(9.8)
- float y = values[1];//上侧面向上时为g(9.8)
- float z = values[2];
- //抖动
- float xx = values[0] - usedValues[0];
- float yy = values[1] - usedValues[1];
- float zz = values[2] - usedValues[2];
- float Tense = Math.abs(xx)+Math.abs(yy)+Math.abs(zz);
- usedValues[0] = x;
- usedValues[1] = y;
- usedValues[2] = z;
- if(Tense >=15)
- tempTense = 1;
- else if(Tense >=6&&Tense < 15)
- tempTense = 2;
- else if(Tense>=4&&Tense < 6)
- tempTense = 3;
- else if(Tense >=2&&Tense<4)
- tempTense = 4;
- else if(Tense>=1&&Tense<2)
- tempTense = 5;
- else
- tempTense = 10;
- //倾斜
- float angle;
- if(y>0)
- {
- angle = x*8;
- if(angle>25)
- angle = 25;
- }
- else
- angle = 0;
- numboardUtil.getSkewData(angle);
- }
- numboardUtil.getSensorData(tempTense);
- }else if (sensorEvent.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
- }
- }
- /*获得触键时间*/
- class touchKeyListener implements View.OnTouchListener{
- @Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
- switch (motionEvent.getAction()) {
- case MotionEvent.ACTION_DOWN://按键的时间
- Calendar calendar = Calendar.getInstance();
- int SS = calendar.get(Calendar.SECOND);
- int MI = calendar.get(Calendar.MILLISECOND);
- second1 = SS;
- millisecond1 = MI;
- break;
- case MotionEvent.ACTION_UP://抬起的时间
- Calendar c = Calendar.getInstance();
- int S = c.get(Calendar.SECOND);
- int mi = c.get(Calendar.MILLISECOND);
- second2 = S;
- millisecond2 = mi;
- totalMilliSecond = (second2-second1)*1000+millisecond2-millisecond1;//时间差,以毫秒计
- int thick;
- if(totalMilliSecond<20)
- thick = 0;
- else if(totalMilliSecond>=20&&totalMilliSecond<80)
- thick = 1;
- else if (totalMilliSecond>=80&&totalMilliSecond<150)
- thick = 3;
- else if(totalMilliSecond>=150&&totalMilliSecond<300)
- thick = 5;
- else if(totalMilliSecond>=300&&totalMilliSecond<600)
- thick = 7;
- else if(totalMilliSecond>=600&&totalMilliSecond<800)
- thick = 8;
- else if(totalMilliSecond>=800&&totalMilliSecond<1000)
- thick = 9;
- else thick = 10;
- numboardUtil.getTouchTime(thick);
- break;
- case MotionEvent.ACTION_MOVE:
- break;
- default:
- break;
- }
- return false;
- }
- }
在按键的同时进行反应当前形态的字符绘制,其中的具体变形方法时在之前的工作中完成过的,这里将传感器获得的数据加工后作为参数传入。
- protected Bitmap paintNewImage(int[][] arr,float tense,int level,float angle) {//抖动程度、画笔粗细、倾斜角度
- int row = arr.length;
- int col = arr[0].length;
- int min=0;
- int max=30;
- Random random = new Random();
- int num1 = random.nextInt(max)%(max-min+1) -15;
- int num2 = random.nextInt(max)%(max-min+1) -15;
- int[][] arr1 = distort1(arr,num1,num2,row,col);//异形文字
- arr = trembleImage(arr1,tense);//抖动
- paint = new Paint();
- //if (showBitmap == null) {
- //}
- int left = 0,right = 0;
- boolean flag = true;
- //判断最左和最右的像素,对图片进行一个裁剪
- for(int i = 0;i<col&&flag;i++)
- {
- for(int j = 0;j<row;j++)
- {
- if(arr[j][i] == 0&&j<0.95*row)
- {
- left = i;
- flag = false;
- break;
- }
- }
- }
- flag = true;
- for(int i = col-1;i>0&&flag;i--)
- {
- for(int j = 0;j<row;j++)
- {
- if(arr[j][i] == 0&&j<0.95*row)
- {
- right = i;
- flag = false;
- break;
- }
- }
- }
- showBitmap = Bitmap.createBitmap(right - left +15,
- MY_ROW, Bitmap.Config.ARGB_8888);
- show_canvas = new Canvas(showBitmap);
- show_canvas.drawColor(Color.WHITE);
- show_canvas.skew((float)Math.tan(angle*3.14/180),0f);
- show_canvas.translate(-50*(float)Math.tan(angle*3.14/180),0);
- for (int i = 0; i < row; i++) {
- for (int j = left; j < right; j++) {
- paint.setARGB(255, 0, 0, 0);
- paint.setStrokeWidth(level);
- if (arr[i][j] == 0&&i<0.95*row)
- show_canvas.drawPoint(j-left+8, i, paint);
- }
- }
- return showBitmap;
- }
字符绘制界面添加了四线三格作为输入参考
键盘的输出效果可以看出手机的左右偏向、按键时间以及抖动程度,同时同一字母的两次绘制不会完全相同,符合书写现实。
张静:
本周完成了如下工作:
(1)初始化
通过NimClient的getService接口获取到UserService(用户资料操作相关接口)服务实例,调用getUserInfo方法从本地数据库中获取用户资料
通过NimClient的getService接口获取到UserServiceObserve(用户资料变更通知)服务实例,调用observeUserInfoUpdate方法进行用户资料变更观察者通知
- public void init(){
- mUserInfo = NIMClient.getService(UserService.class).getUserInfo(mMyAccount);
- mUpdateListeners = new ArrayList<>();
- // 初始化监听
- //用户资料托管接口,提供获取用户资料,修改个人资料等
- NIMClient.getService(UserServiceObserve.class)
- .observeUserInfoUpdate(new Observer<List<NimUserInfo>>() {
- @Override
- public void onEvent(List<NimUserInfo> userInfoList) {
- NimUserInfo userInfo = userInfoList.get(0);
- Log.e(TAG,"UserInfoUpdate"+userInfo.toString());
- }
- },true);
- }
(2)从服务器账户数据到本地数据库
通过NimClient的getService接口获取到UserService(用户资料操作相关接口)服务实例,调用fetchUserInfo从服务器获取用户资料
三种情况:同步成功,同步失败,同步出错
- public void fetchAccountInfo(){
- List<String> accounts = new ArrayList<>();
- accounts.add(mMyAccount);
- NIMClient.getService(UserService.class).fetchUserInfo(accounts)
- .setCallback(new RequestCallback<List<NimUserInfo>>() {
- @Override
- public void onSuccess(List<NimUserInfo> param) {
- Log.e(TAG,"fetchAccountInfo onSuccess ");
- mUserInfo = param.get(0);
- // 同步成功,通知刷新
- for (OnInfoUpdateListener listener : mUpdateListeners){
- listener.myInfoUpdate();
- }
- }
- @Override
- public void onFailed(int code) {
- Log.e(TAG,"fetchAccountInfo onFailed code " + code);
- }
- @Override
- public void onException(Throwable exception) {
- Log.e(TAG,"fetchAccountInfo onException message " + exception.getMessage());
- }
- });
- }
(3)将数据更新到服务器
将各项属性值(头像、生日、地址、签名、昵称、性别)存储到fields
再通过NimClient的getService接口获取到UserService(用户资料操作相关接口)服务实例,调用updateUserInfo更新本人用户资料
上传更新过程同样有三种情况:上传成功(更新本地数据库(调用fetchAccountInfo)),上传失败,上传出错
- public void syncChange2Service(){
- Map<UserInfoFieldEnum,Object> fields = new HashMap<>();
- if(!TextUtils.isEmpty(mLocalAccount.getHeadImgUrl())){
- fields.put(UserInfoFieldEnum.AVATAR,mLocalAccount.getHeadImgUrl());
- }
- if (!TextUtils.isEmpty(mLocalAccount.getBirthDay())){
- fields.put(UserInfoFieldEnum.BIRTHDAY,mLocalAccount.getBirthDay());
- }
- if (!TextUtils.isEmpty(mLocalAccount.getLocation())){
- fields.put(UserInfoFieldEnum.EXTEND,mLocalAccount.getLocation());
- }
- if (!TextUtils.isEmpty(mLocalAccount.getSignature())){
- fields.put(UserInfoFieldEnum.SIGNATURE,mLocalAccount.getSignature());
- }
- fields.put(UserInfoFieldEnum.Name,mLocalAccount.getNick());
- fields.put(UserInfoFieldEnum.GENDER,mLocalAccount.getGenderEnum().getValue());
- NIMClient.getService(UserService.class).updateUserInfo(fields)
- .setCallback(new RequestCallback<Void>() {
- @Override
- public void onSuccess(Void param) {
- Log.e(TAG,"syncChange2Service onSuccess");
- // 上传成功,更新本地数据库
- fetchAccountInfo();
- }
- @Override
- public void onFailed(int code) {
- Log.e(TAG,"syncChange2Service onFailed code " + code);
- //TODO 同步失败应当后台服务上传
- }
- @Override
- public void onException(Throwable exception) {
- Log.e(TAG,"syncChange2Service onException message " + exception.getMessage());
- }
- });
- }
其中mLocalAccount为LocalAccountBean类,LocalAccountBean.java:
设置本地账户中的各项属性以及获取属性的方法
- package com.ezreal.ezchat.bean;
- import com.netease.nimlib.sdk.uinfo.constant.GenderEnum;
- import java.io.Serializable;
- /**
- * Created by 张静.
- */
- public class LocalAccountBean implements Serializable {
- private String mHeadImgUrl;
- private String mAccount;
- private String mNick;
- private GenderEnum mGenderEnum;
- private String mBirthDay;
- private String mLocation;
- private String mSignature;
- public String getHeadImgUrl() {
- return mHeadImgUrl;
- }
- public void setHeadImgUrl(String headImgUrl) {
- mHeadImgUrl = headImgUrl;
- }
- public String getAccount() {
- return mAccount;
- }
- public void setAccount(String account) {
- mAccount = account;
- }
- public String getNick() {
- return mNick;
- }
- public void setNick(String nick) {
- mNick = nick;
- }
- public GenderEnum getGenderEnum() {
- return mGenderEnum;
- }
- public void setGenderEnum(GenderEnum genderEnum) {
- mGenderEnum = genderEnum;
- }
- public String getBirthDay() {
- return mBirthDay;
- }
- public void setBirthDay(String birthDay) {
- mBirthDay = birthDay;
- }
- public String getLocation() {
- return mLocation;
- }
- public void setLocation(String location) {
- mLocation = location;
- }
- public String getSignature() {
- return mSignature;
- }
- public void setSignature(String signature) {
- mSignature = signature;
- }
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- return builder.append("account = ")
- .append(mAccount)
- .append(",url = ")
- .append(mHeadImgUrl)
- .append(",location = ")
- .append(mLocation)
- .toString();
- }
- }
- public LocalAccountBean getLocalAccount() {
- mLocalAccount = new LocalAccountBean();
- mLocalAccount.setAccount(mUserInfo.getAccount());
- mLocalAccount.setHeadImgUrl(mUserInfo.getAvatar());
- mLocalAccount.setBirthDay(mUserInfo.getBirthday());
- mLocalAccount.setNick(mUserInfo.getName());
- mLocalAccount.setSignature(mUserInfo.getSignature());
- mLocalAccount.setGenderEnum(mUserInfo.getGenderEnum());
- String extension = mUserInfo.getExtension();
- if (!TextUtils.isEmpty(extension)){
- mLocalAccount.setLocation(extension);
- }
- return mLocalAccount;
- }
附上完整NimUserHandler.java
- package com.ezreal.ezchat.handler;
- import android.util.Log;
- import com.ezreal.ezchat.bean.LocalAccountBean;
- import com.netease.nimlib.sdk.NIMClient;
- import com.netease.nimlib.sdk.Observer;
- import com.netease.nimlib.sdk.RequestCallback;
- import com.netease.nimlib.sdk.uinfo.UserService;
- import com.netease.nimlib.sdk.uinfo.UserServiceObserve;
- import com.netease.nimlib.sdk.uinfo.constant.UserInfoFieldEnum;
- import com.netease.nimlib.sdk.uinfo.model.NimUserInfo;
- import com.suntek.commonlibrary.utils.TextUtils;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * Created by 张静.
- */
- public class NimUserHandler {
- private static final String TAG = NimUserHandler.class.getSimpleName();
- private static NimUserHandler instance;
- private String mMyAccount;
- private NimUserInfo mUserInfo;
- private LocalAccountBean mLocalAccount;
- private List<OnInfoUpdateListener> mUpdateListeners;
- public static NimUserHandler getInstance(){
- if (instance == null){
- synchronized (NimUserHandler.class){
- if (instance == null){
- instance = new NimUserHandler();
- }
- }
- }
- return instance;
- }
- public void init(){
- mUserInfo = NIMClient.getService(UserService.class).getUserInfo(mMyAccount);
- mUpdateListeners = new ArrayList<>();
- // 初始化监听
- //用户资料托管接口,提供获取用户资料,修改个人资料等
- NIMClient.getService(UserServiceObserve.class)
- .observeUserInfoUpdate(new Observer<List<NimUserInfo>>() {
- @Override
- public void onEvent(List<NimUserInfo> userInfoList) {
- NimUserInfo userInfo = userInfoList.get(0);
- Log.e(TAG,"UserInfoUpdate"+userInfo.toString());
- }
- },true);
- }
- /**
- * 从服务器账户数据到本地数据库
- */
- public void fetchAccountInfo(){
- List<String> accounts = new ArrayList<>();
- accounts.add(mMyAccount);
- NIMClient.getService(UserService.class).fetchUserInfo(accounts)
- .setCallback(new RequestCallback<List<NimUserInfo>>() {
- @Override
- public void onSuccess(List<NimUserInfo> param) {
- Log.e(TAG,"fetchAccountInfo onSuccess ");
- mUserInfo = param.get(0);
- // 同步成功,通知刷新
- for (OnInfoUpdateListener listener : mUpdateListeners){
- listener.myInfoUpdate();
- }
- }
- @Override
- public void onFailed(int code) {
- Log.e(TAG,"fetchAccountInfo onFailed code " + code);
- }
- @Override
- public void onException(Throwable exception) {
- Log.e(TAG,"fetchAccountInfo onException message " + exception.getMessage());
- }
- });
- }
- public void syncChange2Service(){
- Map<UserInfoFieldEnum,Object> fields = new HashMap<>();
- if(!TextUtils.isEmpty(mLocalAccount.getHeadImgUrl())){
- fields.put(UserInfoFieldEnum.AVATAR,mLocalAccount.getHeadImgUrl());
- }
- if (!TextUtils.isEmpty(mLocalAccount.getBirthDay())){
- fields.put(UserInfoFieldEnum.BIRTHDAY,mLocalAccount.getBirthDay());
- }
- if (!TextUtils.isEmpty(mLocalAccount.getLocation())){
- fields.put(UserInfoFieldEnum.EXTEND,mLocalAccount.getLocation());
- }
- if (!TextUtils.isEmpty(mLocalAccount.getSignature())){
- fields.put(UserInfoFieldEnum.SIGNATURE,mLocalAccount.getSignature());
- }
- fields.put(UserInfoFieldEnum.Name,mLocalAccount.getNick());
- fields.put(UserInfoFieldEnum.GENDER,mLocalAccount.getGenderEnum().getValue());
- NIMClient.getService(UserService.class).updateUserInfo(fields)
- .setCallback(new RequestCallback<Void>() {
- @Override
- public void onSuccess(Void param) {
- Log.e(TAG,"syncChange2Service onSuccess");
- // 上传成功,更新本地数据库
- fetchAccountInfo();
- }
- @Override
- public void onFailed(int code) {
- Log.e(TAG,"syncChange2Service onFailed code " + code);
- //TODO 同步失败应当后台服务上传
- }
- @Override
- public void onException(Throwable exception) {
- Log.e(TAG,"syncChange2Service onException message " + exception.getMessage());
- }
- });
- }
- public LocalAccountBean getLocalAccount() {
- mLocalAccount = new LocalAccountBean();
- mLocalAccount.setAccount(mUserInfo.getAccount());
- mLocalAccount.setHeadImgUrl(mUserInfo.getAvatar());
- mLocalAccount.setBirthDay(mUserInfo.getBirthday());
- mLocalAccount.setNick(mUserInfo.getName());
- mLocalAccount.setSignature(mUserInfo.getSignature());
- mLocalAccount.setGenderEnum(mUserInfo.getGenderEnum());
- String extension = mUserInfo.getExtension();
- if (!TextUtils.isEmpty(extension)){
- mLocalAccount.setLocation(extension);
- }
- return mLocalAccount;
- }
- public void setLocalAccount(LocalAccountBean account){
- this.mLocalAccount = account;
- }
- public String getMyAccount() {
- return mMyAccount;
- }
- public void setMyAccount(String account) {
- mMyAccount = account;
- }
- public NimUserInfo getUserInfo() {
- return mUserInfo;
- }
- public void setUpdateListeners(OnInfoUpdateListener listeners){
- mUpdateListeners.add(listeners);
- }
- public interface OnInfoUpdateListener{
- void myInfoUpdate();
- }
- }